Commit ed7ec2eb by Fábián János

Vncproxy has been repaired (python 3.6)

parent ac315429
......@@ -4,6 +4,7 @@
from os import environ
from django.conf import settings
from twisted.internet import defer
from twisted.internet import protocol
from twisted.internet.protocol import Factory, Protocol
......@@ -79,7 +80,8 @@ class ProxyClientFactory(protocol.ReconnectingClientFactory):
class VNCWebSocketHandler(Protocol):
def makeConnection(self, transport):
try:
value = signing.loads(transport.request.args['d'][0],
settings.configure()
value = signing.loads(transport.request.args[b'd'][0].decode(),
key=PROXY_SECRET, max_age=KEY_MAX_AGE)
try:
self.src = transport.request.requestHeaders.getRawHeaders(
......@@ -134,7 +136,7 @@ if __name__ == "__main__":
opts, args = parser.parse_args()
logging.basicConfig(level=opts.loglevel)
resource = File('.')
resource.putChild('vnc', WebSocketsResource(
resource.putChild(b'vnc', WebSocketsResource(
lookupProtocolForFactory(VNCWebSocketFactory())))
reactor.listenTCP(9999, Site(resource))
reactor.run()
......@@ -13,7 +13,7 @@ factory.
"""
import base64
import struct
from hashlib import sha1
from struct import pack, unpack
......@@ -88,7 +88,7 @@ def _makeAccept(key):
@rtype: C{str}
@return: An encoded response.
"""
return sha1("%s%s" % (key, _WS_GUID)).digest().encode("base64").strip()
return base64.b64encode(sha1((key + _WS_GUID).encode("ascii")).digest()).decode("ascii")
def _mask(buf, key):
......@@ -104,10 +104,10 @@ def _mask(buf, key):
@rtype: C{str}
@return: A masked buffer of bytes.
"""
key = [ord(i) for i in key]
key = [i for i in key]
buf = list(buf)
for i, char in enumerate(buf):
buf[i] = chr(ord(char) ^ key[i % 4])
buf[i] = chr(char ^ key[i % 4])
return "".join(buf)
......@@ -129,7 +129,6 @@ def _makeFrame(buf, opcode, fin, mask=None):
@type mask: C{int} or C{NoneType}
@param mask: If specified, the masking key to apply on the created frame.
@rtype: C{str}
@return: A packed frame.
"""
......@@ -140,11 +139,11 @@ def _makeFrame(buf, opcode, fin, mask=None):
lengthMask = 0
if bufferLength > 0xffff:
length = "%s%s" % (chr(lengthMask | 0x7f), pack(">Q", bufferLength))
length = bytes(chr(lengthMask | 0x7f), 'UTF-8') + pack(">Q", bufferLength)
elif bufferLength > 0x7d:
length = "%s%s" % (chr(lengthMask | 0x7e), pack(">H", bufferLength))
length = bytes(chr(lengthMask | 0x7e), 'UTF-8') + pack(">H", bufferLength)
else:
length = chr(lengthMask | bufferLength)
length = bytes( chr(lengthMask | bufferLength), 'UTF-8')
if fin:
header = 0x80
......@@ -154,7 +153,7 @@ def _makeFrame(buf, opcode, fin, mask=None):
header = chr(header | opcode.value)
if mask is not None:
buf = "%s%s" % (mask, _mask(buf, mask))
frame = "%s%s%s" % (header, length, buf)
frame = bytes( header, 'raw_unicode_escape' ).strip() + length + buf
return frame
......@@ -170,7 +169,7 @@ def _parseFrames(frameBuffer, needMask=True):
@type needMask: C{bool}
"""
start = 0
payload = "".join(frameBuffer)
payload = b"".join(frameBuffer)
while True:
# If there's not at least two bytes in the buffer, bail.
......@@ -178,7 +177,7 @@ def _parseFrames(frameBuffer, needMask=True):
break
# Grab the header. This single byte holds some flags and an opcode
header = ord(payload[start])
header = payload[start]
if header & 0x70:
# At least one of the reserved flags is set. Pork chop sandwiches!
raise _WSException("Reserved flag in frame (%d)" % (header,))
......@@ -195,7 +194,7 @@ def _parseFrames(frameBuffer, needMask=True):
# Get the payload length and determine whether we need to look for an
# extra length.
length = ord(payload[start + 1])
length = payload[start + 1]
masked = length & 0x80
if not masked and needMask:
......@@ -343,9 +342,13 @@ class WebSocketsTransport(object):
# Send a closing frame. It's only polite. (And might keep the browser
# from hanging.)
if not self._disconnecting:
data = "%s%s" % (pack(">H", code.value), reason)
frame = _makeFrame(data, CONTROLS.CLOSE, True)
self._transport.write(frame)
msg = b''
if code is not None:
msg += struct.pack(">H", code.value )
if reason is not None:
msg += reason.encode("UTF-8")
self._transport.write(msg)
self._disconnecting = True
self._transport.loseConnection()
......@@ -462,7 +465,7 @@ class _WebSocketsProtocolWrapperReceiver():
return
self._messages.append(data)
if fin:
content = "".join(self._messages)
content = b"".join(self._messages)
self._messages[:] = []
self._wrappedProtocol.dataReceived(content)
......@@ -618,7 +621,7 @@ class WebSocketsResource(object):
# If we fail at all, we'll fail with 400 and no response.
failed = False
if request.method != "GET":
if request.method != b"GET":
# 4.2.1.1 GET is required.
failed = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment