Search in sources :

Example 1 with FingerprintTrustManagerFactory

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

the class SSLUtils method getTrustManagerFactory.

private static TrustManagerFactory getTrustManagerFactory(Configuration config, boolean internal) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
    String trustStoreFilePath = getAndCheckOption(config, internal ? SecurityOptions.SSL_INTERNAL_TRUSTSTORE : SecurityOptions.SSL_REST_TRUSTSTORE, SecurityOptions.SSL_TRUSTSTORE);
    String trustStorePassword = getAndCheckOption(config, internal ? SecurityOptions.SSL_INTERNAL_TRUSTSTORE_PASSWORD : SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, SecurityOptions.SSL_TRUSTSTORE_PASSWORD);
    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream trustStoreFile = Files.newInputStream(new File(trustStoreFilePath).toPath())) {
        trustStore.load(trustStoreFile, trustStorePassword.toCharArray());
    }
    String certFingerprint = config.getString(internal ? SecurityOptions.SSL_INTERNAL_CERT_FINGERPRINT : SecurityOptions.SSL_REST_CERT_FINGERPRINT);
    TrustManagerFactory tmf;
    if (StringUtils.isNullOrWhitespaceOnly(certFingerprint)) {
        tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    } else {
        tmf = new FingerprintTrustManagerFactory(certFingerprint.split(","));
    }
    tmf.init(trustStore);
    return tmf;
}
Also used : InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) FingerprintTrustManagerFactory(org.apache.flink.shaded.netty4.io.netty.handler.ssl.util.FingerprintTrustManagerFactory) FingerprintTrustManagerFactory(org.apache.flink.shaded.netty4.io.netty.handler.ssl.util.FingerprintTrustManagerFactory) KeyStore(java.security.KeyStore) File(java.io.File)

Aggregations

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