|
|
@@ -37,13 +37,16 @@ and a new Lox credential to be issued:
|
|
|
Lox credential above
|
|
|
|
|
|
*/
|
|
|
-
|
|
|
+#[cfg(feature = "bridgeauth")]
|
|
|
+use super::super::dup_filter::SeenType;
|
|
|
use super::super::scalar_u32;
|
|
|
+#[cfg(feature = "bridgeauth")]
|
|
|
+use super::super::BridgeAuth;
|
|
|
use super::errors::CredentialError;
|
|
|
use crate::lox_creds::{BucketReachability, Lox};
|
|
|
use cmz::*;
|
|
|
use curve25519_dalek::ristretto::RistrettoPoint as G;
|
|
|
-use ff::PrimeField;
|
|
|
+use group::Group;
|
|
|
use rand_core::RngCore;
|
|
|
use sha2::Sha512;
|
|
|
|
|
|
@@ -74,17 +77,17 @@ pub const LEVEL_INVITATIONS: [u32; MAX_LEVEL + 1] = [0, 2, 4, 6, 8];
|
|
|
// one or more bits to the ZKP.
|
|
|
pub const MAX_BLOCKAGES: [u32; MAX_LEVEL + 1] = [0, 4, 3, 2, 2];
|
|
|
|
|
|
-CMZProtocol! { level_up<credential_expiry, eligibility_max_age, max_blockage>,
|
|
|
+muCMZProtocol! { level_up<credential_expiry, eligibility_max_age, max_blockage>,
|
|
|
[ L: Lox { id: R, bucket: H, trust_level: R, level_since: H, invites_remaining: H, blockages: H },
|
|
|
B: BucketReachability { date: R, bucket: H } ],
|
|
|
N: Lox {id: J, bucket: H, trust_level: R, level_since: S, invites_remaining: I, blockages: H },
|
|
|
- credential_expiry <= L.level_since,
|
|
|
- L.level_since <= eligibility_max_age,
|
|
|
- 0 <= L.blockages,
|
|
|
- L.blockages <= max_blockage,
|
|
|
+ // credential_expiry <= L.level_since,
|
|
|
+ // L.level_since <= eligibility_max_age,
|
|
|
+ // 0 <= L.blockages,
|
|
|
+ // L.blockages <= max_blockage,
|
|
|
B.bucket = L.bucket,
|
|
|
N.bucket = L.bucket,
|
|
|
- N.trust_level = L.trust_level+1,
|
|
|
+ N.trust_level = L.trust_level + Scalar::ONE,
|
|
|
N.blockages = L.blockages,
|
|
|
}
|
|
|
|
|
|
@@ -159,7 +162,7 @@ pub fn request(
|
|
|
}
|
|
|
// The buckets in the Lox and Bucket Reachability credentials have
|
|
|
// to match
|
|
|
- if L.bucket != B.bucket {
|
|
|
+ if L.bucket.is_some_and(|b| b != B.bucket.unwrap()) {
|
|
|
return Err(CredentialError::CredentialMismatch);
|
|
|
}
|
|
|
// The Bucket Reachability credential has to be dated today
|
|
|
@@ -201,6 +204,7 @@ pub fn request(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#[cfg(feature = "bridgeauth")]
|
|
|
impl BridgeAuth {
|
|
|
pub fn handle_level_up(
|
|
|
&mut self,
|
|
|
@@ -209,10 +213,11 @@ impl BridgeAuth {
|
|
|
let mut rng = rand::thread_rng();
|
|
|
let reqbytes = req.as_bytes();
|
|
|
let recvreq = level_up::Request::try_from(&reqbytes[..]).unwrap();
|
|
|
+ let today = self.today();
|
|
|
match level_up::handle(
|
|
|
&mut rng,
|
|
|
recvreq,
|
|
|
- |L: &mut Lox, B: &mut BucketReachability, N: &mut Lox| {
|
|
|
+ |L: &mut Lox, _B: &mut BucketReachability, N: &mut Lox| {
|
|
|
let trust_level: u32 = match scalar_u32(&L.trust_level.unwrap()) {
|
|
|
Some(v) if v as usize >= 1 && v as usize <= MAX_LEVEL => v,
|
|
|
_ => {
|
|
|
@@ -225,7 +230,7 @@ impl BridgeAuth {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- let eligibility_max_age: u32 = self.today() - LEVEL_INTERVAL[trust_level as usize];
|
|
|
+ let eligibility_max_age: u32 = today - LEVEL_INTERVAL[trust_level as usize];
|
|
|
N.invites_remaining = Some(LEVEL_INVITATIONS[(trust_level + 1) as usize].into());
|
|
|
Ok(level_up::Params {
|
|
|
credential_expiry: (eligibility_max_age - 511).into(),
|
|
|
@@ -233,15 +238,16 @@ impl BridgeAuth {
|
|
|
max_blockage: MAX_BLOCKAGES[(trust_level + 1) as usize].into(),
|
|
|
})
|
|
|
},
|
|
|
- |L: &Lox, B: &BucketReachability, N: &Lox| {
|
|
|
- if self.id_filter.filter(L.id) == SeenType::Seen {
|
|
|
+ |L: &Lox, _B: &BucketReachability, _N: &Lox| {
|
|
|
+ if self.id_filter.filter(&L.id.unwrap()) == SeenType::Seen {
|
|
|
return Err(CMZError::RevealAttrMissing("id", ""));
|
|
|
}
|
|
|
Ok(())
|
|
|
},
|
|
|
) {
|
|
|
- Ok((response, (_L_issuer, _B_isser, _N_issuer))) => Ok(response),
|
|
|
- Err(e) =>(Err(CredentialError::CMZError(e))),
|
|
|
+ Ok((response, (_L_issuer, _B_isser, _N_issuer))) => Ok(response),
|
|
|
+ Err(e) => Err(CredentialError::CMZError(e)),
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|