From e1122ee1f1f2cdf90b2768c3f5553e341010bfb3 Mon Sep 17 00:00:00 2001 From: DaevMithran Date: Wed, 30 Mar 2022 18:25:22 +0530 Subject: [PATCH 1/3] Add auto_verify flag present-proof-v1_0 Signed-off-by: DaevMithran --- .../v1_0/handlers/presentation_handler.py | 2 +- .../protocols/present_proof/v1_0/manager.py | 6 +++- .../v1_0/models/presentation_exchange.py | 7 +++++ .../protocols/present_proof/v1_0/routes.py | 30 ++++++++++++++++++- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_handler.py index 40c4d73dc6..24507b610a 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/presentation_handler.py @@ -49,7 +49,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder): ) # Automatically move to next state if flag is set - if context.settings.get("debug.auto_verify_presentation"): + if presentation_exchange_record and presentation_exchange_record.auto_verify: try: await presentation_manager.verify_presentation( presentation_exchange_record diff --git a/aries_cloudagent/protocols/present_proof/v1_0/manager.py b/aries_cloudagent/protocols/present_proof/v1_0/manager.py index 10354d3d29..2a5245a417 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/manager.py @@ -165,7 +165,10 @@ async def create_bound_request( return presentation_exchange_record, presentation_request_message async def create_exchange_for_request( - self, connection_id: str, presentation_request_message: PresentationRequest + self, + connection_id: str, + presentation_request_message: PresentationRequest, + auto_verify: bool = None, ): """ Create a presentation exchange record for input presentation request. @@ -187,6 +190,7 @@ async def create_exchange_for_request( state=V10PresentationExchange.STATE_REQUEST_SENT, presentation_request=presentation_request_message.indy_proof_request(), presentation_request_dict=presentation_request_message, + auto_verify=auto_verify, trace=(presentation_request_message._trace is not None), ) async with self._profile.session() as session: diff --git a/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py b/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py index bce40f896d..1a68f2d6fa 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py @@ -75,6 +75,7 @@ def __init__( presentation: Union[IndyProof, Mapping] = None, # indy proof verified: str = None, auto_present: bool = False, + auto_verify: bool = False, error_msg: str = None, trace: bool = False, # backward compat: BaseRecord.from_storage() **kwargs, @@ -96,6 +97,7 @@ def __init__( self._presentation = IndyProof.serde(presentation) self.verified = verified self.auto_present = auto_present + self.auto_verify = auto_verify self.error_msg = error_msg @property @@ -203,6 +205,7 @@ def record_value(self) -> Mapping: "role", "state", "auto_present", + "auto_verify", "error_msg", "verified", "trace", @@ -297,6 +300,10 @@ class Meta: description="Prover choice to auto-present proof as verifier requests", example=False, ) + auto_verify = fields.Bool( + required=False, + description="Verifier choice to auto-verify proof presentation" + ) error_msg = fields.Str( required=False, description="Error message", example="Invalid structure" ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/routes.py b/aries_cloudagent/protocols/present_proof/v1_0/routes.py index ddc90d4ef3..a3121d4227 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/routes.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/routes.py @@ -130,6 +130,11 @@ class V10PresentationCreateRequestRequestSchema(AdminAPIMessageTracingSchema): proof_request = fields.Nested(IndyProofRequestSchema(), required=True) comment = fields.Str(required=False, allow_none=True) + auto_verify = fields.Bool( + description="Verifier choice to auto-verify proof presentation", + required=False, + example=False + ) trace = fields.Bool( description="Whether to trace event (default false)", required=False, @@ -146,6 +151,18 @@ class V10PresentationSendRequestRequestSchema( description="Connection identifier", required=True, example=UUIDFour.EXAMPLE ) +class V10PresentationSendRequestToProposalSchema(AdminAPIMessageTracingSchema): + """Request schema for sending a proof request bound to a proposal""" + auto_verify = fields.Bool( + description="Verifier choice to auto-verify proof presentation", + required=False, + example=False + ) + trace = fields.Bool( + description="Whether to trace event (default false)", + required=False, + example=False, + ) class CredentialsFetchQueryStringSchema(OpenAPISchema): """Parameters and validators for credentials fetch request query string.""" @@ -475,6 +492,9 @@ async def presentation_exchange_create_request(request: web.BaseRequest): ) ], ) + auto_verify = body.get( + "auto_verify", context.settings.get("debug.auto_verify_presentation") + ) trace_msg = body.get("trace") presentation_request_message.assign_trace_decorator( context.settings, @@ -487,6 +507,7 @@ async def presentation_exchange_create_request(request: web.BaseRequest): pres_ex_record = await presentation_manager.create_exchange_for_request( connection_id=None, presentation_request_message=presentation_request_message, + auto_verify=auto_verify ) result = pres_ex_record.serialize() except (BaseModelError, StorageError) as err: @@ -562,6 +583,9 @@ async def presentation_exchange_send_free_request(request: web.BaseRequest): context.settings, trace_msg, ) + auto_verify = body.get( + "auto_verify", context.settings.get("debug.auto_verify_presentation") + ) pres_ex_record = None try: @@ -569,6 +593,7 @@ async def presentation_exchange_send_free_request(request: web.BaseRequest): pres_ex_record = await presentation_manager.create_exchange_for_request( connection_id=connection_id, presentation_request_message=presentation_request_message, + auto_verify=auto_verify ) result = pres_ex_record.serialize() except (BaseModelError, StorageError) as err: @@ -595,7 +620,7 @@ async def presentation_exchange_send_free_request(request: web.BaseRequest): summary="Sends a presentation request in reference to a proposal", ) @match_info_schema(V10PresExIdMatchInfoSchema()) -@request_schema(AdminAPIMessageTracingSchema()) +@request_schema(V10PresentationSendRequestToProposalSchema()) @response_schema(V10PresentationExchangeSchema(), 200, description="") async def presentation_exchange_send_bound_request(request: web.BaseRequest): """ @@ -644,6 +669,9 @@ async def presentation_exchange_send_bound_request(request: web.BaseRequest): if not connection_record.is_ready: raise web.HTTPForbidden(reason=f"Connection {conn_id} not ready") + pres_ex_record.auto_verify = body.get( + "auto_verify", context.settings.get("debug.auto_verify_presentation") + ) try: presentation_manager = PresentationManager(profile) ( From 08e9fd20b43eb32679995f2a217ddc7b2d17d466 Mon Sep 17 00:00:00 2001 From: DaevMithran Date: Thu, 31 Mar 2022 11:10:07 +0530 Subject: [PATCH 2/3] Add auto_verify flag present-proof-v2_0 Signed-off-by: DaevMithran --- .../v1_0/models/presentation_exchange.py | 3 +- .../v1_0/models/tests/test_record.py | 1 + .../protocols/present_proof/v1_0/routes.py | 13 +++++--- .../v2_0/handlers/pres_handler.py | 2 +- .../protocols/present_proof/v2_0/manager.py | 6 +++- .../v2_0/models/pres_exchange.py | 5 +++ .../v2_0/models/tests/test_record.py | 1 + .../protocols/present_proof/v2_0/routes.py | 33 ++++++++++++++++++- 8 files changed, 54 insertions(+), 10 deletions(-) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py b/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py index 1a68f2d6fa..bb760a0a64 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/models/presentation_exchange.py @@ -301,8 +301,7 @@ class Meta: example=False, ) auto_verify = fields.Bool( - required=False, - description="Verifier choice to auto-verify proof presentation" + required=False, description="Verifier choice to auto-verify proof presentation" ) error_msg = fields.Str( required=False, description="Error message", example="Invalid structure" diff --git a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py index 62d5c64884..a757dcae2b 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py @@ -110,6 +110,7 @@ async def test_record(self): "role": None, "state": None, "auto_present": True, + "auto_verify": False, "error_msg": None, "verified": None, "trace": False, diff --git a/aries_cloudagent/protocols/present_proof/v1_0/routes.py b/aries_cloudagent/protocols/present_proof/v1_0/routes.py index a3121d4227..95d4906714 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/routes.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/routes.py @@ -133,7 +133,7 @@ class V10PresentationCreateRequestRequestSchema(AdminAPIMessageTracingSchema): auto_verify = fields.Bool( description="Verifier choice to auto-verify proof presentation", required=False, - example=False + example=False, ) trace = fields.Bool( description="Whether to trace event (default false)", @@ -151,12 +151,14 @@ class V10PresentationSendRequestRequestSchema( description="Connection identifier", required=True, example=UUIDFour.EXAMPLE ) + class V10PresentationSendRequestToProposalSchema(AdminAPIMessageTracingSchema): - """Request schema for sending a proof request bound to a proposal""" + """Request schema for sending a proof request bound to a proposal.""" + auto_verify = fields.Bool( description="Verifier choice to auto-verify proof presentation", required=False, - example=False + example=False, ) trace = fields.Bool( description="Whether to trace event (default false)", @@ -164,6 +166,7 @@ class V10PresentationSendRequestToProposalSchema(AdminAPIMessageTracingSchema): example=False, ) + class CredentialsFetchQueryStringSchema(OpenAPISchema): """Parameters and validators for credentials fetch request query string.""" @@ -507,7 +510,7 @@ async def presentation_exchange_create_request(request: web.BaseRequest): pres_ex_record = await presentation_manager.create_exchange_for_request( connection_id=None, presentation_request_message=presentation_request_message, - auto_verify=auto_verify + auto_verify=auto_verify, ) result = pres_ex_record.serialize() except (BaseModelError, StorageError) as err: @@ -593,7 +596,7 @@ async def presentation_exchange_send_free_request(request: web.BaseRequest): pres_ex_record = await presentation_manager.create_exchange_for_request( connection_id=connection_id, presentation_request_message=presentation_request_message, - auto_verify=auto_verify + auto_verify=auto_verify, ) result = pres_ex_record.serialize() except (BaseModelError, StorageError) as err: diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/pres_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/pres_handler.py index 9736a66658..bc002533f9 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/pres_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/pres_handler.py @@ -49,7 +49,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder): ) # Automatically move to next state if flag is set - if context.settings.get("debug.auto_verify_presentation"): + if pres_ex_record and pres_ex_record.auto_verify: try: await pres_manager.verify_pres(pres_ex_record) except (BaseModelError, LedgerError, StorageError) as err: diff --git a/aries_cloudagent/protocols/present_proof/v2_0/manager.py b/aries_cloudagent/protocols/present_proof/v2_0/manager.py index 7693942921..94d5eaaed9 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/manager.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/manager.py @@ -161,7 +161,10 @@ async def create_bound_request( return pres_ex_record, pres_request_message async def create_exchange_for_request( - self, connection_id: str, pres_request_message: V20PresRequest + self, + connection_id: str, + pres_request_message: V20PresRequest, + auto_verify: bool = None, ): """ Create a presentation exchange record for input presentation request. @@ -182,6 +185,7 @@ async def create_exchange_for_request( role=V20PresExRecord.ROLE_VERIFIER, state=V20PresExRecord.STATE_REQUEST_SENT, pres_request=pres_request_message, + auto_verify=auto_verify, trace=(pres_request_message._trace is not None), ) async with self._profile.session() as session: diff --git a/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py b/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py index 298081b848..c790ee6ceb 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py @@ -63,6 +63,7 @@ def __init__( pres: Union[V20Pres, Mapping] = None, # aries message verified: str = None, auto_present: bool = False, + auto_verify: bool = False, error_msg: str = None, trace: bool = False, # backward compat: BaseRecord.FromStorage() by_format: Mapping = None, # backward compat: BaseRecord.FromStorage() @@ -190,6 +191,7 @@ def record_value(self) -> Mapping: "state", "verified", "auto_present", + "auto_verify", "error_msg", "trace", ) @@ -309,6 +311,9 @@ class Meta: description="Prover choice to auto-present proof as verifier requests", example=False, ) + auto_verify = fields.Bool( + required=False, description="Verifier choice to auto-verify proof presentation" + ) error_msg = fields.Str( required=False, description="Error message", example="Invalid structure" ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py index 3f1922cb8d..529b72bb6a 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py @@ -111,6 +111,7 @@ async def test_record(self): "pres_proposal": pres_proposal.serialize(), "verified": "false", "auto_present": True, + "auto_verify": False, "error_msg": "error", "trace": False, } diff --git a/aries_cloudagent/protocols/present_proof/v2_0/routes.py b/aries_cloudagent/protocols/present_proof/v2_0/routes.py index 8d24d1afe4..a74b9203d4 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/routes.py @@ -208,6 +208,11 @@ class V20PresCreateRequestRequestSchema(AdminAPIMessageTracingSchema): presentation_request = fields.Nested(V20PresRequestByFormatSchema(), required=True) comment = fields.Str(required=False, allow_none=True) + auto_verify = fields.Bool( + description="Verifier choice to auto-verify proof presentation", + required=False, + example=False, + ) trace = fields.Bool( description="Whether to trace event (default false)", required=False, @@ -223,6 +228,21 @@ class V20PresSendRequestRequestSchema(V20PresCreateRequestRequestSchema): ) +class V20PresentationSendRequestToProposalSchema(AdminAPIMessageTracingSchema): + """Request schema for sending a proof request bound to a proposal.""" + + auto_verify = fields.Bool( + description="Verifier choice to auto-verify proof presentation", + required=False, + example=False, + ) + trace = fields.Bool( + description="Whether to trace event (default false)", + required=False, + example=False, + ) + + class V20PresSpecByFormatRequestSchema(AdminAPIMessageTracingSchema): """Presentation specification schema by format, for send-presentation request.""" @@ -803,6 +823,9 @@ async def present_proof_create_request(request: web.BaseRequest): will_confirm=True, **_formats_attach(pres_request_spec, PRES_20_REQUEST, "request_presentations"), ) + auto_verify = body.get( + "auto_verify", context.settings.get("debug.auto_verify_presentation") + ) trace_msg = body.get("trace") pres_request_message.assign_trace_decorator( context.settings, @@ -815,6 +838,7 @@ async def present_proof_create_request(request: web.BaseRequest): pres_ex_record = await pres_manager.create_exchange_for_request( connection_id=None, pres_request_message=pres_request_message, + auto_verify=auto_verify, ) result = pres_ex_record.serialize() except (BaseModelError, StorageError) as err: @@ -880,6 +904,9 @@ async def present_proof_send_free_request(request: web.BaseRequest): will_confirm=True, **_formats_attach(pres_request_spec, PRES_20_REQUEST, "request_presentations"), ) + auto_verify = body.get( + "auto_verify", context.settings.get("debug.auto_verify_presentation") + ) trace_msg = body.get("trace") pres_request_message.assign_trace_decorator( context.settings, @@ -892,6 +919,7 @@ async def present_proof_send_free_request(request: web.BaseRequest): pres_ex_record = await pres_manager.create_exchange_for_request( connection_id=connection_id, pres_request_message=pres_request_message, + auto_verify=auto_verify, ) result = pres_ex_record.serialize() except (BaseModelError, StorageError) as err: @@ -918,7 +946,7 @@ async def present_proof_send_free_request(request: web.BaseRequest): summary="Sends a presentation request in reference to a proposal", ) @match_info_schema(V20PresExIdMatchInfoSchema()) -@request_schema(AdminAPIMessageTracingSchema()) +@request_schema(V20PresentationSendRequestToProposalSchema()) @response_schema(V20PresExRecordSchema(), 200, description="") async def present_proof_send_bound_request(request: web.BaseRequest): """ @@ -966,6 +994,9 @@ async def present_proof_send_bound_request(request: web.BaseRequest): if not conn_record.is_ready: raise web.HTTPForbidden(reason=f"Connection {connection_id} not ready") + pres_ex_record.auto_verify = body.get( + "auto_verify", context.settings.get("debug.auto_verify_presentation") + ) pres_manager = V20PresManager(profile) try: ( From d7b4c40f52bb19fd01919e40bec534760e9b9e6e Mon Sep 17 00:00:00 2001 From: DaevMithran Date: Thu, 31 Mar 2022 11:24:27 +0530 Subject: [PATCH 3/3] Fix present proof model tests Signed-off-by: DaevMithran --- .../protocols/present_proof/v2_0/models/pres_exchange.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py b/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py index c790ee6ceb..f77a53166b 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/models/pres_exchange.py @@ -81,6 +81,7 @@ def __init__( self._pres = V20Pres.serde(pres) self.verified = verified self.auto_present = auto_present + self.auto_verify = auto_verify self.error_msg = error_msg @property