I am working on a HTTPS client and I managed to establish a secure connection and get the X509 certificate using: X509 *cert = SSL_get_certificate(ssl);
(ssl is SSL*).
How do I save the certificate to a file?
Also, I need to get "Subject DN" and "Issuer DN" fields from the certificate.
In the details pane, right-click the certificate you want to export, select All Tasks, and then click Export… This action will start the Certificate Export Wizard. On the Welcome to the Certificate Export Wizard page, click Next. On the Export Private Key page, click Yes, Export the Private Key, and then click Next.
Certificates stores are kept in the system registry under the keys HKEY_LOCAL_MACHINE\Software\Microsoft\SystemCertificates and HKEY_CURRENT_USER\Software\Microsoft\SystemCertificates. Each user has a MY certificate store which contains his/her personal certificates.
An X. 509 certificate is a digital certificate that uses the widely accepted international X. 509 public key infrastructure (PKI) standard to verify that a public key belongs to the user, computer or service identity contained within the certificate.
-- How do I save the certificate to a file?
#include <openssl/pem.h>
int PEM_write_X509(FILE *fp, X509 *x);
-- Also, I need to get "Subject DN" and "Issuer DN" fields from the certificate.
#include <openssl/x509.h>
X509_NAME * X509_get_issuer_name(X509 *a);
X509_NAME * X509_get_subject_name(X509 *a);
To encode the certificate into a file you can use this OpenSSL function:
int i2d_X509_fp(X509 *x, FILE *fp);
It encodes the X509 structure pointed by x
into file using the DER encoding. More details on the OpenSSL API reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With