/**
* Initialize SSL/TLS context
* @return void
*/
protected function initSecureContext()
{
if (!\EventUtil::sslRandPoll()) {
Daemon::$process->log(get_class($this->pool) . ': EventUtil::sslRandPoll failed');
$this->erroneous = true;
return;
}
if (!FileSystem::checkFileReadable($this->certfile) || !FileSystem::checkFileReadable($this->pkfile)) {
Daemon::log('Couldn\'t read ' . $this->certfile . ' or ' . $this->pkfile . ' file. To generate a key' . PHP_EOL . 'and self-signed certificate, run' . PHP_EOL . ' openssl genrsa -out ' . escapeshellarg($this->pkfile) . ' 2048' . PHP_EOL . ' openssl req -new -key ' . escapeshellarg($this->pkfile) . ' -out cert.req' . PHP_EOL . ' openssl x509 -req -days 365 -in cert.req -signkey ' . escapeshellarg($this->pkfile) . ' -out ' . escapeshellarg($this->certfile));
return;
}
$params = [\EventSslContext::OPT_LOCAL_CERT => $this->certfile, \EventSslContext::OPT_LOCAL_PK => $this->pkfile, \EventSslContext::OPT_VERIFY_PEER => $this->verifypeer, \EventSslContext::OPT_ALLOW_SELF_SIGNED => $this->allowselfsigned];
if ($this->passphrase !== null) {
$params[\EventSslContext::OPT_PASSPHRASE] = $this->passphrase;
}
if ($this->verifydepth !== null) {
$params[\EventSslContext::OPT_VERIFY_DEPTH] = $this->verifydepth;
}
if ($this->cafile !== null) {
$params[\EventSslContext::OPT_CA_FILE] = $this->cafile;
}
if ($this->tls === true) {
$method = \EventSslContext::TLS_SERVER_METHOD;
} elseif ($this->tls === 'v11') {
$method = \EventSslContext::TLSv11_SERVER_METHOD;
} elseif ($this->tls === 'v12') {
$method = \EventSslContext::TLSv12_SERVER_METHOD;
} elseif ($this->ssl === 'v3' || $this->ssl === true || $this->ssl === '1') {
$method = \EventSslContext::SSLv3_SERVER_METHOD;
} elseif ($this->ssl === 'v2') {
$method = \EventSslContext::SSLv2_SERVER_METHOD;
} elseif ($this->ssl === 'v23') {
$method = \EventSslContext::SSLv23_SERVER_METHOD;
} elseif ($this->ssl) {
Daemon::log(get_class($this) . ': unrecognized SSL version \'' . $this->ssl . '\'');
return;
} else {
return;
}
$this->ctx = new \EventSslContext($method, $params);
}