From f9dce0bf23a4e2e8b42cfa5137d850c4ea86fe76 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Thu, 19 Mar 2015 08:34:36 +0100 Subject: [PATCH] missed code in merge of Avoid distributing private key for realhostip.com --- .../com/cloud/consoleproxy/AgentHookBase.java | 22 ++++++++++--------- .../ConsoleProxySecureServerFactoryImpl.java | 21 ++++++++++-------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/server/src/com/cloud/consoleproxy/AgentHookBase.java b/server/src/com/cloud/consoleproxy/AgentHookBase.java index 05f2b4492bb..c3911826feb 100644 --- a/server/src/com/cloud/consoleproxy/AgentHookBase.java +++ b/server/src/com/cloud/consoleproxy/AgentHookBase.java @@ -17,9 +17,11 @@ package com.cloud.consoleproxy; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Date; -import java.util.Random; +import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; import com.google.gson.Gson; @@ -66,7 +68,6 @@ public abstract class AgentHookBase implements AgentHook { ConfigurationDao _configDao; AgentManager _agentMgr; KeystoreManager _ksMgr; - final Random _random = new Random(System.currentTimeMillis()); KeysManager _keysMgr; public AgentHookBase(VMInstanceDao instanceDao, HostDao hostDao, ConfigurationDao cfgDao, KeystoreManager ksMgr, AgentManager agentMgr, KeysManager keysMgr) { @@ -188,8 +189,6 @@ public abstract class AgentHookBase implements AgentHook { @Override public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) { StartConsoleProxyAgentHttpHandlerCommand cmd = null; - String storePassword = String.valueOf(_random.nextLong()); - byte[] ksBits = _ksMgr.getKeystoreBits(ConsoleProxyManager.CERTIFICATE_NAME, ConsoleProxyManager.CERTIFICATE_NAME, storePassword); try { SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); @@ -213,13 +212,16 @@ public abstract class AgentHookBase implements AgentHook { HostVO consoleProxyHost = findConsoleProxyHost(startupCmd); assert (consoleProxyHost != null); - - Answer answer = _agentMgr.send(consoleProxyHost.getId(), cmd); - if (answer == null || !answer.getResult()) { - s_logger.error("Console proxy agent reported that it failed to execute http handling startup command"); - } else { - s_logger.info("Successfully sent out command to start HTTP handling in console proxy agent"); + if (consoleProxyHost != null) { + Answer answer = _agentMgr.send(consoleProxyHost.getId(), cmd); + if (answer == null || !answer.getResult()) { + s_logger.error("Console proxy agent reported that it failed to execute http handling startup command"); + } else { + s_logger.info("Successfully sent out command to start HTTP handling in console proxy agent"); + } } + }catch (NoSuchAlgorithmException e) { + s_logger.error("Unexpected exception in SecureRandom Algorithm selection ", e); } catch (AgentUnavailableException e) { s_logger.error("Unable to send http handling startup command to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e); } catch (OperationTimedoutException e) { diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxySecureServerFactoryImpl.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxySecureServerFactoryImpl.java index d111527b51a..f28a9f40c18 100644 --- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxySecureServerFactoryImpl.java +++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxySecureServerFactoryImpl.java @@ -16,11 +16,10 @@ // under the License. package com.cloud.consoleproxy; -import com.sun.net.httpserver.HttpServer; -import com.sun.net.httpserver.HttpsConfigurator; -import com.sun.net.httpserver.HttpsParameters; -import com.sun.net.httpserver.HttpsServer; -import org.apache.cloudstack.utils.security.SSLUtils; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.security.KeyStore; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; @@ -28,10 +27,14 @@ import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.TrustManagerFactory; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.security.KeyStore; + +import org.apache.cloudstack.utils.security.SSLUtils; +import org.apache.log4j.Logger; + +import com.sun.net.httpserver.HttpServer; +import com.sun.net.httpserver.HttpsConfigurator; +import com.sun.net.httpserver.HttpsParameters; +import com.sun.net.httpserver.HttpsServer; public class ConsoleProxySecureServerFactoryImpl implements ConsoleProxyServerFactory { private static final Logger s_logger = Logger.getLogger(ConsoleProxySecureServerFactoryImpl.class);