]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Use text compare for PEM and text files
authorJon Spillett <jon.spillett@oracle.com>
Tue, 18 Mar 2025 03:37:15 +0000 (13:37 +1000)
committerTomas Mraz <tomas@openssl.org>
Wed, 19 Mar 2025 10:48:49 +0000 (11:48 +0100)
- Fix ml_dsa_codecs test
- Fix ml_kem_codecs test
- Fix pkey test
- Fix dsaparam test
- Fix dhparam test
- Fix pkcs8 test

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27082)

test/recipes/15-test_dsaparam.t
test/recipes/15-test_ml_dsa_codecs.t
test/recipes/15-test_ml_kem_codecs.t
test/recipes/15-test_pkey.t
test/recipes/20-test_dhparam.t
test/recipes/25-test_pkcs8.t

index 5fd854c474dcde2a7af1ef9d28d54f84b5e84b40..abe561261d46869d5b2845ee0c0a9c35608a2780 100644 (file)
@@ -11,7 +11,7 @@ use warnings;
 
 use File::Spec;
 use File::Copy;
-use File::Compare qw/compare/;
+use File::Compare qw/compare_text/;
 use OpenSSL::Glob;
 use OpenSSL::Test qw/:DEFAULT data_file/;
 use OpenSSL::Test::Utils;
@@ -84,4 +84,4 @@ my $inout = "inout.pem";
 copy($input, $inout);
 ok(run(app(['openssl', 'dsaparam', '-in', $inout, '-out', $inout])),
     "identical infile and outfile");
-ok(!compare($input, $inout), "converted file $inout did not change");
+ok(!compare_text($input, $inout), "converted file $inout did not change");
index 9f4d5e595fa3597f43d303a3c8aea2f84a3dfc1b..527e39daf0a717123ca9081206be860a494ada85 100644 (file)
@@ -63,7 +63,7 @@ foreach my $alg (@algs) {
         ok(run(app(['openssl', 'genpkey', '-out', $pem,
                     '-pkeyopt', "hexseed:$seed", '-algorithm', "ml-dsa-$alg",
                     '-provparam', "ml-dsa.output_formats=$f"])));
-        ok(!compare($in, $pem),
+        ok(!compare_text($in, $pem),
             sprintf("prvkey PEM match: %s, %s", $alg, $f));
 
         ok(run(app(['openssl', 'pkey', '-in', $in, '-noout',
@@ -95,7 +95,7 @@ foreach my $alg (@algs) {
     ok(run(app([qw(openssl genpkey -provparam ml-dsa.retain_seed=no),
                 '-algorithm', "ml-dsa-$alg", '-pkeyopt', "hexseed:$seed",
                 '-out', $seedless])));
-    ok(!compare(data_file($formats{'priv-only'}), $seedless),
+    ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
         sprintf("seedless via cli key match: %s", $alg));
     {
         local $ENV{'OPENSSL_CONF'} = data_file("ml-dsa.cnf");
@@ -104,14 +104,14 @@ foreach my $alg (@algs) {
         ok(run(app(['openssl', 'genpkey',
                     '-algorithm', "ml-dsa-$alg", '-pkeyopt', "hexseed:$seed",
                     '-out', $seedless])));
-        ok(!compare(data_file($formats{'priv-only'}), $seedless),
+        ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
             sprintf("seedless via config match: %s", $alg));
 
         my $seedfull = sprintf("seedfull-%s.gen.conf+cli.pem", $alg);
         ok(run(app(['openssl', 'genpkey', '-provparam', 'ml-dsa.retain_seed=yes',
                     '-algorithm', "ml-dsa-$alg", '-pkeyopt', "hexseed:$seed",
                     '-out', $seedfull])));
-        ok(!compare(data_file($formats{'seed-priv'}), $seedfull),
+        ok(!compare_text(data_file($formats{'seed-priv'}), $seedfull),
             sprintf("seedfull via cli vs. conf key match: %s", $alg));
     }
 
@@ -120,7 +120,7 @@ foreach my $alg (@algs) {
     $seedless = sprintf("seedless-%s.dec.cli.pem", $alg);
     ok(run(app(['openssl', 'pkey', '-provparam', 'ml-dsa.retain_seed=no',
                 '-in', data_file($formats{'seed-only'}), '-out', $seedless])));
-    ok(!compare(data_file($formats{'priv-only'}), $seedless),
+    ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
         sprintf("seedless via provparam key match: %s", $alg));
     {
         local $ENV{'OPENSSL_CONF'} = data_file("ml-dsa.cnf");
@@ -128,13 +128,13 @@ foreach my $alg (@algs) {
         $seedless = sprintf("seedless-%s.dec.cnf.pem", $alg);
         ok(run(app(['openssl', 'pkey',
                     '-in', data_file($formats{'seed-only'}), '-out', $seedless])));
-        ok(!compare(data_file($formats{'priv-only'}), $seedless),
+        ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
             sprintf("seedless via config match: %s", $alg));
 
         my $seedfull = sprintf("seedfull-%s.dec.conf+cli.pem", $alg);
         ok(run(app(['openssl', 'pkey', '-provparam', 'ml-dsa.retain_seed=yes',
                     '-in', data_file($formats{'seed-only'}), '-out', $seedfull])));
-        ok(!compare(data_file($formats{'seed-priv'}), $seedfull),
+        ok(!compare_text(data_file($formats{'seed-priv'}), $seedfull),
             sprintf("seedfull via cli vs. conf key match: %s", $alg));
     }
 
@@ -143,7 +143,7 @@ foreach my $alg (@algs) {
     my $privpref = sprintf("privpref-%s.dec.cli.pem", $alg);
     ok(run(app(['openssl', 'pkey', '-provparam', 'ml-dsa.prefer_seed=no',
                 '-in', data_file($formats{'seed-priv'}), '-out', $privpref])));
-    ok(!compare(data_file($formats{'priv-only'}), $privpref),
+    ok(!compare_text(data_file($formats{'priv-only'}), $privpref),
         sprintf("seed non-preference via provparam key match: %s", $alg));
 
     # (2 * @formats) tests
@@ -154,7 +154,7 @@ foreach my $alg (@algs) {
         my $out = sprintf("prv-%s-%s.txt", $alg, $f);
         ok(run(app(['openssl', 'pkey', '-in', data_file($kf),
                     '-noout', '-text', '-out', $out])));
-        ok(!compare(data_file($txt), $out),
+        ok(!compare_text(data_file($txt), $out),
             sprintf("text form private key: %s with %s", $alg, $f));
     }
 
index 72e1b3333435d142201a33f1628232ef94a15b48..eaa9b2cad1e95cdcee61b30741e4d343e017ca98 100644 (file)
@@ -59,7 +59,7 @@ foreach my $alg (@algs) {
         ok(run(app(['openssl', 'genpkey', '-out', $pem,
                     '-pkeyopt', "hexseed:$seed", '-algorithm', "ml-kem-$alg",
                     '-provparam', "ml-kem.output_formats=$f"])));
-        ok(!compare($in, $pem),
+        ok(!compare_text($in, $pem),
             sprintf("prvkey PEM match: %s, %s", $alg, $f));
 
         ok(run(app(['openssl', 'pkey', '-in', $in, '-noout',
@@ -97,7 +97,7 @@ foreach my $alg (@algs) {
     ok(run(app(['openssl', 'genpkey', '-provparam', 'ml-kem.retain_seed=no',
                 '-algorithm', "ml-kem-$alg", '-pkeyopt', "hexseed:$seed",
                 '-out', $seedless])));
-    ok(!compare(data_file($formats{'priv-only'}), $seedless),
+    ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
         sprintf("seedless via cli key match: %s", $alg));
     {
         local $ENV{'OPENSSL_CONF'} = data_file("ml-kem.cnf");
@@ -106,14 +106,14 @@ foreach my $alg (@algs) {
         ok(run(app(['openssl', 'genpkey',
                     '-algorithm', "ml-kem-$alg", '-pkeyopt', "hexseed:$seed",
                     '-out', $seedless])));
-        ok(!compare(data_file($formats{'priv-only'}), $seedless),
+        ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
             sprintf("seedless via config match: %s", $alg));
 
         my $seedfull = sprintf("seedfull-%s.gen.conf+cli.pem", $alg);
         ok(run(app(['openssl', 'genpkey', '-provparam', 'ml-kem.retain_seed=yes',
                     '-algorithm', "ml-kem-$alg", '-pkeyopt', "hexseed:$seed",
                     '-out', $seedfull])));
-        ok(!compare(data_file($formats{'seed-priv'}), $seedfull),
+        ok(!compare_text(data_file($formats{'seed-priv'}), $seedfull),
             sprintf("seedfull via cli vs. conf key match: %s", $alg));
     }
 
@@ -122,7 +122,7 @@ foreach my $alg (@algs) {
     $seedless = sprintf("seedless-%s.dec.cli.pem", $alg);
     ok(run(app(['openssl', 'pkey', '-provparam', 'ml-kem.retain_seed=no',
                 '-in', data_file($formats{'seed-only'}), '-out', $seedless])));
-    ok(!compare(data_file($formats{'priv-only'}), $seedless),
+    ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
         sprintf("seedless via provparam key match: %s", $alg));
     {
         local $ENV{'OPENSSL_CONF'} = data_file("ml-kem.cnf");
@@ -130,13 +130,13 @@ foreach my $alg (@algs) {
         $seedless = sprintf("seedless-%s.dec.cnf.pem", $alg);
         ok(run(app(['openssl', 'pkey',
                     '-in', data_file($formats{'seed-only'}), '-out', $seedless])));
-        ok(!compare(data_file($formats{'priv-only'}), $seedless),
+        ok(!compare_text(data_file($formats{'priv-only'}), $seedless),
             sprintf("seedless via config match: %s", $alg));
 
         my $seedfull = sprintf("seedfull-%s.dec.conf+cli.pem", $alg);
         ok(run(app(['openssl', 'pkey', '-provparam', 'ml-kem.retain_seed=yes',
                     '-in', data_file($formats{'seed-only'}), '-out', $seedfull])));
-        ok(!compare(data_file($formats{'seed-priv'}), $seedfull),
+        ok(!compare_text(data_file($formats{'seed-priv'}), $seedfull),
             sprintf("seedfull via cli vs. conf key match: %s", $alg));
     }
 
@@ -145,7 +145,7 @@ foreach my $alg (@algs) {
     my $privpref = sprintf("privpref-%s.dec.cli.pem", $alg);
     ok(run(app(['openssl', 'pkey', '-provparam', 'ml-kem.prefer_seed=no',
                 '-in', data_file($formats{'seed-priv'}), '-out', $privpref])));
-    ok(!compare(data_file($formats{'priv-only'}), $privpref),
+    ok(!compare_text(data_file($formats{'priv-only'}), $privpref),
         sprintf("seed non-preference via provparam key match: %s", $alg));
 
     # (2 * @formats) tests
@@ -156,7 +156,7 @@ foreach my $alg (@algs) {
         my $out = sprintf("prv-%s-%s.txt", $alg, $f);
         ok(run(app(['openssl', 'pkey', '-in', data_file($k),
                     '-noout', '-text', '-out', $out])));
-        ok(!compare(data_file($txt), $out),
+        ok(!compare_text(data_file($txt), $out),
             sprintf("text form private key: %s with %s", $alg, $f));
     }
 
index 9242f49a5f267abc40cbb47099d4453a15b5f4b8..85b870f5a9e7c2b4ee67779e36b4d45d341040a0 100644 (file)
@@ -11,7 +11,7 @@ use warnings;
 
 use OpenSSL::Test::Utils;
 use File::Copy;
-use File::Compare qw(compare);
+use File::Compare qw(compare_text);
 use OpenSSL::Test qw/:DEFAULT srctop_file/;
 
 setup("test_pkey");
@@ -40,7 +40,7 @@ subtest "=== pkey typical en-/decryption (using AES256-CBC) ===" => sub {
     ok(run(app([@app, '-in', $encrypted_key, '-out', $decrypted_key,
                 '-passin', $pass])),
        "decrypt key");
-    is(compare($in_key, $decrypted_key), 0,
+    is(compare_text($in_key, $decrypted_key), 0,
        "Same file contents after encrypting and decrypting in separate files");
 };
 
@@ -61,7 +61,7 @@ subtest "=== pkey handling of identical input and output files (using 3DES) and
 
     ok(run(app([@app, '-in', $inout, '-out', $inout, '-passin', $pass])),
        "decrypt using identical infile and outfile");
-    is(compare($in_key, $inout), 0,
+    is(compare_text($in_key, $inout), 0,
        "Same file contents after encrypting and decrypting using same file");
 };
 
@@ -75,19 +75,19 @@ subtest "=== pkey handling of public keys (Ed25519) ===" => sub {
     my $pub_out1 = 'pub1.pem';
     ok(run(app([@app, '-in', $in_ed_key, '-pubout', '-out', $pub_out1])),
        "extract public key");
-    is(compare($in_pubkey, $pub_out1), 0,
+    is(compare_text($in_pubkey, $pub_out1), 0,
        "extracted public key is same as original public key");
 
     my $pub_out2 = 'pub2.pem';
     ok(run(app([@app, '-in', $in_pubkey, '-pubin', '-pubout', '-out', $pub_out2])),
        "read public key from pubfile");
-    is(compare($in_pubkey, $pub_out2), 0,
+    is(compare_text($in_pubkey, $pub_out2), 0,
        "public key read using pubfile is same as original public key");
 
     my $pub_out3 = 'pub3.pem';
     ok(run(app([@app, '-in', $in_ed_key, '-pubin', '-pubout', '-out', $pub_out3])),
        "extract public key from pkey file with -pubin");
-    is(compare($in_pubkey, $pub_out3), 0,
+    is(compare_text($in_pubkey, $pub_out3), 0,
        "public key extraced from pkey file with -pubin is same as original");
 };
 
@@ -108,7 +108,7 @@ subtest "=== pkey handling of DER encoding ===" => sub {
     ok(run(app([@app, '-in', $der_out, '-inform', 'DER',
                  '-out', $pem_out])),
        "read DER-encoded key");
-    is(compare($in_key, $pem_out), 0,
+    is(compare_text($in_key, $pem_out), 0,
        "Same file contents after converting to DER and back");
 };
 
index f81e74c5667c45eed9bc5d8db6dc3d9517042f8d..cfae79ab57b8e9aaae6cab9158edfccb77fbc845 100644 (file)
@@ -11,7 +11,7 @@ use strict;
 use warnings;
 
 use File::Copy;
-use File::Compare qw/compare/;
+use File::Compare qw/compare_text/;
 use OpenSSL::Test qw(:DEFAULT data_file srctop_file);
 use OpenSSL::Test::Utils;
 
@@ -221,4 +221,4 @@ my $inout = "inout.pem";
 copy($input, $inout);
 ok(run(app(['openssl', 'dhparam', '-in', $inout, '-out', $inout])),
     "identical infile and outfile");
-ok(!compare($input, $inout), "converted file $inout did not change");
+ok(!compare_text($input, $inout), "converted file $inout did not change");
index a0f8644744827e87185f9be37dcff36fb4dade2a..cb8a77dd3d0ced85c2862f859a7155ae9be5326d 100644 (file)
@@ -28,7 +28,7 @@ ok(run(app(['openssl', 'pkcs8', '-topk8', '-in', $inout,
 ok(run(app(['openssl', 'pkcs8', '-in', $inout,
             '-out', $inout, '-passin', 'pass:password'])),
    "identical infile and outfile, from PKCS#8");
-is(compare($pc5_key, $inout), 0,
+is(compare_text($pc5_key, $inout), 0,
    "Same file contents after converting forth and back");
 
 ok(run(app(([ 'openssl', 'pkcs8', '-topk8',