Skip to content

Commit 7b2f68e

Browse files
committed
CLOUDSTACK-3362: use POST instead of GET and encode/decode cert/key in uploadCustomCertificate
1 parent 5174b00 commit 7b2f68e

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
// under the License.
1717
package com.cloud.server;
1818

19+
import java.io.UnsupportedEncodingException;
1920
import java.lang.reflect.Field;
2021
import java.net.Inet6Address;
2122
import java.net.InetAddress;
2223
import java.net.URI;
2324
import java.net.URISyntaxException;
2425
import java.net.UnknownHostException;
26+
import java.net.URLDecoder;
2527
import java.security.NoSuchAlgorithmException;
2628
import java.security.SecureRandom;
2729
import java.util.ArrayList;
@@ -2808,18 +2810,32 @@ public String uploadCertificate(UploadCustomCertificateCmd cmd) {
28082810
}
28092811
}
28102812

2811-
if (cmd.getPrivateKey() != null && !_ksMgr.validateCertificate(cmd.getCertificate(), cmd.getPrivateKey(), cmd.getDomainSuffix())) {
2813+
String certificate = cmd.getCertificate();
2814+
String key = cmd.getPrivateKey();
2815+
try {
2816+
if (certificate != null)
2817+
certificate = URLDecoder.decode(certificate, "UTF-8");
2818+
if (key != null)
2819+
key = URLDecoder.decode(key, "UTF-8");
2820+
} catch (UnsupportedEncodingException e) {
2821+
} finally {
2822+
}
2823+
2824+
if (cmd.getPrivateKey() != null && !_ksMgr.validateCertificate(certificate, key, cmd.getDomainSuffix())) {
28122825
throw new InvalidParameterValueException("Failed to pass certificate validation check");
28132826
}
28142827

28152828
if (cmd.getPrivateKey() != null) {
2816-
_ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, cmd.getCertificate(), cmd.getPrivateKey(), cmd.getDomainSuffix());
2829+
_ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, certificate, key, cmd.getDomainSuffix());
28172830
} else {
2818-
_ksMgr.saveCertificate(cmd.getAlias(), cmd.getCertificate(), cmd.getCertIndex(), cmd.getDomainSuffix());
2831+
_ksMgr.saveCertificate(cmd.getAlias(), certificate, cmd.getCertIndex(), cmd.getDomainSuffix());
28192832
}
28202833

28212834
_consoleProxyMgr.setManagementState(ConsoleProxyManagementState.ResetSuspending);
2822-
return "Certificate has been updated, we will stop all running console proxy VMs to propagate the new certificate, please give a few minutes for console access service to be up again";
2835+
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, State.Running, State.Migrating, State.Starting);
2836+
for (SecondaryStorageVmVO ssVmVm : alreadyRunning)
2837+
_secStorageVmMgr.rebootSecStorageVm(ssVmVm.getId());
2838+
return "Certificate has been updated, we will stop all running console proxy VMs and secondary storage VMs to propagate the new certificate, please give a few minutes for console access service to be up again";
28232839
}
28242840

28252841
@Override

‎ui/scripts/ui-custom/physicalResources.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@
7777
var $loading = $('<div>').addClass('loading-overlay');
7878
$('.system-dashboard-view:visible').prepend($loading);
7979
$.ajax({
80+
type: "POST",
8081
url: createURL('uploadCustomCertificate'),
8182
data: {
82-
certificate: args.data.certificate,
83-
privatekey: args.data.privatekey,
83+
certificate: encodeURIComponent(args.data.certificate),
84+
privatekey: encodeURIComponent(args.data.privatekey),
8485
domainsuffix: args.data.domainsuffix
8586
},
8687
dataType: 'json',
@@ -130,4 +131,4 @@
130131
return resourceChart(args);
131132
};
132133
};
133-
}(cloudStack, jQuery));
134+
}(cloudStack, jQuery));

0 commit comments

Comments
 (0)