mirror of https://github.com/apache/cloudstack.git
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:
parent
29ce03e946
commit
81f16b6261
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue