From 0dfdbe064c380b23ab991cca001e24c583cb0452 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 4 Oct 2017 09:53:49 +0530 Subject: [PATCH] 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 --- .../apache/cloudstack/ca/provider/RootCAProvider.java | 2 +- .../cloudstack/ca/provider/RootCAProviderTest.java | 4 ++-- .../debian/config/opt/cloud/bin/patchsystemvm.sh | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/ca/root-ca/src/org/apache/cloudstack/ca/provider/RootCAProvider.java b/plugins/ca/root-ca/src/org/apache/cloudstack/ca/provider/RootCAProvider.java index 1f39853568b..f21cae38d79 100644 --- a/plugins/ca/root-ca/src/org/apache/cloudstack/ca/provider/RootCAProvider.java +++ b/plugins/ca/root-ca/src/org/apache/cloudstack/ca/provider/RootCAProvider.java @@ -249,7 +249,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con TrustManager[] tms = new TrustManager[]{new RootCACustomTrustManager(remoteAddress, authStrictness, allowExpiredCertificate, certMap, caCertificate, crlDao)}; sslContext.init(kmf.getKeyManagers(), tms, new SecureRandom()); final SSLEngine sslEngine = sslContext.createSSLEngine(); - sslEngine.setWantClientAuth(authStrictness); + sslEngine.setNeedClientAuth(authStrictness); return sslEngine; } diff --git a/plugins/ca/root-ca/test/org/apache/cloudstack/ca/provider/RootCAProviderTest.java b/plugins/ca/root-ca/test/org/apache/cloudstack/ca/provider/RootCAProviderTest.java index bdd3f08ddfe..44e2bcfcc49 100644 --- a/plugins/ca/root-ca/test/org/apache/cloudstack/ca/provider/RootCAProviderTest.java +++ b/plugins/ca/root-ca/test/org/apache/cloudstack/ca/provider/RootCAProviderTest.java @@ -136,7 +136,7 @@ public class RootCAProviderTest { overrideDefaultConfigValue(RootCAProvider.rootCAAuthStrictness, "_defaultValue", "false"); final SSLEngine e = provider.createSSLEngine(SSLUtils.getSSLContext(), "/1.2.3.4:5678", null); Assert.assertFalse(e.getUseClientMode()); - Assert.assertFalse(e.getWantClientAuth()); + Assert.assertFalse(e.getNeedClientAuth()); } @Test @@ -144,7 +144,7 @@ public class RootCAProviderTest { overrideDefaultConfigValue(RootCAProvider.rootCAAuthStrictness, "_defaultValue", "true"); final SSLEngine e = provider.createSSLEngine(SSLUtils.getSSLContext(), "/1.2.3.4:5678", null); Assert.assertFalse(e.getUseClientMode()); - Assert.assertTrue(e.getWantClientAuth()); + Assert.assertTrue(e.getNeedClientAuth()); } @Test diff --git a/systemvm/patches/debian/config/opt/cloud/bin/patchsystemvm.sh b/systemvm/patches/debian/config/opt/cloud/bin/patchsystemvm.sh index 9222a8c89b7..34450dc08ca 100755 --- a/systemvm/patches/debian/config/opt/cloud/bin/patchsystemvm.sh +++ b/systemvm/patches/debian/config/opt/cloud/bin/patchsystemvm.sh @@ -21,10 +21,21 @@ logfile="/var/log/patchsystemvm.log" # To use existing console proxy .zip-based package file patch_console_proxy() { local patchfile=$1 + local backupfolder="/tmp/.conf.backup" + if [ -f /usr/local/cloud/systemvm/conf/cloud.jks ]; then + rm -fr $backupfolder + mkdir -p $backupfolder + cp -r /usr/local/cloud/systemvm/conf/* $backupfolder/ + fi rm /usr/local/cloud/systemvm -rf mkdir -p /usr/local/cloud/systemvm echo "All" | unzip $patchfile -d /usr/local/cloud/systemvm >$logfile 2>&1 find /usr/local/cloud/systemvm/ -name \*.sh | xargs chmod 555 + if [ -f $backupfolder/cloud.jks ]; then + cp -r $backupfolder/* /usr/local/cloud/systemvm/conf/ + echo "Restored keystore file and certs using backup" >> $logfile + fi + rm -fr $backupfolder return 0 }