// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// static final String KEY_KEYSTORE_TYPE = "keystore-type";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String KEY_P12_FILE_LOCATION = "p12-file-location";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String KEY_P12_PASSWORD = "p12-password";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// static final String KEY_TLS_VERSION = "tlsVersion";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_P12_FILE_EXTERNAL = "adeptj.rt.p12-file-external";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_P12_FILE_LOCATION = "adeptj.rt.p12-file-location";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_P12_PASSWORD = "adeptj.rt.p12-password";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_TLS_VERSION = "tls.version";


import static com.adeptj.runtime.common.Constants.KEY_TLS_VERSION;
import static com.adeptj.runtime.common.Constants.SYS_PROP_P12_FILE_EXTERNAL;
import static com.adeptj.runtime.common.Constants.SYS_PROP_P12_FILE_LOCATION;
import static com.adeptj.runtime.common.Constants.SYS_PROP_P12_PASSWORD;
import static com.adeptj.runtime.common.Constants.SYS_PROP_TLS_VERSION;
import com.typesafe.config.Config;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import static com.adeptj.runtime.common.Constants.KEY_KEYSTORE_TYPE;
import static com.adeptj.runtime.common.Constants.KEY_P12_FILE_LOCATION;
import static com.adeptj.runtime.common.Constants.KEY_P12_PASSWORD;
/*
###############################################################################
#                                                                             #
#    Copyright 2016, AdeptJ (http://www.adeptj.com)                           #
#                                                                             #
#    Licensed under the Apache License, Version 2.0 (the "License");          #
#    you may not use this file except in compliance with the License.         #
#    You may obtain a copy of the License at                                  #
#                                                                             #
#        http://www.apache.org/licenses/LICENSE-2.0                           #
#                                                                             #
#    Unless required by applicable law or agreed to in writing, software      #
#    distributed under the License is distributed on an "AS IS" BASIS,        #
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
#    See the License for the specific language governing permissions and      #
#    limitations under the License.                                           #
#                                                                             #
###############################################################################
*/

package com.adeptj.runtime.common;




/**
 * Utilities for SSL/TLS.
 *
 * @author Rakesh.Kumar, AdeptJ
 */
public final class SslContextFactory {

    private SslContextFactory() {
    }

    public static SSLContext newSslContext(Config httpsConf) throws GeneralSecurityException {
        String p12Loc;
        char[] p12Pwd;
        boolean p12FileExternal = Boolean.getBoolean(SYS_PROP_P12_FILE_EXTERNAL);
        if (p12FileExternal) {
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// static final String KEY_KEYSTORE_TYPE = "keystore-type";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String KEY_P12_FILE_LOCATION = "p12-file-location";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String KEY_P12_PASSWORD = "p12-password";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// static final String KEY_TLS_VERSION = "tlsVersion";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_P12_FILE_EXTERNAL = "adeptj.rt.p12-file-external";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_P12_FILE_LOCATION = "adeptj.rt.p12-file-location";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_P12_PASSWORD = "adeptj.rt.p12-password";
// 
// Path: src/main/java/com/adeptj/runtime/common/Constants.java
// public static final String SYS_PROP_TLS_VERSION = "tls.version";


// Path: src/main/java/com/adeptj/runtime/common/SslContextFactory.java
import static com.adeptj.runtime.common.Constants.KEY_TLS_VERSION;
import static com.adeptj.runtime.common.Constants.SYS_PROP_P12_FILE_EXTERNAL;
import static com.adeptj.runtime.common.Constants.SYS_PROP_P12_FILE_LOCATION;
import static com.adeptj.runtime.common.Constants.SYS_PROP_P12_PASSWORD;
import static com.adeptj.runtime.common.Constants.SYS_PROP_TLS_VERSION;
import com.typesafe.config.Config;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import static com.adeptj.runtime.common.Constants.KEY_KEYSTORE_TYPE;
import static com.adeptj.runtime.common.Constants.KEY_P12_FILE_LOCATION;
import static com.adeptj.runtime.common.Constants.KEY_P12_PASSWORD;

/*
###############################################################################
#                                                                             #
#    Copyright 2016, AdeptJ (http://www.adeptj.com)                           #
#                                                                             #
#    Licensed under the Apache License, Version 2.0 (the "License");          #
#    you may not use this file except in compliance with the License.         #
#    You may obtain a copy of the License at                                  #
#                                                                             #
#        http://www.apache.org/licenses/LICENSE-2.0                           #
#                                                                             #
#    Unless required by applicable law or agreed to in writing, software      #
#    distributed under the License is distributed on an "AS IS" BASIS,        #
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
#    See the License for the specific language governing permissions and      #
#    limitations under the License.                                           #
#                                                                             #
###############################################################################
*/

package com.adeptj.runtime.common;




/**
 * Utilities for SSL/TLS.
 *
 * @author Rakesh.Kumar, AdeptJ
 */
public final class SslContextFactory {

    private SslContextFactory() {
    }

    public static SSLContext newSslContext(Config httpsConf) throws GeneralSecurityException {
        String p12Loc;
        char[] p12Pwd;
        boolean p12FileExternal = Boolean.getBoolean(SYS_PROP_P12_FILE_EXTERNAL);
        if (p12FileExternal) {
            p12Loc = System.getProperty(SYS_PROP_P12_FILE_LOCATION);