Compare commits
2 Commits
68137981fc
...
58ab310a40
Author | SHA1 | Date |
---|---|---|
|
58ab310a40 | |
|
5935d3d78c |
|
@ -4,11 +4,9 @@ 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)]
|
||||
pub struct BridgeInfo {
|
||||
pub struct BridgeVerificationInfo {
|
||||
/// BridgeLine for this bridge
|
||||
pub bridge_line: BridgeLine,
|
||||
|
||||
|
@ -18,13 +16,3 @@ pub struct BridgeInfo {
|
|||
/// Key used to verify bridge tokens
|
||||
pub pubkey: Option<VerifyingKey>,
|
||||
}
|
||||
|
||||
impl BridgeInfo {
|
||||
pub fn new(bl: BridgeLine) -> Self {
|
||||
BridgeInfo {
|
||||
bridge_line: bl,
|
||||
buckets: HashSet::<Scalar>::new(),
|
||||
pubkey: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ use std::{
|
|||
io::BufReader,
|
||||
};
|
||||
|
||||
pub mod bridge_info;
|
||||
pub mod bridge_verification_info;
|
||||
pub mod extra_info;
|
||||
pub mod negative_report;
|
||||
pub mod positive_report;
|
||||
|
@ -20,7 +20,7 @@ use positive_report::*;
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub db: DbConfig,
|
||||
require_bridge_token: bool,
|
||||
//require_bridge_token: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use crate::{bridge_info::BridgeInfo, get_date, BridgeDistributor, COUNTRY_CODES};
|
||||
use crate::{
|
||||
bridge_verification_info::BridgeVerificationInfo, get_date, BridgeDistributor, COUNTRY_CODES,
|
||||
};
|
||||
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use lox_library::{bridge_table::BridgeLine, cred::Lox};
|
||||
|
@ -101,7 +103,7 @@ impl NegativeReport {
|
|||
}
|
||||
|
||||
/// Verify the report
|
||||
pub fn verify(self, bridge_info: &BridgeInfo) -> bool {
|
||||
pub fn verify(self, bridge_info: &BridgeVerificationInfo) -> bool {
|
||||
match self.bridge_pok {
|
||||
ProofOfBridgeKnowledge::HashOfBridgeLine(pok) => {
|
||||
let hash = HashOfBridgeLine::new(&bridge_info.bridge_line);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// For Lox-related code where points are uppercase and scalars are lowercase
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use crate::{bridge_info::BridgeInfo, get_date, CONFIG, COUNTRY_CODES};
|
||||
use crate::{bridge_verification_info::BridgeVerificationInfo, get_date, CONFIG, COUNTRY_CODES};
|
||||
|
||||
use curve25519_dalek::ristretto::RistrettoBasepointTable;
|
||||
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier};
|
||||
|
@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
|
|||
use sha1::{Digest, Sha1};
|
||||
use std::option::Option;
|
||||
|
||||
pub const REQUIRE_BRIDGE_TOKEN: bool = false;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PositiveReportError {
|
||||
DateInFuture,
|
||||
|
@ -46,7 +48,8 @@ impl PositiveReport {
|
|||
lox_proof: lox_pr::Request,
|
||||
country: String,
|
||||
) -> Self {
|
||||
if CONFIG.require_bridge_token && bridge_token.is_none() {
|
||||
//if CONFIG.require_bridge_token && bridge_token.is_none() {
|
||||
if REQUIRE_BRIDGE_TOKEN && bridge_token.is_none() {
|
||||
panic!("Bridge tokens are required for positive reports.");
|
||||
}
|
||||
let mut hasher = Sha1::new();
|
||||
|
@ -106,11 +109,12 @@ impl PositiveReport {
|
|||
pub fn verify(
|
||||
self,
|
||||
la: &mut BridgeAuth,
|
||||
bridge_info: &BridgeInfo,
|
||||
bridge_info: &BridgeVerificationInfo,
|
||||
Htable: &RistrettoBasepointTable,
|
||||
) -> bool {
|
||||
// Verify bridge token
|
||||
if CONFIG.require_bridge_token {
|
||||
//if CONFIG.require_bridge_token {
|
||||
if REQUIRE_BRIDGE_TOKEN {
|
||||
let bridge_token = self.bridge_token.unwrap();
|
||||
let bridge_key = bridge_info.pubkey;
|
||||
if bridge_key.is_none() {
|
||||
|
@ -153,7 +157,8 @@ pub struct SerializablePositiveReport {
|
|||
impl SerializablePositiveReport {
|
||||
pub fn to_report(self) -> Result<PositiveReport, PositiveReportError> {
|
||||
// Check that fields are valid
|
||||
if CONFIG.require_bridge_token && self.bridge_token.is_none() {
|
||||
//if CONFIG.require_bridge_token && self.bridge_token.is_none() {
|
||||
if REQUIRE_BRIDGE_TOKEN && self.bridge_token.is_none() {
|
||||
return Err(PositiveReportError::MissingBridgeToken);
|
||||
}
|
||||
if self.country == "" {
|
||||
|
|
Loading…
Reference in New Issue