diff --git a/agent/src/main/java/com/cloud/agent/AgentShell.java b/agent/src/main/java/com/cloud/agent/AgentShell.java index f5920a8e037..b693ce1b2b3 100644 --- a/agent/src/main/java/com/cloud/agent/AgentShell.java +++ b/agent/src/main/java/com/cloud/agent/AgentShell.java @@ -27,6 +27,7 @@ import com.cloud.utils.PropertiesUtil; import com.cloud.utils.backoff.BackoffAlgorithm; import com.cloud.utils.backoff.impl.ConstantTimeBackoff; import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.DaemonContext; import org.apache.commons.daemon.DaemonInitException; @@ -374,6 +375,7 @@ public class AgentShell implements IAgentShell, Daemon { loadProperties(); parseCommand(args); + enableSSL(); if (s_logger.isDebugEnabled()) { List properties = Collections.list((Enumeration)_properties.propertyNames()); @@ -397,6 +399,27 @@ public class AgentShell implements IAgentShell, Daemon { _backoff.configure("ConstantTimeBackoff", new HashMap()); } + private void enableSSL() { + final File agentFile = PropertiesUtil.findConfigFile("agent.properties"); + if (agentFile == null) { + s_logger.info("Failed to find agent.properties file"); + return; + } + String keystorePass = getProperty(null, "keystore.passphrase"); + if (StringUtils.isBlank(keystorePass)) { + s_logger.info("Failed to find passphrase for keystore: " + KeyStoreUtils.KS_FILENAME); + return; + } + final String keyStoreFile = agentFile.getParent() + "/" + KeyStoreUtils.KS_FILENAME; + File f = new File(keyStoreFile); + if (f.exists() && !f.isDirectory()) { + System.setProperty("javax.net.ssl.trustStore", keyStoreFile); + System.setProperty("javax.net.ssl.trustStorePassword", keystorePass); + } else { + s_logger.info("Failed to find keystore file: " + keyStoreFile); + } + } + private void launchAgent() throws ConfigurationException { String resourceClassNames = getProperty(null, "resource"); s_logger.trace("resource=" + resourceClassNames);