Skip to content

Commit 769b557

Browse files
committed
pkcs7: allow recipient's certificate to be omitted for PKCS7#decrypt
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
1 parent b8b8f74 commit 769b557

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

ext/openssl/ossl_pkcs7.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ ossl_pkcs7_decrypt(int argc, VALUE *argv, VALUE self)
803803
BIO *out;
804804
VALUE str;
805805

806-
rb_scan_args(argc, argv, "21", &pkey, &cert, &flags);
806+
rb_scan_args(argc, argv, "12", &pkey, &cert, &flags);
807807
key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */
808-
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
808+
x509 = NIL_P(cert) ? NULL : GetX509CertPtr(cert); /* NO NEED TO DUP */
809809
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
810810
GetPKCS7(self, p7);
811811
if(!(out = BIO_new(BIO_s_mem())))

test/test_pkcs7.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def test_enveloped
133133
assert_equal(@ca_cert.subject.to_s, recip[1].issuer.to_s)
134134
assert_equal(3, recip[1].serial)
135135
assert_equal(data, p7.decrypt(@rsa1024, @ee2_cert))
136+
137+
assert_equal(data, p7.decrypt(@rsa1024))
136138
end
137139

138140
def test_graceful_parsing_failure #[ruby-core:43250]

0 commit comments

Comments
 (0)