Compare commits
2 Commits
548c94f834
...
68137981fc
Author | SHA1 | Date |
---|---|---|
|
68137981fc | |
|
4f5bec56ad |
|
@ -2,6 +2,9 @@ use curve25519_dalek::Scalar;
|
|||
use ed25519_dalek::VerifyingKey;
|
||||
use lox_library::bridge_table::BridgeLine;
|
||||
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
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -9,8 +12,8 @@ pub struct BridgeInfo {
|
|||
/// BridgeLine for this bridge
|
||||
pub bridge_line: BridgeLine,
|
||||
|
||||
/// Bucket for this bridge if this bridge is a Lox bridge
|
||||
pub bucket: Option<Scalar>,
|
||||
/// Buckets containing this bridge if this bridge is a Lox bridge
|
||||
pub buckets: HashSet<Scalar>,
|
||||
|
||||
/// Key used to verify bridge tokens
|
||||
pub pubkey: Option<VerifyingKey>,
|
||||
|
@ -20,7 +23,7 @@ impl BridgeInfo {
|
|||
pub fn new(bl: BridgeLine) -> Self {
|
||||
BridgeInfo {
|
||||
bridge_line: bl,
|
||||
bucket: None,
|
||||
buckets: HashSet::<Scalar>::new(),
|
||||
pubkey: None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,11 @@ pub fn get_date() -> u32 {
|
|||
.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
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct BridgeInfo {
|
||||
|
|
|
@ -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 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
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct NegativeReport {
|
||||
/// hashed fingerprint (SHA-1 hash of 20-byte bridge ID)
|
||||
pub fingerprint: [u8; 20],
|
||||
|
@ -28,10 +29,18 @@ pub struct NegativeReport {
|
|||
|
||||
/// today's Julian date
|
||||
pub date: u32,
|
||||
|
||||
/// the bridge distributor, e.g., Lox, Https, or Moat
|
||||
pub distributor: BridgeDistributor,
|
||||
}
|
||||
|
||||
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();
|
||||
hasher.update(bridge_id);
|
||||
let fingerprint: [u8; 20] = hasher.finalize().into();
|
||||
|
@ -41,25 +50,30 @@ impl NegativeReport {
|
|||
bridge_pok,
|
||||
country,
|
||||
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 =
|
||||
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();
|
||||
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)
|
||||
NegativeReport::new(bridge_id, bridge_pok, country, BridgeDistributor::Lox)
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -69,6 +83,7 @@ impl NegativeReport {
|
|||
bridge_pok: self.bridge_pok,
|
||||
country: self.country,
|
||||
date: self.date,
|
||||
distributor: self.distributor,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,13 +107,15 @@ impl NegativeReport {
|
|||
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
|
||||
hash == pok
|
||||
}
|
||||
ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket {
|
||||
Some(b) => {
|
||||
ProofOfBridgeKnowledge::HashOfBucket(pok) => {
|
||||
for b in &bridge_info.buckets {
|
||||
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,
|
||||
pub country: String,
|
||||
pub date: u32,
|
||||
pub distributor: BridgeDistributor,
|
||||
}
|
||||
|
||||
impl SerializableNegativeReport {
|
||||
|
@ -129,6 +147,7 @@ impl SerializableNegativeReport {
|
|||
bridge_pok: self.bridge_pok,
|
||||
country: self.country.to_string(),
|
||||
date: self.date.try_into().unwrap(),
|
||||
distributor: self.distributor,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,13 +128,14 @@ impl PositiveReport {
|
|||
}
|
||||
}
|
||||
// Verify knowledge of bucket ID
|
||||
let bucket = bridge_info.bucket.unwrap();
|
||||
let buckets = &bridge_info.buckets;
|
||||
let BP = self.lox_proof.BP;
|
||||
if &bucket * Htable != BP {
|
||||
return false;
|
||||
for bucket in buckets {
|
||||
if bucket * Htable != BP {
|
||||
return la.handle_positive_report(self.lox_proof, &Htable).is_ok();
|
||||
}
|
||||
}
|
||||
// Verify Lox proof
|
||||
la.handle_positive_report(self.lox_proof, &Htable).is_ok()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue