gang cao wrote:
>
> hi all,
> in x509.c , load_cert(char * file , int format)
> read certificate from a file .
> i need read a certificate from a buf ( unsigned char * ),
> a function like
> static X509 *load_cert(unsigned char *data , int len , int format )
> len is the length of data.
> so i change the following :
>
> if ((cert=BIO_new(BIO_s_file())) == NULL)
> {
> ERR_print_errors(bio_err);
> goto end;
> }
>
> if (file == NULL)
> BIO_set_fp(cert,stdin,BIO_NOCLOSE);
> else
> {
> if (BIO_read_filename(cert,file) <= 0)
> {
> perror(file);
> goto end;
> }
> }
>
> to :
>
> if ((cert=BIO_new(BIO_f_buffer)) == NULL)
> {
> ERR_print_errors(bio_err);
> goto end;
> }
> if( BIO_set_buffer_read_data ( cert ,data , len ) <=0 )
> {
> ERR_print_errors(bio_err);
> goto end;
> }
> compile is ok ,but core dumped .
> error is :
> any one can help me?
>
Yes. A buffer bio buffers a read from another bio next in the chain
which doesn't exist in this case. You could I suppose stuff a null bio
on the end but a buffer bio isn't really what you want.
If you are going to use a BIO for this then a memory bio is more suited.
Just make the BIO with:
mem = BIO_new(BIO_s_mem());
and write the data with
BIO_write(mem, data, datalen);
then you can pass this memory BIO to the PEM_read stuff. If its a DER
encoded certificate in the buffer then see my other message about using
i2d_X509() directly.
Steve.
--
Dr Stephen N. Henson. http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED]
Senior crypto engineer, Celo Communications: http://www.celocom.com/
Core developer of the OpenSSL project: http://www.openssl.org/
Business Email: [EMAIL PROTECTED] PGP key: via homepage.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]