epugh commented on code in PR #5107: URL: https://github.com/apache/solr/pull/5107#discussion_r4444418464
########## solr/core/src/java/org/apache/solr/cli/SecureExampleSSL.java: ########## @@ -0,0 +1,183 @@ +/* + * 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.solr.cli; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.GeneralSecurityException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** Manages the HTTPS files and certificate verification for the secure Solr example. */ +final class SecureExampleSSL { + private final Path directory; + private final ToolRuntime runtime; + + SecureExampleSSL(Path solrHome, ToolRuntime runtime) { + this.directory = solrHome.toAbsolutePath().resolve("tls"); + this.runtime = runtime; + } + + Path includeFile() { + return directory.resolve("solr.in.sh"); + } + + Path certificate() { + return directory.resolve("cert.pem"); + } + + Path passwordFile() { + return directory.resolve("keystore-password.txt"); + } + + Path keystore() { + return directory.resolve("solr-ssl.keystore.jks"); + } + + boolean isConfigured() { + return Files.isRegularFile(includeFile()) + && Files.isRegularFile(certificate()) + && Files.isRegularFile(passwordFile()) + && Files.isRegularFile(keystore()) + && Files.isRegularFile(Path.of(keystore() + ".truststore")); + } + + void generate(String password) throws Exception { + Files.createDirectories(directory); + IncludeFileEditor.write(passwordFile(), password.getBytes(StandardCharsets.UTF_8)); + Path key = directory.resolve("key.pem"); + IncludeFileEditor.write(key, new byte[0]); + Path config = directory.resolve("openssl.cnf"); + Files.writeString( + config, + "[req]\ndistinguished_name=dn\n[dn]\n[v3]\nsubjectAltName=DNS:localhost,IP:127.0.0.1\n"); + run( + List.of( + "openssl", Review Comment: could be all java! don't we run openssl elsewhere too? -- 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]
