Why dont you try something as,
  X509* user_cert = NULL;
  if ((user_cert  = PEM_read_X509(fp, NULL, NULL, NULL)) == NULL)
  {
/* Error */
  }

or with a bio as,

X509 *x = NULL;

if (!PEM_read_bio_X509(bp, &x, 0, NULL))
       {
       /* Error */
       }


On Tue, Aug 18, 2009 at 5:24 AM, Azlan <mohanvarma...@gmail.com> wrote:

>
>
>
> Azlan wrote:
> >
> > Hello every one..I'm working with an application in which a module should
> > read a "pem" certificate successfully.I've written 2 types of programs,
> > but both are failing(PEM_read constantly returning null )..here are my
> > codes..
> >
> >
> > #include<stdio.h>
> > #include <string.h>
> > #include <openssl/crypto.h>
> > #include <openssl/err.h>
> > #include <openssl/bio.h>
> > #include <openssl/evp.h>
> > #include <openssl/objects.h>
> > #include <openssl/x509.h>
> > #include <openssl/pem.h>
> > int main( int argc,char *argv[])
> > {
> >     FILE *fp;
> >     X509 *x=X509_new();
> > if(x==NULL)
> > printf("error\n");
> >
> > fp=fopen(argv[1],"r");
> > PEM_read_X509(fp,&x,NULL,NULL);
> > if(x==NULL)
> > printf("error reading \n");
> > else
> > printf("reading success\n");
> > fclose(fp);
> > X509_free(x);
> > return(0);
> > }
> >
> >
> > here is my second one..using "bio"
> >
> > do
> >    {
> >        X509 *x509Cert    /*=X509_new();  result is same even if this
> > statement is X509 *x509Cert = X509_new(); */
> >        BIO *cert;
> >        if ((cert=BIO_new(BIO_s_file())) == NULL)
> >         {
> >             printf("Error Initializing BIO pointer");
> >             break;
> >         }
> >
> >        if (BIO_read_filename(cert,argv[1]) <= 0)
> >        {
> >             printf("Error opening file\n");
> >             break;
> >        }
> >
> >         if (PEM_read_bio_X509(cert,&x509Cert,NULL,NULL)!=NULL)
> >         {
> >                  printf("\nReading from file success!\n");
> >         }
> >
> >     }while(0);
> >
> > Both programs are returning "NULL " out of PEM_read.
> > Even though i found similar post sabout PEM_read, none of them is solving
> > my problem..please help me with this..
> >
> > Thank you in advance.
> >
> Sorry..I forgot to mention something..
> In my first program,the result would be "reading success"..the problem is
> PEM_read_X509(fp,&x,NULL,NULL)
> is not returning valid X509 into "x"(it's returning null..u can check by
> if(PEM_read_X509(fp,&x,NULL,NULL)==NULL).Even after the call of function
> PEM_read; x has the previous value(X509_new()   which is not null).Thats
> why
> out put is "reading success."
> Please help me getting out of this.
> Thanks.
> --
> View this message in context:
> http://www.nabble.com/PEM_read-is-always-returning-null-tp25022589p25023748.html
> Sent from the OpenSSL - User mailing list archive at Nabble.com.
>
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    openssl-users@openssl.org
> Automated List Manager                           majord...@openssl.org
>

Reply via email to