Dear maintainers, In some circumstances, OpenSSL fails to decrypt an S/MIME message when we generate a key and encrypt a message using OpenSSL.
The conditions are as follows: * Generate a private key and certificate in certain environments. * Specify multiple recipients with "smime -encrypt". When we try to decrypt the S/MIME message with each different recipient keys, only one of the recipient can decrypt it, but the others fail with the following error: + openssl smime -decrypt -in test.pk7 -recip cert3.pem -inkey privkey3.pem Error decrypting PKCS#7 structure 26734:error:0407106B:rsa routines:RSA_padding_check_PKCS1_type_2:block type is not 02:rsa_pk1.c:190: 26734:error:04065072:rsa routines:RSA_EAY_PRIVATE_DECRYPT:padding check failed:rsa_eay.c:481: 26734:error:21070006:PKCS7 routines:PKCS7_dataDecode:EVP lib:pk7_doit.c:426: 26734:error:21072077:PKCS7 routines:PKCS7_decrypt:decrypt error:pk7_smime.c:414: We confirmed this problem in the following environments: CentOS release 4.5 Linux localhost.localdomain 2.6.9-55.ELsmp #1 SMP Wed May 2 14:28:44 EDT 2007 i686 i686 i386 GNU/Linux openssl-0.9.7a-43.16 SUSE LINUX Enterprise Server 9 (x86_64) Linux forcast-dev1 2.6.5-7.201-smp #1 SMP Thu Aug 25 06:20:45 UTC 2005 x86_64 x86_64 x86_64 GNU/Linux openssl-devel-0.9.7d-15.32 SuSE Linux 9.2 (i586) Linux forcast-dev2 2.6.8-24-bigsmp #1 SMP Wed Oct 6 09:16:23 UTC 2004 i686 i686 i386 GNU/Linux openssl-0.9.7d-25.8 SuSE Linux 9.2 (i586) Linux pepper 2.6.8-24.16-smp #1 SMP Thu Jun 2 12:09:57 UTC 2005 i686 i686 i386 GNU/Linux openssl-0.9.7d-25 We however confirmed the problem doesn't occur in these environments: SUSE LINUX Enterprise Server 9 (i586) Linux jojo-mana 2.6.5-7.244-default #1 Mon Dec 12 18:32:25 UTC 2005 i686 i686 i386 GNU/Linux openssl-0.9.7d-15.21 openSUSE 10.2 (X86-64) Linux pepper 2.6.18.8-0.3-default #1 SMP Tue Apr 17 08:42:35 UTC 2007 x86_64 x86_64 x86_64 GNU/Linux openssl-0.9.8d-23.1 We've attached some scripts which may reproduce the issue. test0.sh does reproduce the issue. But if we encrypt a message with only one recipient (like test1.sh), the problem never occurs in any environments. The problem also occurs when we copy *.pem files from one problematic environment to another unproblematic one, and run test.sh (not test0.sh because it overwrites the files with new ones). ================ test0.sh ================ #!/bin/sh set -x cat <<EOF >test.mime From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: SMIME test This is a test mail. Please ignore... EOF openssl genrsa > privkey1.pem openssl req -new -key privkey1.pem -out csr1.pem -config test.config openssl x509 -in csr1.pem -out cert1.pem -req -signkey privkey1.pem openssl genrsa > privkey2.pem openssl req -new -key privkey2.pem -out csr2.pem -config test.config openssl x509 -in csr2.pem -out cert2.pem -req -signkey privkey2.pem openssl genrsa > privkey3.pem openssl req -new -key privkey3.pem -out csr3.pem -config test.config openssl x509 -in csr3.pem -out cert3.pem -req -signkey privkey3.pem openssl smime -encrypt -in test.mime -out test.pk7 cert1.pem cert2.pem cert3.pem #openssl smime -encrypt -in test.mime -out test.pk7 cert3.pem openssl smime -decrypt -in test.pk7 -recip cert1.pem -inkey privkey1.pem openssl smime -decrypt -in test.pk7 -recip cert2.pem -inkey privkey2.pem openssl smime -decrypt -in test.pk7 -recip cert3.pem -inkey privkey3.pem rm test.mime rm test.pk7 ================ test.sh ================ #!/bin/sh set -x cat <<EOF >test.mime From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: SMIME test This is a test mail. Please ignore... EOF #openssl genrsa > privkey1.pem #openssl req -new -key privkey1.pem -out csr1.pem -config test.config #openssl x509 -in csr1.pem -out cert1.pem -req -signkey privkey1.pem #openssl genrsa > privkey2.pem #openssl req -new -key privkey2.pem -out csr2.pem -config test.config #openssl x509 -in csr2.pem -out cert2.pem -req -signkey privkey2.pem #openssl genrsa > privkey3.pem #openssl req -new -key privkey3.pem -out csr3.pem -config test.config #openssl x509 -in csr3.pem -out cert3.pem -req -signkey privkey3.pem openssl smime -encrypt -in test.mime -out test.pk7 cert1.pem cert2.pem cert3.pem #openssl smime -encrypt -in test.mime -out test.pk7 cert3.pem openssl smime -decrypt -in test.pk7 -recip cert1.pem -inkey privkey1.pem openssl smime -decrypt -in test.pk7 -recip cert2.pem -inkey privkey2.pem openssl smime -decrypt -in test.pk7 -recip cert3.pem -inkey privkey3.pem rm test.mime rm test.pk7 ================ test1.sh ================ #!/bin/sh set -x cat <<EOF >test.mime From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: SMIME test This is a test mail. Please ignore... EOF #openssl genrsa > privkey1.pem #openssl req -new -key privkey1.pem -out csr1.pem -config test.config #openssl x509 -in csr1.pem -out cert1.pem -req -signkey privkey1.pem #openssl genrsa > privkey2.pem #openssl req -new -key privkey2.pem -out csr2.pem -config test.config #openssl x509 -in csr2.pem -out cert2.pem -req -signkey privkey2.pem #openssl genrsa > privkey3.pem #openssl req -new -key privkey3.pem -out csr3.pem -config test.config #openssl x509 -in csr3.pem -out cert3.pem -req -signkey privkey3.pem #openssl smime -encrypt -in test.mime -out test.pk7 cert1.pem cert2.pem cert3.pem openssl smime -encrypt -in test.mime -out test-1.pk7 cert1.pem openssl smime -encrypt -in test.mime -out test-2.pk7 cert2.pem openssl smime -encrypt -in test.mime -out test-3.pk7 cert3.pem openssl smime -decrypt -in test-1.pk7 -recip cert1.pem -inkey privkey1.pem openssl smime -decrypt -in test-2.pk7 -recip cert2.pem -inkey privkey2.pem openssl smime -decrypt -in test-3.pk7 -recip cert3.pem -inkey privkey3.pem rm test.mime rm test.pk7 ================ test.config ================ [ req ] distinguished_name = req_distinguished_name attributes = req_attributes prompt = no [ req_distinguished_name ] C = AU ST = Some-State L = Test Locality O = Organization Name OU = Organizational Unit Name CN = Common Name emailAddress = [EMAIL PROTECTED] [ req_attributes ] ================ Thanks, SANO Taku (SAWATARI Mikage) ______________________________________________________________________ OpenSSL Project http://www.openssl.org Development Mailing List [email protected] Automated List Manager [EMAIL PROTECTED]
