ConfigFileBasedTlsContext implements TlsContext { @Override public SSLEngine createSslEngine() { return tlsContext.createSslEngine(); } ConfigFileBasedTlsContext(Path tlsOptionsConfigFile, AuthorizationMode mode);  ConfigFileBasedTlsContext(Path tlsOptionsConfigFile, AuthorizationMode mode, PeerAuthentication peerAuthentication); @Override SSLContext context(); @Override SSLParameters parameters(); @Override SSLEngine createSslEngine(); @Override SSLEngine createSslEngine(String peerHost, int peerPort); @Override void close();  }
@Test public void can_create_sslcontext_from_credentials() throws IOException, InterruptedException { KeyPair keyPair = KeyUtils.generateKeypair(EC); Path privateKeyFile = tempDirectory.newFile().toPath(); com.yahoo.vespa.jdk8compat.Files.writeString(privateKeyFile, KeyUtils.toPem(keyPair.getPrivate())); X509Certificate certificate = X509CertificateBuilder .fromKeypair(keyPair, new X500Principal("CN=dummy"), EPOCH, EPOCH.plus(1, DAYS), SHA256_WITH_ECDSA, BigInteger.ONE) .build(); Path certificateChainFile = tempDirectory.newFile().toPath(); String certificatePem = X509CertificateUtils.toPem(certificate); com.yahoo.vespa.jdk8compat.Files.writeString(certificateChainFile, certificatePem); Path caCertificatesFile = tempDirectory.newFile().toPath(); com.yahoo.vespa.jdk8compat.Files.writeString(caCertificatesFile, certificatePem); TransportSecurityOptions options = new TransportSecurityOptions.Builder() .withCertificates(certificateChainFile, privateKeyFile) .withCaCertificates(caCertificatesFile) .build(); Path optionsFile = tempDirectory.newFile().toPath(); options.toJsonFile(optionsFile); try (TlsContext tlsContext = new ConfigFileBasedTlsContext(optionsFile, AuthorizationMode.ENFORCE)) { 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"); } }