On Thu, Sep 09, 2004, Hellan.Kim KHE wrote: > Using OpenSSL 0.9.7c > > I'm trying to parse an S/MIME encoded (signed) PKCS#7, but I simply can't get it to > work with SMIME_read_PKCS7(). > I have the data in a memory BIO and I always get the error: > error:0D06B08E:asn1 encoding routines:ASN1_d2i_bio:not enough data > > However, if I flush the data to a file and create a file BIO like: > BIO* mybio = BIO_new_file("C:\\myfile.p7m", "rb"); > ...and use that BIO instead, everything works fine. > > I suspect some problems with the <CR>/<LF> characters for the following reasons: > If I look at the data that I feed to the memory BIO, it only contains <LF> > characters to separate the Base64 lines. This BIO, as mentioned earlier, can not be > parsed by SMIME_read_PKCS7(). > But if I write the data to a file, Windows automatically replaces <LF> with > <CR><LF>. This (BIO) file is parsed by SMIME_read_PKCS7() without problems. >
You need to tell the memory BIO what to do when it runs out of data. By default it will just signal that it needs more data which can cause problems with some APIs that cannot retry failed reads. In this case you need to tell the application that when no more data is available that EOF has been reached. You do this with BIO_set_mem_eof_return(). See the BIO_s_mem() manual page for more details. Steve. -- Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage OpenSSL project core developer and freelance consultant. Funding needed! Details on homepage. Homepage: http://www.drh-consultancy.demon.co.uk ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]