szetszwo commented on code in PR #1462:
URL: https://github.com/apache/ratis/pull/1462#discussion_r3284487826


##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcTlsConfig.java:
##########
@@ -34,6 +37,10 @@
  */
 public class GrpcTlsConfig extends TlsConf {
   private final boolean fileBasedConfig;
+  private final SslProvider sslProvider;
+  private final String jsseProviderName;
+  private final List<String> protocols;
+  private final List<String> cipherSuites;

Review Comment:
   Let's move them up to TlsConf so ratis-netty could also use it.
   
   (Indeed, GrpcTlsConfig is a poor designed class.  TlsConf is a replacement 
of it.  Unfortunately, we cannot remove GrpcTlsConfig for compatibility.)



##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcTlsConfig.java:
##########
@@ -131,4 +158,124 @@ private static Builder newBuilder(File privateKeyFile, 
File certChainFile, File
   private static Builder newBuilder(KeyManager keyManager, TrustManager 
trustManager, boolean mTlsEnabled) {
     return 
newBuilder().setMutualTls(mTlsEnabled).setKeyManager(keyManager).setTrustManager(trustManager);
   }
-}
\ No newline at end of file
+
+  public static Builder newBuilder(GrpcTlsConfig conf) {

Review Comment:
   This is only used in testNewBuilderCopiesGrpcTlsOptions().  So, we should 
remove both this method and also testNewBuilderCopiesGrpcTlsOptions().



##########
ratis-grpc/src/test/java/org/apache/ratis/grpc/TestGrpcTlsConfig.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.ratis.grpc;
+
+import org.apache.ratis.thirdparty.io.netty.handler.ssl.SslContextBuilder;
+import org.apache.ratis.thirdparty.io.netty.handler.ssl.SslProvider;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.security.Provider;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class TestGrpcTlsConfig {
+  @Test
+  public void testGrpcTlsConfigCopiesLists() {
+    final List<String> protocols = new 
ArrayList<>(Collections.singletonList("TLSv1.2"));
+    final List<String> cipherSuites = new 
ArrayList<>(Collections.singletonList("TLS_AES_128_GCM_SHA256"));
+
+    final GrpcTlsConfig conf = GrpcTlsConfig.newBuilder()
+        .setProtocols(protocols)
+        .setCipherSuites(cipherSuites)
+        .build();
+
+    protocols.add("TLSv1.3");
+    cipherSuites.add("TLS_AES_256_GCM_SHA384");
+
+    Assertions.assertEquals(Collections.singletonList("TLSv1.2"), 
conf.getProtocols());
+    
Assertions.assertEquals(Collections.singletonList("TLS_AES_128_GCM_SHA256"), 
conf.getCipherSuites());
+    Assertions.assertThrows(UnsupportedOperationException.class, () -> 
conf.getProtocols().add("TLSv1.3"));
+    Assertions.assertThrows(UnsupportedOperationException.class,
+        () -> conf.getCipherSuites().add("TLS_AES_256_GCM_SHA384"));
+  }
+
+  @Test
+  public void testNewBuilderCopiesGrpcTlsOptions() {
+    final GrpcTlsConfig conf = GrpcTlsConfig.newBuilder()
+        .setSslProvider(SslProvider.OPENSSL)
+        .setJsseProviderName("SunJSSE")
+        .setProtocols("TLSv1.2")
+        .setCipherSuites("TLS_AES_128_GCM_SHA256")
+        .build();
+
+    final GrpcTlsConfig updated = GrpcTlsConfig.newBuilder(conf).build();
+    Assertions.assertSame(SslProvider.OPENSSL, updated.getSslProvider());
+    Assertions.assertEquals("SunJSSE", updated.getJsseProviderName());
+    Assertions.assertEquals(Collections.singletonList("TLSv1.2"), 
updated.getProtocols());
+    Assertions.assertEquals(Arrays.asList("TLS_AES_128_GCM_SHA256"), 
updated.getCipherSuites());
+  }
+
+  @Test
+  public void testUnknownJsseProviderUsesGenericJdkConfiguration() {
+    final SslContextBuilder builder = GrpcUtil.configureJsseProvider(
+        SslContextBuilder.forClient(), new TestProvider());
+    Assertions.assertNotNull(builder);
+  }

Review Comment:
   This test seems incomplete?  Should we build it and expect an exception?



##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcFactory.java:
##########
@@ -91,9 +89,10 @@ private SslContexts(GrpcTlsConfig tlsConfig, GrpcTlsConfig 
adminTlsConfig,
   }
 
   private final GrpcServices.Customizer servicesCustomizer;
-
-  private final Supplier<SslContexts> forServerSupplier;
-  private final Supplier<SslContexts> forClientSupplier;

Review Comment:
   We should keep using MemoizedSupplier.  Otherwise, the same SslContexts will 
be built multiple times; see RATIS-2331.
   
   Indeed, all the change in GrpcFactory are not needed.



-- 
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]

Reply via email to