[Libguestfs] [PATCH v2 2/2] v2v: ova: support SHA256 hashes in manifest

Tomáš Golembiovský tgolembi at redhat.com
Wed Oct 5 10:51:06 UTC 2016


The OVF standard allows the use of SHA256 hashes in the manifest file.
Adding support for this.

Signed-off-by: Tomáš Golembiovský <tgolembi at redhat.com>
---
 v2v/input_ova.ml | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index 44e41ed..3c1a296 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. Line is \"%s\"")
-- 
2.10.0




More information about the Libguestfs mailing list