Fixed byte-ordering in SHA1, added separate Origin header, and added support for prefixed MozWebSocket.

master
Nicolas Favre-Felix 13 years ago
parent 5e41e76778
commit 9b2cadadab

@ -91,7 +91,15 @@ function log(id, dir, msg) {
}
function testJSON() {
var jsonSocket = new WebSocket("ws://"+host+":"+port+"/.json");
if(typeof(WebSocket) == 'function')
f = WebSocket;
if(typeof(MozWebSocket) == 'function')
f = MozWebSocket;
var jsonSocket = new f("ws://"+host+":"+port+"/.json");
var self = this;
send = function(j) {

@ -28,7 +28,7 @@ ws_compute_handshake(struct http_client *c, char *out, size_t *out_sz) {
char magic[] = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
SHA1Context ctx;
base64_encodestate b64_ctx;
int pos;
int pos, i;
// websocket handshake
const char *key = client_get_header(c, "Sec-WebSocket-Key");
@ -43,7 +43,10 @@ ws_compute_handshake(struct http_client *c, char *out, size_t *out_sz) {
SHA1Reset(&ctx);
SHA1Input(&ctx, buffer, buffer_sz);
SHA1Result(&ctx);
memcpy(sha1_output, &ctx.Message_Digest[0], 20);
for(i = 0; i < 5; ++i) { // put in correct byte order before memcpy.
ctx.Message_Digest[i] = ntohl(ctx.Message_Digest[i]);
}
memcpy(sha1_output, (unsigned char*)ctx.Message_Digest, 20);
// encode `sha1_output' in base 64, into `out'.
base64_init_encodestate(&b64_ctx);
@ -83,6 +86,8 @@ ws_handshake_reply(struct http_client *c) {
if((origin = client_get_header(c, "Origin"))) {
origin_sz = strlen(origin);
} else if((origin = client_get_header(c, "Sec-WebSocket-Origin"))) {
origin_sz = strlen(origin);
}
if((host = client_get_header(c, "Host"))) {
host_sz = strlen(host);

Loading…
Cancel
Save