From 76dd7246131059fb11925a61a971e445c9269429 Mon Sep 17 00:00:00 2001 From: Vecna Date: Wed, 17 Jan 2024 18:53:40 -0500 Subject: [PATCH] Add Lox proof for positive reports --- Cargo.toml | 4 ++-- src/lib.rs | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ffc1113..3f1d797 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ array-bytes = "6.2.0" bincode = "1" curve25519-dalek = { version = "4", default-features = false, features = ["serde", "rand_core", "digest"] } ed25519-dalek = { version = "2", features = ["serde", "rand_core"] } -lox-library = { git = "https://gitlab.torproject.org/tpo/anti-censorship/lox.git", version = "0.1.0" } -serde = "1.0.192" +lox-library = { git = "https://gitlab.torproject.org/vecna/lox.git", version = "0.1.0" } +serde = "1.0.195" serde_with = {version = "3.4.0", features = ["json"]} sha1 = "0.10" sha3 = "0.10" diff --git a/src/lib.rs b/src/lib.rs index 1ea34d2..8d04f27 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,8 @@ use curve25519_dalek::scalar::Scalar; use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey}; use lox_library::bridge_table::{BridgeLine, MAX_BRIDGES_PER_BUCKET}; use lox_library::cred::Lox; +use lox_library::IssuerPubKey; +use lox_library::proto::positive_report; use serde::{Deserialize, Serialize}; use sha1::{Digest, Sha1}; use sha3::Sha3_256; @@ -12,6 +14,10 @@ use rand::rngs::OsRng; // TODO: These should be loaded from config file pub const REQUIRE_BRIDGE_TOKEN: bool = true; +/// The minimum trust level a Lox credential must have to be allowed to +/// submit a positive report +pub const PR_MIN_TRUST_LEVEL: u32 = 3; + /// Get Julian date pub fn today() -> u32 { time::OffsetDateTime::now_utc() @@ -197,7 +203,8 @@ pub struct PositiveUserReport { pub fingerprint: [u8; 20], /// token from the bridge indicating it was reached bridge_token: Option, - // TODO: proof of level, something involving credential show + // proof of Lox cred with level >= 3 and this bridge + lox_proof: positive_report::Request, /// user's country code, may be an empty string pub country: String, /// today's Julian date @@ -205,7 +212,7 @@ pub struct PositiveUserReport { } impl PositiveUserReport { - pub fn new(bridge_id: [u8; 20], bridge_token: Option, country: String) -> Self { + pub fn new(bridge_id: [u8; 20], bridge_token: Option, lox_proof: positive_report::Request, country: String) -> Self { let mut hasher = Sha1::new(); hasher.update(bridge_id); let fingerprint: [u8; 20] = hasher.finalize().into(); @@ -213,11 +220,17 @@ impl PositiveUserReport { Self { fingerprint, bridge_token, + lox_proof, country, today, } } + pub fn from_lox_credential(bridge_id: [u8; 20], bridge_token: Option, lox_cred: &Lox, lox_pub: &IssuerPubKey, country: String) -> Self { + let lox_proof = positive_report::request(lox_cred, lox_pub).unwrap(); + PositiveUserReport::new(bridge_id, bridge_token, lox_proof, country) + } + fn verify(&self) -> bool { // possibly include check that self.today is recent as well self.today <= today()