Test HMAC output from the dgst CLI
authorMatt Caswell <matt@openssl.org>
Mon, 14 Sep 2020 15:13:54 +0000 (16:13 +0100)
committerDmitry Belyavskiy <beldmit@gmail.com>
Thu, 17 Sep 2020 08:12:08 +0000 (11:12 +0300)
We run two HMAC operations on the same file and confirm that both provide
us with the expected values.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/12850)

test/recipes/20-test_dgst.t

index 0b7ab2d5d1e5a622d83bae1f8c412ea160f9ee0d..9dcf6d31a21096a14e84998c1575b2f4fa752ae5 100644 (file)
@@ -17,7 +17,7 @@ use OpenSSL::Test::Utils;
 
 setup("test_dgst");
 
-plan tests => 5;
+plan tests => 6;
 
 sub tsignverify {
     my $testtext = shift;
@@ -102,3 +102,17 @@ SKIP: {
                     srctop_file("test","tested448pub.pem"));
     };
 }
+
+subtest "HMAC generation with `dgst` CLI" => sub {
+    plan tests => 2;
+
+    my $testdata = srctop_file('test', 'data.txt');
+    #HMAC the data twice to check consistency
+    my @hmacdata = run(app(['openssl', 'dgst', '-sha256', '-hmac', '123456',
+                            $testdata, $testdata]), capture => 1);
+    chomp(@hmacdata);
+    my $expected = qr/HMAC-SHA256\([^\)]*data.txt\)= 6f12484129c4a761747f13d8234a1ff0e074adb34e9e9bf3a155c391b97b9a7c/;
+    ok($hmacdata[0] =~ $expected, "HMAC: Check HMAC value is as expected ($hmacdata[0]) vs ($expected)");
+    ok($hmacdata[1] =~ $expected,
+       "HMAC: Check second HMAC value is consistent with the first ($hmacdata[1]) vs ($expected)");
+};