Skip to content

Commit 838cfa2

Browse files
committed
CLOUDSTACK-3362: use POST instead of GET and encode/decode cert/key in uploadCustomCertificate
1 parent f3a2fc2 commit 838cfa2

2 files changed

Lines changed: 23 additions & 6 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,7 +16,9 @@
1616
// under the License.
1717
package com.cloud.server;
1818

19+
import java.io.UnsupportedEncodingException;
1920
import java.lang.reflect.Field;
21+
import java.net.URLDecoder;
2022
import java.security.NoSuchAlgorithmException;
2123
import java.security.SecureRandom;
2224
import java.util.ArrayList;
@@ -3301,18 +3303,32 @@ public String uploadCertificate(UploadCustomCertificateCmd cmd) {
33013303
}
33023304
}
33033305

3304-
if (cmd.getPrivateKey() != null && !_ksMgr.validateCertificate(cmd.getCertificate(), cmd.getPrivateKey(), cmd.getDomainSuffix())) {
3306+
String certificate = cmd.getCertificate();
3307+
String key = cmd.getPrivateKey();
3308+
try {
3309+
if (certificate != null)
3310+
certificate = URLDecoder.decode(certificate, "UTF-8");
3311+
if (key != null)
3312+
key = URLDecoder.decode(key, "UTF-8");
3313+
} catch (UnsupportedEncodingException e) {
3314+
} finally {
3315+
}
3316+
3317+
if (cmd.getPrivateKey() != null && !_ksMgr.validateCertificate(certificate, key, cmd.getDomainSuffix())) {
33053318
throw new InvalidParameterValueException("Failed to pass certificate validation check");
33063319
}
33073320

33083321
if (cmd.getPrivateKey() != null) {
3309-
_ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, cmd.getCertificate(), cmd.getPrivateKey(), cmd.getDomainSuffix());
3322+
_ksMgr.saveCertificate(ConsoleProxyManager.CERTIFICATE_NAME, certificate, key, cmd.getDomainSuffix());
33103323
} else {
3311-
_ksMgr.saveCertificate(cmd.getAlias(), cmd.getCertificate(), cmd.getCertIndex(), cmd.getDomainSuffix());
3324+
_ksMgr.saveCertificate(cmd.getAlias(), certificate, cmd.getCertIndex(), cmd.getDomainSuffix());
33123325
}
33133326

33143327
_consoleProxyMgr.setManagementState(ConsoleProxyManagementState.ResetSuspending);
3315-
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";
3328+
List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, State.Running, State.Migrating, State.Starting);
3329+
for (SecondaryStorageVmVO ssVmVm : alreadyRunning)
3330+
_secStorageVmMgr.rebootSecStorageVm(ssVmVm.getId());
3331+
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";
33163332
}
33173333

33183334
@Override

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@
8080
var $loading = $('<div>').addClass('loading-overlay');
8181
$('.system-dashboard-view:visible').prepend($loading);
8282
$.ajax({
83+
type: "POST",
8384
url: createURL('uploadCustomCertificate'),
8485
data: {
85-
certificate: args.data.certificate,
86-
privatekey: args.data.privatekey,
86+
certificate: encodeURIComponent(args.data.certificate),
87+
privatekey: encodeURIComponent(args.data.privatekey),
8788
domainsuffix: args.data.domainsuffix
8889
},
8990
dataType: 'json',

0 commit comments

Comments
 (0)