From 52a8202635b22557416b8aa19ca44557c8e5c168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Date: Fri, 7 Oct 2016 14:12:22 +0200 Subject: [PATCH] v2v: ova: support SHA256 hashes in manifest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OVF standard allows the use of SHA256 hashes in the manifest file. Adding support for this. One of the tests was updated to put SHA256 into manifest file. Signed-off-by: Tomáš Golembiovský --- test-data/guestfs-hashsums.sh | 13 +++++++++++++ v2v/input_ova.ml | 13 +++++++------ v2v/test-v2v-i-ova.sh | 4 ++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/test-data/guestfs-hashsums.sh b/test-data/guestfs-hashsums.sh index 96e1238ec..86a5aaf12 100755 --- a/test-data/guestfs-hashsums.sh +++ b/test-data/guestfs-hashsums.sh @@ -41,3 +41,16 @@ do_sha1 () ;; esac } + +do_sha256 () +{ + case "$(uname)" in + Linux) + sha256sum "$1" | awk '{print $1}' + ;; + *) + echo "$0: unknown method to calculate SHA256 of file on $(uname)" + exit 1 + ;; + esac +} diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml index 0d0465967..0eb37d4d1 100644 --- a/v2v/input_ova.ml +++ b/v2v/input_ova.ml @@ -133,7 +133,7 @@ object (* Read any .mf (manifest) files and verify sha1. *) let mf = find_files exploded ".mf" in - let rex = Str.regexp "SHA1(\\(.*\\))= \\([0-9a-fA-F]+\\)\r?" in + let rex = Str.regexp "\\(SHA1\\|SHA256\\)(\\(.*\\))= \\([0-9a-fA-F]+\\)\r?" in List.iter ( fun mf -> debug "processing manifest %s" mf; @@ -142,13 +142,14 @@ object let rec loop () = let line = input_line chan in if Str.string_match rex line 0 then ( - let disk = Str.matched_group 1 line in - let expected = Str.matched_group 2 line in - let csum = Checksums.SHA1 expected in + let mode = Str.matched_group 1 line in + let disk = Str.matched_group 2 line in + let expected = Str.matched_group 3 line in + let csum = Checksums.of_string mode expected in try Checksums.verify_checksum csum (mf_folder // disk) with Checksums.Mismatched_checksum (_, actual) -> - error (f_"checksum of disk %s does not match manifest %s (actual sha1(%s) = %s, expected sha1 (%s) = %s)") - disk mf disk actual disk expected; + error (f_"checksum of disk %s does not match manifest %s (actual %s(%s) = %s, expected %s(%s) = %s)") + disk mf mode disk actual mode disk expected; ) else warning (f_"unable to parse line from manifest file: %S") line diff --git a/v2v/test-v2v-i-ova.sh b/v2v/test-v2v-i-ova.sh index ea4f3df45..716cd3395 100755 --- a/v2v/test-v2v-i-ova.sh +++ b/v2v/test-v2v-i-ova.sh @@ -57,8 +57,8 @@ qemu-img convert $f -O vmdk $d/$vmdk cp $ovf $d/$ovf sha1=`do_sha1 $d/$ovf` echo "SHA1($ovf)= $sha1" > $d/$mf -sha1=`do_sha1 $d/$vmdk` -echo "SHA1($vmdk)= $sha1" >> $d/$mf +sha256=`do_sha256 $d/$vmdk` +echo "SHA256($vmdk)= $sha256" >> $d/$mf pushd . cd $d