> I'm having trouble with the d2i_X509() call.  I've googled all the
> errors that I get and I can't figure out what's going on.
> I'm using OpenSSL 0.9.7d.
>
> Basically, I'm trying to read a cert off disk (PEM format).  Then I
> convert it into a DER buffer using i2d_X509().  Sometime later, I need
> to convert the DER buffer back into an X509 structure using d2i_X509()
> and that's when the wheels come off the wagon.
>
> I've attached a code snippet that shows the problem.  Can anyone help me
> out?

        The i2d/d2i fucntions have some subtleties. Try using them *exactly* like
this and see if it solves your problem:

   int len=i2d_X509(x, NULL);
   void *ptr=malloc(len);
   unsigned char *bp=(unsigned char *) ptr;
   i2d_X509(x, &bp);

 unsigned char *p=(unsigned char *) privkey;
 DSA *pkey=d2i_DSAPrivateKey(NULL, &p, keylen);

        Notice two things. First, for 'i2d' functions, you do a first call with a
NULL buffer to get the length. For 'd2i' functions, you make the function a
*private* copy of the buffer pointer and then pass it a pointer to that
private copy.

        DS


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to