engine/schema: prepend algorithm to checksum during systemvm template registration (#12165)

* engine/schema: prepend algorithm to checksum during systemvm template registration

* Update utils/src/main/java/org/apache/cloudstack/utils/security/DigestHelper.java
This commit is contained in:
Wei Zhou 2026-01-30 08:01:50 +01:00 committed by GitHub
parent 29ce03e946
commit 81f16b6261
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -513,7 +513,7 @@ public class SystemVmTemplateRegistration {
template.setBits(64);
template.setAccountId(Account.ACCOUNT_ID_SYSTEM);
template.setUrl(details.getUrl());
template.setChecksum(details.getChecksum());
template.setChecksum(DigestHelper.prependAlgorithm(details.getChecksum()));
template.setEnablePassword(false);
template.setDisplayText(details.getName());
template.setFormat(details.getFormat());
@ -1008,7 +1008,7 @@ public class SystemVmTemplateRegistration {
private void updateTemplateUrlChecksumAndGuestOsId(VMTemplateVO templateVO, MetadataTemplateDetails templateDetails) {
templateVO.setUrl(templateDetails.getUrl());
templateVO.setChecksum(templateDetails.getChecksum());
templateVO.setChecksum(DigestHelper.prependAlgorithm(templateDetails.getChecksum()));
GuestOSVO guestOS = guestOSDao.findOneByDisplayName(templateDetails.getGuestOs());
if (guestOS != null) {
templateVO.setGuestOSId(guestOS.getId());

View File

@ -142,4 +142,19 @@ public class DigestHelper {
throw new CloudRuntimeException(errMsg, e);
}
}
public static String prependAlgorithm(String checksum) {
if (StringUtils.isEmpty(checksum)) {
return checksum;
}
int checksumLength = checksum.length();
Map<String, Integer> paddingLengths = getChecksumLengthsMap();
for (Map.Entry<String, Integer> entry : paddingLengths.entrySet()) {
if (entry.getValue().equals(checksumLength)) {
String algorithm = entry.getKey();
return String.format("{%s}%s", algorithm, checksum);
}
}
return checksum;
}
}