Compare commits

...

4 Commits

4 changed files with 51 additions and 31 deletions

27
src/bridge_info.rs Normal file
View File

@ -0,0 +1,27 @@
use curve25519_dalek::Scalar;
use ed25519_dalek::VerifyingKey;
use lox_library::bridge_table::BridgeLine;
use serde::{Deserialize, Serialize};
/// Information that needs to be known to verify a Troll Patrol report
#[derive(Debug, Serialize, Deserialize)]
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>,
/// Key used to verify bridge tokens
pub pubkey: Option<VerifyingKey>,
}
impl BridgeInfo {
pub fn new(bl: BridgeLine) -> Self {
BridgeInfo {
bridge_line: bl,
bucket: None,
pubkey: None,
}
}
}

View File

@ -8,6 +8,7 @@ use std::{
io::BufReader, io::BufReader,
}; };
pub mod bridge_info;
pub mod extra_info; pub mod extra_info;
pub mod negative_report; pub mod negative_report;
pub mod positive_report; pub mod positive_report;

View File

@ -1,4 +1,4 @@
use crate::{get_date, 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};
@ -85,25 +85,20 @@ impl NegativeReport {
} }
} }
/// Verify report if proof of bridge knowledge is bridge line hash /// Verify the report
pub fn verify_with_hash_of_bridge_line(self, bl: &BridgeLine) -> bool { pub fn verify(self, bridge_info: &BridgeInfo) -> bool {
match self.bridge_pok { match self.bridge_pok {
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => { ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
let hash = HashOfBridgeLine::new(bl); let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
hash == pok hash == pok
} }
_ => false, ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket {
} Some(b) => {
} let hash = HashOfBucket::new(&b);
hash == pok
/// Verify report if proof of bridge knowledge is bucket hash }
pub fn verify_with_hash_of_bucket(self, bucket: &Scalar) -> bool { None => false,
match self.bridge_pok { },
ProofOfBridgeKnowledge::HashOfBucket(pok) => {
let hash = HashOfBucket::new(bucket);
hash == pok
}
_ => false,
} }
} }
} }

View File

@ -1,11 +1,11 @@
// For Lox-related code where points are uppercase and scalars are lowercase // For Lox-related code where points are uppercase and scalars are lowercase
#![allow(non_snake_case)] #![allow(non_snake_case)]
use crate::{get_date, CONFIG, COUNTRY_CODES}; use crate::{bridge_info::BridgeInfo, get_date, CONFIG, COUNTRY_CODES};
use curve25519_dalek::{ristretto::RistrettoBasepointTable, Scalar}; use curve25519_dalek::ristretto::RistrettoBasepointTable;
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey}; use ed25519_dalek::{Signature, Signer, SigningKey, Verifier};
use lox_library::{cred::Lox, proto::positive_report as lox_pr, IssuerPubKey}; use lox_library::{cred::Lox, proto::positive_report as lox_pr, BridgeAuth, IssuerPubKey};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sha1::{Digest, Sha1}; use sha1::{Digest, Sha1};
use std::option::Option; use std::option::Option;
@ -102,22 +102,17 @@ impl PositiveReport {
} }
} }
/// Verify everything except the Lox proof. /// Verify report
/// Parameters: pub fn verify(
/// - The bucket ID for the bucket containing this bridge
/// - A basepoint table for computing multiples of H
/// - The bridge verifying key for this bridge (if bridge token is required)
/// These parameters are assumed to be correct and are NOT checked against
/// the fingerprint listed in the report.
pub fn verify_excluding_lox_proof(
self, self,
bucket: Scalar, la: &mut BridgeAuth,
bridge_info: &BridgeInfo,
Htable: &RistrettoBasepointTable, Htable: &RistrettoBasepointTable,
bridge_key: Option<VerifyingKey>,
) -> bool { ) -> bool {
// Verify bridge token // Verify bridge token
if CONFIG.require_bridge_token { if CONFIG.require_bridge_token {
let bridge_token = self.bridge_token.unwrap(); let bridge_token = self.bridge_token.unwrap();
let bridge_key = bridge_info.pubkey;
if bridge_key.is_none() { if bridge_key.is_none() {
return false; return false;
} }
@ -133,11 +128,13 @@ impl PositiveReport {
} }
} }
// Verify knowledge of bucket ID // Verify knowledge of bucket ID
let bucket = bridge_info.bucket.unwrap();
let BP = self.lox_proof.BP; let BP = self.lox_proof.BP;
if &bucket * Htable != BP { if &bucket * Htable != BP {
return false; return false;
} }
true // Verify Lox proof
la.handle_positive_report(self.lox_proof, &Htable).is_ok()
} }
} }