From ba670f052d72bdc0cc6c3d9c0a8d11c4b937cc4b Mon Sep 17 00:00:00 2001 From: Amauri de Melo Junior Date: Sun, 6 Dec 2020 12:04:05 -0300 Subject: [PATCH] Allowing TLS options (for WSS) on App facade --- src/Ratchet/App.php | 30 ++++++++++++---- src/Ratchet/Tls/TlsOptions.php | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 src/Ratchet/Tls/TlsOptions.php diff --git a/src/Ratchet/App.php b/src/Ratchet/App.php index f1cd4ddb..09ed6c49 100644 --- a/src/Ratchet/App.php +++ b/src/Ratchet/App.php @@ -1,5 +1,8 @@ httpHost = $httpHost; $this->port = $port; - $socket = new Reactor($address . ':' . $port, $loop); + $options = []; + + if (null !== $tlsOptions) { + $options[self::OPTION_TLS] = $tlsOptions->toArray(); + } + + $socket = new Reactor($address . ':' . $port, $loop, $options); $this->routes = new RouteCollection; $this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext))), $socket, $loop); diff --git a/src/Ratchet/Tls/TlsOptions.php b/src/Ratchet/Tls/TlsOptions.php new file mode 100644 index 00000000..e36d35cb --- /dev/null +++ b/src/Ratchet/Tls/TlsOptions.php @@ -0,0 +1,64 @@ +certificatePath = $certificatePath; + $this->certificateKey = $certificateKey; + $this->allowSelfSigned = $allowSelfSigned; + $this->verifyPeer = $verifyPeer; + $this->verifyPeerName = $verifyPeerName; + } + + /** + * @return array + */ + public function toArray() + { + return [ + self::FIELD_CERTIFICATE_PATH => $this->certificatePath, + self::FIELD_CERTIFICATE_KEY => $this->certificateKey, + self::FIELD_ALLOW_SELF_SIGNED => $this->allowSelfSigned, + self::FIELD_VERIFY_PEER => $this->verifyPeer, + self::FIELD_VERIFY_PEER_NAME => $this->verifyPeerName, + ]; + } +} \ No newline at end of file