[ https://issues.apache.org/jira/browse/CLOUDSTACK-10146?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16326835#comment-16326835 ]
ASF GitHub Bot commented on CLOUDSTACK-10146: --------------------------------------------- marcaurele commented on a change in pull request #2405: CLOUDSTACK-10146 checksum in java instead of script URL: https://github.com/apache/cloudstack/pull/2405#discussion_r161675698 ########## File path: agent/src/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java ########## @@ -149,36 +154,16 @@ public DirectTemplateInformation getTemplateInformation() { return new DirectTemplateInformation(installPath, size, checksum); } - /** - * Return checksum command from algorithm - */ - private String getChecksumCommandFromAlgorithm(String algorithm) { - if (algorithm.equalsIgnoreCase("MD5")) { - return "md5sum"; - } else if (algorithm.equalsIgnoreCase("SHA-1")) { - return "sha1sum"; - } else if (algorithm.equalsIgnoreCase("SHA-224")) { - return "sha224sum"; - } else if (algorithm.equalsIgnoreCase("SHA-256")) { - return "sha256sum"; - } else if (algorithm.equalsIgnoreCase("SHA-384")) { - return "sha384sum"; - } else if (algorithm.equalsIgnoreCase("SHA-512")) { - return "sha512sum"; - } else { - throw new CloudRuntimeException("Unknown checksum algorithm: " + algorithm); - } - } - @Override public boolean validateChecksum() { if (StringUtils.isNotBlank(checksum)) { - ChecksumValue providedChecksum = new ChecksumValue(checksum); - String algorithm = providedChecksum.getAlgorithm(); - String checksumCommand = "echo '%s %s' | %s -c --quiet"; - String cmd = String.format(checksumCommand, providedChecksum.getChecksum(), downloadedFilePath, getChecksumCommandFromAlgorithm(algorithm)); - int result = Script.runSimpleBashScriptForExitValue(cmd); - return result == 0; + try { + return DigestHelper.check(checksum, new FileInputStream(downloadedFilePath)); + } catch (IOException e) { + throw new CloudRuntimeException("could not check sum for file: " + downloadedFilePath); Review comment: IMO if the exception is due to some system/programming problem, the stack should be given to give a clear hint to people where to look for the error in the code. If the exception is aimed at the end user (API end user), then it does not make sens as it is a purely parameter, state,... error. So i'll keep the root cause for the NoSuchAlgorithmException. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Bypass Secondary Storage for KVM templates > ------------------------------------------ > > Key: CLOUDSTACK-10146 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10146 > Project: CloudStack > Issue Type: Bug > Security Level: Public(Anyone can view this level - this is the > default.) > Affects Versions: 4.11.0.0 > Reporter: Nicolas Vazquez > Assignee: Nicolas Vazquez > Priority: Major > -- This message was sent by Atlassian JIRA (v7.6.3#76005)