Java Code Examples for io.vertx.core.net.SelfSignedCertificate#create()

The following examples show how to use io.vertx.core.net.SelfSignedCertificate#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClientTofuTest.java    From cava with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void startServers(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caSignedCert = SelfSignedCertificate.create("localhost");
  SecurityTestUtils.configureJDKTrustStore(tempDir, caSignedCert);
  caValidFingerprint = certificateHexFingerprint(Paths.get(caSignedCert.keyCertOptions().getCertPath()));
  caValidServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(caSignedCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(caValidServer);

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  fooServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(fooCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(fooServer);

  SelfSignedCertificate foobarCert = SelfSignedCertificate.create("foobar.com");
  foobarFingerprint = certificateHexFingerprint(Paths.get(foobarCert.keyCertOptions().getCertPath()));
  foobarServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(foobarCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(foobarServer);
}
 
Example 2
Source File: ServerCaOrTofaTest.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  knownClientsFile = tempDir.resolve("known-clients.txt");
  Files.write(knownClientsFile, Arrays.asList("#First line", "foobar.com " + DUMMY_FINGERPRINT));

  SelfSignedCertificate serverCert = SelfSignedCertificate.create();
  HttpServerOptions options = new HttpServerOptions();
  options
      .setSsl(true)
      .setClientAuth(ClientAuth.REQUIRED)
      .setPemKeyCertOptions(serverCert.keyCertOptions())
      .setTrustOptions(VertxTrustOptions.trustClientOnFirstAccess(knownClientsFile))
      .setIdleTimeout(1500)
      .setReuseAddress(true)
      .setReusePort(true);
  httpServer = vertx.createHttpServer(options);
  SecurityTestUtils.configureAndStartTestServer(httpServer);
}
 
Example 3
Source File: ClientCaOrTofuTest.java    From cava with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void startServers(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caSignedCert = SelfSignedCertificate.create("localhost");
  SecurityTestUtils.configureJDKTrustStore(tempDir, caSignedCert);
  caValidFingerprint = certificateHexFingerprint(Paths.get(caSignedCert.keyCertOptions().getCertPath()));
  caValidServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(caSignedCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(caValidServer);

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  fooServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(fooCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(fooServer);

  SelfSignedCertificate foobarCert = SelfSignedCertificate.create("foobar.com");
  foobarFingerprint = certificateHexFingerprint(Paths.get(foobarCert.keyCertOptions().getCertPath()));
  foobarServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(foobarCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(foobarServer);
}
 
Example 4
Source File: ServerWhitelistTest.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@BeforeEach
void startServer(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  knownClientsFile = tempDir.resolve("known-clients.txt");
  Files.write(knownClientsFile, Arrays.asList("#First line", "foo.com " + fooFingerprint));

  SelfSignedCertificate serverCert = SelfSignedCertificate.create();
  HttpServerOptions options = new HttpServerOptions();
  options
      .setSsl(true)
      .setClientAuth(ClientAuth.REQUIRED)
      .setPemKeyCertOptions(serverCert.keyCertOptions())
      .setTrustOptions(VertxTrustOptions.whitelistClients(knownClientsFile, false))
      .setIdleTimeout(1500)
      .setReuseAddress(true)
      .setReusePort(true);
  httpServer = vertx.createHttpServer(options);
  SecurityTestUtils.configureAndStartTestServer(httpServer);
}
 
Example 5
Source File: ClientTofuTest.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void startServers(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caSignedCert = SelfSignedCertificate.create("localhost");
  SecurityTestUtils.configureJDKTrustStore(tempDir, caSignedCert);
  caValidFingerprint = certificateHexFingerprint(Paths.get(caSignedCert.keyCertOptions().getCertPath()));
  caValidServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(caSignedCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(caValidServer);

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  fooServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(fooCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(fooServer);

  SelfSignedCertificate foobarCert = SelfSignedCertificate.create("foobar.com");
  foobarFingerprint = certificateHexFingerprint(Paths.get(foobarCert.keyCertOptions().getCertPath()));
  foobarServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(foobarCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(foobarServer);
}
 
Example 6
Source File: ClientWhitelistTest.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@BeforeAll
static void startServers(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caSignedCert = SelfSignedCertificate.create("localhost");
  caValidFingerprint = certificateHexFingerprint(Paths.get(caSignedCert.keyCertOptions().getCertPath()));
  SecurityTestUtils.configureJDKTrustStore(tempDir, caSignedCert);
  caValidServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(caSignedCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(caValidServer);

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  fooServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(fooCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(fooServer);

  SelfSignedCertificate barCert = SelfSignedCertificate.create("bar.com");
  barFingerprint = certificateHexFingerprint(Paths.get(barCert.keyCertOptions().getCertPath()));
  barServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(barCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(barServer);
}
 
Example 7
Source File: WhiteListSecurityTest.java    From orion with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setUp(@TempDirectory final Path tempDir) throws Exception {
  final SelfSignedCertificate serverCertificate = SelfSignedCertificate.create("localhost");
  config = generateAndLoadConfiguration(tempDir, writer -> {
    writer.write("tlsservertrust='" + TRUST_MODE + "'\n");
    writer.write("clientconnectiontls='strict'\n");
    writer.write("clientconnectiontlsservertrust='" + TRUST_MODE + "'\n");
    writeServerCertToConfig(writer, serverCertificate);
    writeClientConnectionServerCertToConfig(writer, serverCertificate);
  });

  configureJDKTrustStore(serverCertificate, tempDir);

  final SelfSignedCertificate clientCertificate = SelfSignedCertificate.create("example.com");
  final String fingerprint = certificateHexFingerprint(Paths.get(clientCertificate.keyCertOptions().getCertPath()));

  Files.write(config.tlsKnownClients(), Arrays.asList("#First line", "example.com " + fingerprint));
  Files.write(config.clientConnectionTlsKnownClients(), Arrays.asList("#First line", "example.com " + fingerprint));
  httpClient = vertx
      .createHttpClient(new HttpClientOptions().setSsl(true).setKeyCertOptions(clientCertificate.keyCertOptions()));

  final SelfSignedCertificate fooCertificate = SelfSignedCertificate.create("foo.bar.baz");
  httpClientWithUnregisteredCert =
      vertx.createHttpClient(new HttpClientOptions().setSsl(true).setKeyCertOptions(fooCertificate.keyCertOptions()));

  final SelfSignedCertificate noCNCert = SelfSignedCertificate.create("");
  httpClientWithImproperCertificate =
      vertx.createHttpClient(new HttpClientOptions().setSsl(true).setKeyCertOptions(noCNCert.keyCertOptions()));

  final SelfSignedCertificate anotherExampleDotComCert = SelfSignedCertificate.create("example.com");
  anotherExampleComClient = vertx.createHttpClient(
      new HttpClientOptions().setSsl(true).setKeyCertOptions(anotherExampleDotComCert.keyCertOptions()));

  orion = new Orion(vertx);
  orion.run(config, false);
}
 
Example 8
Source File: MqttConnectionIT.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets up the fixture.
 */
@BeforeEach
@Override
public void setUp(final TestInfo testInfo) {
    LOGGER.info("running {}", testInfo.getDisplayName());
    tenantId = helper.getRandomTenantId();
    deviceId = helper.getRandomDeviceId(tenantId);
    password = "secret";
    deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());
}
 
Example 9
Source File: CertificateAuthorityNodeClientTest.java    From orion with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setUp(@TempDirectory final Path tempDir) throws Exception {
  final SelfSignedCertificate clientCert = SelfSignedCertificate.create("localhost");
  final Config config = generateAndLoadConfiguration(tempDir, writer -> {
    writer.write("tlsclienttrust='ca'\n");
    writeClientCertToConfig(writer, clientCert);
  });

  final Path knownServersFile = config.tlsKnownServers();

  final SelfSignedCertificate serverCert = SelfSignedCertificate.create("localhost");
  TestUtils.configureJDKTrustStore(serverCert, tempDir);
  Files.write(knownServersFile, Collections.singletonList("#First line"));

  final Router dummyRouter = Router.router(vertx);
  final ReadOnlyNetworkNodes payload =
      new ReadOnlyNetworkNodes(URI.create("http://www.example.com"), Collections.emptyMap());
  dummyRouter.post("/partyinfo").handler(routingContext -> {
    routingContext.response().end(Buffer.buffer(Serializer.serialize(HttpContentType.CBOR, payload)));
  });

  client = NodeHttpClientBuilder.build(vertx, config, 100);
  caValidServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(serverCert.keyCertOptions()))
      .requestHandler(dummyRouter::accept);
  startServer(caValidServer);
  unknownServer = vertx
      .createHttpServer(
          new HttpServerOptions().setSsl(true).setPemKeyCertOptions(SelfSignedCertificate.create().keyCertOptions()))
      .requestHandler(dummyRouter::accept);
  startServer(unknownServer);
}
 
Example 10
Source File: TrustedCertificateAuthorityTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets up class fixture.
 *
 * @throws GeneralSecurityException if the self signed certificate cannot be created.
 * @throws IOException if the self signed certificate cannot be read.
 */
@BeforeAll
public static void setUp() throws GeneralSecurityException, IOException {
    final SelfSignedCertificate selfSignedCert = SelfSignedCertificate.create("eclipse.org");
    final CertificateFactory factory = CertificateFactory.getInstance("X.509");
    certificate = (X509Certificate) factory.generateCertificate(new FileInputStream(selfSignedCert.certificatePath()));
}
 
Example 11
Source File: ClientRecordTest.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void startServers(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caSignedCert = SelfSignedCertificate.create("localhost");
  SecurityTestUtils.configureJDKTrustStore(tempDir, caSignedCert);
  caValidFingerprint = certificateHexFingerprint(Paths.get(caSignedCert.keyCertOptions().getCertPath()));
  caValidServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(caSignedCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(caValidServer);

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  fooServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(fooCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(fooServer);

  SelfSignedCertificate barCert = SelfSignedCertificate.create("bar.com");
  barFingerprint = certificateHexFingerprint(Paths.get(barCert.keyCertOptions().getCertPath()));
  barServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(barCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(barServer);

  SelfSignedCertificate foobarCert = SelfSignedCertificate.create("foobar.com");
  foobarFingerprint = certificateHexFingerprint(Paths.get(foobarCert.keyCertOptions().getCertPath()));
  foobarServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(foobarCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(foobarServer);
}
 
Example 12
Source File: ServerWhitelistTest.java    From cava with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setupClients(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caClientCert = SelfSignedCertificate.create();
  SecurityTestUtils.configureJDKTrustStore(tempDir, caClientCert);
  caClient = vertx.createHttpClient(
      new HttpClientOptions().setTrustOptions(InsecureTrustOptions.INSTANCE).setSsl(true).setKeyCertOptions(
          caClientCert.keyCertOptions()));

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  HttpClientOptions fooClientOptions = new HttpClientOptions();
  fooClientOptions
      .setSsl(true)
      .setKeyCertOptions(fooCert.keyCertOptions())
      .setTrustOptions(InsecureTrustOptions.INSTANCE)
      .setConnectTimeout(1500)
      .setReuseAddress(true)
      .setReusePort(true);
  fooClient = vertx.createHttpClient(fooClientOptions);

  SelfSignedCertificate barCert = SelfSignedCertificate.create("bar.com");
  HttpClientOptions barClientOptions = new HttpClientOptions();
  barClientOptions
      .setSsl(true)
      .setKeyCertOptions(barCert.keyCertOptions())
      .setTrustOptions(InsecureTrustOptions.INSTANCE)
      .setConnectTimeout(1500)
      .setReuseAddress(true)
      .setReusePort(true);
  barClient = vertx.createHttpClient(barClientOptions);
}
 
Example 13
Source File: TofuSecurityTest.java    From orion with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp(@TempDirectory final Path tempDir) throws Exception {
  final SelfSignedCertificate serverCertificate = SelfSignedCertificate.create("localhost");
  config = generateAndLoadConfiguration(tempDir, writer -> {
    writer.write("tlsservertrust='" + TRUST_MODE + "'\n");
    writer.write("clientconnectiontls='strict'\n");
    writer.write("clientconnectiontlsservertrust='" + TRUST_MODE + "'\n");
    writeServerCertToConfig(writer, serverCertificate);
    writeClientConnectionServerCertToConfig(writer, serverCertificate);
  });

  configureJDKTrustStore(serverCertificate, tempDir);

  final SelfSignedCertificate clientCertificate = SelfSignedCertificate.create("example.com");
  exampleComFingerprint = certificateHexFingerprint(Paths.get(clientCertificate.keyCertOptions().getCertPath()));
  Files.write(config.tlsKnownClients(), Collections.singletonList("#First line"));
  Files.write(config.clientConnectionTlsKnownClients(), Collections.singletonList("#First line"));
  httpClient = vertx
      .createHttpClient(new HttpClientOptions().setSsl(true).setKeyCertOptions(clientCertificate.keyCertOptions()));

  final SelfSignedCertificate anotherExampleDotComCert = SelfSignedCertificate.create("example.com");
  anotherExampleComClient = vertx.createHttpClient(
      new HttpClientOptions().setSsl(true).setKeyCertOptions(anotherExampleDotComCert.keyCertOptions()));

  orion = new Orion(vertx);
  orion.run(config, false);
}
 
Example 14
Source File: HttpEndpointTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecordCreation(TestContext testContext) {
  Record record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, null);
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/");

  record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, "foo");
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/foo");

  record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, "foo", new JsonObject().put("language", "en"));
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/foo");
  assertThat(record.getMetadata().getString("language")).isEqualTo("en");

  record = HttpEndpoint.createRecord("some-name", "acme.org");
  assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://acme.org:80/");

  SelfSignedCertificate selfSignedCertificate = SelfSignedCertificate.create();
  vertx.createHttpServer(new HttpServerOptions()
    .setHost("127.0.0.1")
    .setSsl(true)
    .setKeyCertOptions(selfSignedCertificate.keyCertOptions())
  ).requestHandler(request -> {
    request.response().end(new JsonObject().put("url", request.absoluteURI()).encode());
  }).listen(0, testContext.asyncAssertSuccess(server -> {

    Record sslRecord = HttpEndpoint.createRecord("http-bin", true, "127.0.0.1", server.actualPort(), "/get", null);
    ServiceReference reference = discovery.getReferenceWithConfiguration(sslRecord, new HttpClientOptions()
      .setSsl(true)
      .setTrustAll(true)
      .setVerifyHost(false)
      .toJson());

    WebClient webClient = WebClient.wrap(reference.get());
    webClient.get("/get").as(BodyCodec.jsonObject()).send(testContext.asyncAssertSuccess(resp -> {
      assertEquals("https://127.0.0.1:" + server.actualPort() + "/get", resp.body().getString("url"));
    }));
  }));
}
 
Example 15
Source File: InsecureNodeClientTest.java    From orion with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setUp(@TempDirectory final Path tempDir) throws Exception {
  final SelfSignedCertificate clientCert = SelfSignedCertificate.create("localhost");
  final Config config = generateAndLoadConfiguration(tempDir, writer -> {
    writer.write("tlsclienttrust='insecure-no-validation'\n");
    writeClientCertToConfig(writer, clientCert);
  });

  knownServersFile = config.tlsKnownServers();

  final SelfSignedCertificate serverCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(serverCert.keyCertOptions().getCertPath()));
  Files.write(knownServersFile, Collections.singletonList("#First line"));

  client = NodeHttpClientBuilder.build(vertx, config, 100);

  final Router dummyRouter = Router.router(vertx);
  final ReadOnlyNetworkNodes payload =
      new ReadOnlyNetworkNodes(URI.create("http://www.example.com"), Collections.emptyMap());
  dummyRouter.post("/partyinfo").handler(routingContext -> {
    routingContext.response().end(Buffer.buffer(Serializer.serialize(HttpContentType.CBOR, payload)));
  });

  insecureServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(serverCert.keyCertOptions()))
      .requestHandler(dummyRouter::accept);
  startServer(insecureServer);
  foobarComServer = vertx
      .createHttpServer(
          new HttpServerOptions().setSsl(true).setPemKeyCertOptions(
              SelfSignedCertificate.create("foobar.com").keyCertOptions()))
      .requestHandler(dummyRouter::accept);
  startServer(foobarComServer);
}
 
Example 16
Source File: WhitelistNodeClientTest.java    From orion with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setUp(@TempDirectory final Path tempDir) throws Exception {
  final SelfSignedCertificate clientCert = SelfSignedCertificate.create("localhost");
  final Config config = generateAndLoadConfiguration(tempDir, writer -> {
    writer.write("tlsclienttrust='whitelist'\n");
    writeClientCertToConfig(writer, clientCert);
  });

  final Path knownServersFile = config.tlsKnownServers();

  final SelfSignedCertificate serverCert = SelfSignedCertificate.create("localhost");
  final Router dummyRouter = Router.router(vertx);
  whitelistedServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(serverCert.keyCertOptions()))
      .requestHandler(dummyRouter::accept);
  startServer(whitelistedServer);
  final String fingerprint = certificateHexFingerprint(Paths.get(serverCert.keyCertOptions().getCertPath()));
  Files.write(
      knownServersFile,
      Arrays.asList("#First line", "localhost:" + whitelistedServer.actualPort() + " " + fingerprint));

  client = NodeHttpClientBuilder.build(vertx, config, 100);

  final ReadOnlyNetworkNodes payload =
      new ReadOnlyNetworkNodes(URI.create("http://www.example.com"), Collections.emptyMap());
  dummyRouter.post("/partyinfo").handler(routingContext -> {
    routingContext.response().end(Buffer.buffer(Serializer.serialize(HttpContentType.CBOR, payload)));
  });

  unknownServer = vertx
      .createHttpServer(
          new HttpServerOptions().setSsl(true).setPemKeyCertOptions(SelfSignedCertificate.create().keyCertOptions()))
      .requestHandler(dummyRouter::accept);
  startServer(unknownServer);
}
 
Example 17
Source File: ServerCaOrWhitelistTest.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setupClients(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caClientCert = SelfSignedCertificate.create();
  SecurityTestUtils.configureJDKTrustStore(tempDir, caClientCert);
  caClient = vertx
      .createHttpClient(
          new HttpClientOptions()
              .setTrustOptions(InsecureTrustOptions.INSTANCE)
              .setSsl(true)
              .setKeyCertOptions(caClientCert.keyCertOptions()));

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  HttpClientOptions fooClientOptions = new HttpClientOptions();
  fooClientOptions
      .setSsl(true)
      .setKeyCertOptions(fooCert.keyCertOptions())
      .setTrustOptions(InsecureTrustOptions.INSTANCE)
      .setConnectTimeout(1500)
      .setReuseAddress(true)
      .setReusePort(true);
  fooClient = vertx.createHttpClient(fooClientOptions);

  SelfSignedCertificate barCert = SelfSignedCertificate.create("bar.com");
  HttpClientOptions barClientOptions = new HttpClientOptions();
  barClientOptions
      .setSsl(true)
      .setKeyCertOptions(barCert.keyCertOptions())
      .setTrustOptions(InsecureTrustOptions.INSTANCE)
      .setConnectTimeout(1500)
      .setReuseAddress(true)
      .setReusePort(true);
  barClient = vertx.createHttpClient(barClientOptions);
}
 
Example 18
Source File: AmqpConnectionIT.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Verifies that the adapter opens a connection if auto-provisioning is enabled for the device certificate.
 *
 * @param ctx The test context.
 */
@Test
public void testConnectSucceedsWithAutoProvisioning(final VertxTestContext ctx) {
    final String tenantId = helper.getRandomTenantId();
    final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());

    helper.getCertificate(deviceCert.certificatePath())
            .compose(cert -> {
                final var tenant = Tenants.createTenantForTrustAnchor(cert);
                tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(true);
                return helper.registry.addTenant(tenantId, tenant);
            })
            .compose(ok -> connectToAdapter(deviceCert))
            .onComplete(ctx.completing());
}
 
Example 19
Source File: TenantTest.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets up class fixture.
 * @throws GeneralSecurityException if the self signed certificate cannot be created.
 * @throws IOException if the self signed certificate cannot be read.
 */
@BeforeAll
public static void setUp() throws GeneralSecurityException, IOException {
    final SelfSignedCertificate selfSignedCert = SelfSignedCertificate.create("eclipse.org");
    final CertificateFactory factory = CertificateFactory.getInstance("X.509");
    certificate = (X509Certificate) factory.generateCertificate(new FileInputStream(selfSignedCert.certificatePath()));
}
 
Example 20
Source File: ClientRecordTest.java    From cava with Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void startServers(@TempDirectory Path tempDir, @VertxInstance Vertx vertx) throws Exception {
  SelfSignedCertificate caSignedCert = SelfSignedCertificate.create("localhost");
  SecurityTestUtils.configureJDKTrustStore(tempDir, caSignedCert);
  caValidFingerprint = certificateHexFingerprint(Paths.get(caSignedCert.keyCertOptions().getCertPath()));
  caValidServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(caSignedCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(caValidServer);

  SelfSignedCertificate fooCert = SelfSignedCertificate.create("foo.com");
  fooFingerprint = certificateHexFingerprint(Paths.get(fooCert.keyCertOptions().getCertPath()));
  fooServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(fooCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(fooServer);

  SelfSignedCertificate barCert = SelfSignedCertificate.create("bar.com");
  barFingerprint = certificateHexFingerprint(Paths.get(barCert.keyCertOptions().getCertPath()));
  barServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(barCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(barServer);

  SelfSignedCertificate foobarCert = SelfSignedCertificate.create("foobar.com");
  foobarFingerprint = certificateHexFingerprint(Paths.get(foobarCert.keyCertOptions().getCertPath()));
  foobarServer = vertx
      .createHttpServer(new HttpServerOptions().setSsl(true).setPemKeyCertOptions(foobarCert.keyCertOptions()))
      .requestHandler(context -> context.response().end("OK"));
  startServer(foobarServer);
}