I'm opening my key file and it is saying that it is false and I have no idea why it that. My key looks ok when I open it with notepad. Why it's not working, I'm doing this for the first time so please excuse me if it's something obvious..
This is where I read it
// Reading private key
$fp = fopen("certs/cert.pem", "r");
$priv_key = fread($fp, 8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key); // Empty
openssl_error_string()
gives me error:0906D06C:PEM routines:func(109):reason(108)
.
It looks like you're trying to get a private key out of a certificate file; the private key isn't stored in the certificate, it's stored separately. Where did you get the certificate from? If you generated a CSR yourself and had it signed by a CA later, the key file was generated for you along with the CSR. If you generated the CSR with openssl without specifying any further options, e.g. openssl -req -new The key will be in a file named privkey.pem. It will be delimited by ---- BEGIN RSA PRIVATE KEY --- and the contents are password protected (you were prompted for a password when you generated the CSR).
How to diagnose OpenSSL errors:
Look at the error message:
error:0906D06C:PEM routines:func(109):reason(108)
Take the reason code (108) and determine the error:
grep 108 include/openssl/ssl.h
#define SSL_F_GET_SERVER_FINISHED 108
#define SSL_R_BAD_DH_G_LENGTH 108
#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
Now google for SSL_R_BAD_DH_G_LENGTH
Well not much luck. Looking into source tells that this error is triggered within
ssl3_get_key_exchange() in s3_clnt.c
Probably this helps.