Compare commits

..

No commits in common. "68137981fcbbe354c446a7ccbbe38c1a3dc5a61f" and "548c94f83409ffa41fa3a95f447b92e3e4d6c620" have entirely different histories.

4 changed files with 20 additions and 48 deletions

View File

@ -2,9 +2,6 @@ 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)]
@ -12,8 +9,8 @@ pub struct BridgeInfo {
/// BridgeLine for this bridge
pub bridge_line: BridgeLine,
/// Buckets containing this bridge if this bridge is a Lox bridge
pub buckets: HashSet<Scalar>,
/// Bucket for this bridge if this bridge is a Lox bridge
pub bucket: Option<Scalar>,
/// Key used to verify bridge tokens
pub pubkey: Option<VerifyingKey>,
@ -23,7 +20,7 @@ impl BridgeInfo {
pub fn new(bl: BridgeLine) -> Self {
BridgeInfo {
bridge_line: bl,
buckets: HashSet::<Scalar>::new(),
bucket: None,
pubkey: None,
}
}

View File

@ -59,11 +59,6 @@ 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 {

View File

@ -1,4 +1,4 @@
use crate::{bridge_info::BridgeInfo, get_date, BridgeDistributor, COUNTRY_CODES};
use crate::{bridge_info::BridgeInfo, get_date, COUNTRY_CODES};
use curve25519_dalek::scalar::Scalar;
use lox_library::{bridge_table::BridgeLine, cred::Lox};
@ -16,7 +16,6 @@ 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],
@ -29,18 +28,10 @@ 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,
distributor: BridgeDistributor,
) -> Self {
pub fn new(bridge_id: [u8; 20], bridge_pok: ProofOfBridgeKnowledge, country: String) -> Self {
let mut hasher = Sha1::new();
hasher.update(bridge_id);
let fingerprint: [u8; 20] = hasher.finalize().into();
@ -50,30 +41,25 @@ impl NegativeReport {
bridge_pok,
country,
date,
distributor,
}
}
pub fn from_bridgeline(
bridgeline: BridgeLine,
country: String,
distributor: BridgeDistributor,
) -> Self {
pub fn from_bridgeline(bridge_id: [u8; 20], bridgeline: BridgeLine, country: String) -> Self {
let bridge_pok =
ProofOfBridgeKnowledge::HashOfBridgeLine(HashOfBridgeLine::new(&bridgeline));
NegativeReport::new(bridgeline.fingerprint, bridge_pok, country, distributor)
NegativeReport::new(bridge_id, bridge_pok, country)
}
pub fn from_lox_bucket(bridge_id: [u8; 20], bucket: Scalar, country: String) -> Self {
pub fn from_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)
NegativeReport::new(bridge_id, bridge_pok, country)
}
pub fn from_lox_credential(bridge_id: [u8; 20], cred: Lox, country: String) -> Self {
NegativeReport::from_lox_bucket(bridge_id, cred.bucket, country)
NegativeReport::from_bucket(bridge_id, cred.bucket, country)
}
/// Convert report to a serializable version
@ -83,7 +69,6 @@ impl NegativeReport {
bridge_pok: self.bridge_pok,
country: self.country,
date: self.date,
distributor: self.distributor,
}
}
@ -107,15 +92,13 @@ impl NegativeReport {
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
hash == pok
}
ProofOfBridgeKnowledge::HashOfBucket(pok) => {
for b in &bridge_info.buckets {
ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket {
Some(b) => {
let hash = HashOfBucket::new(&b);
if hash == pok {
return true;
}
hash == pok
}
false
}
None => false,
},
}
}
}
@ -128,7 +111,6 @@ pub struct SerializableNegativeReport {
bridge_pok: ProofOfBridgeKnowledge,
pub country: String,
pub date: u32,
pub distributor: BridgeDistributor,
}
impl SerializableNegativeReport {
@ -147,7 +129,6 @@ impl SerializableNegativeReport {
bridge_pok: self.bridge_pok,
country: self.country.to_string(),
date: self.date.try_into().unwrap(),
distributor: self.distributor,
})
}
}

View File

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