smiklosovic commented on a change in pull request #1027:
URL: https://github.com/apache/cassandra/pull/1027#discussion_r694632766



##########
File path: 
src/java/org/apache/cassandra/security/FileBasedSslContextFactory.java
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.cassandra.security;
+
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.KeyStore;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.TrustManagerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract implementation for {@link ISslContextFactory} using file based, 
standard keystore format with the ability
+ * to hot-reload the files upon file changes (detected by the {@code last 
modified timestamp}).
+ *
+ * {@code CAUTION:} While this is a useful abstraction, please be careful if 
you need to modify this class
+ * given possible custom implementations out there!
+ */
+abstract public class FileBasedSslContextFactory extends 
AbstractSslContextFactory
+{
+    private static final Logger logger = 
LoggerFactory.getLogger(FileBasedSslContextFactory.class);
+
+    @VisibleForTesting
+    protected volatile boolean checkedExpiry = false;
+
+    /**
+     * List of files that trigger hot reloading of SSL certificates
+     */
+    protected volatile List<HotReloadableFile> hotReloadableFiles = new 
ArrayList<>();
+
+    protected String keystore;
+    protected String keystore_password;
+    protected String truststore;
+    protected String truststore_password;
+
+    public FileBasedSslContextFactory()
+    {
+        keystore = "conf/.keystore";
+        keystore_password = "cassandra";
+        truststore = "conf/.truststore";
+        truststore_password = "cassandra";
+    }
+
+    public FileBasedSslContextFactory(Map<String, Object> parameters)
+    {
+        super(parameters);
+        keystore = getString("keystore");
+        keystore_password = getString("keystore_password");
+        truststore = getString("truststore");
+        truststore_password = getString("truststore_password");
+    }
+
+    @Override
+    public boolean shouldReload()
+    {
+        return 
hotReloadableFiles.stream().anyMatch(HotReloadableFile::shouldReload);
+    }
+
+    @Override
+    public boolean hasKeystore() {
+        return keystore != null && new File(keystore).exists();
+    }
+
+    private boolean hasTruststore() {
+        return truststore != null && new File(truststore).exists();
+    }
+
+    @Override
+    public synchronized void initHotReloading() {
+        boolean hasKeystore = hasKeystore();
+        boolean hasTruststore = hasTruststore();
+
+        if (hasKeystore || hasTruststore) {
+            List<HotReloadableFile> fileList = new ArrayList<>();
+            if ( hasKeystore )

Review comment:
       nit: formatting, should be "if (hasKeystore)", it is same for 
hasTruststore below.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to