Skip to content

Commit ebadd0f

Browse files
authored
Merge pull request #796 from rhenium/ky/pkcs7-encrypt-drop-default-cipher
pkcs7: remove default cipher from PKCS7.encrypt
2 parents 7c6d834 + 439f456 commit ebadd0f

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

ext/openssl/ossl_pkcs7.c

+13-15
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
259259

260260
/*
261261
* call-seq:
262-
* PKCS7.encrypt(certs, data, [, cipher [, flags]]) => pkcs7
262+
* PKCS7.encrypt(certs, data, cipher, flags = 0) => pkcs7
263+
*
264+
* Creates a PKCS #7 enveloped-data structure.
265+
*
266+
* Before version 3.3.0, +cipher+ was optional and defaulted to
267+
* <tt>"RC2-40-CBC"</tt>.
268+
*
269+
* See also the man page PKCS7_encrypt(3).
263270
*/
264271
static VALUE
265272
ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
@@ -273,21 +280,12 @@ ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
273280
PKCS7 *p7;
274281

275282
rb_scan_args(argc, argv, "22", &certs, &data, &cipher, &flags);
276-
if(NIL_P(cipher)){
277-
#if !defined(OPENSSL_NO_RC2)
278-
ciph = EVP_rc2_40_cbc();
279-
#elif !defined(OPENSSL_NO_DES)
280-
ciph = EVP_des_ede3_cbc();
281-
#elif !defined(OPENSSL_NO_RC2)
282-
ciph = EVP_rc2_40_cbc();
283-
#elif !defined(OPENSSL_NO_AES)
284-
ciph = EVP_EVP_aes_128_cbc();
285-
#else
286-
ossl_raise(ePKCS7Error, "Must specify cipher");
287-
#endif
288-
283+
if (NIL_P(cipher)) {
284+
rb_raise(rb_eArgError,
285+
"cipher must be specified. Before version 3.3, " \
286+
"the default cipher was RC2-40-CBC.");
289287
}
290-
else ciph = ossl_evp_get_cipherbyname(cipher);
288+
ciph = ossl_evp_get_cipherbyname(cipher);
291289
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
292290
ret = NewPKCS7(cPKCS7);
293291
in = ossl_obj2bio(&data);

test/openssl/test_pkcs7.rb

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ def test_enveloped
153153
assert_equal(data, p7.decrypt(@rsa1024, @ee2_cert))
154154

155155
assert_equal(data, p7.decrypt(@rsa1024))
156+
157+
# Default cipher has been removed in v3.3
158+
assert_raise_with_message(ArgumentError, /RC2-40-CBC/) {
159+
OpenSSL::PKCS7.encrypt(certs, data)
160+
}
156161
end
157162

158163
def test_empty_signed_data_ruby_bug_19974

0 commit comments

Comments
 (0)