[openssl-users] openssl get certificate from SSL_CTX

radiatejava radiatejava at gmail.com
Tue Aug 21 19:04:59 UTC 2018


I want to get the client certificate and the CA certificates that I
set to SSL_CTX. Is there any sample code to do this ? I have not been
successful so far. I set the certificate and CA certs this way.

char* cacertFile = "cacert.crt";
char* certFile = "client.crt";
char* keyFile = "client.key";

if (!SSL_CTX_load_verify_locations(ctx, cacertFile, NULL)) {
    std::cout << "cannot load cacerts" << std::endl;
} else {
    std::cout << "cacert loaded" << std::endl;
}

if (!SSL_CTX_use_certificate_file(ctx, certFile, SSL_FILETYPE_PEM)) {
    std::cout << "cannot load certfile" << std::endl;
} else {
    std::cout << "certfile loaded" << std::endl;
}

if (!SSL_CTX_use_PrivateKey_file(ctx, keyFile, SSL_FILETYPE_PEM)) {
    std::cout << "cannot load private key" << std::endl;
} else {
    std::cout << "private key loaded" << std::endl;
}

Later I want to see what is the client cert and CA certs. I am looking
for any example code to do this.

Thanks.


More information about the openssl-users mailing list