Skip to content

Commit

Permalink
pkcs7: allow recipient's certificate to be omitted for PKCS7#decrypt
Browse files Browse the repository at this point in the history
The recipient's certificate is not mandatory for PKCS7_decrypt(). Make
it possible to call OpenSSL::PKCS7#decrypt with only the private key to
match the functionality.

Reference: #182
  • Loading branch information
rhenium committed Jan 4, 2018
1 parent b8b8f74 commit 769b557
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/openssl/ossl_pkcs7.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,9 @@ ossl_pkcs7_decrypt(int argc, VALUE *argv, VALUE self)
BIO *out;
VALUE str;

rb_scan_args(argc, argv, "21", &pkey, &cert, &flags);
rb_scan_args(argc, argv, "12", &pkey, &cert, &flags);
key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
x509 = NIL_P(cert) ? NULL : GetX509CertPtr(cert); /* NO NEED TO DUP */
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
GetPKCS7(self, p7);
if(!(out = BIO_new(BIO_s_mem())))
Expand Down
2 changes: 2 additions & 0 deletions test/test_pkcs7.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def test_enveloped
assert_equal(@ca_cert.subject.to_s, recip[1].issuer.to_s)
assert_equal(3, recip[1].serial)
assert_equal(data, p7.decrypt(@rsa1024, @ee2_cert))

assert_equal(data, p7.decrypt(@rsa1024))
end

def test_graceful_parsing_failure #[ruby-core:43250]
Expand Down

0 comments on commit 769b557

Please sign in to comment.