Compare commits

...

2 Commits

Author SHA1 Message Date
Vecna 68137981fc One bridge may be in multiple buckets 2024-03-15 02:24:52 -04:00
Vecna 4f5bec56ad Add distributor enum so we know where to send NRs
For now, I'm not adding this to PRs because PRs are very Lox-specific
2024-03-14 18:09:24 -04:00
4 changed files with 48 additions and 20 deletions

View File

@ -2,6 +2,9 @@ use curve25519_dalek::Scalar;
use ed25519_dalek::VerifyingKey; use ed25519_dalek::VerifyingKey;
use lox_library::bridge_table::BridgeLine; use lox_library::bridge_table::BridgeLine;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashSet;
// TODO: Rename this. We already have a different BridgeInfo in lib.rs.
/// Information that needs to be known to verify a Troll Patrol report /// Information that needs to be known to verify a Troll Patrol report
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
@ -9,8 +12,8 @@ pub struct BridgeInfo {
/// BridgeLine for this bridge /// BridgeLine for this bridge
pub bridge_line: BridgeLine, pub bridge_line: BridgeLine,
/// Bucket for this bridge if this bridge is a Lox bridge /// Buckets containing this bridge if this bridge is a Lox bridge
pub bucket: Option<Scalar>, pub buckets: HashSet<Scalar>,
/// Key used to verify bridge tokens /// Key used to verify bridge tokens
pub pubkey: Option<VerifyingKey>, pub pubkey: Option<VerifyingKey>,
@ -20,7 +23,7 @@ impl BridgeInfo {
pub fn new(bl: BridgeLine) -> Self { pub fn new(bl: BridgeLine) -> Self {
BridgeInfo { BridgeInfo {
bridge_line: bl, bridge_line: bl,
bucket: None, buckets: HashSet::<Scalar>::new(),
pubkey: None, pubkey: None,
} }
} }

View File

@ -59,6 +59,11 @@ pub fn get_date() -> u32 {
.unwrap() .unwrap()
} }
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
pub enum BridgeDistributor {
Lox,
}
/// All the info for a bridge, to be stored in the database /// All the info for a bridge, to be stored in the database
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct BridgeInfo { pub struct BridgeInfo {

View File

@ -1,4 +1,4 @@
use crate::{bridge_info::BridgeInfo, get_date, COUNTRY_CODES}; use crate::{bridge_info::BridgeInfo, get_date, BridgeDistributor, COUNTRY_CODES};
use curve25519_dalek::scalar::Scalar; use curve25519_dalek::scalar::Scalar;
use lox_library::{bridge_table::BridgeLine, cred::Lox}; use lox_library::{bridge_table::BridgeLine, cred::Lox};
@ -16,6 +16,7 @@ pub enum NegativeReportError {
} }
/// A report that the user was unable to connect to the bridge /// A report that the user was unable to connect to the bridge
#[derive(Eq, PartialEq, Ord, PartialOrd)]
pub struct NegativeReport { pub struct NegativeReport {
/// hashed fingerprint (SHA-1 hash of 20-byte bridge ID) /// hashed fingerprint (SHA-1 hash of 20-byte bridge ID)
pub fingerprint: [u8; 20], pub fingerprint: [u8; 20],
@ -28,10 +29,18 @@ pub struct NegativeReport {
/// today's Julian date /// today's Julian date
pub date: u32, pub date: u32,
/// the bridge distributor, e.g., Lox, Https, or Moat
pub distributor: BridgeDistributor,
} }
impl NegativeReport { impl NegativeReport {
pub fn new(bridge_id: [u8; 20], bridge_pok: ProofOfBridgeKnowledge, country: String) -> Self { pub fn new(
bridge_id: [u8; 20],
bridge_pok: ProofOfBridgeKnowledge,
country: String,
distributor: BridgeDistributor,
) -> 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();
@ -41,25 +50,30 @@ impl NegativeReport {
bridge_pok, bridge_pok,
country, country,
date, date,
distributor,
} }
} }
pub fn from_bridgeline(bridge_id: [u8; 20], bridgeline: BridgeLine, country: String) -> Self { pub fn from_bridgeline(
bridgeline: BridgeLine,
country: String,
distributor: BridgeDistributor,
) -> Self {
let bridge_pok = let bridge_pok =
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline)); ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline));
NegativeReport::new(bridge_id, bridge_pok, country) NegativeReport::new(bridgeline.fingerprint, bridge_pok, country, distributor)
} }
pub fn from_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 mut hasher = Sha3_256::new();
hasher.update(bucket.to_bytes()); hasher.update(bucket.to_bytes());
let bucket_hash: [u8; 32] = hasher.finalize().into(); let bucket_hash: [u8; 32] = hasher.finalize().into();
let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket { hash: bucket_hash }); let bridge_pok = ProofOfBridgeKnowledge::HashOfBucket(HashOfBucket { hash: bucket_hash });
NegativeReport::new(bridge_id, bridge_pok, country) 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 {
NegativeReport::from_bucket(bridge_id, cred.bucket, country) NegativeReport::from_lox_bucket(bridge_id, cred.bucket, country)
} }
/// Convert report to a serializable version /// Convert report to a serializable version
@ -69,6 +83,7 @@ impl NegativeReport {
bridge_pok: self.bridge_pok, bridge_pok: self.bridge_pok,
country: self.country, country: self.country,
date: self.date, date: self.date,
distributor: self.distributor,
} }
} }
@ -92,13 +107,15 @@ impl NegativeReport {
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line); let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
hash == pok hash == pok
} }
ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket { ProofOfBridgeKnowledge::HashOfBucket(pok) => {
Some(b) => { for b in &bridge_info.buckets {
let hash = HashOfBucket::new(&b); let hash = HashOfBucket::new(&b);
hash == pok if hash == pok {
return true;
}
} }
None => false, false
}, }
} }
} }
} }
@ -111,6 +128,7 @@ pub struct SerializableNegativeReport {
bridge_pok: ProofOfBridgeKnowledge, bridge_pok: ProofOfBridgeKnowledge,
pub country: String, pub country: String,
pub date: u32, pub date: u32,
pub distributor: BridgeDistributor,
} }
impl SerializableNegativeReport { impl SerializableNegativeReport {
@ -129,6 +147,7 @@ impl SerializableNegativeReport {
bridge_pok: self.bridge_pok, bridge_pok: self.bridge_pok,
country: self.country.to_string(), country: self.country.to_string(),
date: self.date.try_into().unwrap(), date: self.date.try_into().unwrap(),
distributor: self.distributor,
}) })
} }
} }

View File

@ -128,13 +128,14 @@ impl PositiveReport {
} }
} }
// Verify knowledge of bucket ID // Verify knowledge of bucket ID
let bucket = bridge_info.bucket.unwrap(); let buckets = &bridge_info.buckets;
let BP = self.lox_proof.BP; let BP = self.lox_proof.BP;
if &bucket * Htable != BP { for bucket in buckets {
return false; if bucket * Htable != BP {
return la.handle_positive_report(self.lox_proof, &Htable).is_ok();
}
} }
// Verify Lox proof false
la.handle_positive_report(self.lox_proof, &Htable).is_ok()
} }
} }