async def _do_wait_peer(self) -> Tuple[SASCode, SASCode, SecretKey]: claimer_private_key = PrivateKey.generate() rep = await self._cmds.invite_1_claimer_wait_peer( claimer_public_key=claimer_private_key.public_key) _check_rep(rep, step_name="step 1") shared_secret_key = generate_shared_secret_key( our_private_key=claimer_private_key, peer_public_key=rep["greeter_public_key"]) claimer_nonce = generate_nonce() rep = await self._cmds.invite_2a_claimer_send_hashed_nonce( claimer_hashed_nonce=HashDigest.from_data(claimer_nonce)) _check_rep(rep, step_name="step 2a") claimer_sas, greeter_sas = generate_sas_codes( claimer_nonce=claimer_nonce, greeter_nonce=rep["greeter_nonce"], shared_secret_key=shared_secret_key, ) rep = await self._cmds.invite_2b_claimer_send_nonce( claimer_nonce=claimer_nonce) _check_rep(rep, step_name="step 2b") return claimer_sas, greeter_sas, shared_secret_key
async def _do_wait_peer(self) -> Tuple[SASCode, SASCode, SecretKey]: claimer_private_key = PrivateKey.generate() rep = await self._cmds.invite_1_claimer_wait_peer( claimer_public_key=claimer_private_key.public_key) if rep["status"] != "ok": raise InviteError(f"Backend error during step 1: {rep}") shared_secret_key = generate_shared_secret_key( our_private_key=claimer_private_key, peer_public_key=rep["greeter_public_key"]) claimer_nonce = generate_nonce() rep = await self._cmds.invite_2a_claimer_send_hashed_nonce( claimer_hashed_nonce=HashDigest.from_data(claimer_nonce)) if rep["status"] == "invalid_state": raise InvitePeerResetError() elif rep["status"] != "ok": raise InviteError(f"Backend error during step 2a: {rep}") claimer_sas, greeter_sas = generate_sas_codes( claimer_nonce=claimer_nonce, greeter_nonce=rep["greeter_nonce"], shared_secret_key=shared_secret_key, ) rep = await self._cmds.invite_2b_claimer_send_nonce( claimer_nonce=claimer_nonce) if rep["status"] == "invalid_state": raise InvitePeerResetError() elif rep["status"] != "ok": raise InviteError(f"Backend error during step 2b: {rep}") return claimer_sas, greeter_sas, shared_secret_key
async def _do_wait_peer(self) -> Tuple[SASCode, SASCode, SecretKey]: greeter_private_key = PrivateKey.generate() rep = await self._cmds.invite_1_greeter_wait_peer( token=self.token, greeter_public_key=greeter_private_key.public_key) if rep["status"] in ("not_found", "already_deleted"): raise InviteNotAvailableError() elif rep["status"] != "ok": raise InviteError(f"Backend error during step 1: {rep}") shared_secret_key = generate_shared_secret_key( our_private_key=greeter_private_key, peer_public_key=rep["claimer_public_key"]) greeter_nonce = generate_nonce() rep = await self._cmds.invite_2a_greeter_get_hashed_nonce( token=self.token) if rep["status"] in ("not_found", "already_deleted"): raise InviteNotAvailableError() elif rep["status"] == "invalid_state": raise InvitePeerResetError() elif rep["status"] != "ok": raise InviteError(f"Backend error during step 2a: {rep}") claimer_hashed_nonce = rep["claimer_hashed_nonce"] rep = await self._cmds.invite_2b_greeter_send_nonce( token=self.token, greeter_nonce=greeter_nonce) if rep["status"] in ("not_found", "already_deleted"): raise InviteNotAvailableError() elif rep["status"] == "invalid_state": raise InvitePeerResetError() elif rep["status"] != "ok": raise InviteError(f"Backend error during step 2b: {rep}") if HashDigest.from_data(rep["claimer_nonce"]) != claimer_hashed_nonce: raise InviteError("Invitee nonce and hashed nonce doesn't match") claimer_sas, greeter_sas = generate_sas_codes( claimer_nonce=rep["claimer_nonce"], greeter_nonce=greeter_nonce, shared_secret_key=shared_secret_key, ) return claimer_sas, greeter_sas, shared_secret_key