Skip to content

Commit 0dfdbe0

Browse files
authored
CLOUDSTACK-9993: With auth strictness stop SSL handshake for rogue clients (#2278)
When auth strictness is set to true, terminate SSH handshake for clients that do not present valid certificates. This uses the `setNeedClientAuth`, where if the option is set and the client chooses not to provide authentication information about itself, the negotiations will stop and the engine will begin its closure procedure: https://docs.oracle.com/javase/7/docs/api/javax/net/ssl/SSLEngine.html#setNeedClientAuth(boolean) During systemvm reboot, the conf folder is removed and certificate re-setup is not done. This may cause the agent to not connect, this fixes the case by backing up and restoring keystore and other config files when re-patching is done after rebooting of a systemvm (cpvm, ssvm). Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 74ec9ce commit 0dfdbe0

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

plugins/ca/root-ca/src/org/apache/cloudstack/ca/provider/RootCAProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public SSLEngine createSSLEngine(final SSLContext sslContext, final String remot
249249
TrustManager[] tms = new TrustManager[]{new RootCACustomTrustManager(remoteAddress, authStrictness, allowExpiredCertificate, certMap, caCertificate, crlDao)};
250250
sslContext.init(kmf.getKeyManagers(), tms, new SecureRandom());
251251
final SSLEngine sslEngine = sslContext.createSSLEngine();
252-
sslEngine.setWantClientAuth(authStrictness);
252+
sslEngine.setNeedClientAuth(authStrictness);
253253
return sslEngine;
254254
}
255255

plugins/ca/root-ca/test/org/apache/cloudstack/ca/provider/RootCAProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ public void testCreateSSLEngineWithoutAuthStrictness() throws Exception {
136136
overrideDefaultConfigValue(RootCAProvider.rootCAAuthStrictness, "_defaultValue", "false");
137137
final SSLEngine e = provider.createSSLEngine(SSLUtils.getSSLContext(), "/1.2.3.4:5678", null);
138138
Assert.assertFalse(e.getUseClientMode());
139-
Assert.assertFalse(e.getWantClientAuth());
139+
Assert.assertFalse(e.getNeedClientAuth());
140140
}
141141

142142
@Test
143143
public void testCreateSSLEngineWithAuthStrictness() throws Exception {
144144
overrideDefaultConfigValue(RootCAProvider.rootCAAuthStrictness, "_defaultValue", "true");
145145
final SSLEngine e = provider.createSSLEngine(SSLUtils.getSSLContext(), "/1.2.3.4:5678", null);
146146
Assert.assertFalse(e.getUseClientMode());
147-
Assert.assertTrue(e.getWantClientAuth());
147+
Assert.assertTrue(e.getNeedClientAuth());
148148
}
149149

150150
@Test

systemvm/patches/debian/config/opt/cloud/bin/patchsystemvm.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ logfile="/var/log/patchsystemvm.log"
2121
# To use existing console proxy .zip-based package file
2222
patch_console_proxy() {
2323
local patchfile=$1
24+
local backupfolder="/tmp/.conf.backup"
25+
if [ -f /usr/local/cloud/systemvm/conf/cloud.jks ]; then
26+
rm -fr $backupfolder
27+
mkdir -p $backupfolder
28+
cp -r /usr/local/cloud/systemvm/conf/* $backupfolder/
29+
fi
2430
rm /usr/local/cloud/systemvm -rf
2531
mkdir -p /usr/local/cloud/systemvm
2632
echo "All" | unzip $patchfile -d /usr/local/cloud/systemvm >$logfile 2>&1
2733
find /usr/local/cloud/systemvm/ -name \*.sh | xargs chmod 555
34+
if [ -f $backupfolder/cloud.jks ]; then
35+
cp -r $backupfolder/* /usr/local/cloud/systemvm/conf/
36+
echo "Restored keystore file and certs using backup" >> $logfile
37+
fi
38+
rm -fr $backupfolder
2839
return 0
2940
}
3041

0 commit comments

Comments
 (0)