Skip to content

Commit e47b78b

Browse files
directdownload: fix keytool importcert (apache#11113)
* directdownload: fix keytool importcert ``` $ /usr/bin/keytool -importcert file /etc/cloudstack/agent/CSCERTIFICATE-full -keystore /etc/cloudstack/agent/cloud.jks -alias full -storepass DAWsfkJeeGrmhta6 Illegal option: file keytool -importcert [OPTION]... Imports a certificate or a certificate chain Options: -noprompt do not prompt -trustcacerts trust certificates from cacerts -protected password through protected mechanism -alias <alias> alias name of the entry to process -file <file> input file name -keypass <arg> key password -keystore <keystore> keystore name -cacerts access the cacerts keystore -storepass <arg> keystore password -storetype <type> keystore type -providername <name> provider name -addprovider <name> add security provider by name (e.g. SunPKCS11) [-providerarg <arg>] configure argument for -addprovider -providerclass <class> add security provider by fully-qualified class name [-providerarg <arg>] configure argument for -providerclass -providerpath <list> provider classpath -v verbose output Use "keytool -?, -h, or --help" for this help message ``` * DirectDownload: drop HttpsMultiTrustManager
1 parent 39c8c4d commit e47b78b

File tree

3 files changed

+6
-109
lines changed

3 files changed

+6
-109
lines changed

core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939

4040
import javax.net.ssl.HttpsURLConnection;
4141
import javax.net.ssl.SSLContext;
42-
import javax.net.ssl.TrustManager;
4342

44-
import org.apache.cloudstack.utils.security.SSLUtils;
4543
import org.apache.commons.collections.MapUtils;
4644
import org.apache.commons.httpclient.HttpStatus;
4745
import org.apache.commons.io.IOUtils;
@@ -55,6 +53,7 @@
5553
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
5654
import org.apache.http.impl.client.CloseableHttpClient;
5755
import org.apache.http.impl.client.HttpClients;
56+
import org.apache.http.ssl.SSLContexts;
5857
import org.apache.http.util.EntityUtils;
5958

6059
import com.cloud.utils.Pair;
@@ -120,10 +119,10 @@ private SSLContext getSSLContext() {
120119
String password = "changeit";
121120
defaultKeystore.load(is, password.toCharArray());
122121
}
123-
TrustManager[] tm = HttpsMultiTrustManager.getTrustManagersFromKeyStores(customKeystore, defaultKeystore);
124-
SSLContext sslContext = SSLUtils.getSSLContext();
125-
sslContext.init(null, tm, null);
126-
return sslContext;
122+
return SSLContexts.custom()
123+
.loadTrustMaterial(customKeystore, null)
124+
.loadTrustMaterial(defaultKeystore, null)
125+
.build();
127126
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | KeyManagementException e) {
128127
s_logger.error(String.format("Failure getting SSL context for HTTPS downloader, using default SSL context: %s", e.getMessage()), e);
129128
try {

core/src/main/java/org/apache/cloudstack/direct/download/HttpsMultiTrustManager.java

Lines changed: 0 additions & 102 deletions
This file was deleted.

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private String getKeyStoreFilePath(File agentFile) {
8686
private void importCertificate(String tempCerFilePath, String keyStoreFile, String certificateName, String privatePassword) {
8787
s_logger.debug("Importing certificate from temporary file to keystore");
8888
String keyToolPath = Script.getExecutableAbsolutePath("keytool");
89-
int result = Script.executeCommandForExitValue(keyToolPath, "-importcert", "file", tempCerFilePath,
89+
int result = Script.executeCommandForExitValue(keyToolPath, "-importcert", "-file", tempCerFilePath,
9090
"-keystore", keyStoreFile, "-alias", sanitizeBashCommandArgument(certificateName), "-storepass",
9191
privatePassword, "-noprompt");
9292
if (result != 0) {

0 commit comments

Comments
 (0)