Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use X509_verify()

How can we use X509_verify(). I have two certificates. The first certificate is the Root Certificate which signed the next certificate (which is my Certificate). So I want to check if my certificate is signed by the root certificate using x509_verify() in C++. My goal is to keep the code simple and Understandable so I can also put it online.

like image 561
Geek Avatar asked Nov 30 '22 21:11

Geek


1 Answers

Signature of X509_verify is

 int X509_verify(X509 * x509, EVP_PKEY * pkey);

Suppose of you have root certificate in root and your certificate in mycert;

   X509 * root;
   X509 * mycert;

//Get root certificate into root
//Get mycert into mycert.

//Get the public key.
EVP_PKEY * pubkey = X509_get_pubkey(root);

//verify. result less than or 0 means not verified or some error.
int result = X509_verify(mycert, pubkey);

//free the public key.
EVP_PKEY_free(pubkey);

I think this would help you.

like image 145
doptimusprime Avatar answered Dec 09 '22 10:12

doptimusprime