]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix output corruption in req command
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 8 Sep 2023 08:33:24 +0000 (10:33 +0200)
committerBernd Edlinger <bernd.edlinger@hotmail.de>
Sat, 9 Sep 2023 14:44:33 +0000 (16:44 +0200)
when used in conjunction with -out and -modulus options.

Fixes #21403

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22026)

apps/req.c
test/recipes/25-test_req.t

index e65bdad9b6fe9fd6053bac5b2fa6dfa9c0117068..c4c9ba292cb057a78c9b159e714daed148350575 100644 (file)
@@ -973,10 +973,10 @@ int req_main(int argc, char **argv)
         else
             tpubkey = X509_REQ_get0_pubkey(req);
         if (tpubkey == NULL) {
-            fprintf(stdout, "Modulus is unavailable\n");
+            BIO_puts(bio_err, "Modulus is unavailable\n");
             goto end;
         }
-        fprintf(stdout, "Modulus=");
+        BIO_puts(out, "Modulus=");
         if (EVP_PKEY_is_a(tpubkey, "RSA") || EVP_PKEY_is_a(tpubkey, "RSA-PSS")) {
             BIGNUM *n = NULL;
 
@@ -985,9 +985,9 @@ int req_main(int argc, char **argv)
             BN_print(out, n);
             BN_free(n);
         } else {
-            fprintf(stdout, "Wrong Algorithm type");
+            BIO_puts(out, "Wrong Algorithm type");
         }
-        fprintf(stdout, "\n");
+        BIO_puts(out, "\n");
     }
 
     if (!noout && !gen_x509) {
index 07a5975655a52e426e4e3d7e2b8d63cf7ca3e524..32dc4ded8c89961525b916bada32f2db7f8d47c9 100644 (file)
@@ -15,7 +15,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;
 
 setup("test_req");
 
-plan tests => 102;
+plan tests => 104;
 
 require_ok(srctop_file('test', 'recipes', 'tconversion.pl'));
 
@@ -590,3 +590,14 @@ $cert = "self-signed_CA_with_keyUsages.pem";
 generate_cert($cert, "-in", srctop_file(@certs, "ext-check.csr"),
     "-copy_extensions", "copy");
 has_keyUsage($cert, 1);
+
+# Generate cert using req with '-modulus'
+ok(run(app(["openssl", "req", "-x509", "-new", "-days", "365",
+            "-key", srctop_file("test", "testrsa.pem"),
+            "-config", srctop_file('test', 'test.cnf'),
+            "-out", "testreq-cert.pem",
+            "-modulus"])), "cert req creation - with -modulus");
+
+# Verify cert
+ok(run(app(["openssl", "x509", "-in", "testreq-cert.pem",
+            "-noout", "-text"])), "cert verification");