My first attempt at using OpenSSL. (BTW I haven't found anything much in the way of documentation - is there any that I might have missed?)

The first thing I'm trying to do is call d2i_PKCS12_fp, so this call is the very first line of OpenSSL I've written.

It fails. In particular it eventually calls down to _setmode in the C runtime library which fails at this line:

   _VALIDATE_RETURN((_osfile(fh) & FOPEN), EBADF, -1);

I've found various things about crashes in d2i_PKCS12_fp, so I'm including applink.c and calling CRYPTO_malloc_init, and I've found the sample code for reading a PKCS12 file, so I've copied that and am calling (without knowing what they do) SSLeay_add_all_algorithms and ERR_load_crypto_strings.

So, my code looks like this:

   #include "openssl\applink.c" // copied from FAQ, don't know what it does

and then

   CRYPTO_malloc_init(); // copied from FAQ, don't know what it does
   SSLeay_add_all_algorithms(); // copied from sample code, don't know what
it does
   ERR_load_crypto_strings(); // copied from sample code, don't know what
it does

   FILE *file;
   file = fopen( filename, "rb" );

   if ( file != 0 )
   {
       PKCS12 *pkcs12 = d2i_PKCS12_fp( file, 0 ); // from the O'Reilly book

What's wrong with that please? And what documentation should I have found, and where, that would have helped me get it right first time?

Tim Ward - Brett Ward Limited - 07801 703 600
www.brettward.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to