From commits-return-71718-archive-asf-public=cust-asf.ponee.io@cloudstack.apache.org Wed Feb 7 10:48:55 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 47E3B18065B for ; Wed, 7 Feb 2018 10:48:55 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 36FA9160C5B; Wed, 7 Feb 2018 09:48:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7DA2C160C3C for ; Wed, 7 Feb 2018 10:48:54 +0100 (CET) Received: (qmail 26995 invoked by uid 500); 7 Feb 2018 09:48:53 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 26986 invoked by uid 99); 7 Feb 2018 09:48:53 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Feb 2018 09:48:53 +0000 From: GitBox To: commits@cloudstack.apache.org Subject: [GitHub] DaanHoogland closed pull request #2405: CLOUDSTACK-10146 checksum in java instead of script Message-ID: <151799693301.16372.16736146247788855275.gitbox@gitbox.apache.org> DaanHoogland closed pull request #2405: CLOUDSTACK-10146 checksum in java instead of script URL: https://github.com/apache/cloudstack/pull/2405 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/agent/src/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java b/agent/src/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java index 3b6bc9a6dd3..e120d847b17 100644 --- a/agent/src/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java +++ b/agent/src/com/cloud/agent/direct/download/DirectTemplateDownloaderImpl.java @@ -20,10 +20,13 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; -import org.apache.cloudstack.utils.security.ChecksumValue; +import org.apache.cloudstack.utils.security.DigestHelper; import org.apache.commons.lang.StringUtils; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.security.NoSuchAlgorithmException; import java.util.UUID; public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDownloader { @@ -149,36 +152,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,e); + } catch (NoSuchAlgorithmException e) { + throw new CloudRuntimeException("Unknown checksum algorithm: " + checksum, e); + } } return true; } ---------------------------------------------------------------- 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: users@infra.apache.org With regards, Apache Git Services