commit bb9a328ffe0d8234ef6157585b9bee1d63e6107f Author: David Fifield david@bamsoftware.com Date: Sun Apr 8 20:31:02 2012 -0700
Python 2.4–compatible sha1 import. --- connector.py | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/connector.py b/connector.py index d000a54..dad0071 100755 --- a/connector.py +++ b/connector.py @@ -4,7 +4,6 @@ import array import base64 import cStringIO import getopt -import hashlib import httplib import os import re @@ -19,6 +18,12 @@ import urllib import xml.sax.saxutils import BaseHTTPServer
+try: + from hashlib import sha1 +except ImportError: + # Python 2.4 uses this name. + from sha import sha as sha1 + DEFAULT_REMOTE_ADDRESS = "0.0.0.0" DEFAULT_REMOTE_PORT = 9000 DEFAULT_LOCAL_ADDRESS = "127.0.0.1" @@ -502,7 +507,7 @@ def handle_websocket_request(fd): # 4.2.2, with the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", taking the # SHA-1 hash of this concatenated value to obtain a 20-byte value and # base64-encoding (see Section 4 of [RFC4648]) this 20-byte hash. - accept_key = base64.b64encode(hashlib.sha1(key + MAGIC_GUID).digest()) + accept_key = base64.b64encode(sha1(key + MAGIC_GUID).digest()) handler.send_header("Sec-WebSocket-Accept", accept_key) # 5. Optionally, a |Sec-WebSocket-Protocol| header field, with a value # /subprotocol/ as defined in step 4 in Section 4.2.2.
tor-commits@lists.torproject.org