Skip to content

Instantly share code, notes, and snippets.

@mark-ignacio
Created July 12, 2015 01:00
Show Gist options
  • Save mark-ignacio/b9015b681630552cdfad to your computer and use it in GitHub Desktop.
Save mark-ignacio/b9015b681630552cdfad to your computer and use it in GitHub Desktop.
Returns the CA type of a pem file
#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