Beispiel #1
0
    async def response(self, msg, _agent):
        """ Process a response. """
        print("Got response:", msg.pretty_print())
        their_conn_key = msg['connection~sig']['signer']
        connection = self.connections[their_conn_key]

        connection.state.transition(Events.RECV_RESP)

        msg['connection'] = crypto.verify_signed_message_field(
            msg['connection~sig'])
        del msg['connection~sig']
        print("Got response (sig unpacked)", msg.pretty_print())

        # Update connection
        del self.connections[their_conn_key]
        connection.their_did = msg['connection']['DIDDoc']['publicKey'][0][
            'controller']
        connection.their_vk = crypto.b58_to_bytes(
            msg['connection']['DIDDoc']['publicKey'][0]['publicKeyBase58'])
        connection.endpoint = msg['connection']['DIDDoc']['service'][0][
            'serviceEndpoint']
        self.connections[connection.vk_b58] = connection

        connection.state.transition(Events.SEND_ACK)

        await connection.send_async({
            '@type': self.type('ack'),
            'status': 'OK',
            '~thread': {
                'thid': msg.id
            }
        })
Beispiel #2
0
async def test_connection_started_by_tested_agent(config, temporary_channel):
    """Test a connection as started by the agent under test."""
    invite_url = input('Input generated connection invite: ')

    invite_msg = parse_invite(invite_url)

    print("\nReceived Invite:\n", invite_msg.pretty_print())

    # Create my information for connection
    with temporary_channel(invite_msg['recipientKeys'][0],
                           invite_msg['serviceEndpoint']) as conn:

        did = crypto.bytes_to_b58(conn.my_vk[:16])
        my_vk_b58 = crypto.bytes_to_b58(conn.my_vk)

        # Send Connection Request to inviter
        request = build_request('test-connection-started-by-tested-agent', did,
                                my_vk_b58, config['endpoint'])

        print("\nSending Request:\n", request.pretty_print())
        print("Awaiting response from tested agent...")
        response = await conn.send_and_await_reply_async(
            request, condition=lambda msg: msg.type == RESPONSE, timeout=30)

        RESPONSE_SCHEMA_PRE_SIG_VERIFY(response)
        print("\nReceived Response (pre signature verification):\n",
              response.pretty_print())

        signer, response['connection'] = \
            crypto.verify_signed_message_field(response['connection~sig'])
        assert signer == invite_msg['recipientKeys'][0], 'Unexpected signer'
        del response['connection~sig']

        RESPONSE_SCHEMA_POST_SIG_VERIFY(response)
        assert response['~thread']['thid'] == request.id

        print("\nReceived Response (post signature verification):\n",
              response.pretty_print())
Beispiel #3
0
 def verify_sig(self, expected_signer: str):
     """Verify signature on this response message."""
     signer, self['connection'] = \
         crypto.verify_signed_message_field(self['connection~sig'])
     assert signer == expected_signer, 'Unexpected signer'
     del self['connection~sig']