Created
July 12, 2015 01:00
-
-
Save mark-ignacio/b9015b681630552cdfad to your computer and use it in GitHub Desktop.
Returns the CA type of a pem file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <openssl/pem.h> | |
#include <openssl/x509v3.h> | |
int main(int argc, char *argv[]) { | |
if (argc != 2) { | |
std::cout << "usage: ./what-ca-are-you [certificate.crt]" << std::endl; | |
return 0; | |
} | |
FILE *infile = fopen(argv[1], "rb"); | |
if (!infile) { | |
std::cerr << "Unable to open file: " << argv[1] << std::endl; | |
return 1; | |
} | |
X509* cert = PEM_read_X509(infile, NULL, NULL, NULL); | |
if (!cert) { | |
std::cerr << "Unable to parse certificate: " << argv[1] << std::endl; | |
} | |
int is_ca = X509_check_ca(cert); | |
std::cout << "CA Type: " << is_ca << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment