Skip to content

Commit

Permalink
Add SSL/TLS function
Browse files Browse the repository at this point in the history
  • Loading branch information
sysRandom committed Sep 6, 2018
1 parent 7f9c1ff commit bb35b2b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/Console/Commands/RatchetServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ class RatchetServerCommand extends Command
*/
protected $keepAlive;

/**
* SSL/TLS Options.
*
* @var array
*/
protected $tls;

/**
* The ReactPHP event loop.
*
Expand Down Expand Up @@ -124,6 +131,16 @@ public function handle()

$this->keepAlive = $this->option('keepAlive');

$this->tls = config('ratchet.tls', []);
$peer_name = env('APP_URL');
$pos = strpos($peer_name, '://');
if ($pos !== false) {
$peer_name = substr($peer_name, $pos+3);
}
$this->tls += [
'peer_name' => $peer_name
];

$this->startServer();
}

Expand Down Expand Up @@ -245,7 +262,10 @@ private function startIoServer()
*/
private function bootIoServer()
{
$socket = new SocketServer($this->host.':'.$this->port, $this->getEventLoop());
$context = [
'tls' => $this->tls,
];
$socket = new SocketServer($this->host.':'.$this->port, $this->getEventLoop(), $context);

return new IoServer(
$this->serverInstance,
Expand Down
16 changes: 15 additions & 1 deletion src/config/ratchet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

'class' => \Askedio\LaravelRatchet\Examples\Pusher::class,
'host' => '0.0.0.0',
'host' => '0.0.0.0', // Prepend tls:// to host address to enable SSL/TLS. Example: tls://0.0.0.0
'port' => '8080',
'connectionLimit' => false,
'throttle' => [
Expand All @@ -26,4 +26,18 @@
'port' => 5555,
'method' => \ZMQ::SOCKET_PULL,
],
/**
* Look up http://php.net/manual/en/context.ssl.php to configure SSL/TLS.
*/
'tls' => [
// 'peer_name' => '',
// 'verify_peer' => true,
// 'verify_peer_name' => true,
// 'allow_self_signed' => false,
'cafile' => env('SSL_CA_FILE', ''),
'capath' => env('SSL_CA_PATH', ''),
'local_cert' => env('SSL_PUBLIC_CERT', ''),
'local_pk' => env('SSL_PRIVATE_KEY', ''),
'passphrase' => env('SSL_PASSPHRASE', ''),
],
];

0 comments on commit bb35b2b

Please sign in to comment.