Create struct for bridge info which must be externally provided
This commit is contained in:
parent
495f196107
commit
4f88df6171
|
@ -0,0 +1,25 @@
|
||||||
|
use curve25519_dalek::Scalar;
|
||||||
|
use ed25519_dalek::VerifyingKey;
|
||||||
|
use lox_library::bridge_table::BridgeLine;
|
||||||
|
|
||||||
|
/// Information that needs to be known to verify a Troll Patrol report
|
||||||
|
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,
|
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;
|
||||||
|
|
|
@ -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};
|
||||||
|
@ -87,18 +87,15 @@ impl NegativeReport {
|
||||||
|
|
||||||
/// Verify report. Caller must pass Some of the bridge knowledge proof type
|
/// Verify report. Caller must pass Some of the bridge knowledge proof type
|
||||||
/// in the report.
|
/// in the report.
|
||||||
pub fn verify(self, bl: Option<&BridgeLine>, bucket: Option<&Scalar>) -> bool {
|
pub fn verify(self, bridge_info: &BridgeInfo) -> bool {
|
||||||
match self.bridge_pok {
|
match self.bridge_pok {
|
||||||
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => match bl {
|
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
|
||||||
Some(b) => {
|
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
|
||||||
let hash = HashOfBridgeLine::new(b);
|
|
||||||
hash == pok
|
hash == pok
|
||||||
}
|
}
|
||||||
None => false,
|
ProofOfBridgeKnowledge::HashOfBucket(pok) => match bridge_info.bucket {
|
||||||
},
|
|
||||||
ProofOfBridgeKnowledge::HashOfBucket(pok) => match bucket {
|
|
||||||
Some(b) => {
|
Some(b) => {
|
||||||
let hash = HashOfBucket::new(b);
|
let hash = HashOfBucket::new(&b);
|
||||||
hash == pok
|
hash == pok
|
||||||
}
|
}
|
||||||
None => false,
|
None => false,
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// 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, IssuerPubKey};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sha1::{Digest, Sha1};
|
use sha1::{Digest, Sha1};
|
||||||
|
@ -111,13 +111,13 @@ impl PositiveReport {
|
||||||
/// the fingerprint listed in the report.
|
/// the fingerprint listed in the report.
|
||||||
pub fn verify_excluding_lox_proof(
|
pub fn verify_excluding_lox_proof(
|
||||||
self,
|
self,
|
||||||
bucket: Scalar,
|
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,6 +133,7 @@ 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;
|
||||||
|
|
Loading…
Reference in New Issue