Skip to content

Commit

Permalink
Changed Proof (Verifier) API for checking presentation status (#770)
Browse files Browse the repository at this point in the history
* Remove Verifier's Proof method get_presentation_status(...)

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Rename get_revocation_status to get_presentation_verification_status, rename enum variants

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Use new enum PresentationVerificationStatus instead of RevocationStatus

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Modify libvcx api get_proof_msg to only return presentation msg (removed proofStatus from result set)

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix test in libvcx_core

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix test compile errs

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix unit test

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix integration test

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Make unimplemented mock logs more explicit

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Reformat

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix libvcx ios header file

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Rename field revocation_status->verification_status, sync up nodejs wrapper, unify method names

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix nodejs vcxagent-core

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix ci

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix formatting

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix libvcx java wrapper

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Address code review

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Optimize deserialization

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Address code review

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Address code review

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

* Fix deserialization case when verification_status/revocation_status is undefined

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>

---------

Signed-off-by: Patrik Stas <patrik.stas@absa.africa>
  • Loading branch information
Patrik-Stas authored Mar 21, 2023
1 parent bbcbbf3 commit 26c1cbe
Show file tree
Hide file tree
Showing 30 changed files with 453 additions and 278 deletions.
14 changes: 7 additions & 7 deletions agents/node/vcxagent-core/demo/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,30 @@ async function runFaber (options) {

logger.info('#27 Process the proof provided by alice.')
const presentation = vcxProof.getPresentationMsg()
const verificationState = vcxProof.getPresentationVerificationStatus()
logger.info(`#27 Proof: proofVerificationStatus=${verificationState}, proof=${presentation}`)
assert(verificationState)
const verificationStatus = vcxProof.getVerificationStatus()
logger.info(`#27 Proof: proofVerificationStatus=${verificationStatus}, proof=${presentation}`)
assert(verificationStatus)
assert(presentation)
logger.info(`Proof protocol state = ${JSON.stringify(proofProtocolState)}`)
logger.info(`Proof verification state =${verificationState}`)
logger.info(`Proof verification state =${verificationStatus}`)
logger.debug(`Proof presentation = ${JSON.stringify(presentation, null, 2)}`)
logger.debug(`Serialized Proof state machine ${JSON.stringify(await vcxProof.serialize())}`)

if (verificationState === ProofVerificationStatus.Verified) {
if (verificationStatus === ProofVerificationStatus.Valid) {
if (options.revocation) {
throw Error('Proof was verified, but was expected to be invalid, because revocation was enabled.')
} else {
logger.info('Proof was verified.')
}
} else if (verificationState === ProofVerificationStatus.Invalid) {
} else if (verificationStatus === ProofVerificationStatus.Invalid) {
if (options.revocation) {
logger.info('Proof was determined as invalid, which was expected because the used credential was revoked.')
} else {
throw Error('Proof was invalid, but was expected to be verified. Revocation was not enabled.')
}
await sleepPromise(1000)
} else {
logger.error(`Unexpected proof state '${verificationState}'.`)
logger.error(`Unexpected proof state '${verificationStatus}'.`)
process.exit(-1)
}

Expand Down
8 changes: 4 additions & 4 deletions agents/node/vcxagent-core/src/services/service-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ module.exports.createServiceVerifier = function createServiceVerifier ({ logger,
return JSON.parse(proof.getPresentationRequestAttachment())
}

async function getPresentationVerificationStatus (proofId) {
async function getVerificationStatus (proofId) {
const proof = await loadProof(proofId)
return proof.getPresentationVerificationStatus()
return proof.getVerificationStatus()
}

async function getRevocationStatus (proofId) {
const proof = await loadProof(proofId)
return proof.getPresentationVerificationStatus()
return proof.getVerificationStatus()
}

async function listIds () {
Expand Down Expand Up @@ -107,7 +107,7 @@ module.exports.createServiceVerifier = function createServiceVerifier ({ logger,
getPresentationMsg,
getPresentationAttachment,
getPresentationRequestAttachment,
getPresentationVerificationStatus,
getVerificationStatus,
getRevocationStatus
}
}
25 changes: 9 additions & 16 deletions agents/node/vcxagent-core/test/issue-verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const {
HolderStateType,
ProverStateType,
VerifierStateType,
ProofVerificationStatus,
ProofRevocationStatus
ProofVerificationStatus
} = require('@hyperledger/node-vcx-wrapper')
const sleep = require('sleep-promise')
const { initRustLogger } = require('../src')
Expand Down Expand Up @@ -43,13 +42,11 @@ describe('test update state', () => {
await faber.updateStateVerifierProof(VerifierStateType.Finished)
await alice.updateStateHolderProof(ProverStateType.Finished)
const {
presentationVerificationState,
presentationVerificationStatus,
presentationAttachment,
presentationRequestAttachment,
revocationStatus
presentationRequestAttachment
} = await faber.getPresentationInfo()
expect(revocationStatus).toBe(ProofRevocationStatus.NonRevoked)
expect(presentationVerificationState).toBe(ProofVerificationStatus.Verified)
expect(presentationVerificationStatus).toBe(ProofVerificationStatus.Valid)
expect(presentationRequestAttachment.requested_attributes).toStrictEqual({
attribute_0: {
names: [
Expand Down Expand Up @@ -143,11 +140,9 @@ describe('test update state', () => {
await faber.updateStateVerifierProof(VerifierStateType.Finished)
await alice.updateStateHolderProof(ProverStateType.Finished)
const {
presentationVerificationState,
revocationStatus
presentationVerificationStatus
} = await faber.getPresentationInfo()
expect(revocationStatus).toBe(ProofRevocationStatus.Revoked)
expect(presentationVerificationState).toBe(ProofVerificationStatus.Invalid)
expect(presentationVerificationStatus).toBe(ProofVerificationStatus.Invalid)
})

it('Faber should verify proof with self attestation', async () => {
Expand All @@ -157,13 +152,11 @@ describe('test update state', () => {
await faber.updateStateVerifierProof(VerifierStateType.Finished)
await alice.updateStateHolderProof(ProverStateType.Finished)
const {
presentationVerificationState,
presentationVerificationStatus,
presentationAttachment,
presentationRequestAttachment,
revocationStatus
presentationRequestAttachment
} = await faber.getPresentationInfo()
expect(revocationStatus).toBe(ProofRevocationStatus.NonRevoked)
expect(presentationVerificationState).toBe(ProofVerificationStatus.Verified)
expect(presentationVerificationStatus).toBe(ProofVerificationStatus.Valid)
expect(presentationAttachment.requested_proof).toStrictEqual({
revealed_attrs: {},
self_attested_attrs: {
Expand Down
6 changes: 2 additions & 4 deletions agents/node/vcxagent-core/test/utils/faber.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,18 +401,16 @@ module.exports.createFaber = async function createFaber (serviceEndpoint = 'http
logger.info('Faber is gather info about received presentation')
await vcxAgent.agentInitVcx()
const presentationMsg = await vcxAgent.serviceVerifier.getPresentationMsg(proofId)
const presentationVerificationState = await vcxAgent.serviceVerifier.getPresentationVerificationStatus(proofId)
const presentationVerificationStatus = await vcxAgent.serviceVerifier.getVerificationStatus(proofId)
const presentationAttachment = await vcxAgent.serviceVerifier.getPresentationAttachment(proofId)
const presentationRequestAttachment = await vcxAgent.serviceVerifier.getPresentationRequestAttachment(proofId)
const revocationStatus = await vcxAgent.serviceVerifier.getRevocationStatus(proofId)

await vcxAgent.agentShutdownVcx()
return {
presentationMsg,
presentationVerificationState,
presentationVerificationStatus,
presentationAttachment,
presentationRequestAttachment,
revocationStatus
}
}

Expand Down
5 changes: 3 additions & 2 deletions agents/rust/aries-vcx-agent/src/services/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use aries_vcx::messages::protocols::proof_presentation::presentation::Presentati
use aries_vcx::messages::protocols::proof_presentation::presentation_proposal::PresentationProposal;
use aries_vcx::messages::status::Status;
use aries_vcx::protocols::proof_presentation::verifier::state_machine::VerifierState;
use aries_vcx::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus;
use aries_vcx::protocols::SendClosure;

use super::connection::ServiceConnections;
Expand Down Expand Up @@ -72,9 +73,9 @@ impl ServiceVerifier {
)
}

pub fn get_presentation_status(&self, thread_id: &str) -> AgentResult<Status> {
pub fn get_presentation_status(&self, thread_id: &str) -> AgentResult<PresentationVerificationStatus> {
let VerifierWrapper { verifier, .. } = self.verifiers.get(thread_id)?;
Ok(verifier.get_presentation_status())
Ok(verifier.get_verification_status())
}

pub async fn verify_presentation(&self, thread_id: &str, presentation: Presentation) -> AgentResult<()> {
Expand Down
11 changes: 4 additions & 7 deletions aries_vcx/src/handlers/proof_presentation/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use crate::core::profile::profile::Profile;
use crate::errors::error::prelude::*;
use crate::handlers::connection::mediated_connection::MediatedConnection;
use crate::protocols::proof_presentation::verifier::messages::VerifierMessages;
use crate::protocols::proof_presentation::verifier::state_machine::{RevocationStatus, VerifierSM, VerifierState};
use crate::protocols::proof_presentation::verifier::state_machine::{VerifierSM, VerifierState};
use crate::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus;
use crate::protocols::SendClosure;
use messages::a2a::A2AMessage;
use messages::protocols::proof_presentation::presentation_proposal::PresentationProposal;
Expand Down Expand Up @@ -144,12 +145,8 @@ impl Verifier {
self.verifier_sm.get_presentation_msg()
}

pub fn get_presentation_status(&self) -> Status {
self.verifier_sm.presentation_status()
}

pub fn get_revocation_status(&self) -> Option<RevocationStatus> {
self.verifier_sm.get_revocation_status()
pub fn get_verification_status(&self) -> PresentationVerificationStatus {
self.verifier_sm.get_verification_status()
}

pub fn get_presentation_attachment(&self) -> VcxResult<String> {
Expand Down
1 change: 1 addition & 0 deletions aries_vcx/src/protocols/proof_presentation/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::protocols::proof_presentation::verifier::messages::VerifierMessages;
pub mod messages;
pub mod state_machine;
pub mod states;
pub mod verification_status;

pub fn verify_thread_id(thread_id: &str, message: &VerifierMessages) -> VcxResult<()> {
if !settings::indy_mocks_enabled() && !message.thread_id_matches(thread_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::protocols::proof_presentation::verifier::states::initial::InitialVeri
use crate::protocols::proof_presentation::verifier::states::presentation_proposal_received::PresentationProposalReceivedState;
use crate::protocols::proof_presentation::verifier::states::presentation_request_sent::PresentationRequestSentState;
use crate::protocols::proof_presentation::verifier::states::presentation_request_set::PresentationRequestSetState;
use crate::protocols::proof_presentation::verifier::verification_status::PresentationVerificationStatus;
use crate::protocols::proof_presentation::verifier::verify_thread_id;
use crate::protocols::SendClosure;
use messages::a2a::{A2AMessage, MessageId};
Expand All @@ -21,6 +22,7 @@ use messages::protocols::proof_presentation::presentation_ack::PresentationAck;
use messages::protocols::proof_presentation::presentation_proposal::PresentationProposal;
use messages::protocols::proof_presentation::presentation_request::PresentationRequest;
use messages::status::Status;
use strum_macros::{AsRefStr, EnumString};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct VerifierSM {
Expand Down Expand Up @@ -66,12 +68,6 @@ impl Default for VerifierFullState {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum RevocationStatus {
NonRevoked,
Revoked,
}

fn build_verification_ack(thread_id: &str) -> PresentationAck {
PresentationAck::create().set_thread_id(thread_id).set_out_time()
}
Expand Down Expand Up @@ -220,11 +216,13 @@ impl VerifierSM {
let ack = build_verification_ack(&self.thread_id);
send_message(A2AMessage::PresentationAck(ack)).await?;
match verification_result {
Ok(()) => VerifierFullState::Finished((state, presentation, RevocationStatus::NonRevoked).into()),
Ok(()) => {
VerifierFullState::Finished((state, presentation, PresentationVerificationStatus::Valid).into())
}
Err(err) => match err.kind() {
AriesVcxErrorKind::InvalidProof => {
VerifierFullState::Finished((state, presentation, RevocationStatus::Revoked).into())
}
AriesVcxErrorKind::InvalidProof => VerifierFullState::Finished(
(state, presentation, PresentationVerificationStatus::Invalid).into(),
),
_ => {
let problem_report = build_problem_report_msg(Some(err.to_string()), &self.thread_id);
VerifierFullState::Finished((state, problem_report).into())
Expand Down Expand Up @@ -394,6 +392,7 @@ impl VerifierSM {
}

pub fn get_state(&self) -> VerifierState {
warn!("get_state >>> {:?}", self.state);
match self.state {
VerifierFullState::Initial(_) => VerifierState::Initial,
VerifierFullState::PresentationRequestSet(_) => VerifierState::PresentationRequestSet,
Expand All @@ -416,32 +415,10 @@ impl VerifierSM {
}
}

pub fn presentation_status(&self) -> Status {
match self.state {
VerifierFullState::Finished(ref state) => {
match &state.status {
Status::Success => {
match state.revocation_status {
Some(RevocationStatus::NonRevoked) => Status::Success,
None => Status::Success, // for backward compatibility
Some(RevocationStatus::Revoked) => {
let problem_report = ProblemReport::create()
.set_comment(Some(String::from("Revoked credential was used.")));
Status::Failed(problem_report)
}
}
}
_ => state.status.clone(),
}
}
_ => Status::Undefined,
}
}

pub fn get_revocation_status(&self) -> Option<RevocationStatus> {
pub fn get_verification_status(&self) -> PresentationVerificationStatus {
match self.state {
VerifierFullState::Finished(ref state) => state.revocation_status.clone(),
_ => None,
VerifierFullState::Finished(ref state) => state.verification_status.clone(),
_ => PresentationVerificationStatus::Unavailable,
}
}

Expand Down Expand Up @@ -494,6 +471,8 @@ impl VerifierSM {
#[cfg(test)]
#[cfg(feature = "general_test")]
pub mod unit_tests {
use std::str::FromStr;

use crate::common::proofs::proof_request::test_utils::_presentation_request_data;
use crate::common::test_utils::mock_profile;
use crate::test::source_id;
Expand Down Expand Up @@ -788,8 +767,11 @@ pub mod unit_tests {
.await
.unwrap();

assert_match!(VerifierFullState::Finished(_), verifier_sm.state);
assert_match!(Status::Declined(_), verifier_sm.presentation_status());
assert_match!(VerifierState::Failed, verifier_sm.get_state());
assert_match!(
PresentationVerificationStatus::Unavailable,
verifier_sm.get_verification_status()
);
}

#[tokio::test]
Expand Down Expand Up @@ -839,7 +821,10 @@ pub mod unit_tests {
.unwrap();

assert_match!(VerifierFullState::Finished(_), verifier_sm.state);
assert_eq!(Status::Success, verifier_sm.presentation_status());
assert_eq!(
PresentationVerificationStatus::Valid,
verifier_sm.get_verification_status()
);
}

#[tokio::test]
Expand All @@ -859,9 +844,11 @@ pub mod unit_tests {
.await
.unwrap();

assert_match!(VerifierFullState::Finished(_), verifier_sm.state);
assert_eq!(VerifierState::Finished, verifier_sm.get_state());
assert_match!(Status::Failed(_), verifier_sm.presentation_status());
assert_match!(VerifierState::Finished, verifier_sm.get_state());
assert_match!(
PresentationVerificationStatus::Invalid,
verifier_sm.get_verification_status()
);
}

#[tokio::test]
Expand Down Expand Up @@ -918,14 +905,14 @@ pub mod unit_tests {
.await
.unwrap();

assert_match!(VerifierFullState::Finished(_), verifier_sm.state);
assert_eq!(Status::Failed(_problem_report()), verifier_sm.presentation_status());
assert_match!(VerifierState::Failed, verifier_sm.get_state());
}

#[tokio::test]
#[cfg(feature = "general_test")]
async fn test_prover_handle_messages_from_presentation_finished_state() {
let _setup = SetupMocks::init();
let _mock_builder = MockBuilder::init().set_mock_result_for_validate_indy_proof(Ok(true));

let mut verifier_sm = _verifier_sm_from_request();
verifier_sm = verifier_sm.mark_presentation_request_msg_sent().unwrap();
Expand All @@ -946,7 +933,7 @@ pub mod unit_tests {
)
.await
.unwrap();
assert_match!(VerifierFullState::Finished(_), verifier_sm.state);
assert_match!(VerifierState::Finished, verifier_sm.get_state());

verifier_sm = verifier_sm
.step(
Expand All @@ -956,7 +943,7 @@ pub mod unit_tests {
)
.await
.unwrap();
assert_match!(VerifierFullState::Finished(_), verifier_sm.state);
assert_match!(VerifierState::Finished, verifier_sm.get_state());
}
}

Expand Down
Loading

0 comments on commit 26c1cbe

Please sign in to comment.