Esempio n. 1
0
    async def send_message_to_endpoint_and_key(self, my_ver_key, their_ver_key,
                                               their_endpoint, msg):
        wire_message = {
            'to':
            their_ver_key,
            'from':
            my_ver_key,
            'payload':
            serialize_bytes_json(await crypto.auth_crypt(
                self.wallet_handle, my_ver_key, their_ver_key,
                str_to_bytes(msg.as_json())))
        }

        wire_message = await crypto.pack_message(self.wallet_handle,
                                                 Serializer.pack(msg),
                                                 [their_ver_key], my_ver_key)

        async with aiohttp.ClientSession() as session:
            headers = {'content-type': 'application/ssi-agent-wire'}
            async with session.post(their_endpoint,
                                    data=wire_message,
                                    headers=headers) as resp:
                if resp.status != 202:
                    print(resp.status)
                    print(await resp.text())
Esempio n. 2
0
    async def request_received(self, msg: Message) -> Message:
        their_endpoint_uri = msg['endpoint']

        my_did_str = msg['did']
        my_did_info_str = await did.get_my_did_with_meta(
            self.agent.wallet_handle, my_did_str)
        my_did_info_json = json.loads(my_did_info_str)

        my_verkey = my_did_info_json['verkey']
        metadata_str = my_did_info_json['metadata']
        metadata_dict = json.loads(metadata_str)

        conn_name = metadata_dict['conn_name']

        message_bytes = str_to_bytes(msg['content'])
        message_bytes = base64.b64decode(message_bytes)

        their_key_str, their_data_bytes = await crypto.auth_decrypt(
            self.agent.wallet_handle, my_verkey, message_bytes)

        # change verkey passed via send_invite to the agent without encryption
        my_new_verkey = await did.replace_keys_start(self.agent.wallet_handle,
                                                     my_did_str, '{}')
        await did.replace_keys_apply(self.agent.wallet_handle, my_did_str)

        their_data_json = json.loads(bytes_to_str(their_data_bytes))

        their_did_str = their_data_json['did']

        identity_json = json.dumps({
            "did": their_did_str,
            "verkey": their_key_str
        })

        meta_json = json.dumps({
            "conn_name": conn_name,
            "their_endpoint": their_endpoint_uri,
            "their_verkey": their_key_str,
            "my_verkey": my_new_verkey
        })

        await did.store_their_did(self.agent.wallet_handle, identity_json)
        await pairwise.create_pairwise(self.agent.wallet_handle, their_did_str,
                                       my_did_str, meta_json)

        return Message({
            'type': CONN_UI.REQUEST_RECEIVED,
            'content': {
                'name': conn_name,
                'endpoint_did': their_did_str,
                'history': msg
            }
        })
Esempio n. 3
0
    async def response_received(self, msg: Message) -> Message:
        my_did_str = msg['did']

        my_did_info_str = await did.get_my_did_with_meta(
            self.agent.wallet_handle, my_did_str)
        my_did_info_json = json.loads(my_did_info_str)

        my_verkey = my_did_info_json['verkey']
        metadata_str = my_did_info_json['metadata']
        metadata_dict = json.loads(metadata_str)

        conn_name = metadata_dict['conn_name']
        their_endpoint = metadata_dict['their_endpoint']

        message_bytes = str_to_bytes(msg['content'])
        message_bytes = base64.b64decode(message_bytes)

        their_key_str, their_data_bytes = await crypto.auth_decrypt(
            self.agent.wallet_handle, my_verkey, message_bytes)

        their_data_json = json.loads(bytes_to_str(their_data_bytes))

        their_did_str = their_data_json['did']

        identity_json = json.dumps({
            "did": their_did_str,
            "verkey": their_key_str
        })

        meta_json = json.dumps({
            "conn_name": conn_name,
            "their_endpoint": their_endpoint,
            "their_verkey": their_key_str,
            "my_verkey": my_verkey
        })

        await did.store_their_did(self.agent.wallet_handle, identity_json)
        await pairwise.create_pairwise(self.agent.wallet_handle, their_did_str,
                                       my_did_str, meta_json)

        #  pairwise connection between agents is established to this point
        return Message({
            'type': CONN_UI.RESPONSE_RECEIVED,
            'id': self.agent.ui_token,
            'content': {
                'name': conn_name,
                'their_did': their_did_str,
                'history': msg
            }
        })
Esempio n. 4
0
    async def receive_message(self, msg: Message) -> Message:
        their_did_str = msg['from']

        pairwise_conn_info_str = await pairwise.get_pairwise(self.agent.wallet_handle, their_did_str)
        pairwise_conn_info_json = json.loads(pairwise_conn_info_str)

        my_did_str = pairwise_conn_info_json['my_did']
        metadata = json.loads(pairwise_conn_info_json['metadata'])

        my_did_info_str = await did.get_my_did_with_meta(self.agent.wallet_handle, my_did_str)

        my_did_info_json = json.loads(my_did_info_str)
        my_verkey = my_did_info_json['verkey']

        message_bytes = str_to_bytes(msg['message'])
        message_bytes = base64.b64decode(message_bytes)

        their_key_str, their_data_bytes = await crypto.auth_decrypt(
            self.agent.wallet_handle, my_verkey, message_bytes)

        their_data_json = json.loads(bytes_to_str(their_data_bytes))

        # store message in the wallet
        await non_secrets.add_wallet_record(
            self.agent.wallet_handle,
            "basicmessage",
            uuid.uuid4().hex,
            json.dumps({
                'from': their_did_str,
                'timestamp': their_data_json['timestamp'],
                'content': their_data_json['content']
            }),
            json.dumps({
                "their_did": their_did_str
            })
        )

        return Message({
            '@type': ADMIN_BASICMESSAGE.MESSAGE_RECEIVED,
            'id': self.agent.ui_token,
            'with': their_did_str,
            'message': {
                'from': their_did_str,
                'timestamp': their_data_json['timestamp'],
                'content': their_data_json['content']
            }
        })
Esempio n. 5
0
    async def send_message_to_endpoint_and_key(self, my_ver_key, their_ver_key,
                                               their_endpoint, msg):
        wire_message = {
            'to':
            their_ver_key,
            'from':
            my_ver_key,
            'payload':
            serialize_bytes_json(await crypto.auth_crypt(
                self.wallet_handle, my_ver_key, their_ver_key,
                str_to_bytes(msg.as_json())))
        }

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint,
                                    data=json.dumps(wire_message)) as resp:
                print(resp.status)
                print(await resp.text())
Esempio n. 6
0
    async def message_received(self, msg: Message) -> Message:
        my_did_str = msg['did']
        their_did_str = ""
        conn_name = ""
        my_verkey = ""

        self.agent_pairwises_list_str = await pairwise.list_pairwise(
            self.agent.wallet_handle)
        self.agent_pairwises_list = json.loads(self.agent_pairwises_list_str)

        for self.agent_pairwise_str in self.agent_pairwises_list:
            self.agent_pairwise_json = json.loads(self.agent_pairwise_str)
            if not self.agent_pairwise_json['my_did'] == my_did_str:
                continue
            their_did_str = self.agent_pairwise_json['their_did']

            metadata_str = self.agent_pairwise_json['metadata']
            metadata_json = json.loads(metadata_str)
            conn_name = metadata_json['conn_name']
            my_verkey = metadata_json['my_verkey']

        message_bytes = str_to_bytes(msg['content'])
        message_bytes = base64.b64decode(message_bytes)

        their_key_str, their_data_bytes = await crypto.auth_decrypt(
            self.agent.wallet_handle, my_verkey, message_bytes)

        their_data_json = json.loads(bytes_to_str(their_data_bytes))

        return Message({
            'type': CONN_UI.MESSAGE_RECEIVED,
            'id': self.agent.ui_token,
            'content': {
                'name': conn_name,
                'their_did': their_did_str,
                'history': their_data_json
            }
        })
Esempio n. 7
0
    async def send_request(self, msg: Message) -> Message:
        """ UI activated method.
        """

        their_endpoint = msg['content']['endpoint']
        conn_name = msg['content']['name']
        their_connection_key = msg['content']['key']

        my_endpoint_uri = self.agent.endpoint

        (my_endpoint_did_str,
         my_connection_key) = await did.create_and_store_my_did(
             self.agent.wallet_handle, "{}")

        data_to_send = json.dumps({
            "did": my_endpoint_did_str,
            "key": my_connection_key
        })

        data_to_send_bytes = str_to_bytes(data_to_send)

        meta_json = json.dumps({
            "conn_name": conn_name,
            "their_endpoint": their_endpoint
        })

        await did.set_did_metadata(self.agent.wallet_handle,
                                   my_endpoint_did_str, meta_json)

        inner_msg = Message({
            'type':
            CONN.REQUEST,
            'to':
            "did:sov:ABC",
            'endpoint':
            my_endpoint_uri,
            'content':
            serialize_bytes_json(await
                                 crypto.auth_crypt(self.agent.wallet_handle,
                                                   my_connection_key,
                                                   their_connection_key,
                                                   data_to_send_bytes))
        })

        outer_msg = Message({
            'type': FORWARD.FORWARD_TO_KEY,
            'to': "ABC",
            'content': inner_msg
        })

        serialized_outer_msg = Serializer.pack(outer_msg)

        serialized_outer_msg_bytes = str_to_bytes(serialized_outer_msg)

        all_message = Message({
            'type':
            CONN.REQUEST,
            'content':
            serialize_bytes_json(await
                                 crypto.anon_crypt(their_connection_key,
                                                   serialized_outer_msg_bytes))
        })

        serialized_msg = Serializer.pack(all_message)

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint,
                                    data=serialized_msg) as resp:
                print(resp.status)
                print(await resp.text())

        return Message({
            'type': CONN_UI.REQUEST_SENT,
            'id': self.agent.ui_token,
            'content': {
                'name': conn_name
            }
        })
Esempio n. 8
0
    async def send_message(self, msg: Message) -> Message:
        """ UI activated method.
        """

        their_did_str = msg['content']['their_did']
        message_to_send = msg['content']['message']

        pairwise_conn_info_str = await pairwise.get_pairwise(
            self.agent.wallet_handle, their_did_str)
        pairwise_conn_info_json = json.loads(pairwise_conn_info_str)

        my_did_str = pairwise_conn_info_json['my_did']

        data_to_send = json.dumps({"message": message_to_send})

        data_to_send_bytes = str_to_bytes(data_to_send)

        metadata_json = json.loads(pairwise_conn_info_json['metadata'])
        conn_name = metadata_json['conn_name']
        their_endpoint = metadata_json['their_endpoint']
        their_verkey_str = metadata_json['their_verkey']

        my_did_info_str = await did.get_my_did_with_meta(
            self.agent.wallet_handle, my_did_str)
        my_did_info_json = json.loads(my_did_info_str)
        my_verkey_str = my_did_info_json['verkey']

        inner_msg = Message({
            'type':
            CONN.MESSAGE,
            'to':
            "did:sov:ABC",
            'content':
            serialize_bytes_json(await
                                 crypto.auth_crypt(self.agent.wallet_handle,
                                                   my_verkey_str,
                                                   their_verkey_str,
                                                   data_to_send_bytes))
        })

        outer_msg = Message({
            'type': FORWARD.FORWARD,
            'to': "ABC",
            'content': inner_msg
        })

        serialized_outer_msg = Serializer.pack(outer_msg)

        serialized_outer_msg_bytes = str_to_bytes(serialized_outer_msg)

        all_message = Message({
            'content':
            serialize_bytes_json(await
                                 crypto.anon_crypt(their_verkey_str,
                                                   serialized_outer_msg_bytes))
        })

        serialized_msg = Serializer.pack(all_message)

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint,
                                    data=serialized_msg) as resp:
                print(resp.status)
                print(await resp.text())

        return Message({
            'type': CONN_UI.MESSAGE_SENT,
            'id': self.agent.ui_token,
            'content': {
                'name': conn_name
            }
        })
Esempio n. 9
0
    async def send_message(self, msg: Message) -> Message:
        """ UI activated method.
        """

        their_did_str = msg['to']
        message_to_send = msg['message']

        pairwise_conn_info_str = await pairwise.get_pairwise(self.agent.wallet_handle, their_did_str)
        pairwise_conn_info_json = json.loads(pairwise_conn_info_str)

        my_did_str = pairwise_conn_info_json['my_did']
        time_sent = time.time()

        data_to_send = json.dumps(
            {
                "timestamp": time_sent,
                "content": message_to_send
            }
        )

        # store message in the wallet
        await non_secrets.add_wallet_record(
            self.agent.wallet_handle,
            "basicmessage",
            uuid.uuid4().hex,
            json.dumps({
                'from': my_did_str,
                'timestamp': time_sent,
                'content': message_to_send
            }),
            json.dumps({
                "their_did": their_did_str
            })
        )

        data_to_send_bytes = str_to_bytes(data_to_send)

        metadata_json = json.loads(pairwise_conn_info_json['metadata'])
        conn_name = metadata_json['conn_name']
        their_endpoint = metadata_json['their_endpoint']
        their_verkey_str = metadata_json['their_verkey']

        my_did_info_str = await did.get_my_did_with_meta(self.agent.wallet_handle,
                                                         my_did_str)
        my_did_info_json = json.loads(my_did_info_str)
        my_verkey_str = my_did_info_json['verkey']

        inner_msg = Message({
            '@type': BASICMESSAGE.MESSAGE,
            'from': my_did_str,
            'message': serialize_bytes_json(
                await crypto.auth_crypt(self.agent.wallet_handle, my_verkey_str,
                                        their_verkey_str, data_to_send_bytes))
        })

        outer_msg = Message({
            '@type': FORWARD.FORWARD,
            'to': "ABC",
            'content': inner_msg
        })

        serialized_outer_msg = Serializer.pack(outer_msg)

        serialized_outer_msg_bytes = str_to_bytes(serialized_outer_msg)

        all_message = Message({
            'content': serialize_bytes_json(await crypto.anon_crypt(their_verkey_str,
                                                                 serialized_outer_msg_bytes))
        })

        serialized_msg = Serializer.pack(all_message)

        async with aiohttp.ClientSession() as session:
            async with session.post(their_endpoint, data=serialized_msg) as resp:
                print(resp.status)
                print(await resp.text())

        return Message({
            '@type': ADMIN_BASICMESSAGE.MESSAGE_SENT,
            'id': self.agent.ui_token,
            'with': their_did_str,
            'message': {
                'from': my_did_str,
                'timestamp': time_sent,
                'content': message_to_send
            }
        })