« Return to Thread: Error while reading X509 structure by d2i_X509_bio using memory bio

RE: Error while reading X509 structure by d2i_X509_bio using memory bio

by Dave Thompson-4 :: Rate this Message:

Reply to Author | View in Thread

> From: owner-openssl-users@... On Behalf Of
rajeshk_pec99-openssl@...
> Sent: Thursday, 02 July, 2009 06:53
<snip>
>  FILE *fp = 0;
>  char derCert[MAX_CERT_LEN];
>  long len;
       
>  if (fp = fopen("../der.cer", "rb")) {
>    len=fread(derCert, 1, MAX_CERT_LEN - 1, fp);
>    derCert[len] = '\0';
>   }

DER data is not a C string; adding a null to 'terminate' it
will almost never help. To clarify/document this, I think
it is better style to use unsigned-char arrays (and pointers)
for it, although plain-char will work.

>  //This is working ...[ BIO_new file ]...

>    //This is not working
>      if(( bioCert = BIO_new_mem_buf(derCert, -1)) == NULL)
>      { ...[error]... }

DER data is not a C string; pass len from above instead of -1.

If you (convert to hex and) decode your error code, you get
error:0D06B08E:asn1 encoding routines:ASN1_D2I_READ_BIO:not enough data
which could have been a clue.

Incidentally, you don't need a mem-BIO to decode (or encode) exact
in-memory buffers; you can use the basic d2i and i2d routines.



______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@...
Automated List Manager                           majordomo@...

 « Return to Thread: Error while reading X509 structure by d2i_X509_bio using memory bio