Skip to content

Commit

Permalink
Merge pull request #494 from sklump/fix-pre-verify-logic-and-request-…
Browse files Browse the repository at this point in the history
…schemas

fix logic error in pre-verify, allow trace in issue-cred, present-pro…
  • Loading branch information
andrewwhitehead authored May 7, 2020
2 parents 8ed5722 + b698822 commit 50cc4cc
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 23 deletions.
10 changes: 10 additions & 0 deletions aries_cloudagent/protocols/issue_credential/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class V10CredentialProposalRequestSchemaBase(AdminAPIMessageTracingSchema):
required=False,
)
comment = fields.Str(description="Human-readable comment", required=False)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
example=False,
)


class V10CredentialProposalRequestOptSchema(V10CredentialProposalRequestSchemaBase):
Expand Down Expand Up @@ -145,6 +150,11 @@ class V10CredentialOfferRequestSchema(AdminAPIMessageTracingSchema):
)
comment = fields.Str(description="Human-readable comment", required=False)
credential_preview = fields.Nested(CredentialPreviewSchema, required=True)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
example=False,
)


class V10CredentialIssueRequestSchema(Schema):
Expand Down
15 changes: 15 additions & 0 deletions aries_cloudagent/protocols/present_proof/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class V10PresentationProposalRequestSchema(AdminAPIMessageTracingSchema):
required=False,
default=False,
)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
example=False,
)


class IndyProofReqSpecRestrictionsSchema(Schema):
Expand Down Expand Up @@ -207,6 +212,11 @@ class V10PresentationRequestRequestSchema(AdminAPIMessageTracingSchema):
)
proof_request = fields.Nested(IndyProofRequestSchema(), required=True)
comment = fields.Str(required=False)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
example=False,
)


class IndyRequestedCredsRequestedAttrSchema(Schema):
Expand Down Expand Up @@ -279,6 +289,11 @@ class V10PresentationRequestSchema(AdminAPIMessageTracingSchema):
keys=fields.Str(example="pred_referent"), # marshmallow/apispec v3.0 ignores
values=fields.Nested(IndyRequestedCredsRequestedPredSchema()),
)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
example=False,
)


class CredentialsFetchQueryStringSchema(Schema):
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/verifier/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ async def pre_verify(self, pres_req: dict, pres: dict) -> (PreVerifyResult, str)
if not ident.get("timestamp"):
cred_def_id = ident["cred_def_id"]
cred_def = await self.ledger.get_credential_definition(cred_def_id)
if not cred_def["value"].get("revocation"):
if cred_def["value"].get("revocation"):
return (
PreVerifyResult.INCOMPLETE,
(
f"Missing timestamp in presentation identifier #{ident} "
f"Missing timestamp in presentation identifier #{index} "
f"for cred def id {cred_def_id}"
),
)
Expand Down
31 changes: 18 additions & 13 deletions aries_cloudagent/verifier/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,24 @@ class TestIndyVerifier(AsyncTestCase):
def setUp(self):
mock_ledger = async_mock.MagicMock(
get_credential_definition=async_mock.CoroutineMock(
return_value={"...": "...", "value": {"revocation": None}}
return_value={
"...": "...",
"value": {
"revocation": {
"g": "1 ...",
"g_dash": "1 ...",
"h": "1 ...",
"h0": "1 ...",
"h1": "1 ...",
"h2": "1 ...",
"htilde": "1 ...",
"h_cap": "1 ...",
"u": "1 ...",
"pk": "1 ...",
"y": "1 ...",
}
},
}
)
)
self.verifier = IndyVerifier(mock_ledger)
Expand Down Expand Up @@ -593,8 +610,6 @@ async def test_check_encoding_attr(self, mock_verify):

@async_mock.patch("indy.anoncreds.verifier_verify_proof")
async def test_check_encoding_attr_tamper_raw(self, mock_verify):
mock_verify.return_value = True

INDY_PROOF_X = deepcopy(INDY_PROOF_NAME)
INDY_PROOF_X["requested_proof"]["revealed_attrs"]["19_uuid"][
"raw"
Expand All @@ -615,8 +630,6 @@ async def test_check_encoding_attr_tamper_raw(self, mock_verify):

@async_mock.patch("indy.anoncreds.verifier_verify_proof")
async def test_check_encoding_attr_tamper_encoded(self, mock_verify):
mock_verify.return_value = True

INDY_PROOF_X = deepcopy(INDY_PROOF_NAME)
INDY_PROOF_X["requested_proof"]["revealed_attrs"]["19_uuid"][
"encoded"
Expand Down Expand Up @@ -660,8 +673,6 @@ async def test_check_pred_names(self, mock_verify):

@async_mock.patch("indy.anoncreds.verifier_verify_proof")
async def test_check_pred_names_tamper_pred_value(self, mock_verify):
mock_verify.return_value = True

INDY_PROOF_X = deepcopy(INDY_PROOF_PRED_NAMES)
INDY_PROOF_X["proof"]["proofs"][0]["primary_proof"]["ge_proofs"][0][
"predicate"
Expand All @@ -682,8 +693,6 @@ async def test_check_pred_names_tamper_pred_value(self, mock_verify):

@async_mock.patch("indy.anoncreds.verifier_verify_proof")
async def test_check_pred_names_bypass_timestamp(self, mock_verify):
mock_verify.return_value = True

INDY_PROOF_REQ_X = deepcopy(INDY_PROOF_REQ_PRED_NAMES)
INDY_PROOF_REQ_X["requested_attributes"]["18_uuid"].pop("non_revoked")
INDY_PROOF_REQ_X["requested_predicates"]["18_id_GE_uuid"].pop("non_revoked")
Expand All @@ -708,8 +717,6 @@ async def test_check_pred_names_bypass_timestamp(self, mock_verify):

@async_mock.patch("indy.anoncreds.verifier_verify_proof")
async def test_check_pred_names_tamper_pred_req_attr(self, mock_verify):
mock_verify.return_value = True

INDY_PROOF_REQ_X = deepcopy(INDY_PROOF_REQ_PRED_NAMES)
INDY_PROOF_REQ_X["requested_predicates"]["18_busid_GE_uuid"]["name"] = "dummy"

Expand All @@ -728,8 +735,6 @@ async def test_check_pred_names_tamper_pred_req_attr(self, mock_verify):

@async_mock.patch("indy.anoncreds.verifier_verify_proof")
async def test_check_pred_names_tamper_attr_groups(self, mock_verify):
mock_verify.return_value = True

INDY_PROOF_X = deepcopy(INDY_PROOF_PRED_NAMES)
INDY_PROOF_X["requested_proof"]["revealed_attr_groups"][
"x_uuid"
Expand Down
12 changes: 8 additions & 4 deletions demo/AcmeDemoWorkshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ Now we need to handle receipt of the proof. Locate the code that handles receiv
then replace the ```# TODO``` comment and the ```pass``` statement:

```
log_status("#27 Process the proof provided by X")
log_status("#28 Check if proof is valid")
proof = await self.admin_POST(
f"/present-proof/records/{presentation_exchange_id}/verify-presentation"
)
self.log("Proof = ", proof["verified"])
# if presentation is a degree schema (proof of education),
# check values received
pres_req = message["presentation_request"]
Expand All @@ -147,7 +154,7 @@ then replace the ```# TODO``` comment and the ```pass``` statement:
self.log("#28.1 Received ", message["presentation_request"]["name"])
```

Right now this just prints out information received in the proof, but in "real life" your application could do something useful with this information.
Right now this just verifies the proof received and prints out the attributes it reveals, but in "real life" your application could do something useful with this information.

Now you can run the Faber/Alice/Acme script from the "Preview of the Acme Controller" section above, and you should see Acme receive a proof from Alice!

Expand Down Expand Up @@ -260,9 +267,6 @@ with the following code:
{
"comment": f"Issuing credential, exchange {credential_exchange_id}",
"credential_preview": cred_preview
# "credential_preview": CredentialPreview(
# attributes=CredAttrSpec.list_plain(cred_attrs)
# ).serialize()
}
)
```
Expand Down
2 changes: 1 addition & 1 deletion demo/AriesOpenAPIDemo.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ Finally, we need put into the JSON the data values for the credential proposal s
},
{
"name": "timestamp",
"value": "123456789"
"value": "1234567890"
},
{
"name": "date",
Expand Down
4 changes: 1 addition & 3 deletions demo/runners/faber.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ async def handle_present_proof(self, message):
log_status("#27 Process the proof provided by X")
log_status("#28 Check if proof is valid")
proof = await self.admin_POST(
f"/present-proof/records/{presentation_exchange_id}/"
"verify-presentation"
f"/present-proof/records/{presentation_exchange_id}/verify-presentation"
)
self.log("Proof =", proof["verified"])

Expand Down Expand Up @@ -269,7 +268,6 @@ async def main(
"trace": exchange_tracing,
}
await agent.admin_POST("/issue-credential/send-offer", offer_request)

# TODO issue an additional credential for Student ID

elif option == "2":
Expand Down

0 comments on commit 50cc4cc

Please sign in to comment.