// Path: src/main/java/info/jdavid/ok/server/Logger.java
// static final org.slf4j.Logger logger = LoggerFactory.getLogger(HttpServer.class);


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
import static info.jdavid.ok.server.Logger.logger;
                            @Nullable final String hostname, final boolean http2) throws IOException {
    final SSLSocketFactory sslFactory = getContext(hostname).getSocketFactory();
    final SSLSocket sslSocket = (SSLSocket)sslFactory.createSocket(socket, null, socket.getPort(), true);
    platform.setupSSLSocket(sslSocket, http2);
    sslSocket.setUseClientMode(false);
    sslSocket.setEnabledProtocols(protocols);
    sslSocket.setEnabledCipherSuites(cipherSuites);
    sslSocket.startHandshake();
    return sslSocket;
  }

  private static SSLContext createSSLContext(@Nullable final byte[] certificate) {
    if (certificate == null) return null;
    final InputStream cert = new ByteArrayInputStream(certificate);
    try {
      final KeyStore keyStore = KeyStore.getInstance("PKCS12");
      keyStore.load(cert, new char[0]);
      final KeyManagerFactory kmf =
        KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      kmf.init(keyStore, new char[0]);
      final KeyStore trustStore = KeyStore.getInstance("JKS");
      trustStore.load(null, null);
      final TrustManagerFactory tmf =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
      tmf.init(trustStore);
      final SSLContext context = SSLContext.getInstance("TLS");
      context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
      return context;
    }
    catch (final GeneralSecurityException e) {
// Path: src/main/java/info/jdavid/ok/server/Logger.java
// static final org.slf4j.Logger logger = LoggerFactory.getLogger(HttpServer.class);


// Path: src/main/java/info/jdavid/ok/server/Https.java
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
import static info.jdavid.ok.server.Logger.logger;

                            @Nullable final String hostname, final boolean http2) throws IOException {
    final SSLSocketFactory sslFactory = getContext(hostname).getSocketFactory();
    final SSLSocket sslSocket = (SSLSocket)sslFactory.createSocket(socket, null, socket.getPort(), true);
    platform.setupSSLSocket(sslSocket, http2);
    sslSocket.setUseClientMode(false);
    sslSocket.setEnabledProtocols(protocols);
    sslSocket.setEnabledCipherSuites(cipherSuites);
    sslSocket.startHandshake();
    return sslSocket;
  }

  private static SSLContext createSSLContext(@Nullable final byte[] certificate) {
    if (certificate == null) return null;
    final InputStream cert = new ByteArrayInputStream(certificate);
    try {
      final KeyStore keyStore = KeyStore.getInstance("PKCS12");
      keyStore.load(cert, new char[0]);
      final KeyManagerFactory kmf =
        KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      kmf.init(keyStore, new char[0]);
      final KeyStore trustStore = KeyStore.getInstance("JKS");
      trustStore.load(null, null);
      final TrustManagerFactory tmf =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
      tmf.init(trustStore);
      final SSLContext context = SSLContext.getInstance("TLS");
      context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());
      return context;
    }
    catch (final GeneralSecurityException e) {
      logger.warn("Failed to create SSL context.", e);