Skip to content

Commit

Permalink
Fix output corruption in req command
Browse files Browse the repository at this point in the history
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 #22026)

(cherry picked from commit d287394)
  • Loading branch information
bernd-edlinger committed Sep 9, 2023
1 parent 0c4f6a4 commit a3e71dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions apps/req.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,10 +990,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;

Expand All @@ -1002,9 +1002,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) {
Expand Down
13 changes: 12 additions & 1 deletion test/recipes/25-test_req.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;

setup("test_req");

plan tests => 44;
plan tests => 46;

require_ok(srctop_file('test', 'recipes', 'tconversion.pl'));

Expand Down Expand Up @@ -473,3 +473,14 @@ my $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");

0 comments on commit a3e71dc

Please sign in to comment.