Skip to content

Commit

Permalink
First working version of zbctl-java
Browse files Browse the repository at this point in the history
  • Loading branch information
upgradingdave committed Apr 30, 2024
1 parent b634977 commit f6160f9
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules/
build/
aws-lambda-js/function.zip
.DS_Store
certificates/src/main/resources/application.yaml
certificates/src/main/resources/application.yaml
zbctl.jks
4 changes: 4 additions & 0 deletions zbctl-java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

A very simple command line tool written in java for testing connections to zeebe

# Usage Examples

java -jar zbctl.jar --address my.domain.com:443 --authzUrl "https://my.domain.com:443/auth/realms/camunda-platform/protocol/openid-connect/token" --clientId zeebe --clientSecret MYSECRET


Binary file added zbctl-java/certs/keystore.jks
Binary file not shown.
32 changes: 32 additions & 0 deletions zbctl-java/certs/pretendpear.cer
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-----BEGIN CERTIFICATE-----
MIIFmDCCA4CgAwIBAgIQU9C87nMpOIFKYpfvOHFHFDANBgkqhkiG9w0BAQsFADBm
MQswCQYDVQQGEwJVUzEzMDEGA1UEChMqKFNUQUdJTkcpIEludGVybmV0IFNlY3Vy
aXR5IFJlc2VhcmNoIEdyb3VwMSIwIAYDVQQDExkoU1RBR0lORykgUHJldGVuZCBQ
ZWFyIFgxMB4XDTE1MDYwNDExMDQzOFoXDTM1MDYwNDExMDQzOFowZjELMAkGA1UE
BhMCVVMxMzAxBgNVBAoTKihTVEFHSU5HKSBJbnRlcm5ldCBTZWN1cml0eSBSZXNl
YXJjaCBHcm91cDEiMCAGA1UEAxMZKFNUQUdJTkcpIFByZXRlbmQgUGVhciBYMTCC
AiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBALbagEdDTa1QgGBWSYkyMhsc
ZXENOBaVRTMX1hceJENgsL0Ma49D3MilI4KS38mtkmdF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GLuvvWYzMYgLzDul//rUF10gEMWaXVZV51KpS9DY/
5CunuvCXmEQJHo7kGcViT7sETn6Jz9KOhvYcXkJ7po6d93A/jy4GKPIPnsKKNEmR
xUuXY4xRdh45tMJnLTUDdC9FIU0flTeO9/vNpVA8OPU1i14vCz+MU8KX1bV3GXm/
fxlB7VBBjX9v5oUep0o/j68R/iDlCOM4VVfRa8gX6T2FU7fNdatvGro7uQzIvWof
gN9WUwCbEMBy/YhBSrXycKA8crgGg3x1mIsopn88JKwmMBa68oS7EHM9w7C4y71M
7DiA+/9Qdp9RBWJpTS9i/mDnJg1xvo8Xz49mrrgfmcAXTCJqXi24NatI3Oc=
-----END CERTIFICATE-----
57 changes: 57 additions & 0 deletions zbctl-java/src/main/java/io/camunda/zbctl/KeystoreManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.camunda.zbctl;

import java.io.*;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;

public class KeystoreManager {

private static InputStream fullStream(String fname) throws IOException {
FileInputStream fis = new FileInputStream(fname);
DataInputStream dis = new DataInputStream(fis);
byte[] bytes = new byte[dis.available()];
dis.readFully(bytes);
return new ByteArrayInputStream(bytes);
}

public void createKeystore(
String keystoreFileName, String keystorePassword, String certAlias, String certPath)
throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {

char[] password = keystorePassword.toCharArray();

// Create Keystore if it doesn't exist
File keystoreFile = new File(keystoreFileName);
if (keystoreFile.exists()) {
keystoreFile.delete();
}

KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(null, password);

FileOutputStream fos = new FileOutputStream(keystoreFileName);
keystore.store(fos, password);
fos.close();

// Create Certificate
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream certstream = fullStream(certPath);
Certificate certs = cf.generateCertificate(certstream);

// Add the certificate
keystore.setCertificateEntry(certAlias, certs);

// Update the keystore contents
FileOutputStream out = new FileOutputStream(keystoreFile);
keystore.store(out, password);
out.close();

// Configure the jvm to use the keystore
System.setProperty("javax.net.ssl.trustStore", keystoreFileName);
System.setProperty("javax.net.ssl.trustStorePassword", keystorePassword);
}
}
16 changes: 15 additions & 1 deletion zbctl-java/src/main/java/io/camunda/zbctl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.ZeebeClientBuilder;
import io.camunda.zeebe.client.impl.oauth.OAuthCredentialsProviderBuilder;
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import org.apache.commons.cli.*;

public class Main {
Expand Down Expand Up @@ -115,7 +119,9 @@ public static void main(String[] args) {

if (cmd.hasOption("certPath")) {
String certPath = cmd.getOptionValue("certPath");
zeebeClientBuilder.caCertificatePath(certPath);
KeystoreManager keystoreManager = new KeystoreManager();
keystoreManager.createKeystore("zbctl.jks", "camunda", "camunda", certPath);
// zeebeClientBuilder.caCertificatePath(certPath);
}

ZeebeClient zeebeClient = zeebeClientBuilder.build();
Expand All @@ -124,6 +130,14 @@ public static void main(String[] args) {

} catch (ParseException e) {
throw new RuntimeException(e);
} catch (CertificateException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (KeyStoreException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
}
Empty file.

0 comments on commit f6160f9

Please sign in to comment.