Skip to content

Commit

Permalink
test: anoncreds_demos: revocaable check
Browse files Browse the repository at this point in the history
Signed-off-by: bwty <[email protected]>
  • Loading branch information
whalelephant committed Jan 3, 2023
1 parent 124dc34 commit 629ba44
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
target
Cargo.lock
.tmp
Binary file removed .tmp/.tmpYtxwf1
Binary file not shown.
Binary file removed .tmp/.tmpm00t8T
Binary file not shown.
Binary file removed .tmp/2qxJm1HasDk8ydBJToifu3MhM2VdGT1muGrApPExaQXi
Binary file not shown.
Binary file removed .tmp/3ihh9JWQKrYgW2N9zrFa9MhvvoeRZYWf36utggLmTacm
Binary file not shown.
Binary file removed .tmp/4SDkFYbhNoCRha5fLBvgzP26vhjERXFWyfWWNoJNpetn
Binary file not shown.
Binary file removed .tmp/574xmaMjXnvqufaGnkRwC2dDQqdMZ4wGaDB2hqgMCiPK
Binary file not shown.
Binary file removed .tmp/6wT833GbcqGbEd3wgHvEpebqrcFkB1XaE4JzhtqZkRYa
Binary file not shown.
Binary file removed .tmp/DLtaWoozsJZNceWuzQaSzXT98ZWdcoYiY21jebwVnYuL
Binary file not shown.
Binary file removed .tmp/F2CCN8zbYtvFw6KG58zQLrnuo5sb2uhTiL6vVxhEBHtT
Binary file not shown.
Binary file removed .tmp/FPMhxK1ZjNZKcWxdJETgg6ixr93YHW4NXdYtneXRDzdE
Binary file not shown.
Binary file removed .tmp/HrPXS3xTVh3gsrJbmGP1n11jZmzRk8qPb3CZpsQa4rjs
Binary file not shown.
Binary file removed .tmp/HuUbZPdyMQKAD2LtvMzneA2AheFS8fzjenPkDkmPL1MF
Binary file not shown.
21 changes: 10 additions & 11 deletions anoncreds/src/data_types/anoncreds/rev_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{
};
use std::collections::HashSet;

use crate::{data_types::Validatable, impl_anoncreds_object_identifier};
use crate::{data_types::Validatable, error, impl_anoncreds_object_identifier};
use ursa::cl::Accumulator;

impl_anoncreds_object_identifier!(RevocationRegistryId);
Expand Down Expand Up @@ -66,7 +66,7 @@ pub struct RevocationList {

impl From<&RevocationList> for ursa::cl::RevocationRegistry {
fn from(rev_reg_list: &RevocationList) -> ursa::cl::RevocationRegistry {
ursa::cl::RevocationRegistry::from_accum(rev_reg_list.current_accum)
ursa::cl::RevocationRegistry::from(rev_reg_list.current_accum)
}
}

Expand All @@ -83,19 +83,18 @@ impl RevocationList {
self.revocation_list.clone()
}

#[cfg(test)]
fn new(
pub fn new(
rev_reg_id: &str,
revocation_list: bitvec::vec::BitVec,
current_accum: Accumulator,
current_reg: ursa::cl::RevocationRegistry,
timestamp: u64,
) -> Self {
Self {
rev_reg_id: rev_reg_id.into(),
) -> Result<Self, error::Error> {
Ok(Self {
rev_reg_id: RevocationRegistryId::new(rev_reg_id)?,
revocation_list,
current_accum,
current_accum: current_reg.into(),
timestamp,
}
})
}
}

Expand Down Expand Up @@ -171,7 +170,7 @@ mod tests {
fn test_revocation_list_roundtrip_serde() {
let state = bitvec![1;4];
let accum = Accumulator::new().expect("Should be able to create Accumulator");
let list = RevocationList::new("reg", state, accum, 1234u64);
let list = RevocationList::new("MOCK:uri: reg", state, accum.into(), 1234u64).unwrap();
let ser = serde_json::to_string(&list).unwrap();
let des = serde_json::from_str::<RevocationList>(&ser).unwrap();
let ser2 = serde_json::to_string(&des).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions anoncreds/src/services/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ pub(crate) struct ProvingCredentialKey {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CredentialRevocationState {
pub(crate) witness: Witness,
pub(crate) rev_reg: CryptoRevocationRegistry,
pub(crate) timestamp: u64,
pub witness: Witness,
pub rev_reg: CryptoRevocationRegistry,
pub timestamp: u64,
}

impl Validatable for CredentialRevocationState {
Expand Down
18 changes: 18 additions & 0 deletions anoncreds/src/services/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub fn verify_presentation(
&received_self_attested_attrs,
)?;

// makes sure the for revocable request or attribute,
// there is a timestamp in the `Identifier`
compare_timestamps_from_proof_and_request(
pres_req,
&received_revealed_attrs,
Expand Down Expand Up @@ -111,6 +113,7 @@ pub fn verify_presentation(
));
}

// Revocation registry definition id is the same as the rev reg id
let rev_reg_def_id = RevocationRegistryDefinitionId::new(rev_reg_id.clone())?;
let rev_reg_def = Some(
rev_reg_defs
Expand Down Expand Up @@ -302,6 +305,8 @@ fn compare_attr_from_proof_and_request(
Ok(())
}

// This does not actually compare the non_revoke interval
// see `validate_timestamp` function comments
fn compare_timestamps_from_proof_and_request(
pres_req: &PresentationRequestPayload,
received_revealed_attrs: &HashMap<String, Identifier>,
Expand Down Expand Up @@ -352,6 +357,19 @@ fn compare_timestamps_from_proof_and_request(
Ok(())
}

// This validates that a timestamp is given if either:
// - the `global_interval` rev requirement
// - the `local_interval` rev requirement
// from the PresentationRequest are satisfied.
//
// If either the attribute nor the request has a revocation internal
// i.e. they are non-revocable, then `OK` is returned directly.
//
// Otherwise the Identifier for the referent (attribute) has to have a timestamp,
// which was added by the prover when creating `PresentCredentials`,
// an arg for `create_presentation`.
//
// TODO: this timestamp should be compared with the provided interval
fn validate_timestamp(
received_: &HashMap<String, Identifier>,
referent: &str,
Expand Down
Loading

0 comments on commit 629ba44

Please sign in to comment.