Compare commits
4 Commits
9412817a66
...
548c94f834
Author | SHA1 | Date |
---|---|---|
|
548c94f834 | |
|
6448537c4b | |
|
4f88df6171 | |
|
495f196107 |
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ use std::{
|
|||
io::BufReader,
|
||||
};
|
||||
|
||||
pub mod bridge_info;
|
||||
pub mod extra_info;
|
||||
pub mod negative_report;
|
||||
pub mod positive_report;
|
||||
|
|
|
@ -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 lox_library::{bridge_table::BridgeLine, cred::Lox};
|
||||
|
@ -85,25 +85,20 @@ impl NegativeReport {
|
|||
}
|
||||
}
|
||||
|
||||
/// Verify report if proof of bridge knowledge is bridge line hash
|
||||
pub fn verify_with_hash_of_bridge_line(self, bl: &BridgeLine) -> bool {
|
||||
/// Verify the report
|
||||
pub fn verify(self, bridge_info: &BridgeInfo) -> bool {
|
||||
match self.bridge_pok {
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
|
||||
let hash = HashOfBridgeLine::new(bl);
|
||||
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
|
||||
hash == pok
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify report if proof of bridge knowledge is bucket hash
|
||||
pub fn verify_with_hash_of_bucket(self, bucket: &Scalar) -> bool {
|
||||
match self.bridge_pok {
|
||||
ProofOfBridgeKnowledge::HashOfBucket(pok) => {
|
||||
let hash = HashOfBucket::new(bucket);
|
||||
ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket {
|
||||
Some(b) => {
|
||||
let hash = HashOfBucket::new(&b);
|
||||
hash == pok
|
||||
}
|
||||
_ => false,
|
||||
None => false,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// For Lox-related code where points are uppercase and scalars are lowercase
|
||||
#![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 ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
|
||||
use lox_library::{cred::Lox, proto::positive_report as lox_pr, IssuerPubKey};
|
||||
use curve25519_dalek::ristretto::RistrettoBasepointTable;
|
||||
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier};
|
||||
use lox_library::{cred::Lox, proto::positive_report as lox_pr, BridgeAuth, IssuerPubKey};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sha1::{Digest, Sha1};
|
||||
use std::option::Option;
|
||||
|
@ -102,22 +102,17 @@ impl PositiveReport {
|
|||
}
|
||||
}
|
||||
|
||||
/// Verify everything except the Lox proof.
|
||||
/// Parameters:
|
||||
/// - 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(
|
||||
/// Verify report
|
||||
pub fn verify(
|
||||
self,
|
||||
bucket: Scalar,
|
||||
la: &mut BridgeAuth,
|
||||
bridge_info: &BridgeInfo,
|
||||
Htable: &RistrettoBasepointTable,
|
||||
bridge_key: Option<VerifyingKey>,
|
||||
) -> bool {
|
||||
// Verify bridge token
|
||||
if CONFIG.require_bridge_token {
|
||||
let bridge_token = self.bridge_token.unwrap();
|
||||
let bridge_key = bridge_info.pubkey;
|
||||
if bridge_key.is_none() {
|
||||
return false;
|
||||
}
|
||||
|
@ -133,11 +128,13 @@ impl PositiveReport {
|
|||
}
|
||||
}
|
||||
// Verify knowledge of bucket ID
|
||||
let bucket = bridge_info.bucket.unwrap();
|
||||
let BP = self.lox_proof.BP;
|
||||
if &bucket * Htable != BP {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
// Verify Lox proof
|
||||
la.handle_positive_report(self.lox_proof, &Htable).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue