At which line did it fail?
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Zulkiffli Mohd Nur
Sent: Monday, 10 September 2001 11:22 AM
To: [EMAIL PROTECTED]
Subject: X509

hi

i am new in this industry.

just now i have a certificate.

the problem is how to read serial number from the certificate.

i also have problem to viewed X509v3 extensions, X509v3 Subject key identifier, X509v3 certificate Policies, X509v3 Basic Constraint, and signature algorithm.  

i have no idea. can any body help me.

i have problem with this code:

#include <stdio.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/bio.h>     // MODIFICATION: bio.h needed for BIO operations
    
  
#define X509_get_version(x) ASN1_INTEGER_get((x)->cert_info->version)
  
main()
{
   X509 *x;
   FILE *fp;
   EVP_PKEY *      pkey;
   BIO *bp;  // needed for ASN1_TIME_print
   
   long version;         

   char * s;

  
 
   if ((fp=fopen("C:\\CryptoWeb\\backup 492001\\Haizad.crt","r")) != NULL)
   {
      x=X509_new();
      if (PEM_read_X509(fp,&x,NULL,NULL)!=NULL)
         printf("\nReading success!");
   else
  
   {
   
   printf ("\nError reading certificate!");
   exit (1);
  }
       X509_print_fp(stdout,x); 
     
 
  
  printf("\nCertificate:");
  printf("\n    Data:");
 
  version = X509_get_version(x);
  printf("\nVersion: %ld",version);  

  s = X509_get_serialNumber(x);
  printf("\nSerial Number:  %d\n",s);
 
  s = X509_get_signature_type(x);
  printf("Signature Algorithm:  %1d\n",s);

  s = X509_NAME_oneline(X509_get_issuer_name(x),NULL,NULL);
  printf("ISSUER NAME:  %s\n",s);
     
  
 bp=BIO_new_fp(stdout,BIO_NOCLOSE);     

 if(bp==NULL){
  printf("Error creating BIO.\n");
  exit(1);
 }

  printf("\nNot Before: ");
  ASN1_TIME_print(bp,X509_get_notBefore(x));
    
  printf("\nNot After: ");
  ASN1_TIME_print(bp,X509_get_notAfter(x));
 
  s = X509_NAME_oneline(X509_get_subject_name(x),NULL,NULL);
  printf("\nSUBJECT NAME:  %s\n",s);
 
  BIO_free(bp);

  /* Get public key - eay */
  pkey=X509_get_pubkey(x);
  if (pkey == NULL) {
   printf ("\nPublic key error!");
   exit (1);
  }
 
  if (pkey == NULL) {
    printf ("\nPublic key is NULL!");
   exit (1);
  }
  else
   printf ("\nPublic key found!");
 
  printf("\nPublic key:");
  RSA_print_fp(stdout,pkey->pkey.rsa,0);
 
      X509_free(x);
      fclose(fp);
   }
   else
      perror("ERROR, haizad.crt");
 
}

please reply as soon as possible.

Reply via email to