1
0
mirror of https://github.com/fcwu/docker-ubuntu-vnc-desktop synced 2026-08-05 16:12:41 +02:00

feat: upgrade noVNC

This commit is contained in:
Doro Wu
2017-02-25 12:55:24 +08:00
parent 394c340688
commit 0c04c5ec3b
489 changed files with 18241 additions and 54521 deletions
+2 -3
View File
@@ -2,8 +2,8 @@
"author": "Joel Martin <github@martintribe.org> (http://github.com/kanaka)",
"name": "websockify",
"description": "websockify is a WebSocket-to-TCP proxy/bridge",
"license": "LGPL-3",
"version": "0.6.0",
"license": "LGPL-3.0",
"version": "0.8.0",
"repository": {
"type": "git",
"url": "git://github.com/kanaka/websockify.git"
@@ -17,7 +17,6 @@
},
"dependencies": {
"ws": ">=0.4.27",
"base64": "latest",
"optimist": "latest",
"policyfile": "latest"
}
+5 -30
View File
@@ -5,8 +5,8 @@
// Licensed under LGPL version 3 (see docs/LICENSE.LGPL-3)
// Known to work with node 0.8.9
// Requires node modules: ws, optimist and policyfile
// npm install ws optimist policyfile
// Requires node modules: ws and optimist
// npm install ws optimist
var argv = require('optimist').argv,
@@ -16,7 +16,6 @@ var argv = require('optimist').argv,
url = require('url'),
path = require('path'),
fs = require('fs'),
policyfile = require('policyfile'),
Buffer = require('buffer').Buffer,
WebSocketServer = require('ws').Server,
@@ -42,11 +41,7 @@ new_client = function(client) {
target.on('data', function(data) {
//log("sending message: " + data);
try {
if (client.protocol === 'base64') {
client.send(new Buffer(data).toString('base64'));
} else {
client.send(data,{binary: true});
}
client.send(data);
} catch(e) {
log("Client closed, cleaning up target");
target.end();
@@ -64,11 +59,7 @@ new_client = function(client) {
client.on('message', function(msg) {
//log('got message: ' + msg);
if (client.protocol === 'base64') {
target.write(new Buffer(msg, 'base64'));
} else {
target.write(msg,'binary');
}
target.write(msg);
});
client.on('close', function(code, reason) {
log('WebSocket client disconnected: ' + code + ' [' + reason + ']');
@@ -123,18 +114,6 @@ http_request = function (request, response) {
});
};
// Select 'binary' or 'base64' subprotocol, preferring 'binary'
selectProtocol = function(protocols, callback) {
if (protocols.indexOf('binary') >= 0) {
callback(true, 'binary');
} else if (protocols.indexOf('base64') >= 0) {
callback(true, 'base64');
} else {
console.log("Client must support 'binary' or 'base64' protocol");
callback(false);
}
}
// parse source and target arguments into parts
try {
source_arg = argv._[0].toString();
@@ -183,10 +162,6 @@ if (argv.cert) {
webServer = http.createServer(http_request);
}
webServer.listen(source_port, function() {
wsServer = new WebSocketServer({server: webServer,
handleProtocols: selectProtocol});
wsServer = new WebSocketServer({server: webServer});
wsServer.on('connection', new_client);
});
// Attach Flash policyfile answer service
policyfile.createServer().listen(-1, webServer);
+16 -8
View File
@@ -578,12 +578,6 @@ ws_ctx_t *do_handshake(int sock) {
if (len == 0) {
handler_msg("ignoring empty handshake\n");
return NULL;
} else if (bcmp(handshake, "<policy-file-request/>", 22) == 0) {
len = recv(sock, handshake, 1024, 0);
handshake[len] = 0;
handler_msg("sending flash policy response\n");
send(sock, POLICY_RESPONSE, sizeof(POLICY_RESPONSE), 0);
return NULL;
} else if ((bcmp(handshake, "\x16", 1) == 0) ||
(bcmp(handshake, "\x80", 1) == 0)) {
// SSL
@@ -612,15 +606,28 @@ ws_ctx_t *do_handshake(int sock) {
}
offset = 0;
for (i = 0; i < 10; i++) {
len = ws_recv(ws_ctx, handshake+offset, 4096);
if (len == 0) {
/* (offset + 1): reserve one byte for the trailing '\0' */
if (0 > (len = ws_recv(ws_ctx, handshake + offset, sizeof(handshake) - (offset + 1)))) {
handler_emsg("Read error during handshake: %m\n");
free_ws_ctx(ws_ctx);
return NULL;
} else if (0 == len) {
handler_emsg("Client closed during handshake\n");
free_ws_ctx(ws_ctx);
return NULL;
}
offset += len;
handshake[offset] = 0;
if (strstr(handshake, "\r\n\r\n")) {
break;
} else if (sizeof(handshake) <= (size_t)(offset + 1)) {
handler_emsg("Oversized handshake\n");
free_ws_ctx(ws_ctx);
return NULL;
} else if (9 == i) {
handler_emsg("Incomplete handshake\n");
free_ws_ctx(ws_ctx);
return NULL;
}
usleep(10);
}
@@ -628,6 +635,7 @@ ws_ctx_t *do_handshake(int sock) {
//handler_msg("handshake: %s\n", handshake);
if (!parse_handshake(ws_ctx, handshake)) {
handler_emsg("Invalid WS request\n");
free_ws_ctx(ws_ctx);
return NULL;
}
+24 -83
View File
@@ -13,7 +13,6 @@ require 'openssl'
require 'stringio'
require 'digest/md5'
require 'digest/sha1'
require 'base64'
unless OpenSSL::SSL::SSLSocket.instance_methods.index("read_nonblock")
module OpenSSL
@@ -92,7 +91,6 @@ Sec-WebSocket-Accept: %s\r
t[:my_client_id] = @@client_id
t[:send_parts] = []
t[:recv_part] = nil
t[:base64] = nil
puts "in serve, client: #{t[:my_client_id].inspect}"
@@ -151,11 +149,7 @@ Sec-WebSocket-Accept: %s\r
return data
end
def encode_hybi(buf, opcode, base64=false)
if base64
buf = Base64.encode64(buf).gsub(/\n/, '')
end
def encode_hybi(buf, opcode)
b1 = 0x80 | (opcode & 0x0f) # FIN + opcode
payload_len = buf.length
if payload_len <= 125
@@ -170,7 +164,7 @@ Sec-WebSocket-Accept: %s\r
return [header + buf, header.length, 0]
end
def decode_hybi(buf, base64=false)
def decode_hybi(buf)
f = {'fin' => 0,
'opcode' => 0,
'hlen' => 2,
@@ -216,10 +210,6 @@ Sec-WebSocket-Accept: %s\r
f['payload'] = buf[f['hlen']...full_len]
end
if base64 and [1, 2].include?(f['opcode'])
f['payload'] = Base64.decode64(f['payload'])
end
# close frame
if f['opcode'] == 0x08
if f['length'] >= 2
@@ -251,13 +241,8 @@ Sec-WebSocket-Accept: %s\r
encbuf = ""
bufs.each do |buf|
if t[:version].start_with?("hybi")
if t[:base64]
encbuf, lenhead, lentail = encode_hybi(
buf, opcode=1, base64=true)
else
encbuf, lenhead, lentail = encode_hybi(
buf, opcode=2, base64=false)
end
encbuf, lenhead, lentail = encode_hybi(
buf, opcode=2)
else
encbuf, lenhead, lentail = encode_hixie(buf)
end
@@ -302,7 +287,7 @@ Sec-WebSocket-Accept: %s\r
while buf.length > 0
if t[:version].start_with?("hybi")
frame = decode_hybi(buf, base64=t[:base64])
frame = decode_hybi(buf)
if frame['payload'] == nil
traffic "}."
@@ -359,7 +344,7 @@ Sec-WebSocket-Accept: %s\r
msg = [reason.length, code].pack("na8")
end
buf, lenh, lent = encode_hybi(msg, opcode=0x08, base64=false)
buf, lenh, lent = encode_hybi(msg, opcode=0x08)
t[:client].write(buf)
elsif t[:version] == "hixie-76"
buf = "\xff\x00"
@@ -412,73 +397,29 @@ Sec-WebSocket-Accept: %s\r
protocols = h.fetch("sec-websocket-protocol", h["websocket-protocol"])
ver = h.fetch('sec-websocket-version', nil)
if ver
# HyBi/IETF vesrion of the protocol
# HyBi 07 reports version 7
# HyBi 08 - 12 report version 8
# HyBi 13 and up report version 13
if ['7', '8', '13'].include?(ver)
t[:version] = "hybi-%02d" % [ver.to_i]
else
raise EClose, "Unsupported protocol version %s" % [ver]
end
# choose binary if client supports it
if protocols.include?('binary')
t[:base64] = false
elsif protocols.include?('base64')
t[:base64] = true
else
raise EClose, "Client must support 'binary' or 'base64' sub-protocol"
end
key = h['sec-websocket-key']
# Generate the hash value for the accpet header
accept = Base64.encode64(
Digest::SHA1.digest(key + @@GUID)).gsub(/\n/, '')
response = @@Server_handshake_hybi % [accept]
if t[:base64]
response += "Sec-WebSocket-Protocol: base64\r\n"
else
response += "Sec-WebSocket-Protocol: binary\r\n"
end
response += "\r\n"
# HyBi/IETF vesrion of the protocol
# HyBi 07 reports version 7
# HyBi 08 - 12 report version 8
# HyBi 13 and up report version 13
if ['7', '8', '13'].include?(ver)
t[:version] = "hybi-%02d" % [ver.to_i]
else
# Hixie vesrion of the protocol (75 or 76)
body = handshake.match(/\r\n\r\n(........)/)
if body
h['key3'] = body[1]
trailer = gen_md5(h)
pre = "Sec-"
t[:version] = "hixie-76"
else
trailer = ""
pre = ""
t[:version] = "hixie-75"
end
# base64 required for Hixie since payload is only UTF-8
t[:base64] = true
response = @@Server_handshake_hixie % [pre, h['origin'], pre,
"ws", h['host'], t[:path]]
if protocols && protocols.include?('base64')
response += "%sWebSocket-Protocol: base64\r\n" % [pre]
else
msg "Warning: client does not report 'base64' protocol support"
end
response += "\r\n" + trailer
raise EClose, "Unsupported protocol version %s" % [ver]
end
key = h['sec-websocket-key']
# Generate the hash value for the accpet header
accept = Base64.encode64(
Digest::SHA1.digest(key + @@GUID)).gsub(/\n/, '')
response = @@Server_handshake_hybi % [accept]
response += "\r\n"
msg "%s WebSocket connection" % [stype]
msg "Version %s, base64: '%s'" % [t[:version], t[:base64]]
msg "Version %s" % [t[:version]]
if t[:path] then msg "Path: '%s'" % [t[:path]] end
#puts "sending reponse #{response.inspect}"