'Sec-WebSocket-Accept' header is missing in Chrome 17 - google-chrome

Edit:
I tried this phpwebsocket: http://www.wilky.it/Shared/phpwebsocket.zip and it works in Firefox, but my question still remains: how do I get websockets to work with a php server in Chrome 17?
I'm following the tutorial here: http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/
It appears as though the client connects, and then immediately disconnects. I noticed this error in the console:
Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing
I'm trying it in Chrome 17.0.963.56 on my WAMP localhost with the php_sockets extension enabled.
I saw mentioned somewhere that Chrome had changed what it supported, but it didn't go in depth on how to fix it. I was hoping someone could step me through it. (I'm brand new to websockets).
Server:
{PATH}>php startDaemon.php
2012-02-20 07:02:51 System: Socket Resource id #7 created.
2012-02-20 07:02:51 System: Socket bound to localhost:8000.
2012-02-20 07:02:51 System: Start listening on Socket.
2012-02-20 07:03:01 WebSocket: Resource id #8 CONNECTED!
2012-02-20 07:03:01 WebSocket: Requesting handshake…
2012-02-20 07:03:01 WebSocket: Handshaking…
2012-02-20 07:03:01 WebSocket: Done handshaking…
2012-02-20 07:03:01 WebSocket: Resource id #8 disconnected!
Client:
Socket Status: 0
Socket Status: 3 (Closed)

I have the same problem (and I do not seem to be able to post a comment here, so I post a reply).
Actually, I just downloaded and tested phpwebsocket.
On safari 5.1.4, it works just fine.
On Chrome 17, I got the same error in the script log console:
Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing
So, in websocket.class.php, I added to the header returned by server:
$accept = base64_encode(SHA1($key."258EAFA5-E914-47DA-95CA-C5AB0DC85B11"));
And I get the error:
Error during WebSocket handshake: Sec-WebSocket-Accept mismatch
Now, the header received by the server is:
GET /websocket/server.php HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: localhost:12345
Origin: http://localhost:8888
Sec-WebSocket-Key: OqMJI0t/cOl6d6JNE+Op0g==
Sec-WebSocket-Version: 13
And the header sent back by the server is:
HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Origin: http://localhost:8888
Sec-WebSocket-Location: ws://localhost:12345/websocket/server.php
Sec-WebSocket-Accept: ZjY5ODliNTViYzJlOTNkMjk4OTg3Y2U2NjQ3MTBlZjZiNzliYzk4Yg==
The Sec-WebSocket-Accept seems good, but still there is a mismatch error. Do you see a mistake somewhere? Maybe the protocol has changed to calculate the Sec-WebSocket-Accept, but I don't find it... Thanks for your help!
Edit: Here seems to be the solution (for me, at least): adding the parameter true to the SHA1 function, as found in files given in this issue thread. So, the Sec-WebSocket-Accept must be found like this:
$accept = base64_encode(SHA1($key."258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true));
And, Sec-WebSocket-Key1 and Sec-WebSocket-Key2 does not seem to be present anymore in the client request, instead, $key must be extracted from the header: "Sec-WebSocket-Key".
New issue: It seems too that even if the web socket connection now works on the handshake, it disconnects when the first message is sent.

I noticed that in the console of Chrome 19:
A server must not mask any frames that it sends to the client.
Maybe this is the problem. It disconnects as soon as a message is sent. It works fine in Firefox.
I fixed this websocket problem and it works in chrome now.
First I used:
Then I used the encode function from:
https://github.com/lemmingzshadow/php-websocket
I fixed the replaced the encode function with the one in the connection.php file in lemmingzshadow’s github and it started working. The function is called: hybi10Encode in the \server\lib\WebSocket\connection.php file.
change this parameter in the function encode: $masked = true to $masked = false

An EASY way to fix is add Sec-WebSocket-Accept information when do_handshake, code as below:
list($resource,$host,$origin,$key) = $this->getheaders($buffer);
$accept = base64_encode(SHA1($key."258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true));
$upgrade = "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" .
"Upgrade: WebSocket\r\n" .
"Connection: Upgrade\r\n" .
"WebSocket-Origin: {$origin}\r\n" .
"WebSocket-Location: ws://{$host}{$resource}\r\n".
"Sec-WebSocket-Accept: " . $accept . "\r\n\r\n";
$this->handshakes[$socket_index] = true;
socket_write($socket,$upgrade,strlen($upgrade));
where,
$accept = base64_encode(SHA1($key."258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true));
$key is Sec-WebSocket-Key got from $buffer, you can print_r($buffer) to have a look.
Hope this can solve your problem..

Related

Heroku app: Error during WebSocket handshake: Unexpected response code: 200

I followed a tutorial on how to make a multiplayer tetris game, here is the repo:
https://github.com/Leftier/tetris
It worked just fine on localhost so I tried to deploy it in heroku (https://tetrixtest.herokuapp.com/ --ASD to move Q/E to rotate) but I get the following error:
WebSocket connection to 'wss://tetrixtest.herokuapp.com/' failed: Error during WebSocket handshake: Unexpected response code: 200
while trying to create the webSocket in this line (connection-manager.js line 14):
this.conn = new WebSocket(`wss://${window.location.hostname}:${window.location.port}`)
I don't know much about webSockets,
at first I thought that heroku was not able to handle websockets but that wasn't the case so I tried using the link directly as an argument instead of reading it from the browser but still the same issue.
I would like some clues/hints about why does this happens, I searched in google and github, but I only found issues related to socket.io
For me the solution was to turn on "Session affinity" by running this command heroku features:enable http-session-affinity
More info at https://devcenter.heroku.com/articles/session-affinity
Session affinity, sometimes referred to as sticky sessions, is a
platform feature that associates all HTTP requests coming from an
end-user with a single application instance (web dyno).

Jodd Message parsing failed

I'm using Jodd version 3.7 and I would like to read an outlook account (outlook.it).
Outlook SMTP is :
server: smtp-mail.outlook.com
port: 587 with TLS
and IMAP is :
server: imap-mail.outlook.com
port: 993 with SSL
Sending email is fine, but when I try to receive email with IMAP with method receiveAndDelete I get the following error:
jodd.mail.MailException: Message parsing failed; <--- javax.mail.MessageRemovedException
the email message is really deleted, but I dont want to get that exception.
How can i avoid this?
It's a bug! Let me explain: Jodd copies data from received message to its own structure, however, this is done after the deletion flag is set. Therefore, mail library detects it is a deleted message and throws an exception.
Fixed here, by parsing the message before setting the flags.
Workaround: don't use receiveAndDelete - instead receive and then delete later.

Using outbound Node-RED email to local SMTP server

I have a local SMTP email server I use for testing purposes running on my machine. It listens for SMTP on port 25. I am able to send and receive emails to it using a regular email client.
When I build a Node-RED flow that contains an e-mail output node and configure its properties with:
to: <email address>
server: localhost
port: 25
and submit a flow, I get the error:
25 Feb 16:43:24 - [error] [e-mail:<email address>] Error: 101057795:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794:
I am at a loss on how to proceed. Looking at the messages, it almost appears that there is some form of SSL negotiation/test at play here. Switching on trace on my SMTP server, I find the following logs each time I try and run a flow:
"TCPIP" 10708 "2016-02-25 16:43:08.294" "TCP - 127.0.0.1 connected to 127.0.0.1:25."
"DEBUG" 10708 "2016-02-25 16:43:08.298" "Creating session 22"
"SMTPD" 10708 22 "2016-02-25 16:43:08.298" "127.0.0.1" "SENT: 220 WIN7-X64 ESMTP"
"DEBUG" 9772 "2016-02-25 16:43:08.299" "Ending session 22"
It appears that the Node-RED node is sending a connection request, getting back the SMTP 220 response and then failing immediately after that.
I came across the same problem and have a nasty hack that will enable mail to go via my local exchange server's plain SMTP, with no auth.
Edit the .../61-email.js file and change it thusly:
var smtpTransport = nodemailer.createTransport({
host: node.outserver,
port: node.outport,
secure: false,
ignoreTLS: true //,
// auth: {
// user: node.userid,
// pass: node.password
// }
});
I see Dave has replied to the github issue but just to close the loop on this question.
At this time (Feb 2016) the node assumes SSL is always available and enabled, at some point we need to go back to the email node and find a simple way to expose a lot more of the nodemailer options to allow connections to a wider range of email providers both public and private.

502 (BAD GATEWAY) and 504 (GATEWAY TIMEOUT) in Wirecloud

Time ago we set up a PEP proxy to secure the API our widgets are using. All have being working correctly until today, that we are receiving a 502 Bad Gateway error code for every call going through the proxy.
We have checked the requests are reaching our server and it is responsing correctly to them. The parameters added by the proxy (x-nick-name, x-display-name...) are defined correctly too.
We have also checked the requests outside wirecloud and all go well: we get the token properly and use it in the subsequent calls without problem.
We do not know where this error comes from, any ideas?
EDIT 06/11/2015
After Alvaro's new setting we are receiving the following error in the response body:
{
"description": "Connection Error",
"details": "('Connection aborted.', error(104, 'Connection reset by peer'))"
}
EDIT 09/11/15
Today, the code received in the request's response is different: 504 GATEWAY TIMEOUT
{
"description": "Connection Error",
"details": "('Connection aborted.', error(104, 'Connection reset by peer'))"
}
EDIT 16/11/15
Answering to Mr. Alonso's question:
1.- If we request directly to the server, the response is correctly displayed in the application.
2.- Here you can see the logs from the PEP Proxy with the new line added. As you can see the request is redirected correctly but the info is not displayed in the app.
Seems that the problem is in the PEP proxy side.
I've checked using other tools like curl (I obtained the connection details from the server log). Making the same request using curl gives the same result than using WireCloud: connection reset by peer. Also, if I make the request without the X-Auth-Token header, your service responds with an 401 error code. This is important, because it means that there is not a communication problem between the Mashup portal and your server. I don't know why, but the PEP proxy seems to be crashing when making the authenticated request from the Mashup portal (the same command works executing it from my machine).
I suggest you to restart the PEP proxy. If the problem persist, please attach any available info about the crash from the PEP proxy logs.
You can check three things to give us more information:
Try to remove the PEP and send the request directly to your service.
Introduce a new log in PEP to print the headers of the response: line 41 of lib/HTTPClient.js, log.debug("Headers: ", headers);
Try to send a request to the root path (directly to the tomacat or apache)
If not perhaps we can talk in private to check more information

curl: (56) Failure when receiving data from the peer while accessing http://maps.google.com/maps/api/geocode/xml

I am facing problem while accessing http://maps.google.com/maps/api/geocode/xml through code (simplexml_load_file). Its not working from putty console also.
Here are the alternatives i used:
Option1 >
$url = 'Above URL?adress=XXXAddress HereXXX';
$xml = simplexml_load_file($url);
Error:Warning: simplexml_load_file(above URL?address=XXXAddress HereXXX): failed to open stream: Connection timed out in /data/mgr_3.2.x_5/www/manager/support_scripts/geocode.php on line 5
Warning: simplexml_load_file(): I/O warning : failed to load external entity "Above URL?address=XXXAddress HereXXX" in /data/mgr_3.2.x_5/www/manager/support_scripts/geocode.php on line 5
bool(false)
Option 2 >
Tried it from Server:
]# curl --data "XXXXXXXXXXXXXXXXX" --verbose http://maps.google.com/maps/api/geocode/
Error:
* Closing connection #0
* Failure when receiving data from the peer
curl: (56) Failure when receiving data from the peer
Curl Details:
rpm -qa|grep curl
python-pycurl-7.19.0-8.el6.x86_64
curl-7.19.7-36.el6_4.x86_64
libcurl-7.19.7-36.el6_4.x86_64
Recently my code migrated to another server and latest PHP version (5.4.14).
Tried all solutions given on various sites. I am badly stucked. Please Help out.
Thanks in advance
Sandip
http://maps.google.com/ was blocked on the server which caused this issue. Now it is allowed and issue is resolved. Thanks