From cc7e77ae84e12315d76a2417bf11aa82069259fb Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Thu, 8 Oct 2020 21:33:03 +0200 Subject: [PATCH 1/4] Add tests, filter offers by comment Signed-off-by: Miroslav Kovar --- libvcx/src/api/issuer_credential.rs | 2 +- .../aries/handlers/issuance/issuer/issuer.rs | 4 +- .../handlers/issuance/issuer/state_machine.rs | 31 +-- .../src/aries/handlers/issuance/messages.rs | 2 +- .../messages/issuance/credential_offer.rs | 10 +- libvcx/src/aries/mod.rs | 2 +- libvcx/src/credential_def.rs | 1 + libvcx/src/filters.rs | 23 ++ libvcx/src/issuer_credential.rs | 18 +- libvcx/src/lib.rs | 215 ++++++++++++++++-- 10 files changed, 258 insertions(+), 50 deletions(-) diff --git a/libvcx/src/api/issuer_credential.rs b/libvcx/src/api/issuer_credential.rs index c6c6c5cfa8..cdcc87110d 100644 --- a/libvcx/src/api/issuer_credential.rs +++ b/libvcx/src/api/issuer_credential.rs @@ -184,7 +184,7 @@ pub extern fn vcx_issuer_send_credential_offer(command_handle: CommandHandle, } spawn(move || { - let err = match issuer_credential::send_credential_offer(credential_handle, connection_handle) { + let err = match issuer_credential::send_credential_offer(credential_handle, connection_handle, None) { Ok(x) => { trace!("vcx_issuer_send_credential_cb(command_handle: {}, credential_handle: {}, rc: {}) source_id: {}", command_handle, credential_handle, error::SUCCESS.message, source_id); diff --git a/libvcx/src/aries/handlers/issuance/issuer/issuer.rs b/libvcx/src/aries/handlers/issuance/issuer/issuer.rs index 07b571eac0..2888626d1d 100644 --- a/libvcx/src/aries/handlers/issuance/issuer/issuer.rs +++ b/libvcx/src/aries/handlers/issuance/issuer/issuer.rs @@ -19,8 +19,8 @@ impl Issuer { Ok(Issuer { issuer_sm }) } - pub fn send_credential_offer(&mut self, connection_handle: u32) -> VcxResult<()> { - self.step(CredentialIssuanceMessage::CredentialInit(connection_handle)) + pub fn send_credential_offer(&mut self, connection_handle: u32, comment: Option) -> VcxResult<()> { + self.step(CredentialIssuanceMessage::CredentialInit(connection_handle, comment)) } pub fn send_credential(&mut self, connection_handle: u32) -> VcxResult<()> { diff --git a/libvcx/src/aries/handlers/issuance/issuer/state_machine.rs b/libvcx/src/aries/handlers/issuance/issuer/state_machine.rs index c1f5c16fb2..a675b68e10 100644 --- a/libvcx/src/aries/handlers/issuance/issuer/state_machine.rs +++ b/libvcx/src/aries/handlers/issuance/issuer/state_machine.rs @@ -221,10 +221,11 @@ impl IssuerSM { let IssuerSM { state, source_id } = self; let state = match state { IssuerState::Initial(state_data) => match cim { - CredentialIssuanceMessage::CredentialInit(connection_handle) => { + CredentialIssuanceMessage::CredentialInit(connection_handle, comment) => { let cred_offer = libindy_issuer_create_credential_offer(&state_data.cred_def_id)?; let cred_offer_msg = CredentialOffer::create() - .set_offers_attach(&cred_offer)?; + .set_offers_attach(&cred_offer)? + .set_comment(comment); let cred_offer_msg = _append_credential_preview(cred_offer_msg, &state_data.credential_json)?; send_message(connection_handle, cred_offer_msg.to_a2a_message())?; IssuerState::OfferSent((state_data, cred_offer, connection_handle, cred_offer_msg.id).into()) @@ -377,19 +378,19 @@ pub mod test { impl IssuerSM { fn to_offer_sent_state(mut self) -> IssuerSM { - self = self.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + self = self.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); self } fn to_request_received_state(mut self) -> IssuerSM { - self = self.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + self = self.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); self = self.handle_message(CredentialIssuanceMessage::CredentialRequest(_credential_request())).unwrap(); self } fn to_finished_state(mut self) -> IssuerSM { let conn_handle = mock_connection(); - self = self.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle)).unwrap(); + self = self.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle, None)).unwrap(); self = self.handle_message(CredentialIssuanceMessage::CredentialRequest(_credential_request())).unwrap(); self = self.handle_message(CredentialIssuanceMessage::CredentialSend(conn_handle)).unwrap(); self @@ -430,7 +431,7 @@ pub mod test { let _setup = SetupAriesMocks::init(); let mut issuer_sm = _issuer_sm(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); assert_match!(IssuerState::OfferSent(_), issuer_sm.state); } @@ -455,7 +456,7 @@ pub mod test { let _setup = SetupAriesMocks::init(); let mut issuer_sm = _issuer_sm(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialRequest(_credential_request())).unwrap(); assert_match!(IssuerState::RequestReceived(_), issuer_sm.state); @@ -467,7 +468,7 @@ pub mod test { let _setup = SetupAriesMocks::init(); let mut issuer_sm = _issuer_sm(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialProposal(_credential_proposal())).unwrap(); assert_match!(IssuerState::Finished(_), issuer_sm.state); @@ -480,7 +481,7 @@ pub mod test { let _setup = SetupAriesMocks::init(); let mut issuer_sm = _issuer_sm(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::ProblemReport(_problem_report())).unwrap(); assert_match!(IssuerState::Finished(_), issuer_sm.state); @@ -493,7 +494,7 @@ pub mod test { let _setup = SetupAriesMocks::init(); let mut issuer_sm = _issuer_sm(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::Credential(_credential())).unwrap(); assert_match!(IssuerState::OfferSent(_), issuer_sm.state); @@ -506,7 +507,7 @@ pub mod test { let mut issuer_sm = _issuer_sm(); let conn_handle = mock_connection(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle)).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle, None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialRequest(_credential_request())).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialSend(conn_handle)).unwrap(); @@ -521,7 +522,7 @@ pub mod test { let mut issuer_sm = _issuer_sm(); let conn_handle = mock_connection(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle)).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle, None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialRequest(CredentialRequest::create())).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialSend(conn_handle)).unwrap(); @@ -536,7 +537,7 @@ pub mod test { let mut issuer_sm = _issuer_sm(); let conn_handle = mock_connection(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle)).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle, None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialRequest(_credential_request())).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialSend(conn_handle)).unwrap(); @@ -556,11 +557,11 @@ pub mod test { let mut issuer_sm = _issuer_sm(); let conn_handle = mock_connection(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle)).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(conn_handle, None)).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialRequest(_credential_request())).unwrap(); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialSend(conn_handle)).unwrap(); - issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection())).unwrap(); + issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialInit(mock_connection(), None)).unwrap(); assert_match!(IssuerState::Finished(_), issuer_sm.state); issuer_sm = issuer_sm.handle_message(CredentialIssuanceMessage::CredentialRequest(_credential_request())).unwrap(); diff --git a/libvcx/src/aries/handlers/issuance/messages.rs b/libvcx/src/aries/handlers/issuance/messages.rs index 73f8fd8403..54b4e4a7b6 100644 --- a/libvcx/src/aries/handlers/issuance/messages.rs +++ b/libvcx/src/aries/handlers/issuance/messages.rs @@ -8,7 +8,7 @@ use aries::messages::issuance::credential_request::CredentialRequest; #[derive(Debug, Clone)] pub enum CredentialIssuanceMessage { - CredentialInit(u32), + CredentialInit(u32, Option), CredentialSend(u32), CredentialProposal(CredentialProposal), CredentialOffer(CredentialOffer), diff --git a/libvcx/src/aries/messages/issuance/credential_offer.rs b/libvcx/src/aries/messages/issuance/credential_offer.rs index b6e9d8c036..811f0e6ba0 100644 --- a/libvcx/src/aries/messages/issuance/credential_offer.rs +++ b/libvcx/src/aries/messages/issuance/credential_offer.rs @@ -29,8 +29,8 @@ impl CredentialOffer { self } - pub fn set_comment(mut self, comment: String) -> Self { - self.comment = Some(comment); + pub fn set_comment(mut self, comment: Option) -> Self { + self.comment = comment; self } @@ -70,8 +70,8 @@ pub mod tests { }) } - fn _comment() -> String { - String::from("comment") + fn _comment() -> Option { + Some(String::from("comment")) } pub fn _value() -> (&'static str, &'static str) { @@ -98,7 +98,7 @@ pub mod tests { CredentialOffer { id: MessageId::id(), - comment: Some(_comment()), + comment: _comment(), credential_preview: _preview_data(), offers_attach: attachment, thread: Some(_thread()), diff --git a/libvcx/src/aries/mod.rs b/libvcx/src/aries/mod.rs index 5401310e7d..7b128cb31d 100644 --- a/libvcx/src/aries/mod.rs +++ b/libvcx/src/aries/mod.rs @@ -263,7 +263,7 @@ pub mod test { String::from("cred"), credential_data, 0).unwrap(); - ::issuer_credential::send_credential_offer(self.credential_handle, self.connection_handle).unwrap(); + ::issuer_credential::send_credential_offer(self.credential_handle, self.connection_handle, None).unwrap(); ::issuer_credential::update_state(self.credential_handle, None, None).unwrap(); assert_eq!(2, ::issuer_credential::get_state(self.credential_handle).unwrap()); } diff --git a/libvcx/src/credential_def.rs b/libvcx/src/credential_def.rs index c782d35059..0d629d7041 100644 --- a/libvcx/src/credential_def.rs +++ b/libvcx/src/credential_def.rs @@ -158,6 +158,7 @@ impl CredentialDef { rev_reg_delta_payment_txn, rev_reg_def_payment_txn, }; + error!("New rev_reg: {:?}", new_rev_reg); self.rev_reg = Some(new_rev_reg.clone()); Ok(new_rev_reg) diff --git a/libvcx/src/filters.rs b/libvcx/src/filters.rs index cf7fc35f28..d540975905 100644 --- a/libvcx/src/filters.rs +++ b/libvcx/src/filters.rs @@ -4,6 +4,7 @@ use error::prelude::*; use utils::error; use aries::messages::proof_presentation::presentation_request::PresentationRequest; +use aries::messages::issuance::credential_offer::CredentialOffer; fn _filter_proof_requests_by_name(requests: &str, match_name: &str) -> VcxResult> { let presentation_requests: Vec = serde_json::from_str(requests) @@ -31,6 +32,21 @@ fn _filter_proof_requests_by_name(requests: &str, match_name: &str) -> VcxResult Ok(filtered) } +fn _filter_offers_by_comment(offers: &str, match_comment: &str) -> VcxResult> { + let credential_offers: Vec = serde_json::from_str(offers) + .map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Failed to deserialize Vec: {}\nObtained error: {:?}", offers, err)))?; + let filtered = credential_offers + .into_iter() + .filter_map(|credential_offer| { + match &credential_offer.comment { + Some(comment) if String::from(comment) == String::from(match_comment) => Some(credential_offer), + _ => None + } + }) + .collect(); + Ok(filtered) +} + pub fn filter_proof_requests_by_name(requests: &str, name: &str) -> VcxResult { let presentation_requests: Vec = _filter_proof_requests_by_name(requests, name)?; let filtered: String = serde_json::to_string(&presentation_requests) @@ -38,6 +54,13 @@ pub fn filter_proof_requests_by_name(requests: &str, name: &str) -> VcxResult VcxResult { + let credential_offers: Vec = _filter_offers_by_comment(offers, comment)?; + let filtered: String = serde_json::to_string(&credential_offers) + .map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Failed to serialize filtered credential offers: {}\nObtained error: {:?}", offers, err)))?; + Ok(filtered) +} + #[cfg(test)] pub mod tests { use super::*; diff --git a/libvcx/src/issuer_credential.rs b/libvcx/src/issuer_credential.rs index b710223eb2..032b359ee6 100644 --- a/libvcx/src/issuer_credential.rs +++ b/libvcx/src/issuer_credential.rs @@ -83,9 +83,9 @@ pub fn generate_credential_offer_msg(handle: u32) -> VcxResult<(String, String)> }) } -pub fn send_credential_offer(handle: u32, connection_handle: u32) -> VcxResult { +pub fn send_credential_offer(handle: u32, connection_handle: u32, comment: Option) -> VcxResult { ISSUER_CREDENTIAL_MAP.get_mut(handle, |credential| { - credential.send_credential_offer(connection_handle)?; + credential.send_credential_offer(connection_handle, comment.clone())?; let new_credential = credential.clone(); *credential = new_credential; Ok(error::SUCCESS.code_num) @@ -216,7 +216,7 @@ pub mod tests { let handle_cred = _issuer_credential_create(); - assert_eq!(send_credential_offer(handle_cred, handle_conn).unwrap(), error::SUCCESS.code_num); + assert_eq!(send_credential_offer(handle_cred, handle_conn, None).unwrap(), error::SUCCESS.code_num); assert_eq!(get_state(handle_cred).unwrap(), VcxStateType::VcxStateOfferSent as u32); } @@ -243,12 +243,12 @@ pub mod tests { LibindyMock::set_next_result(error::TIMEOUT_LIBINDY_ERROR.code_num); - let res = send_credential_offer(handle, connection_handle).unwrap_err(); + let res = send_credential_offer(handle, connection_handle, None).unwrap_err(); assert_eq!(res.kind(), VcxErrorKind::InvalidState); assert_eq!(get_state(handle).unwrap(), VcxStateType::VcxStateInitialized as u32); // Can retry after initial failure - assert_eq!(send_credential_offer(handle, connection_handle).unwrap(), error::SUCCESS.code_num); + assert_eq!(send_credential_offer(handle, connection_handle, None).unwrap(), error::SUCCESS.code_num); assert_eq!(get_state(handle).unwrap(), VcxStateType::VcxStateOfferSent as u32); } @@ -262,7 +262,7 @@ pub mod tests { let handle_cred = _issuer_credential_create(); assert_eq!(get_state(handle_cred).unwrap(), VcxStateType::VcxStateInitialized as u32); - assert_eq!(send_credential_offer(handle_cred, handle_conn).unwrap(), error::SUCCESS.code_num); + assert_eq!(send_credential_offer(handle_cred, handle_conn, None).unwrap(), error::SUCCESS.code_num); assert_eq!(get_state(handle_cred).unwrap(), VcxStateType::VcxStateOfferSent as u32); issuer_credential::update_state(handle_cred, Some(ARIES_CREDENTIAL_REQUEST.to_string()), Some(handle_conn)).unwrap(); @@ -307,7 +307,7 @@ pub mod tests { let handle_conn = build_test_connection_inviter_requested(); let handle_cred = _issuer_credential_create(); - assert_eq!(send_credential_offer(handle_cred, handle_conn).unwrap(), error::SUCCESS.code_num); + assert_eq!(send_credential_offer(handle_cred, handle_conn, None).unwrap(), error::SUCCESS.code_num); assert_eq!(get_state(handle_cred).unwrap(), VcxStateType::VcxStateOfferSent as u32); issuer_credential::update_state(handle_cred, Some(ARIES_CREDENTIAL_REQUEST.to_string()), Some(handle_conn)).unwrap(); @@ -322,7 +322,7 @@ pub mod tests { let handle_conn = build_test_connection_inviter_requested(); let handle_cred = _issuer_credential_create(); - assert_eq!(send_credential_offer(handle_cred, handle_conn).unwrap(), error::SUCCESS.code_num); + assert_eq!(send_credential_offer(handle_cred, handle_conn, None).unwrap(), error::SUCCESS.code_num); assert_eq!(get_state(handle_cred).unwrap(), VcxStateType::VcxStateOfferSent as u32); // try to update state with nonsense message @@ -369,7 +369,7 @@ pub mod tests { let handle_cred = _issuer_credential_create(); assert_eq!(get_state(handle_cred).unwrap(), VcxStateType::VcxStateInitialized as u32); - assert_eq!(send_credential_offer(handle_cred, handle_conn).unwrap(), error::SUCCESS.code_num); + assert_eq!(send_credential_offer(handle_cred, handle_conn, None).unwrap(), error::SUCCESS.code_num); assert_eq!(get_state(handle_cred).unwrap(), VcxStateType::VcxStateOfferSent as u32); issuer_credential::update_state(handle_cred, Some(ARIES_CREDENTIAL_REQUEST.to_string()), Some(handle_conn)).unwrap(); diff --git a/libvcx/src/lib.rs b/libvcx/src/lib.rs index f63689aeb6..03c764e3d8 100644 --- a/libvcx/src/lib.rs +++ b/libvcx/src/lib.rs @@ -71,6 +71,7 @@ mod tests { use proof; use settings; use filters; + use credential_def; use utils::{ constants::TEST_TAILS_FILE, devsetup::{set_consumer, set_institution}, @@ -152,7 +153,7 @@ mod tests { ]) } - fn create_and_send_cred_offer(did: &str, cred_def_handle: u32, connection: u32, credential_data: &str) -> u32 { + fn create_and_send_cred_offer(did: &str, cred_def_handle: u32, connection: u32, credential_data: &str, comment: Option) -> u32 { set_institution(None); info!("create_and_send_cred_offer >> creating issuer credential"); let handle_cred = issuer_credential::issuer_credential_create(cred_def_handle, @@ -162,18 +163,28 @@ mod tests { credential_data.to_string(), 1).unwrap(); info!("create_and_send_cred_offer :: sending credential offer"); - issuer_credential::send_credential_offer(handle_cred, connection).unwrap(); + issuer_credential::send_credential_offer(handle_cred, connection, comment).unwrap(); info!("create_and_send_cred_offer :: credential offer was sent"); thread::sleep(Duration::from_millis(2000)); handle_cred } - fn send_cred_req(connection: u32, consumer_handle: Option) -> u32 { + fn send_cred_req(connection: u32, consumer_handle: Option, comment: Option) -> u32 { info!("send_cred_req >>> switching to consumer"); set_consumer(consumer_handle); info!("send_cred_req :: getting offers"); let credential_offers = credential::get_credential_offer_messages(connection).unwrap(); + let credential_offers = match comment { + Some(comment) => { + let filtered = filters::filter_credential_offers_by_comment(&credential_offers, &comment).unwrap(); + info!("send_cred_req :: credential offer messages filtered by comment {}: {}", comment, filtered); + filtered + } + _ => credential_offers + }; let offers: Value = serde_json::from_str(&credential_offers).unwrap(); + let offers = offers.as_array().unwrap(); + assert_eq!(offers.len(), 1); let offers = serde_json::to_string(&offers[0]).unwrap(); info!("send_cred_req :: creating credential from offer"); let credential = credential::credential_create_with_offer("TEST_CREDENTIAL", &offers).unwrap(); @@ -267,6 +278,11 @@ mod tests { assert_ne!(delta, delta_after_revoke); // They will not equal as we have saved the delta in cache } + fn rotate_rev_reg(cred_def_handle: u32 ) { + set_institution(None); + credential_def::rotate_rev_reg_def(cred_def_handle); + } + fn publish_revocation(rev_reg_id: String) { set_institution(None); ::utils::libindy::anoncreds::publish_local_revocations(rev_reg_id.as_str()).unwrap(); @@ -278,11 +294,12 @@ mod tests { ::utils::libindy::anoncreds::tests::create_and_store_credential_def(&attrs_list, true) } - fn _exchange_credential(credential_data: String, cred_def_handle: u32, faber: u32, alice: u32, consumer_handle: Option) -> u32 { + fn _exchange_credential(credential_data: String, cred_def_handle: u32, faber: u32, alice: u32, consumer_handle: Option, comment: Option) -> u32 { + set_institution(None); info!("Generated credential data: {}", credential_data); - let credential_offer = create_and_send_cred_offer(settings::CONFIG_INSTITUTION_DID, cred_def_handle, alice, &credential_data); + let credential_offer = create_and_send_cred_offer(settings::CONFIG_INSTITUTION_DID, cred_def_handle, alice, &credential_data, comment.clone()); info!("AS CONSUMER SEND CREDENTIAL REQUEST"); - let credential = send_cred_req(faber, consumer_handle); + let credential = send_cred_req(faber, consumer_handle, comment.clone()); info!("AS INSTITUTION SEND CREDENTIAL"); send_credential(credential_offer, alice, credential, consumer_handle); credential_offer @@ -295,7 +312,7 @@ mod tests { let (address1, address2, city, state, zip) = attr_names(); let credential_data = json!({address1: "123 Main St", address2: "Suite 3", city: "Draper", state: "UT", zip: "84000"}).to_string(); - let credential_handle = _exchange_credential(credential_data, cred_def_handle, faber, alice, consumer_handle); + let credential_handle = _exchange_credential(credential_data, cred_def_handle, faber, alice, consumer_handle, None); (schema_id, cred_def_id, rev_reg_id, cred_def_handle, credential_handle) } @@ -392,13 +409,12 @@ mod tests { let (consumer2_to_verifier, verifier_to_consumer2) = ::connection::tests::create_connected_connections(Some(consumer2), Some(verifier)); let (consumer2_to_issuer, issuer_to_consumer2) = ::connection::tests::create_connected_connections(Some(consumer2), None); // Issuer - let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer1_to_issuer, issuer_to_consumer1, Some(consumer1)); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer1_to_issuer, issuer_to_consumer1, Some(consumer1), None); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer2_to_issuer, issuer_to_consumer2, Some(consumer2)); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer2_to_issuer, issuer_to_consumer2, Some(consumer2), None); let request_name1 = Some("request1"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer1, Some(verifier), request_name1); @@ -453,7 +469,7 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address, city, state, zip) = attr_names(); let credential_data = json!({address1.clone(): "5th Avenue", address.clone(): "Suite 1234", city.clone(): "NYC", state.clone(): "NYS", zip.clone(): "84712"}).to_string(); - let credential_handle = _exchange_credential(credential_data, cred_def_handle, consumer_to_institution, institution_to_consumer, None); + let credential_handle = _exchange_credential(credential_data, cred_def_handle, consumer_to_institution, institution_to_consumer, None, None); let request_name1 = Some("request1"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer, None, request_name1); @@ -489,11 +505,11 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_institution1, institution_to_consumer1, Some(consumer1)); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_institution1, institution_to_consumer1, Some(consumer1), None); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_institution2, institution_to_consumer2, Some(consumer2)); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_institution2, institution_to_consumer2, Some(consumer2), None); let credential_data3 = json!({address1.clone(): "5th Avenue", address2.clone(): "Suite 1234", city.clone(): "NYC", state.clone(): "NYS", zip.clone(): "84712"}).to_string(); - let credential_handle3 = _exchange_credential(credential_data3, cred_def_handle, consumer_to_institution3, institution_to_consumer3, Some(consumer3)); + let credential_handle3 = _exchange_credential(credential_data3, cred_def_handle, consumer_to_institution3, institution_to_consumer3, Some(consumer3), None); revoke_credential_local(credential_handle1, rev_reg_id.clone()); revoke_credential_local(credential_handle2, rev_reg_id.clone()); @@ -624,10 +640,10 @@ mod tests { info!("test_real_proof :: sending credential offer"); let credential_data = credential_data.to_string(); info!("test_real_proof :: generated credential data: {}", credential_data); - let credential_offer = create_and_send_cred_offer(&institution_did, cred_def_handle, alice, &credential_data); + let credential_offer = create_and_send_cred_offer(&institution_did, cred_def_handle, alice, &credential_data, None); info!("test_real_proof :: AS CONSUMER SEND CREDENTIAL REQUEST"); - let credential = send_cred_req(faber, None); + let credential = send_cred_req(faber, None, None); info!("test_real_proof :: AS INSTITUTION SEND CREDENTIAL"); send_credential(credential_offer, alice, credential, None); @@ -659,4 +675,171 @@ mod tests { proof::update_state(proof_req_handle, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_req_handle).unwrap(), ProofStateType::ProofValidated as u32); } + + #[test] + #[cfg(feature = "agency_pool_tests")] + fn test_two_creds_one_rev_reg() { + let _setup = SetupLibraryAgencyV2ZeroFees::init(); + let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap(); // Issuer's did + + let verifier = create_institution_config(); + let consumer = create_consumer_config(); + let (consumer_to_verifier, verifier_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), Some(verifier)); + let (consumer_to_issuer, issuer_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), None); + + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); + let (address1, address2, city, state, zip) = attr_names(); + let (req1, req2) = (String::from("request1"), String::from("request2")); + let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + } + + #[test] + #[cfg(feature = "agency_pool_tests")] + fn test_two_creds_one_rev_reg_revoke_first() { + let _setup = SetupLibraryAgencyV2ZeroFees::init(); + let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap(); // Issuer's did + + let verifier = create_institution_config(); + let consumer = create_consumer_config(); + let (consumer_to_verifier, verifier_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), Some(verifier)); + let (consumer_to_issuer, issuer_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), None); + + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); + let (address1, address2, city, state, zip) = attr_names(); + let (req1, req2) = (String::from("request1"), String::from("request2")); + let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + + revoke_credential(credential_handle1, rev_reg_id); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + } + + #[test] + #[cfg(feature = "agency_pool_tests")] + fn test_two_creds_one_rev_reg_revoke_second() { + let _setup = SetupLibraryAgencyV2ZeroFees::init(); + let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap(); + + let verifier = create_institution_config(); + let consumer = create_consumer_config(); + let (consumer_to_verifier, verifier_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), Some(verifier)); + let (consumer_to_issuer, issuer_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), None); + + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); + let (address1, address2, city, state, zip) = attr_names(); + let (req1, req2) = (String::from("request1"), String::from("request2")); + let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + + revoke_credential(credential_handle2, rev_reg_id); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + } + + #[test] + #[cfg(feature = "agency_pool_tests")] + fn test_two_creds_two_rev_reg_id() { + let _setup = SetupLibraryAgencyV2ZeroFees::init(); + let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap(); // Issuer's did + + let verifier = create_institution_config(); + let consumer = create_consumer_config(); + let (consumer_to_verifier, verifier_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), Some(verifier)); + let (consumer_to_issuer, issuer_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), None); + + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); + let (address1, address2, city, state, zip) = attr_names(); + let (req1, req2) = (String::from("request1"), String::from("request2")); + let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + rotate_rev_reg(cred_def_handle); + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + } + + #[test] + #[cfg(feature = "agency_pool_tests")] + fn test_two_creds_two_rev_reg_id_revoke_first() { + let _setup = SetupLibraryAgencyV2ZeroFees::init(); + let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap(); // Issuer's did + + let verifier = create_institution_config(); + let consumer = create_consumer_config(); + let (consumer_to_verifier, verifier_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), Some(verifier)); + let (consumer_to_issuer, issuer_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), None); + + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); + let (address1, address2, city, state, zip) = attr_names(); + let (req1, req2) = (String::from("request1"), String::from("request2")); + let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + rotate_rev_reg(cred_def_handle); + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + + revoke_credential(credential_handle1, rev_reg_id); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + } + + #[test] + #[cfg(feature = "agency_pool_tests")] + fn test_two_creds_two_rev_reg_id_revoke_second() { + let _setup = SetupLibraryAgencyV2ZeroFees::init(); + let institution_did = settings::get_config_value(settings::CONFIG_INSTITUTION_DID).unwrap(); // Issuer's did + + let verifier = create_institution_config(); + let consumer = create_consumer_config(); + let (consumer_to_verifier, verifier_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), Some(verifier)); + let (consumer_to_issuer, issuer_to_consumer) = ::connection::tests::create_connected_connections(Some(consumer), None); + + let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); + let (address1, address2, city, state, zip) = attr_names(); + let (req1, req2) = (String::from("request1"), String::from("request2")); + let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); + let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + rotate_rev_reg(cred_def_handle); + let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); + let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + + revoke_credential(credential_handle2, rev_reg_id); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + } } From 737779dba8ca2b2c79bcc45fc516e4655e915573 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Wed, 14 Oct 2020 12:48:49 +0200 Subject: [PATCH 2/4] Filter by requested values Signed-off-by: Miroslav Kovar --- .../proof_presentation/prover/prover.rs | 6 +- libvcx/src/disclosed_proof.rs | 6 ++ libvcx/src/lib.rs | 92 +++++++++++++------ 3 files changed, 76 insertions(+), 28 deletions(-) diff --git a/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs b/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs index 7b3b8853e7..13574dd209 100644 --- a/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs +++ b/libvcx/src/aries/handlers/proof_presentation/prover/prover.rs @@ -34,7 +34,7 @@ impl Prover { pub fn retrieve_credentials(&self) -> VcxResult { trace!("Prover::retrieve_credentials >>>"); - let presentation_request = self.prover_sm.presentation_request().request_presentations_attach.content()?; + let presentation_request = self.presentation_request_data()?; anoncreds::libindy_prover_get_credentials_for_proof_req(&presentation_request) } @@ -134,6 +134,10 @@ impl Prover { Ok(presentation_requests) } + pub fn presentation_request_data(&self) -> VcxResult { + self.prover_sm.presentation_request().request_presentations_attach.content() + } + pub fn get_source_id(&self) -> String { self.prover_sm.source_id() } pub fn step(&mut self, message: ProverMessages) -> VcxResult<()> { diff --git a/libvcx/src/disclosed_proof.rs b/libvcx/src/disclosed_proof.rs index ab5c6a3e7b..8e6d313fde 100644 --- a/libvcx/src/disclosed_proof.rs +++ b/libvcx/src/disclosed_proof.rs @@ -161,6 +161,12 @@ pub fn retrieve_credentials(handle: u32) -> VcxResult { }) } +pub fn get_proof_request_data(handle: u32) -> VcxResult { + HANDLE_MAP.get_mut(handle, |proof| { + proof.presentation_request_data() + }) +} + pub fn is_valid_handle(handle: u32) -> bool { HANDLE_MAP.has_handle(handle) } diff --git a/libvcx/src/lib.rs b/libvcx/src/lib.rs index 03c764e3d8..9bc535273b 100644 --- a/libvcx/src/lib.rs +++ b/libvcx/src/lib.rs @@ -322,14 +322,21 @@ mod tests { send_proof_request(alice, &requested_attrs_string, "[]", "{}", institution_handle, request_name) } - fn _prover_select_credentials_and_send_proof(faber: u32, consumer_handle: Option, request_name: Option<&str>) { + fn _prover_select_credentials_and_send_proof(faber: u32, consumer_handle: Option, request_name: Option<&str>, requested_values: Option<&str>) { set_consumer(consumer_handle); info!("Prover :: Going to create proof"); let proof_handle_prover = create_proof(faber, consumer_handle, request_name); info!("Prover :: Retrieving matching credentials"); let retrieved_credentials = disclosed_proof::retrieve_credentials(proof_handle_prover).unwrap(); info!("Prover :: Based on proof, retrieved credentials: {}", &retrieved_credentials); - let selected_credentials_value = retrieved_to_selected_credentials_simple(&retrieved_credentials, true); + let selected_credentials_value = match requested_values { + Some(requested_values) => { + let credential_data = disclosed_proof::get_proof_request_data(proof_handle_prover).unwrap(); + retrieved_to_selected_credentials_specific(&retrieved_credentials, requested_values, &credential_data, true) + } + _ => retrieved_to_selected_credentials_simple(&retrieved_credentials, true) + }; + let proof_req_data = disclosed_proof::get_proof_request_data(proof_handle_prover); let selected_credentials_str = serde_json::to_string(&selected_credentials_value).unwrap(); info!("Prover :: Retrieved credential converted to selected: {}", &selected_credentials_str); generate_and_send_proof(proof_handle_prover, faber, &selected_credentials_str, consumer_handle); @@ -358,7 +365,7 @@ mod tests { info!("test_basic_revocation :: Going to seng proof request with attributes {}", &requested_attrs_string); let proof_handle_verifier = send_proof_request(alice, &requested_attrs_string, "[]", &interval, None, None); - _prover_select_credentials_and_send_proof(faber, None, None); + _prover_select_credentials_and_send_proof(faber, None, None, None); info!("test_basic_revocation :: verifier :: going to verify proof"); set_institution(None); @@ -379,7 +386,7 @@ mod tests { revoke_credential_local(credential_handle, rev_reg_id.clone()); let request_name1 = Some("request1"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer, None, request_name1); - _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name1); + _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name1, None); set_institution(None); proof::update_state(proof_handle_verifier, None, None).unwrap(); @@ -388,7 +395,7 @@ mod tests { publish_revocation(rev_reg_id.clone().unwrap()); let request_name2 = Some("request2"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer, None, request_name2); - _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name2); + _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name2, None); set_institution(None); proof::update_state(proof_handle_verifier, None, None).unwrap(); @@ -418,14 +425,14 @@ mod tests { let request_name1 = Some("request1"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer1, Some(verifier), request_name1); - _prover_select_credentials_and_send_proof(consumer1_to_verifier, Some(consumer1), None); + _prover_select_credentials_and_send_proof(consumer1_to_verifier, Some(consumer1), None, None); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); let request_name2 = Some("request2"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer2, Some(verifier), request_name2); - _prover_select_credentials_and_send_proof(consumer2_to_verifier, Some(consumer2), None); + _prover_select_credentials_and_send_proof(consumer2_to_verifier, Some(consumer2), None, None); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -445,14 +452,14 @@ mod tests { let (schema_id, cred_def_id, rev_reg_id, _cred_def_handle, credential_handle) = _issue_address_credential(consumer_to_issuer, issuer_to_consumer, Some(consumer)); let request_name1 = Some("request1"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), request_name1); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), request_name1); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), request_name1, None); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); let request_name2 = Some("request2"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), request_name2); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), request_name2); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), request_name2, None); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -473,14 +480,14 @@ mod tests { let request_name1 = Some("request1"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer, None, request_name1); - _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name1); + _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name1, None); set_institution(None); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); let request_name2 = Some("request2"); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer, None, request_name2); - _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name2); + _prover_select_credentials_and_send_proof(consumer_to_institution, None, request_name2, None); set_institution(None); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -517,11 +524,11 @@ mod tests { // Revoke two locally and verify their are all still valid let request_name1 = Some("request1"); let request_name2 = Some("request2"); let proof_handle_verifier1 = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer1, None, request_name1); - _prover_select_credentials_and_send_proof(consumer_to_institution1, Some(consumer1), request_name1); + _prover_select_credentials_and_send_proof(consumer_to_institution1, Some(consumer1), request_name1, None); let proof_handle_verifier2 = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer2, None, request_name1); - _prover_select_credentials_and_send_proof(consumer_to_institution2, Some(consumer2), request_name1); + _prover_select_credentials_and_send_proof(consumer_to_institution2, Some(consumer2), request_name1, None); let proof_handle_verifier3 = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer3, None, request_name1); - _prover_select_credentials_and_send_proof(consumer_to_institution3, Some(consumer3), request_name1); + _prover_select_credentials_and_send_proof(consumer_to_institution3, Some(consumer3), request_name1, None); set_institution(None); proof::update_state(proof_handle_verifier1, None, None).unwrap(); @@ -536,11 +543,11 @@ mod tests { thread::sleep(Duration::from_millis(2000)); let request_name2 = Some("request2"); let proof_handle_verifier1 = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer1, None, request_name2); - _prover_select_credentials_and_send_proof(consumer_to_institution1, Some(consumer1), request_name2); + _prover_select_credentials_and_send_proof(consumer_to_institution1, Some(consumer1), request_name2, None); let proof_handle_verifier2 = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer2, None, request_name2); - _prover_select_credentials_and_send_proof(consumer_to_institution2, Some(consumer2), request_name2); + _prover_select_credentials_and_send_proof(consumer_to_institution2, Some(consumer2), request_name2, None); let proof_handle_verifier3 = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, institution_to_consumer3, None, request_name2); - _prover_select_credentials_and_send_proof(consumer_to_institution3, Some(consumer3), request_name2); + _prover_select_credentials_and_send_proof(consumer_to_institution3, Some(consumer3), request_name2, None); assert_ne!(proof_handle_verifier1, proof_handle_verifier2); assert_ne!(proof_handle_verifier1, proof_handle_verifier3); assert_ne!(proof_handle_verifier2, proof_handle_verifier3); set_institution(None); @@ -614,6 +621,37 @@ mod tests { return credentials_mapped; } + fn retrieved_to_selected_credentials_specific(retrieved_credentials: &str, requested_values: &str, credential_data: &str, with_tails: bool) -> Value { + info!("test_real_proof >>> retrieved matching credentials {}", retrieved_credentials); + let retrieved_credentials: Value = serde_json::from_str(retrieved_credentials).unwrap(); + let credential_data: Value = serde_json::from_str(credential_data).unwrap(); + let requested_values: Value = serde_json::from_str(requested_values).unwrap(); + let requested_attributes: &Value = &credential_data["requested_attributes"]; + let mut credentials_mapped: Value = json!({"attrs":{}, "predicates":{}}); + + for (key, val) in retrieved_credentials["attrs"].as_object().unwrap().iter() { + let filtered: Vec<&Value> = val.as_array().unwrap() + .into_iter() + .filter_map(|cred| { + let attribute_name = requested_attributes[key]["name"].as_str().unwrap(); + let requested_value = requested_values[attribute_name].as_str().unwrap(); + if cred["cred_info"]["attrs"][attribute_name].as_str().unwrap() == requested_value { + Some(cred) + } else { + None + } + }) + .collect(); + let first_cred: &serde_json::Value = &filtered[0]; + credentials_mapped["attrs"][key]["credential"] = first_cred.clone(); + if with_tails { + credentials_mapped["attrs"][key]["tails_file"] = Value::from(get_temp_dir_path(TEST_TAILS_FILE).to_str().unwrap()); + } + } + return credentials_mapped; + } + + #[test] #[cfg(feature = "agency_pool_tests")] fn test_real_proof() { @@ -696,7 +734,7 @@ mod tests { let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, None); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -719,12 +757,12 @@ mod tests { let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); revoke_credential(credential_handle1, rev_reg_id); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data2)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -745,14 +783,14 @@ mod tests { let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (String::from("request1"), String::from("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); revoke_credential(credential_handle2, rev_reg_id); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data1)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -779,7 +817,7 @@ mod tests { let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, None); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -803,12 +841,12 @@ mod tests { let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); rotate_rev_reg(cred_def_handle); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); revoke_credential(credential_handle1, rev_reg_id); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data2)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -829,7 +867,7 @@ mod tests { let (address1, address2, city, state, zip) = attr_names(); let (req1, req2) = (String::from("request1"), String::from("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); rotate_rev_reg(cred_def_handle); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); @@ -837,7 +875,7 @@ mod tests { revoke_credential(credential_handle2, rev_reg_id); let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data1)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); From 481b7f7ab0e0281130e86eea1b31f18d99755296 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Wed, 14 Oct 2020 17:51:33 +0200 Subject: [PATCH 3/4] Add status verification for both credentials Signed-off-by: Miroslav Kovar --- libvcx/src/lib.rs | 112 ++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 38 deletions(-) diff --git a/libvcx/src/lib.rs b/libvcx/src/lib.rs index 9bc535273b..ad73a26c66 100644 --- a/libvcx/src/lib.rs +++ b/libvcx/src/lib.rs @@ -153,7 +153,7 @@ mod tests { ]) } - fn create_and_send_cred_offer(did: &str, cred_def_handle: u32, connection: u32, credential_data: &str, comment: Option) -> u32 { + fn create_and_send_cred_offer(did: &str, cred_def_handle: u32, connection: u32, credential_data: &str, comment: Option<&str>) -> u32 { set_institution(None); info!("create_and_send_cred_offer >> creating issuer credential"); let handle_cred = issuer_credential::issuer_credential_create(cred_def_handle, @@ -163,20 +163,20 @@ mod tests { credential_data.to_string(), 1).unwrap(); info!("create_and_send_cred_offer :: sending credential offer"); - issuer_credential::send_credential_offer(handle_cred, connection, comment).unwrap(); + issuer_credential::send_credential_offer(handle_cred, connection, comment.map(|s| String::from(s))).unwrap(); info!("create_and_send_cred_offer :: credential offer was sent"); thread::sleep(Duration::from_millis(2000)); handle_cred } - fn send_cred_req(connection: u32, consumer_handle: Option, comment: Option) -> u32 { + fn send_cred_req(connection: u32, consumer_handle: Option, comment: Option<&str>) -> u32 { info!("send_cred_req >>> switching to consumer"); set_consumer(consumer_handle); info!("send_cred_req :: getting offers"); let credential_offers = credential::get_credential_offer_messages(connection).unwrap(); let credential_offers = match comment { Some(comment) => { - let filtered = filters::filter_credential_offers_by_comment(&credential_offers, &comment).unwrap(); + let filtered = filters::filter_credential_offers_by_comment(&credential_offers, comment).unwrap(); info!("send_cred_req :: credential offer messages filtered by comment {}: {}", comment, filtered); filtered } @@ -294,12 +294,12 @@ mod tests { ::utils::libindy::anoncreds::tests::create_and_store_credential_def(&attrs_list, true) } - fn _exchange_credential(credential_data: String, cred_def_handle: u32, faber: u32, alice: u32, consumer_handle: Option, comment: Option) -> u32 { + fn _exchange_credential(credential_data: String, cred_def_handle: u32, faber: u32, alice: u32, consumer_handle: Option, comment: Option<&str>) -> u32 { set_institution(None); info!("Generated credential data: {}", credential_data); - let credential_offer = create_and_send_cred_offer(settings::CONFIG_INSTITUTION_DID, cred_def_handle, alice, &credential_data, comment.clone()); + let credential_offer = create_and_send_cred_offer(settings::CONFIG_INSTITUTION_DID, cred_def_handle, alice, &credential_data, comment); info!("AS CONSUMER SEND CREDENTIAL REQUEST"); - let credential = send_cred_req(faber, consumer_handle, comment.clone()); + let credential = send_cred_req(faber, consumer_handle, comment); info!("AS INSTITUTION SEND CREDENTIAL"); send_credential(credential_offer, alice, credential, consumer_handle); credential_offer @@ -336,7 +336,6 @@ mod tests { } _ => retrieved_to_selected_credentials_simple(&retrieved_credentials, true) }; - let proof_req_data = disclosed_proof::get_proof_request_data(proof_handle_prover); let selected_credentials_str = serde_json::to_string(&selected_credentials_value).unwrap(); info!("Prover :: Retrieved credential converted to selected: {}", &selected_credentials_str); generate_and_send_proof(proof_handle_prover, faber, &selected_credentials_str, consumer_handle); @@ -727,17 +726,24 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); - let (req1, req2) = (String::from("request1"), String::from("request2")); + let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req1); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req2); - let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, None); + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req1); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req1, Some(&credential_data1)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req2); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req2, Some(&credential_data2)); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + } #[test] @@ -753,16 +759,22 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); - let (req1, req2) = (String::from("request1"), String::from("request2")); + let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req1); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req2); revoke_credential(credential_handle1, rev_reg_id); - let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data2)); + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req1); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req1, Some(&credential_data1)); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofInvalid as u32); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req2); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req2, Some(&credential_data2)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -781,19 +793,25 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); - let (req1, req2) = (String::from("request1"), String::from("request2")); + let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req1); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req2); revoke_credential(credential_handle2, rev_reg_id); - let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data1)); + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req1); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req1, Some(&credential_data1)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req2); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req2, Some(&credential_data2)); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofInvalid as u32); } #[test] @@ -809,15 +827,21 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); - let (req1, req2) = (String::from("request1"), String::from("request2")); + let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req1); rotate_rev_reg(cred_def_handle); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req2); - let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, None); + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req1); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req1, Some(&credential_data1)); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req2); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req2, Some(&credential_data2)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -836,17 +860,23 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); - let (req1, req2) = (String::from("request1"), String::from("request2")); + let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req1); rotate_rev_reg(cred_def_handle); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req2); revoke_credential(credential_handle1, rev_reg_id); - let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data2)); + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req1); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req1, Some(&credential_data1)); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofInvalid as u32); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req2); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req2, Some(&credential_data2)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); @@ -865,19 +895,25 @@ mod tests { let (schema_id, _schema_json, cred_def_id, _cred_def_json, cred_def_handle, rev_reg_id) = _create_address_schema(); let (address1, address2, city, state, zip) = attr_names(); - let (req1, req2) = (String::from("request1"), String::from("request2")); + let (req1, req2) = (Some("request1"), Some("request2")); let credential_data1 = json!({address1.clone(): "123 Main St", address2.clone(): "Suite 3", city.clone(): "Draper", state.clone(): "UT", zip.clone(): "84000"}).to_string(); - let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req1)); + let credential_handle1 = _exchange_credential(credential_data1.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req1); rotate_rev_reg(cred_def_handle); let credential_data2 = json!({address1.clone(): "101 Tela Lane", address2.clone(): "Suite 1", city.clone(): "SLC", state.clone(): "WA", zip.clone(): "8721"}).to_string(); - let credential_handle2 = _exchange_credential(credential_data2, cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), Some(req2)); + let credential_handle2 = _exchange_credential(credential_data2.clone(), cred_def_handle, consumer_to_issuer, issuer_to_consumer, Some(consumer), req2); revoke_credential(credential_handle2, rev_reg_id); - let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), None); - _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), None, Some(&credential_data1)); + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req1); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req1, Some(&credential_data1)); set_institution(Some(verifier)); proof::update_state(proof_handle_verifier, None, None).unwrap(); assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofValidated as u32); + + let proof_handle_verifier = _verifier_create_proof_and_send_request(&institution_did, &schema_id, &cred_def_id, verifier_to_consumer, Some(verifier), req2); + _prover_select_credentials_and_send_proof(consumer_to_verifier, Some(consumer), req2, Some(&credential_data2)); + set_institution(Some(verifier)); + proof::update_state(proof_handle_verifier, None, None).unwrap(); + assert_eq!(proof::get_proof_state(proof_handle_verifier).unwrap(), ProofStateType::ProofInvalid as u32); } } From 1ebf5c8ca329eb04bd544432e4855d63c1ea23b4 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Thu, 15 Oct 2020 14:24:10 +0200 Subject: [PATCH 4/4] Remove forgotten log Signed-off-by: Miroslav Kovar --- libvcx/src/credential_def.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/libvcx/src/credential_def.rs b/libvcx/src/credential_def.rs index 0d629d7041..c782d35059 100644 --- a/libvcx/src/credential_def.rs +++ b/libvcx/src/credential_def.rs @@ -158,7 +158,6 @@ impl CredentialDef { rev_reg_delta_payment_txn, rev_reg_def_payment_txn, }; - error!("New rev_reg: {:?}", new_rev_reg); self.rev_reg = Some(new_rev_reg.clone()); Ok(new_rev_reg)