I am trying to use SMIME_read_PKCS7 to read a signed and encrypted MIME
message from memory BIO, but I can't get it to work. It works fine if I
construct a file BIO to read from. I can't see anything I am doing wrong
(and nobody answered to my openssl-users post about this) so I am
assuming this is a bug, hence filing this ticket.

See the test application below that shows the problem. Please note that
you need to save the contents of smime_text variable into a file called
"smime_text.txt" manually, before the file BIO case will work.

When I run the program, I get the following output:

3445
Memory BIO case, error: 218542222

This is on Cygwin, with OpenSSL 0.9.8a. (I think I tested this earlier
on various other OSes with same results.)

---CLIP---

#include
#include
#include
#include
#include
#include
#include
#include

char smime_text[] =
"MIME-Version: 1.0\n"
"Content-Disposition: attachment; filename=\"smime.p7m\"\n"
"Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data;
name=\"smime.p7m\"\n"
"Content-Transfer-Encoding: base64\n"
"\n"
"MIIJXQYJKoZIhvcNAQcDoIIJTjCCCUoCAQAxgeMwgeACAQAwST BEMQswCQYDVQQG\n"
"EwJVUzELMAkGA1UECBMCQ0ExFDASBgNVBAoTC00yQ3J5cHRvIE NBMRIwEAYDVQQD\n"
"Ewlsb2NhbGhvc3QCAQQwDQYJKoZIhvcNAQEBBQAEgYCac8jhFI MOgOxMbvdEJwYt\n"
"84CLHCdtSA/3y6ex6PrN5NlxNfpNIRsrmRyJQb5MJIiOuFFUbN6DMWbki0MYx 1Pf\n"
"X4+2i924p+5wTNv8DsTeInjSryiz5CcUS5Bq117vZfZ0H8+zNo uF+Hf19Qam5gT5\n"
"gaMBXzLKx9P+xd4qBXKsqTCCCF0GCSqGSIb3DQEHATAUBggqhk iG9w0DBwQIvboS\n"
"cTawrl6Aggg4WbNItj3soy1iAfF38ZYbFftVoHqzYXsD2ZeVl1 DTOgnTPltQomGw\n"
"Vlb8eLAzn4MEh/K8vzZXumuc9hCHnr0TXsHUPMpzDnBtTplyahfPNxqI0fBmelZH \n"
"DoJ85UXk4iURnadzywIU83Krl8yJAmirKxjA3IiwD2gU9/Xni8kD0kxhgi9ghjHW\n"
"WiefD1e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YfdAuJmK2dEpu/obwKWq/0gdnngNk1UjLBMwQKk+8SFaOJikp1G4d3v\n"
"1RylODneJJtFsl1JHtJ2t4KfT+JZ++qd3w1CT5G79cqFAQB1Tx gAr5AQwa84KcaR\n"
"NCyczJn1w2l7DGevWsEZhPVSmKkiLB1U0wnakVHF4Xeyc+gRR/l8r2F51l5jt3rd\n"
"nvpjikCgiRLthKWhgss4I4clHNM4oOkcuQPtzOrqErHayHeV25 rfuJQtlcsTHlnw\n"
"MV7FIaV2TCcutoOCJIHJvPv1hCQiOnWOvW4V8vzPCvXc1kPRVm FfzP5Ogmf8OUxa\n"
"DNy7VfRfwQOUL/r4WtLf8bdEsaFjsuDM2WNRc14vh8k054qaAmGTmkJPV0hub6kB \n"
"pp2vme963FcTy9v5uJNUIiC6oc0K9L7TdoA4EOeojg5HjGkfii np4+gfcSpEssVM\n"
"iAo1iNdnXVadr/1CqFh0CDU6ZAww/jc164rjZyGSHceoEv2IHK+9eG3kPPFIA04/\n"
"Ldfk2XI2W2Kai1ySk95j5OsKK0COZYe8vzH8Cxasy/HRUsml0EnPdCcqRnErIURQ\n"
"9TTgAN28f6po85zOkod4Ou63bEfqdjlLtvaX3gPvrU7h+eddxS NSSqqXqH3ayCDo\n"
"zg==";

int main(void)
{
{
/* This does not work */
PKCS7 *p7;
BIO *bcont = NULL;
BIO *signedEncryptedBio = BIO_new(BIO_s_mem());
printf("%d\n",
BIO_write(signedEncryptedBio, smime_text, strlen(smime_text)));
p7 = SMIME_read_PKCS7(signedEncryptedBio, &bcont);
if (!p7) {
printf("Memory BIO case, error: %ld\n", ERR_get_error());
}
}

{
/* This works after you manually save the smime_text contents to
smime_text.txt first. */
BIO *bcont = NULL;
BIO *f = BIO_new_file("smime_text.txt", "rb");
PKCS7 *p7 = SMIME_read_PKCS7(f, &bcont);
if (!p7) {
printf("File BIO case, error: %ld\n", ERR_get_error());
}
}

return 0;
}

---CLIP---

--
Heikki Toivonen

__________________________________________________ ____________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-dev@openssl.org
Automated List Manager majordomo@openssl.org