def handle_pair_verify(self): content_len = int(self.headers["Content-Length"]) body = self.rfile.read(content_len) if not self.server.hap: self.server.hap = Hap() res = self.server.hap.pair_verify(body) self.send_response(200) self.send_header("Content-Length", len(res)) self.send_header("Content-Type", HTTP_CT_OCTET) self.send_header("Server", self.version_string()) self.send_header("CSeq", self.headers["CSeq"]) self.end_headers() self.wfile.write(res) if self.server.hap.encrypted: hexdump(self.server.hap.accessory_shared_key) self.upgrade_to_encrypted(self.server.hap.accessory_shared_key)
def handle_pair_SV(self, op): body = self.rfile.read(int(self.headers["Content-Length"])) if not self.server.hap: self.server.hap = Hap(PI) if op == 'verify': res = self.server.hap.pair_verify(body) elif op == 'setup': res = self.server.hap.pair_setup(body) self.send_response(200) self.send_header("Content-Length", len(res)) self.send_header("Content-Type", self.headers["Content-Type"]) self.send_header("Server", self.version_string()) self.send_header("CSeq", self.headers["CSeq"]) self.end_headers() self.wfile.write(res) if self.server.hap.encrypted: hexdump(self.server.hap.accessory_shared_key) self.upgrade_to_encrypted(self.server.hap.accessory_shared_key)
def __init__(self): announce_id, self.ltpk = Hap(PI).configure() self.public_int = int.from_bytes(self.ltpk, byteorder='big') # builds a 64 char hex string, for the 32 byte pub key self.public_string = str.lower("{0:0>4X}".format(self.public_int))