Skip to content

Commit f9dce0b

Browse files
committed
missed code in merge of Avoid distributing private key for realhostip.com
1 parent c2dc53c commit f9dce0b

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

‎server/src/com/cloud/consoleproxy/AgentHookBase.java‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
package com.cloud.consoleproxy;
1919

20+
import java.security.NoSuchAlgorithmException;
21+
import java.security.SecureRandom;
2022
import java.util.Date;
21-
import java.util.Random;
2223

24+
import org.apache.commons.codec.binary.Base64;
2325
import org.apache.log4j.Logger;
2426

2527
import com.google.gson.Gson;
@@ -66,7 +68,6 @@ public abstract class AgentHookBase implements AgentHook {
6668
ConfigurationDao _configDao;
6769
AgentManager _agentMgr;
6870
KeystoreManager _ksMgr;
69-
final Random _random = new Random(System.currentTimeMillis());
7071
KeysManager _keysMgr;
7172

7273
public AgentHookBase(VMInstanceDao instanceDao, HostDao hostDao, ConfigurationDao cfgDao, KeystoreManager ksMgr, AgentManager agentMgr, KeysManager keysMgr) {
@@ -188,8 +189,6 @@ public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticat
188189
@Override
189190
public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) {
190191
StartConsoleProxyAgentHttpHandlerCommand cmd = null;
191-
String storePassword = String.valueOf(_random.nextLong());
192-
byte[] ksBits = _ksMgr.getKeystoreBits(ConsoleProxyManager.CERTIFICATE_NAME, ConsoleProxyManager.CERTIFICATE_NAME, storePassword);
193192

194193
try {
195194
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
@@ -213,13 +212,16 @@ public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) {
213212
HostVO consoleProxyHost = findConsoleProxyHost(startupCmd);
214213

215214
assert (consoleProxyHost != null);
216-
217-
Answer answer = _agentMgr.send(consoleProxyHost.getId(), cmd);
218-
if (answer == null || !answer.getResult()) {
219-
s_logger.error("Console proxy agent reported that it failed to execute http handling startup command");
220-
} else {
221-
s_logger.info("Successfully sent out command to start HTTP handling in console proxy agent");
215+
if (consoleProxyHost != null) {
216+
Answer answer = _agentMgr.send(consoleProxyHost.getId(), cmd);
217+
if (answer == null || !answer.getResult()) {
218+
s_logger.error("Console proxy agent reported that it failed to execute http handling startup command");
219+
} else {
220+
s_logger.info("Successfully sent out command to start HTTP handling in console proxy agent");
221+
}
222222
}
223+
}catch (NoSuchAlgorithmException e) {
224+
s_logger.error("Unexpected exception in SecureRandom Algorithm selection ", e);
223225
} catch (AgentUnavailableException e) {
224226
s_logger.error("Unable to send http handling startup command to the console proxy resource for proxy:" + startupCmd.getProxyVmId(), e);
225227
} catch (OperationTimedoutException e) {

‎services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxySecureServerFactoryImpl.java‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@
1616
// under the License.
1717
package com.cloud.consoleproxy;
1818

19-
import com.sun.net.httpserver.HttpServer;
20-
import com.sun.net.httpserver.HttpsConfigurator;
21-
import com.sun.net.httpserver.HttpsParameters;
22-
import com.sun.net.httpserver.HttpsServer;
23-
import org.apache.cloudstack.utils.security.SSLUtils;
19+
import java.io.ByteArrayInputStream;
20+
import java.io.IOException;
21+
import java.net.InetSocketAddress;
22+
import java.security.KeyStore;
2423

2524
import javax.net.ssl.KeyManagerFactory;
2625
import javax.net.ssl.SSLContext;
2726
import javax.net.ssl.SSLParameters;
2827
import javax.net.ssl.SSLServerSocket;
2928
import javax.net.ssl.SSLServerSocketFactory;
3029
import javax.net.ssl.TrustManagerFactory;
31-
import java.io.ByteArrayInputStream;
32-
import java.io.IOException;
33-
import java.net.InetSocketAddress;
34-
import java.security.KeyStore;
30+
31+
import org.apache.cloudstack.utils.security.SSLUtils;
32+
import org.apache.log4j.Logger;
33+
34+
import com.sun.net.httpserver.HttpServer;
35+
import com.sun.net.httpserver.HttpsConfigurator;
36+
import com.sun.net.httpserver.HttpsParameters;
37+
import com.sun.net.httpserver.HttpsServer;
3538

3639
public class ConsoleProxySecureServerFactoryImpl implements ConsoleProxyServerFactory {
3740
private static final Logger s_logger = Logger.getLogger(ConsoleProxySecureServerFactoryImpl.class);

0 commit comments

Comments
 (0)