@Override public PemTrustOptions trustOptions() { return new PemTrustOptions().addCertPath(certificatePath()); }
@Test public void testCopyTrustOptions() throws Exception { PemTrustOptions options = new PemTrustOptions(new JsonObject()); String certPath = TestUtils.randomAlphaString(100); Buffer certValue = Buffer.buffer(TestUtils.randomAlphaString(100)); options.addCertPath(certPath); options.addCertValue(certValue); options = new PemTrustOptions(options); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(certValue), options.getCertValues()); options = new PemTrustOptions(options.toJson()); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(certValue), options.getCertValues()); }
/** * Copy constructor * * @param other the options to copy */ public PemTrustOptions(PemTrustOptions other) { super(); this.certPaths = new ArrayList<>(other.getCertPaths()); this.certValues = new ArrayList<>(other.getCertValues()); }
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, PemTrustOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "certPaths": if (member.getValue() instanceof JsonArray) { ((Iterable<Object>)member.getValue()).forEach( item -> { if (item instanceof String) obj.addCertPath((String)item); }); } break; case "certValues": if (member.getValue() instanceof JsonArray) { ((Iterable<Object>)member.getValue()).forEach( item -> { if (item instanceof String) obj.addCertValue(io.vertx.core.buffer.Buffer.buffer(java.util.Base64.getDecoder().decode((String)item))); }); } break; } } }
case PEM: PEMTrustStore pemTrustStore = (PEMTrustStore) sslOptions.getTrustStore(); PemTrustOptions pemTrustOptions = new PemTrustOptions(); if (pemTrustStore.getPath() != null && !pemTrustStore.getPath().isEmpty()) { pemTrustOptions.addCertPath(pemTrustStore.getPath()); } else { pemTrustOptions.addCertValue(io.vertx.core.buffer.Buffer.buffer(pemTrustStore.getContent()));
@Override protected JsonObject getRetrieverConfiguration() { JsonObject config = new JsonObject(); config.put("host", process.getHost()); config.put("port", process.getPort()); config.put("ssl", true); PemKeyCertOptions options = new PemKeyCertOptions() .addCertPath("target/vault/config/ssl/client-cert.pem") .addKeyPath("target/vault/config/ssl/client-privatekey.pem"); config.put("pemKeyCertOptions", options.toJson()); PemTrustOptions trust = new PemTrustOptions() .addCertPath("target/vault/config/ssl/cert.pem"); config.put("pemTrustStoreOptions", trust.toJson()); JksOptions jks = new JksOptions() .setPath("target/vault/config/ssl/truststore.jks"); config.put("trustStoreOptions", jks.toJson()); config.put("auth-backend", "cert"); return config; }
public static TrustOptions randomTrustOptions() { TrustOptions trustOptions; switch (TestUtils.randomPositiveInt() % 3) { case 0: trustOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); ((JksOptions) trustOptions).setPassword(tsPassword); break; case 1: trustOptions = new PemTrustOptions(); Buffer keyValue = TestUtils.randomBuffer(100); ((PemTrustOptions) trustOptions).addCertValue(keyValue); break; default: trustOptions = new PfxOptions(); String pfxPassword = TestUtils.randomAlphaString(100); ((PfxOptions) trustOptions).setPassword(pfxPassword); } return trustOptions; }
@Test public void testTrustOptionsEquality() { String certPath1 = TestUtils.randomAlphaString(100); String certPath2 = TestUtils.randomAlphaString(100); Buffer certValue1 = Buffer.buffer(TestUtils.randomAlphaString(100)); Buffer certValue2 = Buffer.buffer(TestUtils.randomAlphaString(100)); PemTrustOptions options = new PemTrustOptions(); PemTrustOptions otherOptions = new PemTrustOptions(); assertEquals(options, otherOptions); assertEquals(options.hashCode(), otherOptions.hashCode()); options.addCertPath(certPath1); options.addCertPath(certPath2); options.addCertValue(certValue1); options.addCertValue(certValue2); otherOptions.addCertPath(certPath1); otherOptions.addCertPath(certPath2); otherOptions.addCertValue(certValue1); otherOptions.addCertValue(certValue2); assertEquals(options, otherOptions); assertEquals(options.hashCode(), otherOptions.hashCode()); otherOptions.addCertPath(TestUtils.randomAlphaString(100)); assertNotEquals(options, otherOptions); PemTrustOptions reverseOrderOptions = new PemTrustOptions(); reverseOrderOptions.addCertPath(certPath2); reverseOrderOptions.addCertPath(certPath1); reverseOrderOptions.addCertValue(certValue2); reverseOrderOptions.addCertValue(certValue1); assertNotEquals(options, reverseOrderOptions); }
@Override public PemTrustOptions clone() { return new PemTrustOptions(this); }
@Test public void testDefaultTrustOptionsJson() { PemTrustOptions def = new PemTrustOptions(); PemTrustOptions json = new PemTrustOptions(new JsonObject()); assertEquals(def.getCertPaths(), json.getCertPaths()); assertEquals(def.getCertValues(), json.getCertValues()); }
json.put("pemTrustOptions", obj.getPemTrustOptions().toJson());
@Test public void testCaPathValue() throws Exception { PemTrustOptions options = Trust.SERVER_PEM.get(); options.getCertPaths(). stream(). map(vertx.fileSystem()::readFileBlocking). forEach(options::addCertValue); options.getCertPaths().clear(); testTrustStore(options); }
case PEM: PEMTrustStore pemTrustStore = (PEMTrustStore) sslOptions.getTrustStore(); PemTrustOptions pemTrustOptions = new PemTrustOptions(); if (pemTrustStore.getPath() != null && !pemTrustStore.getPath().isEmpty()) { pemTrustOptions.addCertPath(pemTrustStore.getPath()); } else { pemTrustOptions.addCertValue(io.vertx.core.buffer.Buffer.buffer(pemTrustStore.getContent()));
@Override protected JsonObject getRetrieverConfiguration() { JsonObject config = new JsonObject(); config.put("host", process.getHost()); config.put("port", process.getPort()); config.put("ssl", true); PemKeyCertOptions options = new PemKeyCertOptions() .addCertPath("target/vault/config/ssl/client-cert.pem") .addKeyPath("target/vault/config/ssl/client-privatekey.pem"); config.put("pemKeyCertOptions", options.toJson()); PemTrustOptions trust = new PemTrustOptions() .addCertPath("target/vault/config/ssl/cert.pem"); config.put("pemTrustStoreOptions", trust.toJson()); JksOptions jks = new JksOptions() .setPath("target/vault/config/ssl/truststore.jks"); config.put("trustStoreOptions", jks.toJson()); config.put("auth-backend", "cert"); return config; }
public static TrustOptions randomTrustOptions() { TrustOptions trustOptions; switch (TestUtils.randomPositiveInt() % 3) { case 0: trustOptions = new JksOptions(); String tsPassword = TestUtils.randomAlphaString(100); ((JksOptions) trustOptions).setPassword(tsPassword); break; case 1: trustOptions = new PemTrustOptions(); Buffer keyValue = TestUtils.randomBuffer(100); ((PemTrustOptions) trustOptions).addCertValue(keyValue); break; default: trustOptions = new PfxOptions(); String pfxPassword = TestUtils.randomAlphaString(100); ((PfxOptions) trustOptions).setPassword(pfxPassword); } return trustOptions; }
@Test public void testTrustOptionsEquality() { String certPath1 = TestUtils.randomAlphaString(100); String certPath2 = TestUtils.randomAlphaString(100); Buffer certValue1 = Buffer.buffer(TestUtils.randomAlphaString(100)); Buffer certValue2 = Buffer.buffer(TestUtils.randomAlphaString(100)); PemTrustOptions options = new PemTrustOptions(); PemTrustOptions otherOptions = new PemTrustOptions(); assertEquals(options, otherOptions); assertEquals(options.hashCode(), otherOptions.hashCode()); options.addCertPath(certPath1); options.addCertPath(certPath2); options.addCertValue(certValue1); options.addCertValue(certValue2); otherOptions.addCertPath(certPath1); otherOptions.addCertPath(certPath2); otherOptions.addCertValue(certValue1); otherOptions.addCertValue(certValue2); assertEquals(options, otherOptions); assertEquals(options.hashCode(), otherOptions.hashCode()); otherOptions.addCertPath(TestUtils.randomAlphaString(100)); assertNotEquals(options, otherOptions); PemTrustOptions reverseOrderOptions = new PemTrustOptions(); reverseOrderOptions.addCertPath(certPath2); reverseOrderOptions.addCertPath(certPath1); reverseOrderOptions.addCertValue(certValue2); reverseOrderOptions.addCertValue(certValue1); assertNotEquals(options, reverseOrderOptions); }
case "pemTrustOptions": if (member.getValue() instanceof JsonObject) { obj.setPemTrustOptions(new io.vertx.core.net.PemTrustOptions((JsonObject)member.getValue()));
@Test public void testTrustOptionsJson() throws Exception { PemTrustOptions options = new PemTrustOptions(new JsonObject()); assertEquals(Collections.emptyList(), options.getCertPaths()); assertEquals(Collections.emptyList(), options.getCertValues()); String certPath = TestUtils.randomAlphaString(100); String certValue = TestUtils.randomAlphaString(100); JsonObject json = new JsonObject(). put("certPaths", new JsonArray().add(certPath)). put("certValues", new JsonArray().add(certValue.getBytes())); options = new PemTrustOptions(json); assertEquals(Collections.singletonList(certPath), options.getCertPaths()); assertEquals(Collections.singletonList(Buffer.buffer(certValue)), options.getCertValues()); }
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, PemTrustOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "certPaths": if (member.getValue() instanceof JsonArray) { ((Iterable<Object>)member.getValue()).forEach( item -> { if (item instanceof String) obj.addCertPath((String)item); }); } break; case "certValues": if (member.getValue() instanceof JsonArray) { ((Iterable<Object>)member.getValue()).forEach( item -> { if (item instanceof String) obj.addCertValue(io.vertx.core.buffer.Buffer.buffer(java.util.Base64.getDecoder().decode((String)item))); }); } break; } } }
json.put("pemTrustOptions", obj.getPemTrustOptions().toJson());