Repository navigation
Problem with enabling crypto on stream socket connection #9261
Description
Activity
I would like to add when I don't call
stream_socket_enable_cryptofor the first time to enable it, it does work against non-SSL host without any problem.- changed the title
[-]Problem with enabling crypto on steam socket connection[/-][+]Problem with enabling crypto on stream socket connection[/+]on Aug 6, 2022 I did some sniffing with Wireshark and I discovered when you invoke TLS handshake and host doesn't have SSL it answers with flag FIN (connection finish). That means the connection is closed by host immediatelly.
Still the warning "SSL: The operation completed successfully." doesn't make sense.
Hmm I can't find any place where we would trigger such warning. I even double checked OpenSSL and nothing like this is there either. Are you sure this is a PHP warning and not something triggered by application?
I'll check it out more deeply and return.
I found the warning - it's actually OS socket error message prefixed with SSL:
.Lines 234 to 237 in cb5d5d8
char *estr = php_socket_strerror(php_socket_errno(), NULL, 0); php_error_docref(NULL, E_WARNING, "SSL: %s", estr); Coincidentally I just stumbled on it when writing a test for some SNI error and have to agree that this really does not make much sense. I will look into it.
- added a commit that references this issue
on Jul 26, 2025 I have been looking into this more closely.
The error that I noticed before was actually something else: #19245 . It doesn't actually hit this specific
SSL: %sat all.This looks more like a Windows specific issue because on syscall, errno should be usually set but it seems that for this particular case, it's 0 for some reason. I can't really see from the code why so might need to try it on Windows. I pushed a simple test (the linked commit above which is not the actual fix but just the test) so will give a try later and see.
Description
Hi.
I'm trying to deal with some things in php and I can't find my workaround about it and it starting to feel like there is something buggy. I tried looking on internet even asked on stackoverflow but nothing.
My goal is to create stream socket connection with disabled SSL but request certificate, then analyze it and update connection parameters. It works great on server with SSL but when I try it on server without SSL I'm not able to write into that connection even when I try to disable crypto on it.
You can see in the code what I described. I'm testing the connectivity against graph database Neo4j but I believe it doesn't matter. SSL certificate request is executed at first
stream_socket_enable_crypto. Maybe there is different way to request capture of that certificate, I don't know.What is weird when I enable crypto with
stream_socket_enable_cryptoagainst non-SSL host I get warning:and $enableCrypto contains (int)0. The warning doesn't make sense.
After all this logic the connection is still open but when I try to use it I get error
At this moment it feels like the encryption is enabled on client side (php) and the messages sent over socket therefore are not properly decoded on host, because there is no encryption at all. Like
stream_socket_enable_crypto($stream, false)did not disable crypto.PHP Version
PHP 7.4.16 with OpenSSL/1.1.1k and PHP 8.1.9 with OpenSSL/1.1.1q
Operating System
Windows 10