diff --git a/src/ServerSocket.php b/src/ServerSocket.php index 5ca035b..829cd53 100644 --- a/src/ServerSocket.php +++ b/src/ServerSocket.php @@ -13,6 +13,15 @@ public function enableCrypto(): Promise { return new Failure(new ClosedException("The socket has been closed")); } + $ctx = \stream_context_get_options($resource); + if (empty($ctx['ssl'])) { + return new Failure(new SocketException( + "Can't enable TLS without configuration. " . + "If you used Amp\\Socket\\listen(), be sure to pass a ServerTlsContext as third argument, " . + "otherwise set the 'ssl' context option to the PHP stream resource." + )); + } + return Internal\enableCrypto($resource, [], true); } }