ghedipunk / PHP-Websockets

A Websockets server written in PHP.
BSD 3-Clause "New" or "Revised" License
913 stars 376 forks source link

PHP-Websockets in SSL #24

Closed pedropuppim closed 9 years ago

pedropuppim commented 9 years ago

I'm using the PHP-Websockets with SSL. The client connection is: var host = "wss: //127.0.0.1: 9000 /";

As I boot the server to meet SSL call?

ghedipunk commented 9 years ago

I do not provide support for TLS (SSL) because I know better than to try to do it myself.

Additionally, even if I were willing to help people hand over data that they feel should be secure to J. Random Hacker, I don't know of any libraries that are robust and widely enough used that also happen to be written for PHP sockets for me to feel comfortable in implementing it.

ghedipunk commented 9 years ago

To expand on things a bit... (I don't want anyone to think that I'm just being short)

Websockets is a whole separate connection to a server from the HTTP connection. Yes, Websockets can work through properly configured HTTP servers that can forward the connection on to a separate system, thus allowing Websockets to work in heavily firewalled environments. However, once the handshake successfully transfers control of the socket from the web server to the websockets server, any pre-existing TLS connection will have to be maintained. I don't see anything in the Websockets RFC that allows passing TLS connection information between two services on the same host, and I strongly suspect that, besides being a Very Bad Idea (tm), it also breaks TLS itself.

So, in order for websockets to work with TLS in an environment where a web server passes the connection, the web server itself would have to maintain the socket... which is the exact opposite of the philosophy behind HTTP, and is why most web servers don't support websockets out of the box. It also introduces the issue of unencrypted sensitive data floating around in a server sitting outside of your DMZ.

There are third party TLS terminators out there that will work as reverse proxies for a websockets server, but I haven't done any research into them so can not recommend any. If you do decide to use a third party TLS terminator, keep in mind that you're taking on additional risk by having unencrypted sensitive data outside of your DMZ, and that many TLS terminators are tuned to handle HTTP traffic -- that is, they expect the web server itself to close connections routinely (hence the need for a connection "heartbeat", and hence the Heartbleed vulnerability a bit ago). Websockets, on the other hand, are persistent connections, so could complicate TLS terminators.

And finally, there are very few use cases for PHP to interact directly with network traffic... The vast majority of times that PHP interacts through the network is through a web server or through very specific connections to well documented services such as to a database. There are even fewer use cases to use end-to-end encryption on that direct network traffic. Thus, I personally don't trust any TLS implementations written in PHP. While I'm certain that some very bright security professionals have written pretty good PHP implementations of TLS, these implementations haven't been battle hardened. "Pretty good" isn't good enough. In the security world, "pretty good" is a wide open doorway with a plush red carpet and neon signs saying "steal this data."

So no, I will not be implementing TLS in this websockets server. If you do want TLS in websockets, I strongly discourage using PHP. Perhaps you'd be happier writing a websockets server in C++ that uses OpenSSL. I know that if any of your users knew better, they'd be happier as well.

pedropuppim commented 9 years ago

thanks for the reply!