async def run_send_wire_message(msg):
     await asyncio.sleep(3)
     t = EndpointTransport(address=endpoint_receiver)
     s = await t.send_wire_message(
         json.dumps(msg).encode('utf-8'),
         content_type=JSON_CONTENT_TYPES[0])
     assert 202 == s
Exemple #2
0
 async def send_message_to_endpoint_and_key(their_ver_key: str, their_endpoint: str, msg: Message,
                                            wallet: WalletConnection, my_ver_key: str=None):
     # If my_ver_key is omitted, anon-crypt is used inside pack.
     try:
         wire_message = await wallet.pack_message(
             Serializer.serialize(msg).decode('utf-8'),
             their_ver_key,
             my_ver_key
         )
     except Exception as e:
         logging.exception(str(e))
         raise
     else:
         transport = EndpointTransport(address=their_endpoint)
         await transport.send_wire_message(wire_message)
Exemple #3
0
 async def send_problem_report(wallet: WalletConnection,
                               problem_code: str,
                               problem_str: str,
                               context: Context,
                               thread_id: str = None):
     err_msg = IssueCredentialProtocol.build_problem_report_for_connections(
         problem_code, problem_str, thread_id)
     try:
         wire_message = await wallet.pack_message(
             Serializer.serialize(err_msg).decode('utf-8'),
             context.their_verkey, context.my_ver_key)
     except Exception as e:
         logging.exception(str(e))
         raise
     else:
         transport = EndpointTransport(address=context.their_endpoint)
         await transport.send_wire_message(wire_message)
         return err_msg
Exemple #4
0
 async def __send_connection_request(self, invitation: Message):
     """Connection Request"""
     their = dict(
         label=invitation['label'],
         connection_key=invitation['recipientKeys'][0],
         endpoint=invitation['serviceEndpoint']
     )
     # Create my information for connection
     my_did, my_vk = await indy_sdk_utils.create_and_store_my_did(self.get_wallet())
     await self.get_wallet().set_did_metadata(my_did, their)
     # Send Connection Request to inviter
     request = DIDExchange.Request.build(self.label, my_did, my_vk, self.endpoint)
     try:
         wire_message = await self.get_wallet().pack_message(
             message=Serializer.serialize(request).decode('utf-8'),
             their_ver_key=their['connection_key'],
             my_ver_key=my_vk
         )
         transport = EndpointTransport(address=their['endpoint'])
         await transport.send_wire_message(wire_message)
         await self.__log('Send', request.to_dict())
     except Exception as e:
         logging.exception(str(e))
         raise
 async def run_send_wire_message(msg):
     await asyncio.sleep(3)
     t = EndpointTransport(address=endpoint_receiver)
     s = await t.send_wire_message(json.dumps(msg).encode('utf-8'))
     assert 202 == s
    def test_receive_wired_message(self):
        headers = dict()
        headers[HEADER_PASS_PHRASE] = self.WALLET_PASS_PHRASE
        account_sender = self.IDENTITY1
        account_receiver = self.IDENTITY2
        wallet_sender = self.WALLET1_UID
        wallet_receiver = self.WALLET2_UID
        endpoint_sender = self.create_and_open_wallet(wallet_sender,
                                                      account_sender)
        endpoint_receiver = self.create_and_open_wallet(
            wallet_receiver, account_receiver)
        try:
            did_sender, verkey_sender = self.create_did(
                account_sender, wallet_sender)
            did_receiver, verkey_receiver = self.create_did(
                account_receiver, wallet_receiver)
            # create pairwise on receiver-side
            url = self.live_server_url + '/agent/admin/wallets/%s/pairwise/create_pairwise_statically/' % wallet_receiver
            pairwise = dict(my_did=did_receiver,
                            their_did=did_sender,
                            their_verkey=verkey_sender,
                            metadata={
                                'their_endpoint': endpoint_sender,
                                'their_vk': verkey_sender,
                                'my_vk': verkey_receiver,
                            })
            resp = requests.post(url,
                                 json=pairwise,
                                 auth=HTTPBasicAuth(account_receiver,
                                                    self.PASS),
                                 headers=headers)
            self.assertEqual(200, resp.status_code, resp.text)
            # create auth-crypt message
            url = self.live_server_url + '/agent/admin/wallets/%s/messaging/auth_crypt/' % wallet_sender
            message = dict(content=uuid.uuid4().hex)
            entity = dict(message=message,
                          their_verkey=verkey_receiver,
                          my_verkey=verkey_sender)
            resp = requests.post(url,
                                 json=entity,
                                 auth=HTTPBasicAuth(account_sender, self.PASS))
            self.assertEqual(200, resp.status_code)
            encrypted_message = resp.json()
            extra_field_value = uuid.uuid4().hex
            encrypted_message['extra_field'] = extra_field_value
            # send to receiver endpoint
            transport = EndpointTransport(address=endpoint_receiver)
            status = run_async(
                transport.send_wire_message(
                    json.dumps(encrypted_message).encode('utf-8')))
            self.assertEqual(410, status)

            # allocate channel
            ws = StubWalletStatusNotification(
                scope={},
                agent_name=wallet_receiver,
                pass_phrase=self.WALLET_PASS_PHRASE)

            async def run_websocket():
                chan_wired = await ReadOnlyChannel.create(
                    make_wallet_wired_messages_channel_name(wallet_receiver))
                await ws.listen_wired(chan_wired)

            async def run_send_wire_message(msg):
                await asyncio.sleep(3)
                t = EndpointTransport(address=endpoint_receiver)
                s = await t.send_wire_message(json.dumps(msg).encode('utf-8'))
                assert 202 == s

            async def run_tests():
                done, pending = await asyncio.wait([
                    run_websocket(),
                    run_send_wire_message(encrypted_message)
                ],
                                                   timeout=5)
                for f in pending:
                    f.cancel()
                for f in done:
                    if f.exception():
                        raise f.exception()
                await asyncio.sleep(1)
                assert ws.is_closed
                assert len(ws.send_queue) == 1
                # check structure
                recv = ws.send_queue[0]
                assert recv.get('topic') == UNPACKED_TRANSPORT
                data = recv.get('data')
                assert data['content_type'] == DEFAULT_WIRE_CONTENT_TYPE
                assert data['unpacked']['message']['content'] == message[
                    'content']
                assert data['unpacked']['recipient_verkey'] == verkey_receiver
                assert data['unpacked']['sender_verkey'] == verkey_sender
                assert data['their_did'] == did_sender
                assert data['extra']['extra_field'] == extra_field_value

            f = asyncio.ensure_future(run_tests())
            asyncio.get_event_loop().run_until_complete(f)
            if f.exception():
                raise f.exception()
        finally:
            self.close_and_delete_wallet(wallet_sender, account_sender)
            self.close_and_delete_wallet(wallet_receiver, account_receiver)