package com.palacesun.engine.gateway.netty;

import java.io.InputStream;
import java.security.KeyStore;
import java.security.SecureRandom;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;

public class SSLContextFactory {
   public static SSLContext getSslContext() throws Exception {
      char[] passArray = "syghca".toCharArray();
      SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
      KeyStore ks = KeyStore.getInstance("jks");
      InputStream inputStream = SSLContext.class.getResourceAsStream("/tomcat.keystore");
      ks.load(inputStream, passArray);
      KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      kmf.init(ks, passArray);
      sslContext.init(kmf.getKeyManagers(), (TrustManager[])null, (SecureRandom)null);
      inputStream.close();
      return sslContext;
   }
}
