From 97424f276626c6bbd945a2a351e1d71c79e4ac41 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Fri, 28 Nov 2025 14:45:11 +0100 Subject: [PATCH] engine/schema: prepend algorithm to checksum during systemvm template registration --- .../upgrade/SystemVmTemplateRegistration.java | 4 ++-- .../cloudstack/utils/security/DigestHelper.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java b/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java index 9b1420f22c37..85ea84c7c4e1 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java @@ -513,7 +513,7 @@ private VMTemplateVO createTemplateObjectInDB(SystemVMTemplateDetails details) { 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 @@ private void updateRegisteredTemplateDetails(Long templateId, MetadataTemplateDe 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()); diff --git a/utils/src/main/java/org/apache/cloudstack/utils/security/DigestHelper.java b/utils/src/main/java/org/apache/cloudstack/utils/security/DigestHelper.java index 4b57ec2dad0e..b9824941d4fc 100644 --- a/utils/src/main/java/org/apache/cloudstack/utils/security/DigestHelper.java +++ b/utils/src/main/java/org/apache/cloudstack/utils/security/DigestHelper.java @@ -148,4 +148,18 @@ public static String calculateChecksum(File file) { throw new CloudRuntimeException(errMsg, e); } } + + public static String prependAlgorithm(String checksum) { + if (StringUtils.isEmpty(checksum)) { + return checksum; + } + int checksumLength = checksum.length(); + for (Map.Entry entry : paddingLengths.entrySet()) { + if (entry.getValue().equals(checksumLength)) { + String algorithm = entry.getKey(); + return String.format("{%s}%s", algorithm, checksum); + } + } + return checksum; + } }