Reputation: 1422
I'm trying to use SSL in my socket client-server application. And for some reason I'm getting the following response:
Warning: stream_socket_enable_crypto(): Unable to set private key file
I can write and read from the file.
I use the following code to retrieve the data:
$socket = stream_socket_accept($this->server);
stream_set_blocking($socket, true);
stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_SSLv3_SERVER);
$data = fread($socket, 1024);
stream_set_blocking($socket, false);
fclose($socket);
Here's my server init:
$this->server = stream_socket_server(self::SERVER_ADDRESS, $errno, $errstr, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $this->ssl->getStreamContextForSSL());
stream_socket_enable_crypto($this->server, false);
Context:
public function getStreamContextForSSL() {
$context = stream_context_create();
$this->setContextSSLOptions($context, array(
'local_cert' => self::PEM_FILE,
'passphrase' => self::PEM_PASSPHRASE,
'allow_self_signed' => true,
'verify_peer' => false
));
return $context;
}
Upvotes: 2
Views: 874
Reputation: 1422
Be sure to check if your private key is valid, because php realisation of OpenSSL doesn't tell you in case it isn't.
Upvotes: 2