Skip to content

Commit

Permalink
Add logging, do not silently consume errors on proof verifier
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Aug 3, 2023
1 parent f696fde commit 5855757
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
32 changes: 12 additions & 20 deletions aries_vcx/src/common/proofs/verifier/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,18 @@ pub async fn validate_indy_proof(
validate_proof_revealed_attributes(proof_json)?;

let credential_data = get_credential_info(proof_json)?;

let credential_defs_json = build_cred_defs_json_verifier(ledger, &credential_data)
.await
.unwrap_or(json!({}).to_string());
let schemas_json = build_schemas_json_verifier(ledger, &credential_data)
.await
.unwrap_or(json!({}).to_string());
let rev_reg_defs_json = build_rev_reg_defs_json(ledger, &credential_data)
.await
.unwrap_or(json!({}).to_string());
let rev_regs_json = build_rev_reg_json(ledger, &credential_data)
.await
.unwrap_or(json!({}).to_string());

debug!("credential_defs_json: {credential_defs_json}");
debug!("schemas_json: {schemas_json}");
debug!("proof_json: {proof_json}");
debug!("proof_req_json: {proof_req_json}");
debug!("rev_reg_defs_json: {rev_reg_defs_json}");
debug!("rev_regs_json: {rev_regs_json}");
debug!("validate_indy_proof >> credential_data: {credential_data:?}");
let credential_defs_json = build_cred_defs_json_verifier(ledger, &credential_data).await?;
let schemas_json = build_schemas_json_verifier(ledger, &credential_data).await?;
let rev_reg_defs_json = build_rev_reg_defs_json(ledger, &credential_data).await?;
let rev_regs_json = build_rev_reg_json(ledger, &credential_data).await?;

debug!("validate_indy_proof >> credential_defs_json: {credential_defs_json}");
debug!("validate_indy_proof >> schemas_json: {schemas_json}");
trace!("validate_indy_proof >> proof_json: {proof_json}");
debug!("validate_indy_proof >> proof_req_json: {proof_req_json}");
debug!("validate_indy_proof >> rev_reg_defs_json: {rev_reg_defs_json}");
debug!("validate_indy_proof >> rev_regs_json: {rev_regs_json}");
anoncreds
.verifier_verify_proof(
proof_req_json,
Expand Down
16 changes: 8 additions & 8 deletions aries_vcx/src/common/proofs/verifier/verifier_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub async fn build_cred_defs_json_verifier(
ledger: &Arc<dyn AnoncredsLedgerRead>,
credential_data: &[CredInfoVerifier],
) -> VcxResult<String> {
debug!("building credential_def_json for proof validation");
trace!("build_cred_defs_json_verifier >>");
let mut credential_json = json!({});

for cred_info in credential_data.iter() {
Expand All @@ -126,7 +126,7 @@ pub async fn build_schemas_json_verifier(
ledger: &Arc<dyn AnoncredsLedgerRead>,
credential_data: &[CredInfoVerifier],
) -> VcxResult<String> {
debug!("building schemas json for proof validation");
trace!("build_schemas_json_verifier >>");

let mut schemas_json = json!({});

Expand Down Expand Up @@ -154,14 +154,14 @@ pub async fn build_rev_reg_defs_json(
ledger: &Arc<dyn AnoncredsLedgerRead>,
credential_data: &[CredInfoVerifier],
) -> VcxResult<String> {
debug!("building rev_reg_def_json for proof validation");
trace!("build_rev_reg_defs_json >>");

let mut rev_reg_defs_json = json!({});

for cred_info in credential_data.iter() {
for cred_info in credential_data.iter().filter(|r| r.rev_reg_id.is_some()) {
let rev_reg_id = cred_info.rev_reg_id.as_ref().ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidRevocationDetails,
format!("Missing rev_reg_id in the record {:?}", cred_info),
format!("build_rev_reg_defs_json >> Missing rev_reg_id in the record {:?}", cred_info),
))?;

if rev_reg_defs_json.get(rev_reg_id).is_none() {
Expand All @@ -181,14 +181,14 @@ pub async fn build_rev_reg_json(
ledger: &Arc<dyn AnoncredsLedgerRead>,
credential_data: &[CredInfoVerifier],
) -> VcxResult<String> {
debug!("building rev_reg_json for proof validation from credential_data: {credential_data:?}");
trace!("build_rev_reg_json >>");

let mut rev_regs_json = json!({});

for cred_info in credential_data.iter() {
for cred_info in credential_data.iter().filter(|r| r.rev_reg_id.is_some()) {
let rev_reg_id = cred_info.rev_reg_id.as_ref().ok_or(AriesVcxError::from_msg(
AriesVcxErrorKind::InvalidRevocationDetails,
format!("Missing rev_reg_id in the record {:?}", cred_info),
format!("build_rev_reg_json >> missing rev_reg_id in the record {:?}", cred_info),
))?;

let timestamp = cred_info.timestamp.as_ref().ok_or(AriesVcxError::from_msg(
Expand Down
61 changes: 37 additions & 24 deletions aries_vcx_core/src/ledger/indy_vdr_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,26 @@ where

async fn submit_request(&self, cache_id: Option<&str>, request: PreparedRequest) -> VcxCoreResult<String> {
trace!("submit_request >> Submitting ledger request, cache_id: {cache_id:?}, request: {request:?}");
let response = match cache_id {
let (response, is_from_cache) = match cache_id {
Some(cache_id) => match self.response_cacher.get(cache_id, None).await? {
Some(response) => {
trace!("submit_request << Returning cached response");
response
(response, true)
}
None => {
trace!("submit_request << cache miss, will make ledger request. Response will be cached.");
let response = self.request_submitter.submit(request).await?;
self.response_cacher.put(cache_id, response.clone()).await?;
response
(response, false)
}
},
None => {
trace!("submit_request << caching is disabled for this request");
let response = self.request_submitter.submit(request).await?;
response
(response, false)
}
};
trace!("submit_request << Returning response: {response}");
trace!("submit_request << ledger response (is from cache: {is_from_cache}): {response}");
Ok(response)
}
}
Expand Down Expand Up @@ -185,39 +187,46 @@ where
V: ResponseCacher + Send + Sync,
{
async fn get_attr(&self, target_did: &str, attr_name: &str) -> VcxCoreResult<String> {
trace!("get_attr >> target_did: {target_did}, attr_name: {attr_name}");
debug!("get_attr >> target_did: {target_did}, attr_name: {attr_name}");
let dest = DidValue::from_str(target_did)?;
let request =
self.request_builder()?
.build_get_attrib_request(None, &dest, Some(attr_name.to_string()), None, None)?;
self.submit_request(None, request).await
let response = self.submit_request(None, request).await?;
debug!("get_attr << response: {response}");
Ok(response)
}

async fn get_nym(&self, did: &str) -> VcxCoreResult<String> {
trace!("get_nym >> did: {did}");
debug!("get_nym >> did: {did}");
let dest = DidValue::from_str(did)?;
let request = self.request_builder()?.build_get_nym_request(None, &dest)?;
self.submit_request(None, request).await
let response = self.submit_request(None, request).await?;
debug!("get_nym << response: {response}");
Ok(response)
}

async fn get_txn_author_agreement(&self) -> VcxCoreResult<Option<String>> {
trace!("get_txn_author_agreement >>");
debug!("get_txn_author_agreement >>");
let request = self
.request_builder()?
.build_get_txn_author_agreement_request(None, None)?;
let response = self.submit_request(None, request).await?;
debug!("get_txn_author_agreement << response: {response}");
map_error_not_found_to_none(self.response_parser.parse_get_txn_author_agreement_response(&response))?
.map(|taa| serde_json::to_string(&taa).map_err(Into::into))
.transpose()
}

async fn get_ledger_txn(&self, seq_no: i32, submitter_did: Option<&str>) -> VcxCoreResult<String> {
trace!("get_ledger_txn >> seq_no: {seq_no}");
debug!("get_ledger_txn >> seq_no: {seq_no}");
let identifier = submitter_did.map(DidValue::from_str).transpose()?;
let request =
self.request_builder()?
.build_get_txn_request(identifier.as_ref(), LedgerType::DOMAIN.to_id(), seq_no)?;
self.submit_request(None, request).await
let response = self.submit_request(None, request).await?;
debug!("get_ledger_txn << response: {response}");
Ok(response)
}
}

Expand Down Expand Up @@ -310,17 +319,18 @@ where
V: ResponseCacher + Send + Sync,
{
async fn get_schema(&self, schema_id: &str, _submitter_did: Option<&str>) -> VcxCoreResult<String> {
trace!("get_schema >> schema_id: {schema_id}");
debug!("get_schema >> schema_id: {schema_id}");
let request = self
.request_builder()?
.build_get_schema_request(None, &SchemaId::from_str(schema_id)?)?;
let response = self.submit_request(None, request).await?;
debug!("get_schema << response: {response}");
let schema = self.response_parser.parse_get_schema_response(&response, None)?;
Ok(serde_json::to_string(&schema)?)
}

async fn get_cred_def(&self, cred_def_id: &str, submitter_did: Option<&str>) -> VcxCoreResult<String> {
trace!("get_cred_def >> cred_def_id: {cred_def_id}");
debug!("get_cred_def >> cred_def_id: {cred_def_id}");
let identifier = submitter_did.map(DidValue::from_str).transpose()?;
let id = CredentialDefinitionId::from_str(cred_def_id)?;
let request = self
Expand All @@ -333,16 +343,18 @@ where
// if ledger response was found / the response is success.
// Therefore parsing should happen prior to caching.
let response = self.submit_request(None, request).await?;
debug!("get_cred_def << response: {response}");
let cred_def = self.response_parser.parse_get_cred_def_response(&response, None)?;
Ok(serde_json::to_string(&cred_def)?)
}

async fn get_rev_reg_def_json(&self, rev_reg_id: &str) -> VcxCoreResult<String> {
trace!("get_rev_reg_def_json >> rev_reg_id: {rev_reg_id}");
debug!("get_rev_reg_def_json >> rev_reg_id: {rev_reg_id}");
let id = RevocationRegistryId::from_str(rev_reg_id)?;
let request = self.request_builder()?.build_get_revoc_reg_def_request(None, &id)?;
let res = self.submit_request(Some(rev_reg_id), request).await?;
let rev_reg_def = self.response_parser.parse_get_revoc_reg_def_response(&res)?;
let response = self.submit_request(Some(rev_reg_id), request).await?;
debug!("get_rev_reg_def_json << response: {response}");
let rev_reg_def = self.response_parser.parse_get_revoc_reg_def_response(&response)?;
Ok(serde_json::to_string(&rev_reg_def)?)
}

Expand All @@ -352,7 +364,7 @@ where
from: Option<u64>,
to: Option<u64>,
) -> VcxCoreResult<(String, String, u64)> {
trace!("get_rev_reg_delta_json >> rev_reg_id: {rev_reg_id}, from: {from:?}, to: {to:?}");
debug!("get_rev_reg_delta_json >> rev_reg_id: {rev_reg_id}, from: {from:?}, to: {to:?}");
let revoc_reg_def_id = RevocationRegistryId::from_str(rev_reg_id)?;

let from = from.map(|x| x as i64);
Expand All @@ -362,14 +374,14 @@ where
let request = self
.request_builder()?
.build_get_revoc_reg_delta_request(None, &revoc_reg_def_id, from, to)?;
let res = self.submit_request(None, request).await?;
let response = self.submit_request(None, request).await?;
debug!("get_rev_reg_delta_json << response: {response}");

let RevocationRegistryDeltaInfo {
revoc_reg_def_id,
revoc_reg_delta,
timestamp,
} = self.response_parser.parse_get_revoc_reg_delta_response(&res)?;

} = self.response_parser.parse_get_revoc_reg_delta_response(&response)?;
Ok((
revoc_reg_def_id.to_string(),
serde_json::to_string(&revoc_reg_delta)?,
Expand All @@ -378,21 +390,22 @@ where
}

async fn get_rev_reg(&self, rev_reg_id: &str, timestamp: u64) -> VcxCoreResult<(String, String, u64)> {
trace!("get_rev_reg >> rev_reg_id: {rev_reg_id}, timestamp: {timestamp}");
debug!("get_rev_reg >> rev_reg_id: {rev_reg_id}, timestamp: {timestamp}");
let revoc_reg_def_id = RevocationRegistryId::from_str(rev_reg_id)?;

let request = self.request_builder()?.build_get_revoc_reg_request(
None,
&revoc_reg_def_id,
timestamp.try_into().unwrap(),
)?;
let res = self.submit_request(None, request).await?;
let response = self.submit_request(None, request).await?;
debug!("get_rev_reg << response: {response}");

let RevocationRegistryInfo {
revoc_reg_def_id,
revoc_reg,
timestamp,
} = self.response_parser.parse_get_revoc_reg_response(&res)?;
} = self.response_parser.parse_get_revoc_reg_response(&response)?;

Ok((
revoc_reg_def_id.to_string(),
Expand Down

0 comments on commit 5855757

Please sign in to comment.