Skip to content

Commit

Permalink
Test that Host: header is present
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc2k committed Apr 14, 2019
1 parent 5be2878 commit 1ac741a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/secure_http_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

from homekit.http_impl.secure_http import SecureHttp
from homekit.exceptions import AccessoryDisconnectedError, EncryptionError
from homekit.crypto.chacha20poly1305 import chacha20_aead_encrypt

from homekit.crypto.chacha20poly1305 import chacha20_aead_encrypt, chacha20_aead_decrypt

class ResponseProvider(threading.Thread):
"""
Expand All @@ -41,16 +40,18 @@ def __init__(self, sock, c2a_key, a2c_key, encryption_fail=False):
self.encryption_fail = encryption_fail

def run(self):
# tmp = self.sock.recv(1024)
# length = int.from_bytes(tmp[0:2], 'little')
# tmp = tmp[2:]
# block = tmp[0:length]
# tmp = tmp[length:]
# tag = tmp[0:16]
# request = chacha20_aead_decrypt(length.to_bytes(2, byteorder='little'),
# self.c2a_key,
# self.c2a_counter.to_bytes(8, byteorder='little'),
# bytes([0, 0, 0, 0]), block + tag)
tmp = self.sock.recv(1024)
length = int.from_bytes(tmp[0:2], 'little')
tmp = tmp[2:]
block = tmp[0:length]
tmp = tmp[length:]
tag = tmp[0:16]
request = chacha20_aead_decrypt(length.to_bytes(2, byteorder='little'),
self.c2a_key,
self.c2a_counter.to_bytes(8, byteorder='little'),
bytes([0, 0, 0, 0]), block + tag)

assert b'Host:' in request

self.c2a_counter += 1

Expand Down

0 comments on commit 1ac741a

Please sign in to comment.