Skip to content

Commit 97424f2

Browse files
committed
engine/schema: prepend algorithm to checksum during systemvm template registration
1 parent e23c7ef commit 97424f2

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ private VMTemplateVO createTemplateObjectInDB(SystemVMTemplateDetails details) {
513513
template.setBits(64);
514514
template.setAccountId(Account.ACCOUNT_ID_SYSTEM);
515515
template.setUrl(details.getUrl());
516-
template.setChecksum(details.getChecksum());
516+
template.setChecksum(DigestHelper.prependAlgorithm(details.getChecksum()));
517517
template.setEnablePassword(false);
518518
template.setDisplayText(details.getName());
519519
template.setFormat(details.getFormat());
@@ -1008,7 +1008,7 @@ private void updateRegisteredTemplateDetails(Long templateId, MetadataTemplateDe
10081008

10091009
private void updateTemplateUrlChecksumAndGuestOsId(VMTemplateVO templateVO, MetadataTemplateDetails templateDetails) {
10101010
templateVO.setUrl(templateDetails.getUrl());
1011-
templateVO.setChecksum(templateDetails.getChecksum());
1011+
templateVO.setChecksum(DigestHelper.prependAlgorithm(templateDetails.getChecksum()));
10121012
GuestOSVO guestOS = guestOSDao.findOneByDisplayName(templateDetails.getGuestOs());
10131013
if (guestOS != null) {
10141014
templateVO.setGuestOSId(guestOS.getId());

utils/src/main/java/org/apache/cloudstack/utils/security/DigestHelper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,18 @@ public static String calculateChecksum(File file) {
148148
throw new CloudRuntimeException(errMsg, e);
149149
}
150150
}
151+
152+
public static String prependAlgorithm(String checksum) {
153+
if (StringUtils.isEmpty(checksum)) {
154+
return checksum;
155+
}
156+
int checksumLength = checksum.length();
157+
for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) {
158+
if (entry.getValue().equals(checksumLength)) {
159+
String algorithm = entry.getKey();
160+
return String.format("{%s}%s", algorithm, checksum);
161+
}
162+
}
163+
return checksum;
164+
}
151165
}

0 commit comments

Comments
 (0)