DefaultTlsContext implements TlsContext { @Override public SSLEngine createSslEngine() { SSLEngine sslEngine = sslContext.createSSLEngine(); sslEngine.setSSLParameters(createSslParameters()); return sslEngine; } DefaultTlsContext(List<X509Certificate> certificates,
                             PrivateKey privateKey,
                             List<X509Certificate> caCertificates,
                             AuthorizedPeers authorizedPeers,
                             AuthorizationMode mode,
                             PeerAuthentication peerAuthentication,
                             HostnameVerification hostnameVerification);  DefaultTlsContext(SSLContext sslContext, PeerAuthentication peerAuthentication);  DefaultTlsContext(SSLContext sslContext);   DefaultTlsContext(SSLContext sslContext, Set<String> acceptedCiphers, PeerAuthentication peerAuthentication); @Override SSLContext context(); @Override SSLParameters parameters(); @Override SSLEngine createSslEngine(); @Override SSLEngine createSslEngine(String peerHost, int peerPort);  }
@Test public void can_create_sslcontext_from_credentials() { KeyPair keyPair = KeyUtils.generateKeypair(EC); X509Certificate certificate = X509CertificateBuilder .fromKeypair(keyPair, new X500Principal("CN=dummy"), EPOCH, Instant.now().plus(1, DAYS), SHA256_WITH_ECDSA, generateRandomSerialNumber()) .build(); AuthorizedPeers authorizedPeers = new AuthorizedPeers( singleton( new PeerPolicy( "dummy-policy", singleton(new Role("dummy-role")), singletonList(new RequiredPeerCredential(RequiredPeerCredential.Field.CN, new HostGlobPattern("dummy")))))); DefaultTlsContext tlsContext = new DefaultTlsContext( singletonList(certificate), keyPair.getPrivate(), singletonList(certificate), authorizedPeers, AuthorizationMode.ENFORCE, PeerAuthentication.NEED, HostnameVerification.ENABLED); SSLEngine sslEngine = tlsContext.createSslEngine(); assertThat(sslEngine).isNotNull(); String[] enabledCiphers = sslEngine.getEnabledCipherSuites(); assertThat(enabledCiphers).isNotEmpty(); assertThat(enabledCiphers).isSubsetOf(TlsContext.ALLOWED_CIPHER_SUITES.toArray(new String[0])); String[] enabledProtocols = sslEngine.getEnabledProtocols(); assertThat(enabledProtocols).contains("TLSv1.2"); }