Add date to proof of bridge knowledge in negative reports

This commit is contained in:
Vecna 2024-04-04 22:55:07 -04:00
parent 90071c3e1d
commit b915aea094
2 changed files with 28 additions and 14 deletions

View File

@ -41,12 +41,12 @@ impl NegativeReport {
bridge_id: [u8; 20], bridge_id: [u8; 20],
bridge_pok: ProofOfBridgeKnowledge, bridge_pok: ProofOfBridgeKnowledge,
country: String, country: String,
date: u32,
distributor: BridgeDistributor, distributor: BridgeDistributor,
) -> Self { ) -> Self {
let mut hasher = Sha1::new(); let mut hasher = Sha1::new();
hasher.update(bridge_id); hasher.update(bridge_id);
let fingerprint: [u8; 20] = hasher.finalize().into(); let fingerprint: [u8; 20] = hasher.finalize().into();
let date = get_date();
Self { Self {
fingerprint, fingerprint,
bridge_pok, bridge_pok,
@ -61,17 +61,22 @@ impl NegativeReport {
country: String, country: String,
distributor: BridgeDistributor, distributor: BridgeDistributor,
) -> Self { ) -> Self {
let date = get_date();
let bridge_pok = let bridge_pok =
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline)); ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline, date));
NegativeReport::new(bridgeline.fingerprint, bridge_pok, country, distributor) NegativeReport::new(
bridgeline.fingerprint,
bridge_pok,
country,
date,
distributor,
)
} }
pub fn from_lox_bucket(bridge_id: [u8; 20], bucket: Scalar, country: String) -> Self { pub fn from_lox_bucket(bridge_id: [u8; 20], bucket: Scalar, country: String) -> Self {
let mut hasher = Sha3_256::new(); let date = get_date();
hasher.update(bucket.to_bytes()); let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket::new(&bucket, date));
let bucket_hash: [u8; 32] = hasher.finalize().into(); NegativeReport::new(bridge_id, bridge_pok, country, date, BridgeDistributor::Lox)
let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket { hash: bucket_hash });
NegativeReport::new(bridge_id, bridge_pok, country, BridgeDistributor::Lox)
} }
pub fn from_lox_credential(bridge_id: [u8; 20], cred: Lox, country: String) -> Self { 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 { pub fn verify(self, bridge_info: &BridgeVerificationInfo) -> bool {
match self.bridge_pok { match self.bridge_pok {
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => { ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line); let hash = HashOfBridgeLine::new(&bridge_info.bridge_line, self.date);
hash == pok hash == pok
} }
ProofOfBridgeKnowledge::HashOfBucket(pok) => { ProofOfBridgeKnowledge::HashOfBucket(pok) => {
for b in &bridge_info.buckets { for b in &bridge_info.buckets {
let hash = HashOfBucket::new(&b); let hash = HashOfBucket::new(&b, self.date);
if hash == pok { if hash == pok {
return true; return true;
} }
@ -179,8 +184,9 @@ pub struct HashOfBridgeLine {
} }
impl HashOfBridgeLine { impl HashOfBridgeLine {
pub fn new(bl: &BridgeLine) -> Self { pub fn new(bl: &BridgeLine, date: u32) -> Self {
let mut hasher = Sha3_256::new(); let mut hasher = Sha3_256::new();
hasher.update(date.to_le_bytes());
hasher.update(bincode::serialize(&bl).unwrap()); hasher.update(bincode::serialize(&bl).unwrap());
let hash: [u8; 32] = hasher.finalize().into(); let hash: [u8; 32] = hasher.finalize().into();
Self { hash } Self { hash }
@ -194,8 +200,9 @@ pub struct HashOfBucket {
} }
impl HashOfBucket { impl HashOfBucket {
pub fn new(bucket: &Scalar) -> Self { pub fn new(bucket: &Scalar, date: u32) -> Self {
let mut hasher = Sha3_256::new(); let mut hasher = Sha3_256::new();
hasher.update(date.to_le_bytes());
hasher.update(bucket.to_bytes()); hasher.update(bucket.to_bytes());
let hash: [u8; 32] = hasher.finalize().into(); let hash: [u8; 32] = hasher.finalize().into();
Self { hash } Self { hash }

View File

@ -204,19 +204,26 @@ fn test_negative_reports() {
// Check that verification fails with incorrect data // Check that verification fails with incorrect data
let date = get_date();
// Incorrect BridgeLine hash // Incorrect BridgeLine hash
let invalid_report_3 = NegativeReport::new( let invalid_report_3 = NegativeReport::new(
bridges[0].fingerprint, bridges[0].fingerprint,
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&BridgeLine::default())), ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(
&BridgeLine::default(),
date,
)),
"ru".to_string(), "ru".to_string(),
date,
BridgeDistributor::Lox, BridgeDistributor::Lox,
); );
// Incorrect bucket hash // Incorrect bucket hash
let invalid_report_4 = NegativeReport::new( let invalid_report_4 = NegativeReport::new(
bridges[1].fingerprint, bridges[1].fingerprint,
ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket::new(&Scalar::ZERO)), ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket::new(&Scalar::ZERO, date)),
"ru".to_string(), "ru".to_string(),
date,
BridgeDistributor::Lox, BridgeDistributor::Lox,
); );