def on_connect_estab(*resp): if type(resp[0]) == int: errors.manage_error(resp[0]) else: print('CONNECT ESTAB') if deb2 else None print("response: ", resp[0]) if deb else None print("data response: ", resp[0]['data']) if deb else None print("sign response: ", resp[0]['sign']) if deb else None print("priv_id: ", pri_id) if deb else None resp_data = json.loads( jws.verify(resp[0]['data'], pri_id, algorithms=['HS256']).decode()) print("decrypt data response: ", resp_data) if deb else None print("server key: ", server_key) if deb else None if sign.verify_sign(server_key, resp[0]['sign'], resp[0]['data']): print("valid sign") if deb else None global session_id session_id = resp_data['ses_id'] print("ses_id: ", resp_data['ses_id']) if deb else None print("CONNECT ESTAB DONE") if deb2 else None else: errors.manage_error(6)
def on_connect_response(*resp): print(resp) if deb else None if type(resp[0]) == int: errors.manage_error(resp[0]) else: print('CONNECT RESPONSE') if deb2 else None print("response: ", resp[0]) if deb else None print("data response: ", resp[0]['data']) if deb else None print("sign response: ", resp[0]['sign']) if deb else None resp_data = json.loads( jws.verify(resp[0]['data'], pri_id, algorithms=['HS256']).decode()) print("decrypt data response: ", resp_data) if deb else None print("key in data response: ", resp_data['key']) if deb else None if sign.verify_sign(resp_data['key'], resp[0]['sign'], resp[0]['data']): print("valid sign") if deb else None global server_key server_key = resp_data['key'] req_data = {"otp": resp_data['otp']} print("data to send: ", req_data) if deb else None crypt_data = jws.sign(req_data, pri_id, algorithm='HS256') print("encrypt data to send: ", crypt_data) if deb else None sign_crypt_data = sign.sign_data(key.exportKey(), crypt_data) print("sign of en data send: ", sign_crypt_data) if deb else None req2 = { "pub_id": pub_id, "data": crypt_data, "sign": sign_crypt_data.decode() } print("send: ", req2) if deb else None print("CONNECT RESPONSE DONE") if deb2 else None socketIO.emit('connect_confirm', req2) socketIO.on('connect_estab', on_connect_estab) socketIO.wait(seconds=3) else: errors.manage_error(6)
def on_disc_response(*resp): if type(resp[0]) == int: errors.manage_error(resp[0])