Compare commits
No commits in common. "68137981fcbbe354c446a7ccbbe38c1a3dc5a61f" and "548c94f83409ffa41fa3a95f447b92e3e4d6c620" have entirely different histories.
68137981fc
...
548c94f834
|
@ -2,9 +2,6 @@ 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)]
|
||||||
|
@ -12,8 +9,8 @@ pub struct BridgeInfo {
|
||||||
/// BridgeLine for this bridge
|
/// BridgeLine for this bridge
|
||||||
pub bridge_line: BridgeLine,
|
pub bridge_line: BridgeLine,
|
||||||
|
|
||||||
/// Buckets containing this bridge if this bridge is a Lox bridge
|
/// Bucket for this bridge if this bridge is a Lox bridge
|
||||||
pub buckets: HashSet<Scalar>,
|
pub bucket: Option<Scalar>,
|
||||||
|
|
||||||
/// Key used to verify bridge tokens
|
/// Key used to verify bridge tokens
|
||||||
pub pubkey: Option<VerifyingKey>,
|
pub pubkey: Option<VerifyingKey>,
|
||||||
|
@ -23,7 +20,7 @@ impl BridgeInfo {
|
||||||
pub fn new(bl: BridgeLine) -> Self {
|
pub fn new(bl: BridgeLine) -> Self {
|
||||||
BridgeInfo {
|
BridgeInfo {
|
||||||
bridge_line: bl,
|
bridge_line: bl,
|
||||||
buckets: HashSet::<Scalar>::new(),
|
bucket: None,
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,11 +59,6 @@ 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 {
|
||||||
|
|
|
@ -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 curve25519_dalek::scalar::Scalar;
|
||||||
use lox_library::{bridge_table::BridgeLine, cred::Lox};
|
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
|
/// 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],
|
||||||
|
@ -29,18 +28,10 @@ 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(
|
pub fn new(bridge_id: [u8; 20], bridge_pok: ProofOfBridgeKnowledge, country: String) -> Self {
|
||||||
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();
|
||||||
|
@ -50,30 +41,25 @@ impl NegativeReport {
|
||||||
bridge_pok,
|
bridge_pok,
|
||||||
country,
|
country,
|
||||||
date,
|
date,
|
||||||
distributor,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_bridgeline(
|
pub fn from_bridgeline(bridge_id: [u8; 20], bridgeline: BridgeLine, country: String) -> Self {
|
||||||
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(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();
|
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, BridgeDistributor::Lox)
|
NegativeReport::new(bridge_id, bridge_pok, country)
|
||||||
}
|
}
|
||||||
|
|
||||||
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_lox_bucket(bridge_id, cred.bucket, country)
|
NegativeReport::from_bucket(bridge_id, cred.bucket, country)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert report to a serializable version
|
/// Convert report to a serializable version
|
||||||
|
@ -83,7 +69,6 @@ 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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,15 +92,13 @@ 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) => {
|
ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket {
|
||||||
for b in &bridge_info.buckets {
|
Some(b) => {
|
||||||
let hash = HashOfBucket::new(&b);
|
let hash = HashOfBucket::new(&b);
|
||||||
if hash == pok {
|
hash == pok
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
None => false,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +111,6 @@ 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 {
|
||||||
|
@ -147,7 +129,6 @@ 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,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,14 +128,13 @@ impl PositiveReport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Verify knowledge of bucket ID
|
// Verify knowledge of bucket ID
|
||||||
let buckets = &bridge_info.buckets;
|
let bucket = bridge_info.bucket.unwrap();
|
||||||
let BP = self.lox_proof.BP;
|
let BP = self.lox_proof.BP;
|
||||||
for bucket in buckets {
|
if &bucket * Htable != BP {
|
||||||
if bucket * Htable != BP {
|
return false;
|
||||||
return la.handle_positive_report(self.lox_proof, &Htable).is_ok();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
// Verify Lox proof
|
||||||
|
la.handle_positive_report(self.lox_proof, &Htable).is_ok()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue