I am writing a program with OpenSSL library, to establish a SSL POP connection with other server (E.g. Gmail). For this, I have generated a self signed certificate using OpenSSL and verified it.
./openssl verify -CAfile /home/melluru/openssl/ssl/certs/cert.pem /home/melluru/openssl/ssl/certs/cert.pem >/home/melluru/openssl/ssl/certs/cert.pem: OK The verify option of OpenSSL tools gives 'OK' result. But when I use the below in my program to load the certtificate and verify the result, I am getting the error
/** to add the cert file**/ if(!(SSL_CTX_use_certificate_file(ctx,"/home/melluru/openssl/ssl/certs/cert.pem", SSL_FILETYPE_PEM))) printf("Cant read certificate file\n"); /** to add the private key ***/ if(!(SSL_CTX_use_PrivateKey_file(ctx,"/home/melluru/openssl/ssl/certs/cert.pem", SSL_FILETYPE_PEM))) printf("Cant read keyfile\n"); /** to cadd the trusted cert **/ if(SSL_CTX_load_verify_locations(ctx,"/home/melluru/openssl/ssl/certs/cert.pem", NULL) != 1) { printf("loading trust certificate failed\n"); SSL_CTX_free(ctx); return 0; } /*** BIO code to connect to gmail server *****/ printf("ssl verify error is %d\n",SSL_get_verify_result(ssl)); I am getting error 20 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY.
Can anyone help? Is there anything still I need to add?