Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Revocation registry rotation scenarios #136

Merged
merged 4 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libvcx/src/api/issuer_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions libvcx/src/aries/handlers/issuance/issuer/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> VcxResult<()> {
self.step(CredentialIssuanceMessage::CredentialInit(connection_handle, comment))
}

pub fn send_credential(&mut self, connection_handle: u32) -> VcxResult<()> {
Expand Down
31 changes: 16 additions & 15 deletions libvcx/src/aries/handlers/issuance/issuer/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion libvcx/src/aries/handlers/issuance/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use aries::messages::issuance::credential_request::CredentialRequest;

#[derive(Debug, Clone)]
pub enum CredentialIssuanceMessage {
CredentialInit(u32),
CredentialInit(u32, Option<String>),
CredentialSend(u32),
CredentialProposal(CredentialProposal),
CredentialOffer(CredentialOffer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Prover {

pub fn retrieve_credentials(&self) -> VcxResult<String> {
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)
}

Expand Down Expand Up @@ -134,6 +134,10 @@ impl Prover {
Ok(presentation_requests)
}

pub fn presentation_request_data(&self) -> VcxResult<String> {
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<()> {
Expand Down
10 changes: 5 additions & 5 deletions libvcx/src/aries/messages/issuance/credential_offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) -> Self {
self.comment = comment;
self
}

Expand Down Expand Up @@ -70,8 +70,8 @@ pub mod tests {
})
}

fn _comment() -> String {
String::from("comment")
fn _comment() -> Option<String> {
Some(String::from("comment"))
}

pub fn _value() -> (&'static str, &'static str) {
Expand All @@ -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()),
Expand Down
2 changes: 1 addition & 1 deletion libvcx/src/aries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
6 changes: 6 additions & 0 deletions libvcx/src/disclosed_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ pub fn retrieve_credentials(handle: u32) -> VcxResult<String> {
})
}

pub fn get_proof_request_data(handle: u32) -> VcxResult<String> {
HANDLE_MAP.get_mut(handle, |proof| {
proof.presentation_request_data()
})
}

pub fn is_valid_handle(handle: u32) -> bool {
HANDLE_MAP.has_handle(handle)
}
Expand Down
23 changes: 23 additions & 0 deletions libvcx/src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PresentationRequest>> {
let presentation_requests: Vec<PresentationRequest> = serde_json::from_str(requests)
Expand Down Expand Up @@ -31,13 +32,35 @@ 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<Vec<CredentialOffer>> {
let credential_offers: Vec<CredentialOffer> = serde_json::from_str(offers)
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Failed to deserialize Vec<CredentialOffer>: {}\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<String> {
let presentation_requests: Vec<PresentationRequest> = _filter_proof_requests_by_name(requests, name)?;
let filtered: String = serde_json::to_string(&presentation_requests)
.map_err(|err| VcxError::from_msg(VcxErrorKind::InvalidJson, format!("Failed to serialize filtered proof requests: {}\nObtained error: {:?}", requests, err)))?;
Ok(filtered)
}

pub fn filter_credential_offers_by_comment(offers: &str, comment: &str) -> VcxResult<String> {
let credential_offers: Vec<CredentialOffer> = _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::*;
Expand Down
18 changes: 9 additions & 9 deletions libvcx/src/issuer_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> {
pub fn send_credential_offer(handle: u32, connection_handle: u32, comment: Option<String>) -> VcxResult<u32> {
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)
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Loading