/** * 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 toJson(PemTrustOptions obj, java.util.Map<String, Object> json) { if (obj.getCertPaths() != null) { JsonArray array = new JsonArray(); obj.getCertPaths().forEach(item -> array.add(item)); json.put("certPaths", array); } if (obj.getCertValues() != null) { JsonArray array = new JsonArray(); obj.getCertValues().forEach(item -> array.add(java.util.Base64.getEncoder().encodeToString(item.getBytes()))); json.put("certValues", array); } } }
public static KeyStoreHelper create(VertxInternal vertx, TrustOptions options) throws Exception { if (options instanceof KeyCertOptions) { return create(vertx, (KeyCertOptions) options); } else if (options instanceof PemTrustOptions) { PemTrustOptions trustOptions = (PemTrustOptions) options; Stream<Buffer> certValues = trustOptions. getCertPaths(). stream(). map(path -> vertx.resolveFile(path).getAbsolutePath()). map(vertx.fileSystem()::readFileBlocking); certValues = Stream.concat(certValues, trustOptions.getCertValues().stream()); return new KeyStoreHelper(loadCA(certValues), null); } else { return null; } }
@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()); }
@Test public void testDefaultTrustOptionsJson() { PemTrustOptions def = new PemTrustOptions(); PemTrustOptions json = new PemTrustOptions(new JsonObject()); assertEquals(def.getCertPaths(), json.getCertPaths()); assertEquals(def.getCertValues(), json.getCertValues()); }
@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()); }
@Test public void testTrustOptions() throws Exception { PemTrustOptions options = new PemTrustOptions(); assertEquals(Collections.emptyList(), options.getCertPaths()); assertNullPointerException(() -> options.addCertPath(null)); assertIllegalArgumentException(() -> options.addCertPath("")); String randString = TestUtils.randomAlphaString(100); options.addCertPath(randString); assertEquals(Collections.singletonList(randString), options.getCertPaths()); assertEquals(Collections.emptyList(), options.getCertValues()); assertNullPointerException(() -> options.addCertValue(null)); randString = TestUtils.randomAlphaString(100); options.addCertValue(Buffer.buffer(randString)); assertEquals(Collections.singletonList(Buffer.buffer(randString)), 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 toJson(PemTrustOptions obj, java.util.Map<String, Object> json) { if (obj.getCertPaths() != null) { JsonArray array = new JsonArray(); obj.getCertPaths().forEach(item -> array.add(item)); json.put("certPaths", array); } if (obj.getCertValues() != null) { JsonArray array = new JsonArray(); obj.getCertValues().forEach(item -> array.add(java.util.Base64.getEncoder().encodeToString(item.getBytes()))); json.put("certValues", array); } } }
public static KeyStoreHelper create(VertxInternal vertx, TrustOptions options) throws Exception { if (options instanceof KeyCertOptions) { return create(vertx, (KeyCertOptions) options); } else if (options instanceof PemTrustOptions) { PemTrustOptions trustOptions = (PemTrustOptions) options; Stream<Buffer> certValues = trustOptions. getCertPaths(). stream(). map(path -> vertx.resolveFile(path).getAbsolutePath()). map(vertx.fileSystem()::readFileBlocking); certValues = Stream.concat(certValues, trustOptions.getCertValues().stream()); return new KeyStoreHelper(loadCA(certValues), null); } else { return null; } }
assertNotSame(options.getTrustOptions(), copy.getTrustOptions()); if (copy.getTrustOptions() instanceof PemTrustOptions) { assertEquals(((PemTrustOptions) options.getTrustOptions()).getCertValues(), ((PemTrustOptions) copy.getTrustOptions()).getCertValues()); } else { assertEquals(options.getTrustOptions(), copy.getTrustOptions());
assertNotSame(options.getTrustOptions(), copy.getTrustOptions()); if (copy.getTrustOptions() instanceof PemTrustOptions) { assertEquals(((PemTrustOptions) options.getTrustOptions()).getCertValues(), ((PemTrustOptions) copy.getTrustOptions()).getCertValues()); } else { assertEquals(options.getTrustOptions(), copy.getTrustOptions());
@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()); }
@Test public void testDefaultTrustOptionsJson() { PemTrustOptions def = new PemTrustOptions(); PemTrustOptions json = new PemTrustOptions(new JsonObject()); assertEquals(def.getCertPaths(), json.getCertPaths()); assertEquals(def.getCertValues(), json.getCertValues()); }
@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()); }
@Test public void testTrustOptions() throws Exception { PemTrustOptions options = new PemTrustOptions(); assertEquals(Collections.emptyList(), options.getCertPaths()); assertNullPointerException(() -> options.addCertPath(null)); assertIllegalArgumentException(() -> options.addCertPath("")); String randString = TestUtils.randomAlphaString(100); options.addCertPath(randString); assertEquals(Collections.singletonList(randString), options.getCertPaths()); assertEquals(Collections.emptyList(), options.getCertValues()); assertNullPointerException(() -> options.addCertValue(null)); randString = TestUtils.randomAlphaString(100); options.addCertValue(Buffer.buffer(randString)); assertEquals(Collections.singletonList(Buffer.buffer(randString)), options.getCertValues()); }
assertNotSame(options.getTrustOptions(), copy.getTrustOptions()); if (copy.getTrustOptions() instanceof PemTrustOptions) { assertEquals(((PemTrustOptions) options.getTrustOptions()).getCertValues(), ((PemTrustOptions) copy.getTrustOptions()).getCertValues()); } else { assertEquals(options.getTrustOptions(), copy.getTrustOptions());
assertNotSame(options.getTrustOptions(), copy.getTrustOptions()); if (copy.getTrustOptions() instanceof PemTrustOptions) { assertEquals(((PemTrustOptions) options.getTrustOptions()).getCertValues(), ((PemTrustOptions) copy.getTrustOptions()).getCertValues()); } else { assertEquals(options.getTrustOptions(), copy.getTrustOptions());