Пример #1
0
    async def verifyProof(self, msg: Any):
        body, (frm, _) = msg
        link = self.verifyAndGetLink(msg)
        if not link:
            raise NotImplementedError

        proof = body[PROOF_FIELD]
        proofRequest = ProofRequest.from_str_dict(body[PROOF_REQUEST_FIELD])
        nonce = getNonceForProof(body[NONCE])
        proofName = proofRequest.name

        proofs = {}

        for key, p in proof['proofs'].items():
            schema = await self.verifier.wallet.getSchema(
                ID(schemaId=int(p['schema_seq_no'])))
            pk = await self.verifier.wallet.getPublicKey(
                ID(schemaKey=schema.getKey()))
            proofs[key] = ProofInfo.from_str_dict(p, str(pk.N))

        proof = FullProof(
            proofs, AggregatedProof.from_str_dict(proof['aggregated_proof']),
            RequestedProof.from_str_dict(proof['requested_proof']))

        result = await self.verifier.verify(proofRequest, proof)

        self.logger.info('Proof "{}" accepted with nonce {}'.format(
            proofName, nonce))
        self.logger.info('Verifying proof "{}" from {}'.format(
            proofName, link.name))
        status = 'verified' if result else 'failed verification'
        resp = {
            TYPE:
            PROOF_STATUS,
            DATA:
            '    Your Proof {} {} was received and {}\n'.format(
                proofRequest.name, proofRequest.version, status),
        }
        self.signAndSend(resp,
                         link.localIdentifier,
                         frm,
                         origReqId=body.get(f.REQ_ID.nm))

        if result:
            for uuid, attribute in proofRequest.verifiableAttributes.items():
                # Log attributes that were verified
                self.logger.info('verified {}: {}'.format(
                    attribute.name,
                    proof.requestedProof.revealed_attrs[uuid][1]))
            self.logger.info(
                'Verified that proof "{}" contains attributes '
                'from claim(s) issued by: {}'.format(
                    proofName, ", ".join(
                        sorted([v.issuer_did
                                for k, v in proof.proofs.items()]))))
            await self._postProofVerif(proofName, link, frm)
        else:
            self.logger.info(
                'Verification failed for proof {} from {} '.format(
                    proofName, link.name))
Пример #2
0
    async def verifyClaimProof(self, msg: Any):
        body, (frm, ha) = msg
        link = self.verifyAndGetLink(msg)
        if not link:
            raise NotImplementedError

        claimName = body[NAME]
        nonce = getNonceForProof(body[NONCE])
        proof = FullProof.fromStrDict(body[PROOF_FIELD])
        proofInput = ProofInput.fromStrDict(body[PROOF_INPUT_FIELD])
        revealedAttrs = fromDictWithStrValues(body[REVEALED_ATTRS_FIELD])

        result = await self.verifier.verify(proofInput, proof, revealedAttrs,
                                            nonce)

        status = 'verified' if result else 'failed verification'
        resp = {
            TYPE:
            CLAIM_PROOF_STATUS,
            DATA:
            '    Your claim {} {} was received and {}\n'.format(
                body[NAME], body[VERSION], status),
        }
        self.signAndSend(resp,
                         link.localIdentifier,
                         frm,
                         origReqId=body.get(f.REQ_ID.nm))

        if result:
            await self._postClaimVerif(claimName, link, frm)
async def verify(proof, conn):
    proof = FullProof.from_str_dict(proof, [global_dict['public_key'].N])

    assert proof.requestedProof.revealed_attrs['attr_uuid'][1] == 'Alex'
    valid = await global_dict['verifier'].verify(global_dict['proof_request'], proof)

    conn.send(json.dumps(valid).encode())
Пример #4
0
async def testClaimProofFromToDictPrimaryOnly(prover1, nonce, claimsProver1Gvt):
    proofInput = ProofInput(['name'], [PredicateGE('age', 18)])
    proof, _ = await prover1.presentProof(proofInput, nonce)

    proofs = [Proof(primaryProof=proof.proofs[0].primaryProof)]
    proof = proof._replace(proofs=proofs)
    assert proof == FullProof.fromStrDict(proof.toStrDict())
Пример #5
0
    async def _prepareProof(self, claims: Dict[SchemaKey, ProofClaims], nonce,
                            requestedProof) -> FullProof:
        m1Tilde = cmod.integer(cmod.randomBits(LARGE_M2_TILDE))
        initProofs = {}
        CList = []
        TauList = []

        # 1. init proofs
        for schemaId, val in claims.items():
            c1, c2, revealedAttrs, predicates = val.claims.primaryClaim, val.claims.nonRevocClaim, val.revealedAttrs, val.predicates

            claim = await self.wallet.getClaimAttributes(ID(schemaId=schemaId))

            nonRevocInitProof = None
            if c2:
                nonRevocInitProof = await self._nonRevocProofBuilder.initProof(
                    schemaId, c2)
                CList += nonRevocInitProof.asCList()
                TauList += nonRevocInitProof.asTauList()

            primaryInitProof = None
            if c1:
                m2Tilde = cmod.integer(int(nonRevocInitProof.TauListParams.m2)
                                       ) if nonRevocInitProof else None
                primaryInitProof = await self._primaryProofBuilder.initProof(
                    schemaId, c1, revealedAttrs, predicates, m1Tilde, m2Tilde,
                    claim)
                CList += primaryInitProof.asCList()
                TauList += primaryInitProof.asTauList()

            initProof = InitProof(nonRevocInitProof, primaryInitProof)
            initProofs[schemaId] = initProof

        # 2. hash
        cH = self._get_hash(self._prepare_collection(CList),
                            self._prepare_collection(TauList), nonce)

        # 3. finalize proofs
        proofs = {}
        for schemaId, initProof in initProofs.items():
            nonRevocProof = None
            if initProof.nonRevocInitProof:
                nonRevocProof = await self._nonRevocProofBuilder.finalizeProof(
                    schemaId, cH, initProof.nonRevocInitProof)
            primaryProof = await self._primaryProofBuilder.finalizeProof(
                schemaId, cH, initProof.primaryInitProof)

            schema = await self.wallet.getSchema(ID(schemaId=schemaId))

            proof = Proof(primaryProof, nonRevocProof)
            proofInfo = ProofInfo(proof=proof,
                                  schema_seq_no=schemaId,
                                  issuer_did=schema.issuerId)

            proofs[str(schemaId)] = proofInfo

        aggregatedProof = AggregatedProof(cH, self._prepare_collection(CList))

        return FullProof(proofs, aggregatedProof, requestedProof)
Пример #6
0
async def testClaimProofFromToDict(prover1, nonce, claimsProver1Gvt):
    proofRequest = ProofRequest("proof1", "1.0", 1,
                                verifiableAttributes={
                                    'attr_uuid': AttributeInfo(name='name')},
                                predicates={'predicate_uuid': PredicateGE('age', 18)})

    proof = await prover1.presentProof(proofRequest)

    assert proof == FullProof.fromStrDict(proof.toStrDict())
Пример #7
0
async def testClaimProofFromToDictPrimaryOnly(prover1, nonce, claimsProver1Gvt, schemaGvt):
    proofRequest = ProofRequest("proof1", "1.0", 1,
                                verifiableAttributes={
                                    'attr_uuid': AttributeInfo(name='name')},
                                predicates={'predicate_uuid': PredicateGE('age', 18)})

    proof = await prover1.presentProof(proofRequest)

    proofInfo = proof.proofs[str(schemaGvt.seqId)]
    proofs = {schemaGvt.seqId: ProofInfo(Proof(primaryProof=proofInfo.proof.primaryProof),
                                         issuer_did=schemaGvt.issuerId,
                                         schema_seq_no=proofInfo.schema_seq_no)}
    proof = proof._replace(proofs=proofs)
    assert proof == FullProof.fromStrDict(proof.toStrDict())
Пример #8
0
    async def _prepareProof(self, claims: Dict[SchemaKey, ProofClaims],
                            nonce) -> FullProof:
        m1Tilde = cmod.integer(cmod.randomBits(LARGE_M2_TILDE))
        initProofs = {}
        CList = []
        TauList = []

        # 1. init proofs
        for schemaKey, val in claims.items():
            c1, c2, revealedAttrs, predicates = val.claims.primaryClaim, val.claims.nonRevocClaim, val.revealedAttrs, val.predicates

            nonRevocInitProof = None
            if c2:
                nonRevocInitProof = await self._nonRevocProofBuilder.initProof(
                    schemaKey, c2)
                CList += nonRevocInitProof.asCList()
                TauList += nonRevocInitProof.asTauList()

            primaryInitProof = None
            if c1:
                m2Tilde = cmod.integer(int(
                    nonRevocInitProof.TauListParams.m2)) if nonRevocInitProof else None
                primaryInitProof = await self._primaryProofBuilder.initProof(
                    schemaKey, c1, revealedAttrs, predicates,
                    m1Tilde, m2Tilde)
                CList += primaryInitProof.asCList()
                TauList += primaryInitProof.asTauList()

            initProof = InitProof(nonRevocInitProof, primaryInitProof)
            initProofs[schemaKey] = initProof

        # 2. hash
        cH = self._get_hash(CList, TauList, nonce)

        # 3. finalize proofs
        proofs = []
        schemaKeys = []
        for schemaKey, initProof in initProofs.items():
            schemaKeys.append(schemaKey)
            nonRevocProof = None
            if initProof.nonRevocInitProof:
                nonRevocProof = await self._nonRevocProofBuilder.finalizeProof(
                    schemaKey, cH, initProof.nonRevocInitProof)
            primaryProof = await self._primaryProofBuilder.finalizeProof(
                schemaKey, cH, initProof.primaryInitProof)
            proofs.append(Proof(primaryProof, nonRevocProof))

        return FullProof(cH, schemaKeys, proofs, CList)
Пример #9
0
    async def verifyProof(self, msg: Any):
        body, (frm, _) = msg
        link = self.verifyAndGetLink(msg)
        if not link:
            raise NotImplementedError

        proofName = body[NAME]
        nonce = getNonceForProof(body[NONCE])
        proof = FullProof.fromStrDict(body[PROOF_FIELD])
        proofInput = ProofInput.fromStrDict(body[PROOF_INPUT_FIELD])
        revealedAttrs = fromDictWithStrValues(body[REVEALED_ATTRS_FIELD])
        result = await self.verifier.verify(proofInput, proof, revealedAttrs,
                                            nonce)

        self.logger.info('Proof "{}" accepted with nonce {}'.format(
            proofName, nonce))
        self.logger.info('Verifying proof "{}" from {}'.format(
            proofName, link.name))
        status = 'verified' if result else 'failed verification'
        resp = {
            TYPE:
            PROOF_STATUS,
            DATA:
            '    Your Proof {} {} was received and {}\n'.format(
                body[NAME], body[VERSION], status),
        }
        self.signAndSend(resp,
                         link.localIdentifier,
                         frm,
                         origReqId=body.get(f.REQ_ID.nm))

        if result:
            for attribute in proofInput.revealedAttrs:
                # Log attributes that were verified
                self.logger.info('verified {}: {}'.format(
                    attribute, revealedAttrs[attribute]))
            self.logger.info(
                'Verified that proof "{}" contains attributes '
                'from claim(s) issued by: {}'.format(
                    proofName,
                    ", ".join(sorted([sk.issuerId
                                      for sk in proof.schemaKeys]))))
            await self._postProofVerif(proofName, link, frm)
        else:
            self.logger.info(
                'Verification failed for proof {} from {} '.format(
                    proofName, link.name))
Пример #10
0
    async def verifyProof(self, msg: Any):
        body, (frm, _) = msg
        link = self.verifyAndGetLink(msg)
        if not link:
            raise NotImplementedError

        proofName = body[NAME]
        nonce = getNonceForProof(body[NONCE])
        proof = FullProof.fromStrDict(body[PROOF_FIELD])
        proofInput = ProofInput.fromStrDict(body[PROOF_INPUT_FIELD])
        revealedAttrs = fromDictWithStrValues(body[REVEALED_ATTRS_FIELD])
        result = await self.verifier.verify(proofInput, proof,
                                            revealedAttrs, nonce)

        self.logger.info('Proof "{}" accepted with nonce {}'
                              .format(proofName, nonce))
        self.logger.info('Verifying proof "{}" from {}'
                              .format(proofName, link.name))
        status = 'verified' if result else 'failed verification'
        resp = {
            TYPE: PROOF_STATUS,
            DATA: '    Your Proof {} {} was received and {}\n'.
                format(body[NAME], body[VERSION], status),
        }
        self.signAndSend(resp, link.localIdentifier, frm,
                         origReqId=body.get(f.REQ_ID.nm))

        if result:
            for attribute in proofInput.revealedAttrs:
                # Log attributes that were verified
                self.logger.info('verified {}: {}'.
                                 format(attribute, revealedAttrs[attribute]))
            self.logger.info('Verified that proof "{}" contains attributes '
                             'from claim(s) issued by: {}'.format(
                proofName, ", ".join(
                    sorted([sk.issuerId for sk in proof.schemaKeys]))))
            await self._postProofVerif(proofName, link, frm)
        else:
            self.logger.info('Verification failed for proof {} from {} '
                              .format(proofName, link.name))
Пример #11
0
async def testClaimProofFromToDict(prover1, nonce, claimsProver1Gvt):
    proofInput = ProofInput(['name'], [PredicateGE('age', 18)])
    proof, _ = await prover1.presentProof(proofInput, nonce)
    assert proof == FullProof.fromStrDict(proof.toStrDict())