From acd943fead82aa892b15698b13753a80367e6a1b Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Wed, 16 Mar 2022 17:21:29 -0700 Subject: [PATCH 1/3] Qualify did exch connection lookup by role Signed-off-by: Ian Costanzo --- aries_cloudagent/connections/models/conn_record.py | 5 ++++- aries_cloudagent/protocols/didexchange/v1_0/manager.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/aries_cloudagent/connections/models/conn_record.py b/aries_cloudagent/connections/models/conn_record.py index 672d9359e0..eb0342970a 100644 --- a/aries_cloudagent/connections/models/conn_record.py +++ b/aries_cloudagent/connections/models/conn_record.py @@ -174,6 +174,7 @@ def __eq__(self, other: Union[str, "ConnRecord.State"]) -> bool: "invitation_key", "their_public_did", "invitation_msg_id", + "their_role", } RECORD_TYPE = "connection" @@ -373,7 +374,7 @@ async def find_existing_connection( @classmethod async def retrieve_by_request_id( - cls, session: ProfileSession, request_id: str + cls, session: ProfileSession, request_id: str, their_role: str = None ) -> "ConnRecord": """Retrieve a connection record from our previous request ID. @@ -382,6 +383,8 @@ async def retrieve_by_request_id( request_id: The ID of the originating connection request """ tag_filter = {"request_id": request_id} + if their_role: + tag_filter["their_role"] = their_role return await cls.retrieve_by_tag_filter(session, tag_filter) @classmethod diff --git a/aries_cloudagent/protocols/didexchange/v1_0/manager.py b/aries_cloudagent/protocols/didexchange/v1_0/manager.py index 282bbb8335..a1456b6f49 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/manager.py @@ -705,7 +705,7 @@ async def accept_response( try: async with self.profile.session() as session: conn_rec = await ConnRecord.retrieve_by_request_id( - session, response._thread_id + session, response._thread_id, their_role="inviter" ) except StorageNotFoundError: pass @@ -812,7 +812,7 @@ async def accept_complete( try: async with self.profile.session() as session: conn_rec = await ConnRecord.retrieve_by_request_id( - session, complete._thread_id + session, complete._thread_id, their_role="invitee" ) except StorageNotFoundError: raise DIDXManagerError( From 780ae76cf1ef113def00578e95542a0e077a90d3 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Wed, 16 Mar 2022 18:42:43 -0700 Subject: [PATCH 2/3] Use connection role enums Signed-off-by: Ian Costanzo --- .../protocols/didexchange/v1_0/manager.py | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/manager.py b/aries_cloudagent/protocols/didexchange/v1_0/manager.py index a1456b6f49..8489cd4964 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/manager.py @@ -702,13 +702,22 @@ async def accept_response( conn_rec = None if response._thread: # identify the request by the thread ID - try: - async with self.profile.session() as session: + async with self.profile.session() as session: + try: conn_rec = await ConnRecord.retrieve_by_request_id( - session, response._thread_id, their_role="inviter" + session, response._thread_id, + their_role=ConnRecord.Role.RESPONDER.rfc23, ) - except StorageNotFoundError: - pass + except StorageNotFoundError: + pass + if not conn_rec: + try: + conn_rec = await ConnRecord.retrieve_by_request_id( + session, response._thread_id, + their_role=ConnRecord.Role.RESPONDER.rfc160, + ) + except StorageNotFoundError: + pass if not conn_rec and receipt.sender_did: # identify connection by the DID they used for us @@ -809,12 +818,25 @@ async def accept_complete( conn_rec = None # identify the request by the thread ID - try: - async with self.profile.session() as session: + async with self.profile.session() as session: + try: conn_rec = await ConnRecord.retrieve_by_request_id( - session, complete._thread_id, their_role="invitee" + session, complete._thread_id, + their_role=ConnRecord.Role.REQUESTER.rfc23, ) - except StorageNotFoundError: + except StorageNotFoundError: + pass + + if not conn_rec: + try: + conn_rec = await ConnRecord.retrieve_by_request_id( + session, complete._thread_id, + their_role=ConnRecord.Role.REQUESTER.rfc160, + ) + except StorageNotFoundError: + pass + + if not conn_rec: raise DIDXManagerError( "No corresponding connection request found", error_code=ProblemReportReason.COMPLETE_NOT_ACCEPTED.value, From 6f8644e451f6a146ed6d7345e41a465580fda1ed Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Wed, 16 Mar 2022 18:45:33 -0700 Subject: [PATCH 3/3] Fix black formatting Signed-off-by: Ian Costanzo --- .../protocols/didexchange/v1_0/manager.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/manager.py b/aries_cloudagent/protocols/didexchange/v1_0/manager.py index 8489cd4964..c7c9e51eaa 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/manager.py @@ -705,7 +705,8 @@ async def accept_response( async with self.profile.session() as session: try: conn_rec = await ConnRecord.retrieve_by_request_id( - session, response._thread_id, + session, + response._thread_id, their_role=ConnRecord.Role.RESPONDER.rfc23, ) except StorageNotFoundError: @@ -713,7 +714,8 @@ async def accept_response( if not conn_rec: try: conn_rec = await ConnRecord.retrieve_by_request_id( - session, response._thread_id, + session, + response._thread_id, their_role=ConnRecord.Role.RESPONDER.rfc160, ) except StorageNotFoundError: @@ -821,7 +823,8 @@ async def accept_complete( async with self.profile.session() as session: try: conn_rec = await ConnRecord.retrieve_by_request_id( - session, complete._thread_id, + session, + complete._thread_id, their_role=ConnRecord.Role.REQUESTER.rfc23, ) except StorageNotFoundError: @@ -830,7 +833,8 @@ async def accept_complete( if not conn_rec: try: conn_rec = await ConnRecord.retrieve_by_request_id( - session, complete._thread_id, + session, + complete._thread_id, their_role=ConnRecord.Role.REQUESTER.rfc160, ) except StorageNotFoundError: