AbstractServiceBase extends ConfigurationSupportingVerticle<T> implements HealthCheckProvider { protected final void addTlsKeyCertOptions(final NetServerOptions serverOptions) { final KeyCertOptions keyCertOptions = getConfig().getKeyCertOptions(); if (keyCertOptions != null) { serverOptions.setSsl(true).setKeyCertOptions(keyCertOptions); } if (serverOptions.isSsl()) { final boolean isOpenSslAvailable = OpenSsl.isAvailable(); final boolean supportsKeyManagerFactory = OpenSsl.supportsKeyManagerFactory(); final boolean useOpenSsl = getConfig().isNativeTlsRequired() || (isOpenSslAvailable && supportsKeyManagerFactory); log.debug("OpenSSL [available: {}, supports KeyManagerFactory: {}]", isOpenSslAvailable, supportsKeyManagerFactory); if (useOpenSsl) { log.info("using OpenSSL [version: {}] instead of JDK's default SSL engine", OpenSsl.versionString()); serverOptions.setSslEngineOptions(new OpenSSLEngineOptions()); } else { log.info("using JDK's default SSL engine"); } serverOptions.getEnabledSecureTransportProtocols() .forEach(protocol -> serverOptions.removeEnabledSecureTransportProtocol(protocol)); getConfig().getSecureProtocols().forEach(protocol -> { log.info("enabling secure protocol [{}]", protocol); serverOptions.addEnabledSecureTransportProtocol(protocol); }); serverOptions.setSni(getConfig().isSni()); log.info("Service supports TLS ServerNameIndication: {}", getConfig().isSni()); } }  @Autowired(required = false) final void setTracer(final Tracer opentracingTracer); @Autowired(required = false) void setHealthCheckServer(final HealthCheckServer healthCheckServer); @Override final void start(final Promise<Void> startPromise); @Override final void stop(final Promise<Void> stopPromise); @Override void registerReadinessChecks(final HealthCheckHandler handler); @Override void registerLivenessChecks(final HealthCheckHandler handler); abstract int getPortDefaultValue(); abstract int getInsecurePortDefaultValue(); final int getPort(); final int getInsecurePort(); final String getBindAddress(); final String getInsecurePortBindAddress();  }
@Test public void testAddTlsKeyCertOptionsDisablesAllProtocolVersionsButTls12() { final ServiceConfigProperties config = new ServiceConfigProperties(); config.setKeyStorePath(PREFIX_KEY_PATH + "/authServerKeyStore.p12"); final AbstractServiceBase<ServiceConfigProperties> service = createService(config); final NetServerOptions options = new NetServerOptions(); service.addTlsKeyCertOptions(options); assertTrue(options.isSsl()); assertTrue(options.getEnabledSecureTransportProtocols().contains("TLSv1.2")); assertTrue(options.getEnabledSecureTransportProtocols().size() == 1); }
@Test public void testAddTlsKeyCertOptionsDisablesTlsProtocolVersions() { final ServiceConfigProperties config = new ServiceConfigProperties(); config.setKeyStorePath(PREFIX_KEY_PATH + "/authServerKeyStore.p12"); config.setSecureProtocols(Arrays.asList("TLSv1", "TLSv1.1")); final AbstractServiceBase<ServiceConfigProperties> service = createService(config); final NetServerOptions options = new NetServerOptions(); service.addTlsKeyCertOptions(options); assertTrue(options.isSsl()); assertTrue(options.getEnabledSecureTransportProtocols().size() == 2); assertTrue(options.getEnabledSecureTransportProtocols().contains("TLSv1")); assertTrue(options.getEnabledSecureTransportProtocols().contains("TLSv1.1")); }
@Test public void testSNIEnable() { final ServiceConfigProperties config = new ServiceConfigProperties(); config.setKeyStorePath(PREFIX_KEY_PATH + "/authServerKeyStore.p12"); config.setSecureProtocols(Arrays.asList("TLSv1.1")); config.setSni(true); final AbstractServiceBase<ServiceConfigProperties> service = createService(config); final NetServerOptions options = new NetServerOptions(); service.addTlsKeyCertOptions(options); assertTrue(options.isSsl()); assertTrue(options.isSni()); }