Add date to proof of bridge knowledge in negative reports
This commit is contained in:
parent
90071c3e1d
commit
b915aea094
|
@ -41,12 +41,12 @@ impl NegativeReport {
|
|||
bridge_id: [u8; 20],
|
||||
bridge_pok: ProofOfBridgeKnowledge,
|
||||
country: String,
|
||||
date: u32,
|
||||
distributor: BridgeDistributor,
|
||||
) -> Self {
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(bridge_id);
|
||||
let fingerprint: [u8; 20] = hasher.finalize().into();
|
||||
let date = get_date();
|
||||
Self {
|
||||
fingerprint,
|
||||
bridge_pok,
|
||||
|
@ -61,17 +61,22 @@ impl NegativeReport {
|
|||
country: String,
|
||||
distributor: BridgeDistributor,
|
||||
) -> Self {
|
||||
let date = get_date();
|
||||
let bridge_pok =
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline));
|
||||
NegativeReport::new(bridgeline.fingerprint, bridge_pok, country, distributor)
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline, date));
|
||||
NegativeReport::new(
|
||||
bridgeline.fingerprint,
|
||||
bridge_pok,
|
||||
country,
|
||||
date,
|
||||
distributor,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from_lox_bucket(bridge_id: [u8; 20], bucket: Scalar, country: String) -> Self {
|
||||
let mut hasher = Sha3_256::new();
|
||||
hasher.update(bucket.to_bytes());
|
||||
let bucket_hash: [u8; 32] = hasher.finalize().into();
|
||||
let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket { hash: bucket_hash });
|
||||
NegativeReport::new(bridge_id, bridge_pok, country, BridgeDistributor::Lox)
|
||||
let date = get_date();
|
||||
let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket::new(&bucket, date));
|
||||
NegativeReport::new(bridge_id, bridge_pok, country, date, BridgeDistributor::Lox)
|
||||
}
|
||||
|
||||
pub fn from_lox_credential(bridge_id: [u8; 20], cred: Lox, country: String) -> Self {
|
||||
|
@ -114,12 +119,12 @@ impl NegativeReport {
|
|||
pub fn verify(self, bridge_info: &BridgeVerificationInfo) -> bool {
|
||||
match self.bridge_pok {
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
|
||||
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
|
||||
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line, self.date);
|
||||
hash == pok
|
||||
}
|
||||
ProofOfBridgeKnowledge::HashOfBucket(pok) => {
|
||||
for b in &bridge_info.buckets {
|
||||
let hash = HashOfBucket::new(&b);
|
||||
let hash = HashOfBucket::new(&b, self.date);
|
||||
if hash == pok {
|
||||
return true;
|
||||
}
|
||||
|
@ -179,8 +184,9 @@ pub struct HashOfBridgeLine {
|
|||
}
|
||||
|
||||
impl HashOfBridgeLine {
|
||||
pub fn new(bl: &BridgeLine) -> Self {
|
||||
pub fn new(bl: &BridgeLine, date: u32) -> Self {
|
||||
let mut hasher = Sha3_256::new();
|
||||
hasher.update(date.to_le_bytes());
|
||||
hasher.update(bincode::serialize(&bl).unwrap());
|
||||
let hash: [u8; 32] = hasher.finalize().into();
|
||||
Self { hash }
|
||||
|
@ -194,8 +200,9 @@ pub struct HashOfBucket {
|
|||
}
|
||||
|
||||
impl HashOfBucket {
|
||||
pub fn new(bucket: &Scalar) -> Self {
|
||||
pub fn new(bucket: &Scalar, date: u32) -> Self {
|
||||
let mut hasher = Sha3_256::new();
|
||||
hasher.update(date.to_le_bytes());
|
||||
hasher.update(bucket.to_bytes());
|
||||
let hash: [u8; 32] = hasher.finalize().into();
|
||||
Self { hash }
|
||||
|
|
11
src/tests.rs
11
src/tests.rs
|
@ -204,19 +204,26 @@ fn test_negative_reports() {
|
|||
|
||||
// Check that verification fails with incorrect data
|
||||
|
||||
let date = get_date();
|
||||
|
||||
// Incorrect BridgeLine hash
|
||||
let invalid_report_3 = NegativeReport::new(
|
||||
bridges[0].fingerprint,
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&BridgeLine::default())),
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(
|
||||
&BridgeLine::default(),
|
||||
date,
|
||||
)),
|
||||
"ru".to_string(),
|
||||
date,
|
||||
BridgeDistributor::Lox,
|
||||
);
|
||||
|
||||
// Incorrect bucket hash
|
||||
let invalid_report_4 = NegativeReport::new(
|
||||
bridges[1].fingerprint,
|
||||
ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket::new(&Scalar::ZERO)),
|
||||
ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket::new(&Scalar::ZERO, date)),
|
||||
"ru".to_string(),
|
||||
date,
|
||||
BridgeDistributor::Lox,
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue