Skip to content

Commit f7c51a2

Browse files
committed
pkcs7: fix flaky test test_enveloped
OpenSSL::PKCS7#decrypt is unreliable when given only a private key and the PKCS#7 structure contains multiple recipients. It may occasionally raise an exception or return garbage data. Update the test to avoid this. This became much more visible in CI after upgrading to OpenSSL versions released on 2026-06-09, which enable the implicit rejection mechanism for PKCS#1 v1.5 decryption in PKCS#7.
1 parent 27c59a4 commit f7c51a2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

test/openssl/test_pkcs7.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ def test_enveloped
238238
assert_equal(@ee2_cert.serial, recip[1].serial)
239239
assert_equal(data, p7.decrypt(@ee2_key, @ee2_cert))
240240

241-
assert_equal(data, p7.decrypt(@ee1_key))
242-
243241
assert_raise(OpenSSL::PKCS7::PKCS7Error) {
244242
p7.decrypt(@ca_key, @ca_cert)
245243
}
@@ -250,6 +248,16 @@ def test_enveloped
250248
}
251249
end
252250

251+
def test_enveloped_decrypt_key_only
252+
omit_on_fips # PKCS #1 v1.5 padding
253+
254+
data = "aaaaa\nbbbbb\nccccc\n"
255+
cipher = "AES-128-CBC"
256+
257+
p7 = OpenSSL::PKCS7.encrypt([@ee1_cert], data, cipher, OpenSSL::PKCS7::BINARY)
258+
assert_equal(data, p7.decrypt(@ee1_key))
259+
end
260+
253261
def test_enveloped_add_recipient
254262
omit_on_fips # PKCS #1 v1.5 padding
255263

0 commit comments

Comments
 (0)