Skip to content

Commit

Permalink
fixed #215
Browse files Browse the repository at this point in the history
  • Loading branch information
liris committed Oct 28, 2015
1 parent 8a73907 commit 4d5bc1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ChangeLog
- 0.34.0

- Change import style (#203)
- fix attribute error on the older python. (#215)

- 0.33.0

Expand Down
13 changes: 8 additions & 5 deletions websocket/_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@

__all__ = ["handshake_response", "handshake"]

if hasattr(hmac, "compare_digest"):
compare_digest = hmac.compare_digest
else:
def compare_digest(s1, s2):
return s1 == s2

# websocket supported version.
VERSION = 13

Expand Down Expand Up @@ -99,7 +105,7 @@ def _get_handshake_headers(resource, host, port, options):
if isinstance(header, dict):
header = map(": ".join, header.items())
headers.extend(header)

cookie = options.get("cookie", None)

if cookie:
Expand Down Expand Up @@ -149,10 +155,7 @@ def _validate(headers, key, subprotocols):

value = (key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").encode('utf-8')
hashed = base64encode(hashlib.sha1(value).digest()).strip().lower()
if sys.version_info[0] == 2 and sys.version_info[1] < 7:
success = (hashed == result)
else:
success = hmac.compare_digest(hashed, result)
success = compare_digest(hashed, result)

if success:
return True, subproto
Expand Down

0 comments on commit 4d5bc1e

Please sign in to comment.