public static SSLSocketFactory getSslSocketFactory(Options options) throws SQLException {

    TrustManager[] trustManager = null;
    KeyManager[] keyManager = null;

    if (options.trustServerCertificate || options.serverSslCert != null
        || options.trustStore != null) {
      trustManager = new X509TrustManager[]{new MariaDbX509TrustManager(options)};
    }

    if (options.keyStore != null) {
      keyManager = new KeyManager[]{
          loadClientCerts(options.keyStore, options.keyStorePassword, options.keyPassword, options.keyStoreType)};
    } else {
      String keyStore = System.getProperty("javax.net.ssl.keyStore");
      String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
      if (keyStore != null) {
        try {
          keyManager = new KeyManager[]{
              loadClientCerts(keyStore, keyStorePassword, keyStorePassword, options.keyStoreType)};
        } catch (SQLException queryException) {
          keyManager = null;
          logger.error("Error loading keymanager from system properties", queryException);
        }
      }
    }

    try {
      SSLContext sslContext = SSLContext.getInstance("TLS");
      sslContext.init(keyManager, trustManager, null);
      return sslContext.getSocketFactory();
    } catch (KeyManagementException keyManagementEx) {
      throw ExceptionMapper.connException("Could not initialize SSL context", keyManagementEx);
    } catch (NoSuchAlgorithmException noSuchAlgorithmEx) {
      throw ExceptionMapper
          .connException("SSLContext TLS Algorithm not unknown", noSuchAlgorithmEx);
    }
  }
public static SSLSocketFactory getSslSocketFactory ( Options options ) throws SQLException { TrustManager [ ] trustManager = null ; KeyManager [ ] keyManager = null ; if ( options . trustServerCertificate || options . serverSslCert != null || options . trustStore != null ) { trustManager = new X509TrustManager [ ] { new MariaDbX509TrustManager ( options ) } ; } if ( options . keyStore != null ) { keyManager = new KeyManager [ ] { loadClientCerts ( options . keyStore , options . keyStorePassword , options . keyPassword , options . keyStoreType ) } ; } else { String keyStore = System . getProperty ( "javax.net.ssl.keyStore" ) ; String keyStorePassword = System . getProperty ( "javax.net.ssl.keyStorePassword" ) ; if ( keyStore != null ) { try { keyManager = new KeyManager [ ] { loadClientCerts ( keyStore , keyStorePassword , keyStorePassword , options . keyStoreType ) } ; } catch ( SQLException queryException ) { keyManager = null ; logger . error ( "Error loading keymanager from system properties" , queryException ) ; } } } try { SSLContext sslContext = SSLContext . getInstance ( "TLS" ) ; sslContext . init ( keyManager , trustManager , null ) ; return sslContext . getSocketFactory ( ) ; } catch ( KeyManagementException keyManagementEx ) { throw ExceptionMapper . connException ( "Could not initialize SSL context" , keyManagementEx ) ; } catch ( NoSuchAlgorithmException noSuchAlgorithmEx ) { throw ExceptionMapper . connException ( "SSLContext TLS Algorithm not unknown" , noSuchAlgorithmEx ) ; } }
Create an SSL factory according to connection string options.

@param options   connection options
@return SSL socket factory
@throws SQLException in case of error initializing context.