mridulm commented on code in PR #2438: URL: https://github.com/apache/celeborn/pull/2438#discussion_r1554820276
########## common/src/main/java/org/apache/celeborn/common/network/ssl/SSLFactory.java: ########## @@ -0,0 +1,405 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.celeborn.common.network.ssl; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.GeneralSecurityException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; + +import com.google.common.io.Files; +import io.netty.buffer.ByteBufAllocator; +import io.netty.handler.ssl.SslProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.celeborn.common.util.JavaUtils; + +/** + * SSLFactory to initialize and configure use of JSSE for SSL in Celeborn. + * + * <p>Note: code was initially copied from Apache Spark. + */ +public class SSLFactory { + private static final Logger logger = LoggerFactory.getLogger(SSLFactory.class); + + /** For a configuration specifying keystore/truststore files */ + private SSLContext jdkSslContext; + + private KeyManager[] keyManagers; + private TrustManager[] trustManagers; + private String requestedProtocol; + private String[] requestedCiphers; + + private SSLFactory(final Builder b) { + this.requestedProtocol = b.requestedProtocol; + this.requestedCiphers = b.requestedCiphers; + try { + initJdkSslContext(b); + } catch (Exception e) { + throw new RuntimeException("SSLFactory creation failed", e); + } + } + + private void initJdkSslContext(final Builder b) throws IOException, GeneralSecurityException { + this.keyManagers = + null != b.keyStore ? keyManagers(b.keyStore, b.keyPassword, b.keyStorePassword) : null; + this.trustManagers = + trustStoreManagers( + b.trustStore, b.trustStorePassword, + b.trustStoreReloadingEnabled, b.trustStoreReloadIntervalMs); + this.jdkSslContext = createSSLContext(requestedProtocol, keyManagers, trustManagers); + } + + public boolean hasKeyManagers() { + return null != keyManagers; + } + + /** + * If OpenSSL is requested, this will check if an implementation is available on the local host. + * If an implementation is not available it will fall back to the JDK {@link SslProvider}. + * + * @param b + * @return + */ + private SslProvider getSslProvider(Builder b) { + return SslProvider.JDK; Review Comment: Thanks for catching this ! This method is not used anymore - removed it. OpenSSL is actually planned, but for later (see CELEBORN-1367). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
