Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit tests exercising pre-verify for tamper evidence #485

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions aries_cloudagent/verifier/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ def pre_verify(pres_req: dict, pres: dict) -> (PreVerifyResult, str):
pres: corresponding presentation

Returns:
An instance of `PreVerifyResult` representing the validation result
A tuple with `PreVerifyResult` representing the validation result and
reason text for failure or None for OK.

"""
if not (
pres_req
and "requested_predicates" in pres_req
and "requested_attributes" in pres_req
):
return (PreVerifyResult.INCOMPLETE, "Incomplete or missing proof request")
if not pres:
return (PreVerifyResult.INCOMPLETE, "No proof provided")
if "requested_proof" not in pres:
Expand All @@ -58,8 +65,8 @@ def pre_verify(pres_req: dict, pres: dict) -> (PreVerifyResult, str):
return (PreVerifyResult.INCOMPLETE, "Missing 'proof'")

for (uuid, req_pred) in pres_req["requested_predicates"].items():
canon_attr = canon(req_pred["name"])
try:
canon_attr = canon(req_pred["name"])
for ge_proof in pres["proof"]["proofs"][
pres["requested_proof"]["predicates"][uuid]["sub_proof_index"]
]["primary_proof"]["ge_proofs"]:
Expand Down
201 changes: 201 additions & 0 deletions aries_cloudagent/verifier/tests/test_indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from asynctest import TestCase as AsyncTestCase
from asynctest import mock as async_mock

from indy.error import IndyError

from ..indy import IndyVerifier, PreVerifyResult


Expand Down Expand Up @@ -328,6 +330,205 @@ async def test_verify_presentation(self, mock_verify):

assert verified == "val"

@async_mock.patch("indy.anoncreds.verifier_verify_proof")
async def test_verify_presentation_x_indy(self, mock_verify):
mock_verify.side_effect = IndyError(error_code=1)

verifier = IndyVerifier("wallet")
with async_mock.patch.object(
verifier, "pre_verify", return_value=(PreVerifyResult.OK, None)
):
verified = await verifier.verify_presentation(
{"nonce": "1234567890"},
"presentation",
"schemas",
"credential_definitions",
"rev_reg_defs",
"rev_reg_entries",
)

mock_verify.assert_called_once_with(
json.dumps({"nonce": "1234567890"}),
json.dumps("presentation"),
json.dumps("schemas"),
json.dumps("credential_definitions"),
json.dumps("rev_reg_defs"),
json.dumps("rev_reg_entries"),
)

assert not verified

async def test_pre_verify(self):
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
None, {"requested_proof": "...", "proof": "..."}
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
{"requested_predicates": "...", "requested_attributes": "..."}, None,
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
{"requested_predicates": "...", "requested_attributes": "..."},
{"requested_proof": "..."},
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
{"requested_predicates": "...", "requested_attributes": "..."},
{"proof": "..."},
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
{
"requested_predicates": {"0_name_uuid": "..."},
"requested_attributes": "...",
},
INDY_PROOF_PRED_NAMES,
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
INDY_PROOF_REQ_NAME,
{
"proof": "...",
"requested_proof": {
"revealed_attrs": {},
"self_attested_attrs": {"19_uuid": "Chicken Hawk"},
"unrevealed_attrs": {},
"predicates": {},
},
"identifiers": "...",
},
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
{
"nonce": "15606741555044336341559",
"name": "proof_req",
"version": "0.0",
"requested_attributes": {"19_uuid": {"name": "Preferred Name"}},
"requested_predicates": {},
},
{
"proof": "...",
"requested_proof": {
"revealed_attrs": {},
"self_attested_attrs": {},
"unrevealed_attrs": {},
"predicates": {},
},
"identifiers": "...",
},
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
{
"nonce": "15606741555044336341559",
"name": "proof_req",
"version": "0.0",
"requested_attributes": {
"19_uuid": {"neither-name-nor-names": "Preferred Name"}
},
"requested_predicates": {},
},
{
"proof": "...",
"requested_proof": {
"revealed_attrs": {
"19_uuid": {
"sub_proof_index": 0,
"raw": "Chicken Hawk",
"encoded": "94607763023542937648705576709896212619553924110058781320304650334433495169960",
}
},
"self_attested_attrs": {},
"unrevealed_attrs": {},
"predicates": {},
},
"identifiers": "...",
},
)[0]
)
assert (
PreVerifyResult.INCOMPLETE
== IndyVerifier.pre_verify(
INDY_PROOF_REQ_NAME,
{
"proof": {
"proofs": [
{
"primary_proof": {
"eq_proof": {
"revealed_attrs": {"otherthing": "..."},
"...": "...",
},
"ge_proofs": [],
},
"...": "...",
}
],
"...": "...",
},
"requested_proof": {
"revealed_attrs": {
"19_uuid": {
"sub_proof_index": 0,
"raw": "Chicken Hawk",
"encoded": "94607763023542937648705576709896212619553924110058781320304650334433495169960",
}
},
"self_attested_attrs": {},
"unrevealed_attrs": {},
"predicates": {},
},
"identifiers": [
{
"schema_id": "LjgpST2rjsoxYegQDRm7EL:2:non-revo:1579888926.0",
"cred_def_id": "LjgpST2rjsoxYegQDRm7EL:3:CL:19:tag",
"rev_reg_id": None,
"timestamp": None,
}
],
},
)[0]
)
assert (
PreVerifyResult.OK
== IndyVerifier.pre_verify(
{
"nonce": "15606741555044336341559",
"name": "proof_req",
"version": "0.0",
"requested_attributes": {"19_uuid": {"name": "Preferred Name"}},
"requested_predicates": {},
},
{
"proof": "...",
"requested_proof": {
"revealed_attrs": {},
"self_attested_attrs": {"19_uuid": "Chicken Hawk"},
"unrevealed_attrs": {},
"predicates": {},
},
"identifiers": "...",
},
)[0]
)

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