You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by gi...@git.apache.org on 2017/09/26 02:51:39 UTC

[GitHub] dongeforever commented on a change in pull request #118: [ROCKETMQ-28] Encrypt transmission layer.

dongeforever commented on a change in pull request #118: [ROCKETMQ-28] Encrypt transmission layer.
URL: https://github.com/apache/incubator-rocketmq/pull/118#discussion_r127116521
 
 

 ##########
 File path: remoting/src/main/java/org/apache/rocketmq/remoting/netty/SslHelper.java
 ##########
 @@ -0,0 +1,127 @@
+/*
+ * 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.rocketmq.remoting.netty;
+
+import io.netty.handler.ssl.ClientAuth;
+import io.netty.handler.ssl.OpenSsl;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.ssl.SslProvider;
+import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+import io.netty.handler.ssl.util.SelfSignedCertificate;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.cert.CertificateException;
+import java.util.Properties;
+import javax.net.ssl.SSLException;
+import org.apache.rocketmq.remoting.common.RemotingHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SslHelper {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING);
+
+    public static SslContext buildSslContext(boolean forClient) throws SSLException, CertificateException {
+
+        File configFile = new File(NettySystemConfig.sslConfigFile);
+        boolean testMode = !(configFile.exists() && configFile.isFile() && configFile.canRead());
+        Properties properties = null;
+
+        if (!testMode) {
+            properties = new Properties();
+            InputStream inputStream = null;
+            try {
+                inputStream = new FileInputStream(configFile);
+                properties.load(inputStream);
+            } catch (FileNotFoundException ignore) {
+            } catch (IOException ignore) {
+            } finally {
+                if (null != inputStream) {
+                    try {
+                        inputStream.close();
+                    } catch (IOException ignore) {
+                    }
+                }
+            }
+        }
+
+        SslProvider provider = null;
+        if (OpenSsl.isAvailable()) {
+            provider = SslProvider.OPENSSL;
+            LOGGER.info("Using OpenSSL provider");
+        } else {
+            provider = SslProvider.JDK;
+            LOGGER.info("Using JDK SSL provider");
+        }
+
+        if (forClient) {
 
 Review comment:
   deep "for" cycle. Maybe it is better to construct two methods: buildSslContextForClient  and buidSslContextForServer
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services