epugh commented on code in PR #5107: URL: https://github.com/apache/solr/pull/5107#discussion_r4444584416
########## solr/core/src/java/org/apache/solr/cli/SSLTool.java: ########## @@ -0,0 +1,345 @@ +/* + * 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.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyStore; +import java.security.cert.X509Certificate; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.apache.solr.common.cloud.ClusterProperties; +import org.apache.solr.common.cloud.SolrZkClient; +import org.apache.solr.common.util.EnvUtils; +import picocli.CommandLine; + +/** Installs PEM certificates and configures HTTPS for a Solr node. */ [email protected]( + name = "ssl", + description = "Convert PEM files to a Java keystore and configure HTTPS in solr.in.sh.", + footerHeading = "%nExamples:%n", + footer = { + " bin/solr ssl --cert fullchain.pem --key privkey.pem --password-file password.txt", + " bin/solr ssl --cert fullchain.pem --key privkey.pem --password-file password.txt --zk-host localhost:9983" + }) +public class SSLTool extends ToolBase { + @CommandLine.Option( + names = "--cert", + paramLabel = "FILE", + required = true, + description = "PEM certificate chain, with the server certificate first.") + private Path certificate; + + @CommandLine.Option( + names = "--key", + paramLabel = "FILE", + required = true, + description = "PEM private key. Requires OpenSSL on PATH.") + private Path privateKey; + + @CommandLine.Option( + names = "--password-file", + paramLabel = "FILE", + required = true, + description = "File containing the keystore password on one line.") + private Path passwordFile; + + @CommandLine.Option( + names = "--key-password-file", + paramLabel = "FILE", + description = "Password file for an encrypted PEM private key.") + private Path keyPasswordFile; + + @CommandLine.Option( + names = "--keystore", + paramLabel = "FILE", + description = "Destination keystore. Default directory: server/etc in the Solr installation.") + private Path keystore; + + @CommandLine.Option( + names = "--store-type", + paramLabel = "TYPE", + defaultValue = "JKS", + description = "Keystore format: JKS or PKCS12. Default: JKS.") + private String storeType = "JKS"; + + @CommandLine.Option( + names = "--solr-include-file", + paramLabel = "FILE", + description = + "Existing solr.in.sh to update. Defaults to bin/solr.in.sh in the Solr installation.") + private Path includeFile; + + @CommandLine.Option( + names = "--zk-host", + paramLabel = "HOST", + description = + "ZooKeeper connection string. If supplied, set urlScheme=https for the entire cluster.") + private String zkHost; + + /** Parameters for the SSL command, independent of the command line parser. */ + record SSLParams( + Path certificate, + Path privateKey, + Path passwordFile, + Path keyPasswordFile, + Path keystore, + String storeType, + Path includeFile, + String zkHost) {} + + public SSLTool() { + this(new DefaultToolRuntime()); + } + + public SSLTool(ToolRuntime runtime) { + super(runtime); + } + + @Override + public String getName() { + return "ssl"; + } + + @Override + public int callTool() throws Exception { + configure( + new SSLParams( + certificate, + privateKey, + passwordFile, + keyPasswordFile, + keystore, + storeType, + includeFile, + zkHost)); + echo("Restart Solr to enable HTTPS."); + if (zkHost == null) { + echo( + "No cluster property changed. For SolrCloud, set urlScheme=https with bin/solr cluster before restarting nodes."); + } + return 0; + } + + void configure(SSLParams params) throws Exception { + if (EnvUtils.getProperty("os.name", "").startsWith("Windows")) { + throw new UnsupportedOperationException( + "bin/solr ssl is not supported on Windows. Configure HTTPS manually using the Enabling SSL section of the Solr Reference Guide."); + } + String type = params.storeType().toUpperCase(Locale.ROOT); + if (!type.equals("JKS") && !type.equals("PKCS12")) { + throw new IllegalArgumentException("--store-type must be JKS or PKCS12."); Review Comment: okay, "PKCS12" is apparently better, and also the future... JKS is deprecated.. so let's not sue it anymore. -- 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]
