On 03/11/2011 11:57 AM, ikuzar wrote:
Ok.
In the doc, I think |i2d_X509() |is adequate to encode X509 *cert; The doc says 
:

int i2d_X509(X509 *x, unsigned char **out);

|i2d_X509()| encodes the structure pointed to by *x* into DER format. If *out* 
is not *NULL* is writes the DER encoded data to the buffer at **out*, and 
increments it to point after the data just written. If the return value is 
negative an error occurred, otherwise it returns the length of the encoded data.

Now, the function which adds certificates into shared map is like this :
int addCertIntoMap(const char* uri, const char* certificate,  unsigned int 
clen, time_t duration);
uri is the key, const char* certificate is the certificate to add into map.

My question :
DER format will be stored in an unsigned char **out. In addCertIntoMap, we add 
a const char* certificate. I do not know how to write the code. I want to write 
somthing like this :

X509* peerCert = SSL_get_peer_certificate(ssl);
unsigned char **DERcert;
i2d_X509(peerCert, DERcert);
addCertIntoMap(uri, DERcert, len, time); // but here DERcert is char** and not 
char* ...



You might want to the example in 
http://www.openssl.org/docs/crypto/d2i_X509.html

Allocate and encode the DER encoding of an X509 structure:

 int len;
 unsigned char *buf, *p;

 len = i2d_X509(x, NULL);

 buf = OPENSSL_malloc(len);

 if (buf == NULL)
        /* error */

 p = buf;

 i2d_X509(x, &p);
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to