public static SSLContext createSSLContext()

in foundations/foundation-ssl/src/main/java/org/apache/servicecomb/foundation/ssl/SSLManager.java [49:99]


  public static SSLContext createSSLContext(SSLOption option, SSLCustom custom) {
    try {
      String keyStoreName = custom.getFullPath(option.getKeyStore());
      char[] keyStoreValue = option.getKeyStoreValue() == null ? new char[0] :
          custom.decode(option.getKeyStoreValue().toCharArray());
      KeyStore keyStore =
          KeyStoreUtil.createKeyStore(keyStoreName,
              option.getKeyStoreType(),
              keyStoreValue);

      KeyManager[] keyManager = null;
      if (keyStore != null) {
        keyManager =
            KeyStoreUtil.createKeyManagers(keyStore, keyStoreValue);
      }

      String trustStoreName = custom.getFullPath(option.getTrustStore());
      char[] trustStoreValue = option.getTrustStoreValue() == null ? new char[0] :
          custom.decode(option.getTrustStoreValue().toCharArray());
      KeyStore trustStore =
          KeyStoreUtil.createKeyStore(trustStoreName,
              option.getTrustStoreType(),
              trustStoreValue);

      TrustManager[] trustManager;
      if (trustStore != null) {
        trustManager =
            KeyStoreUtil.createTrustManagers(trustStore);
      } else {
        trustManager = new TrustManager[] {new TrustAllManager()};
      }

      TrustManager[] wrapped = new TrustManager[trustManager.length];
      for (int i = 0; i < trustManager.length; i++) {
        wrapped[i] =
            new TrustManagerExt((X509ExtendedTrustManager) trustManager[i],
                option, custom);
      }

      // ?: ssl context version
      SSLContext context = SSLContext.getInstance("TLS");
      context.init(keyManager, wrapped, new SecureRandom());
      return context;
    } catch (NoSuchAlgorithmException e) {
      throw new IllegalArgumentException("NoSuchAlgorithmException."
          + e.getMessage());
    } catch (KeyManagementException e) {
      throw new IllegalArgumentException("KeyManagementException."
          + e.getMessage());
    }
  }