Hello:

I want read a certificate, and I use the function "PEM_read_X509". Then, I
get the serial number and the subject name.

I have done it with success reading a certain certificate, but when I read
other certificate I have get a read error. And this certificate it´s ok.
Both certificates are in format ".crt".

This is the funcion that I use to read the certificates:

BIGNUM *ClavePublicaCertificado(char *certificado)
{
 BIO *out;

 FILE *fp;
 X509 *cert;
 X509_NAME *asunto;
 ASN1_INTEGER *bs;

 char *serialHex;
 BIGNUM *serialBN = NULL;

 int error;

 // abre la salida estandar //
    if (!(out = BIO_new_fp (stdout, BIO_NOCLOSE)))
  printf("Error creating stdout BIO\n");


 if (!(fp = fopen(certificado, "r")))
  printf ("Error lectura certificado (%s)\n", certificado);

 if (!(cert = PEM_read_X509(fp, NULL, NULL, NULL)))
  printf ("Error leyendo certificado (%s)\n", certificado);

  fclose(fp);

 bs = X509_get_serialNumber(cert);
 serialBN = ASN1_INTEGER_to_BN(bs,NULL);
 serialHex = BN_bn2hex(serialBN);

 asunto = X509_get_subject_name(cert);
 X509_NAME_print (out, asunto, 0);

 return (serialBN);
}


What is the problem?. Is the problem the certificate, o is this code?

Thanks a lot.

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

Reply via email to