Search in sources :

Example 1 with OpenSslX509KeyManagerFactory

use of org.apache.flink.shaded.netty4.io.netty.handler.ssl.OpenSslX509KeyManagerFactory in project flink by apache.

the class SSLUtils method getKeyManagerFactory.

private static KeyManagerFactory getKeyManagerFactory(Configuration config, boolean internal, SslProvider provider) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException {
    String keystoreFilePath = getAndCheckOption(config, internal ? SecurityOptions.SSL_INTERNAL_KEYSTORE : SecurityOptions.SSL_REST_KEYSTORE, SecurityOptions.SSL_KEYSTORE);
    String keystorePassword = getAndCheckOption(config, internal ? SecurityOptions.SSL_INTERNAL_KEYSTORE_PASSWORD : SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, SecurityOptions.SSL_KEYSTORE_PASSWORD);
    String certPassword = getAndCheckOption(config, internal ? SecurityOptions.SSL_INTERNAL_KEY_PASSWORD : SecurityOptions.SSL_REST_KEY_PASSWORD, SecurityOptions.SSL_KEY_PASSWORD);
    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream keyStoreFile = Files.newInputStream(new File(keystoreFilePath).toPath())) {
        keyStore.load(keyStoreFile, keystorePassword.toCharArray());
    }
    final KeyManagerFactory kmf;
    if (provider == OPENSSL || provider == OPENSSL_REFCNT) {
        kmf = new OpenSslX509KeyManagerFactory();
    } else {
        kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    }
    kmf.init(keyStore, certPassword.toCharArray());
    return kmf;
}
Also used : InputStream(java.io.InputStream) OpenSslX509KeyManagerFactory(org.apache.flink.shaded.netty4.io.netty.handler.ssl.OpenSslX509KeyManagerFactory) KeyStore(java.security.KeyStore) File(java.io.File) OpenSslX509KeyManagerFactory(org.apache.flink.shaded.netty4.io.netty.handler.ssl.OpenSslX509KeyManagerFactory) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

File (java.io.File)1 InputStream (java.io.InputStream)1 KeyStore (java.security.KeyStore)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 OpenSslX509KeyManagerFactory (org.apache.flink.shaded.netty4.io.netty.handler.ssl.OpenSslX509KeyManagerFactory)1