I have a generated a certificate, but I would like to be able to extract the information from the certificate, as for example the country, the validity, the public key and so on. I have to compare this information retrived from the certificate with some other that I have stored in my C programe.
I know that if I use a function like this it will print me the certificate information:
void print_certificate(const char* cert)
{
X509 *x509 = NULL;
BIO *i = BIO_new(BIO_s_file());
BIO *o = BIO_new_fp(stdout,BIO_NOCLOSE);
if((BIO_read_filename(i, cert) <= 0) ||
((x509 = PEM_read_bio_X509_AUX(i, NULL, NULL, NULL)) == NULL)) {
printf("Bad certificate, unable to read\n");
}
X509_print_ex(o, x509, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
if(x509)
X509_free(x509);
}
But what I want is only some parts of that information. how can it be done?
Thanks
try
grep _get_ /usr/include/openssl/x509.h
here are some things you may find useful:
Also check the source code for t_x509.c which contains
X509_print_ex
. This will probably be most useful.See x509.h of OpenSSL (example here). You will find plenty of useful functions. Example: