-
-
Notifications
You must be signed in to change notification settings - Fork 726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Socket] SSL support #2
Comments
I would be willing to implement this feature. We would need this for Websocket (Ratchet) with SSL support. |
That's cool! Having a parameter for |
+1 Please type hint the new parameter as an array. The code inside listen should create a context from it. |
Ok i started implementing this here: |
I spent an hour troubleshooting it (without internet :/). I was able to replicate the problem on server.php, but not able to fix the problem in React. In server.php if you set I'll try to take a look at it again tomorrow evening if anyone hasn't solved it by then. |
Yeah, i also thought it was the blocking mode, so I commented out the appropriate lines, but couldn't get to work it either. I hope I have time at work to have a look at it... |
I admittedly don't know the specifics on how TLS/SSL works. After a bit of reading I think I understand the problem. Given how SSL/TLS works I think |
I also thought about 'socket_select' being the culprit, because its the biggest difference to server.php. Any Idea as to why socket_select is a problem? Any idea for a workaround? @igorw I think stunnel would be the last option. Allthough I understand the reasoning for redis, I think this is a bit different here. Nobody said "use stunnel" when asked about ssl-support for node or apache, because they are both (as well as react/ratchet) something that directly interfaces with the browser. So having directly integrated ssl-support would be beneficial for wider adoption of react/ratchet. - Just my 2 cents. |
Have you tried the |
@Shyru Taking a second look at it, I think the culprit is Server.php.
I think that will solve one problem, but I imagine that's not the only one. If the server is non-blocking how does the handshake happen after |
@cboden It's extremely hacky, and a maliciously crafted connection could essentially halt the entire reactor. |
Any progress on this? Willing to have a crack just don't want to duplicate effort. |
@snorkeyg I don't think there has been any progress, unfortunately. Contribution is very welcome! The issue seems to be that PHPs handling of SSL on sockets expects that sockets block, which they don't in React. To implement SSL I think someone would have to write SSL negotiation in PHP (much like how @igorw wrote an async DNS client in React). |
I spent a lot of time googling around this issue, but did not find any meaningful. Found a lot of bug reports on php but they all dealt with connecting to ssl servers with async. (This was a known bug some time ago).
I even loaded the source code and made a diff between the version's but couldn't find out anything meaningful. I think it also only deals with async connects to ssl enabled servers. Perhaps it would also be an idea to crate a bug report on php to see what the developers say... |
Check out https://github.com/superjimpupcake/Pupcake, it is now supports https server building in PHP, and based on php-uv and stream_socket_server in php |
@superjimpupcake I didn't see anything special in your SSL commit that shows PHP handling SSL asynchronously.
|
I have successfully implemented a secure websocket with http://code.google.com/p/phpws/ before. That was awhile ago now though. Not sure if that may help provide an example of how it can be done? I have implemented stunnel for the moment to secure rachet websocket for the time being. |
Thanks for the link @snorkeyg but that library also blocks. You could turn blocking on in React and easily implement SSL, but that's not ideal. Blocking I/O will severely limit the number of concurrent connections to the server as well has open it up to DOS issues. |
Thanks for your feedback cboden,. I think in Pupcake, ssl does get handled asyncronously. The following code: file_put_contents($certificate, $cert_content); only happens once when the server starts ( calls to $app->run()), for all the client sockets, it is handled in the async fashion because: $loop = uv_default_loop(); php-uv handled all async operations. |
Sorry @cboden only just saw link to that library on Rachet issue for this. I remember now at the time blocking was an issue because it was for one hardware device to send messages to two browser clients. |
Just check out phpws, it is using the same technique as Pupcake to handle ssl: ./demo_ssl.php:57: stream_context_set_option($context, 'ssl', 'local_cert', $this->getPEMFilename()); So I would like to know more details on the potential blocking issues with this technique, if there are any. |
@superjimpupcake Here is the most basic example of an async SSL server in PHP (courtesy of @Shyru): https://gist.github.com/3395757 Run server.php and then run client.php in two CLI environments. You'll notice it works. Then uncomment the PHP sockets are blocking by default. phpws and pupcake don't explicitly set the stream socket server to be non-blocking so SSL works in both of them, but they're both synchronous, which severely limits the server from handling concurrent connections and makes them susceptible to DOS issues. |
The only ways to get this done would be to either patch the C part of PHP that handles stream + SSL to work w/ async SSL connections, or write our own wrapper in C to do it ourselves and install it as a PHP Extension. |
@e000, after a few hours research, i agree with you. I'm trying to see if the author of php-uv extension can help with it. |
We can also implement TLS in userland PHP code. |
Hi! Has there been any development on this feature, or was it abandoned due to the issues with PHP? |
It's quite hard to do this. Seems to me like we have two options:
|
This should in fact be possible to enable SSL after the connection is done with stream_socket_enable_crypto. Thanks to @DaveRandom for pointing that out. |
According to the comments,
|
@e000 Can you check the return value of the |
Implementing this would open possibilities for financial transactions! |
Hi guys. I'm quite interested on this. Any advice if ssl will be supported soon on React/Ratchet? Any workaround in the meanwhile? UPDATE: |
Is there any update on when SSL will be supported? |
@joshwegener Neither @igorw or myself plan to implement SSL in React. If someone else is willing to finish #119 we'll accept the PR. Due to the performance cost of doing SSL in user-land code we recommend having a separate process (Nginx/STunnel) handle SSL. |
@cboden Just took a quick look at both, they appear to be for windows? What do you recommend for Linux (as Server)? And could you point me in the direction of a good tutorial? |
@joshwegener not sure what makes you think that. nginx and stunnel are not windows-only. |
Unfortunately using an SSL wrapper such as nginx/stunnel will break $context = stream_context_get_params($stream);
var_dump($context["options"]["ssl"]["peer_certificate"]); Any chance to have real SSL support on the roadmap again? |
I'd be willing to accept SSL in if someone were to finish PR #119 but it's not work that I intend on doing anytime soon (if at all). In my projects I use a reverse proxy which will usually set the actual remote address as meta data in the stream. For example if you're using HTTP there will usually be a |
FWIW The issue with stream_socket_enable_crypto() blocking has been resolved in Version 5.3.3 (and newer). See https://bugs.php.net/bug.php?id=45808 & http://php.net/ChangeLog-5.php |
Hi, Thanks, |
Since 5.3 Qt (C++ Library) has a Websocket implementation (Client and Server) that also supports SSL. |
Is SSL support still on the roadmap? |
With the SSL changes in 5.6 this is something I'm going to re-evaluate. If an SSL socket server is implemented it will require PHP >= 5.6.1 |
With out any library support also we can do. The only thing is you need to be create secure channel using HTTP CONNECT method. After the channel has established you need to send websocket upgrade request to server through that channel. |
any progress with ssl suport? |
Hi Luke, Thanks, On Tue, Nov 25, 2014 at 1:14 AM, Luke notifications@github.com wrote:
|
Hi everybody! |
Thanks for the elaborate discussion so far! 👍 This is kind of an old issue and things have changed quite a bit since then :-) React now consists of individual components that are maintained individually. Supporting SSL/TLS is related to two components:
As such, I've just filed a new ticket reactphp/socket#24 to keep track of this, so I suppose it makes sense to focus our SSL/TLS related efforts on this component. |
Possible by by using a stream context, see comment in: http://php.net/stream_socket_server
The text was updated successfully, but these errors were encountered: