From f1bca106a8f5fc6a4b88b5ef30603cf31ea531f1 Mon Sep 17 00:00:00 2001 From: Brandon Wood Date: Sat, 23 Jan 2016 22:17:43 -0600 Subject: [PATCH] Added (optional) support for sha256 checksum utils This commit adds (optional) support for additional sha256 checksum utilities for newer versions of node.js and io.js that use sha256 checksums rather than sha1. If nothing is found to do a sha256 checksum on the client machine, a warning is printed and things continue on as normal. Following comments from @ljharb on incorporating some of @DomT4's PR creationix/nvm#664, and making this checksum optional. If I could I would gladly include this as an addon to the now closed PR creationix/nvm#664. I am choosing not to file it onto that PR because it's closed and (currently) significantly behind the master branch. @DomT4 did the hard work of actually finding all the different ways in which one could verify a sha256 checksum, I've just included those here in an effort to move forward with sha256 checksum support. --- nvm.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/nvm.sh b/nvm.sh index 0d68e45..f5dd8bd 100755 --- a/nvm.sh +++ b/nvm.sh @@ -772,14 +772,23 @@ nvm_checksum() { fi else if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then - NVM_CHECKSUM="$(command sha256sum "$1" | command awk '{print $1}')" + NVM_CHECKSUM="$(sha256sum "$1" | awk '{print $1}')" + elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then + NVM_CHECKSUM="$(shasum -a 256 "$1" | awk '{print $1}')" elif nvm_has "sha256" && ! nvm_is_alias "sha256"; then - NVM_CHECKSUM="$(command sha256 -q "$1")" + NVM_CHECKSUM="$(sha256 -q "$1" | awk '{print $1}')" elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then - NVM_CHECKSUM="$(gsha256sum "$1" | command awk '{print $1}')" + NVM_CHECKSUM="$(gsha256sum "$1" | awk '{print $1}')" + elif nvm_has "openssl" && ! nvm_is_alias "openssl"; then + NVM_CHECKSUM="$(openssl dgst -sha256 "$1" | rev | awk '{print $1}' | rev)" + elif nvm_has "libressl" && ! nvm_is_alias "libressl"; then + NVM_CHECKSUM="$(libressl dgst -sha256 "$1" | rev | awk '{print $1}' | rev)" + elif nvm_has "bssl" && ! nvm_is_alias "bssl"; then + NVM_CHECKSUM="$(bssl sha256sum "$1" | awk '{print $1}')" else echo "Unaliased sha256sum, sha256, or gsha256sum not found." >&2 - return 2 + echo "WARNING: Continuing *without checksum verification*" >&2 + return fi fi