Add Lox proof for positive reports

This commit is contained in:
Vecna 2024-01-17 18:53:40 -05:00
parent 326d7e5560
commit 76dd724613
2 changed files with 17 additions and 4 deletions

View File

@ -10,8 +10,8 @@ array-bytes = "6.2.0"
bincode = "1" bincode = "1"
curve25519-dalek = { version = "4", default-features = false, features = ["serde", "rand_core", "digest"] } curve25519-dalek = { version = "4", default-features = false, features = ["serde", "rand_core", "digest"] }
ed25519-dalek = { version = "2", features = ["serde", "rand_core"] } ed25519-dalek = { version = "2", features = ["serde", "rand_core"] }
lox-library = { git = "https://gitlab.torproject.org/tpo/anti-censorship/lox.git", version = "0.1.0" } lox-library = { git = "https://gitlab.torproject.org/vecna/lox.git", version = "0.1.0" }
serde = "1.0.192" serde = "1.0.195"
serde_with = {version = "3.4.0", features = ["json"]} serde_with = {version = "3.4.0", features = ["json"]}
sha1 = "0.10" sha1 = "0.10"
sha3 = "0.10" sha3 = "0.10"

View File

@ -2,6 +2,8 @@ use curve25519_dalek::scalar::Scalar;
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey}; use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
use lox_library::bridge_table::{BridgeLine, MAX_BRIDGES_PER_BUCKET}; use lox_library::bridge_table::{BridgeLine, MAX_BRIDGES_PER_BUCKET};
use lox_library::cred::Lox; use lox_library::cred::Lox;
use lox_library::IssuerPubKey;
use lox_library::proto::positive_report;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sha1::{Digest, Sha1}; use sha1::{Digest, Sha1};
use sha3::Sha3_256; use sha3::Sha3_256;
@ -12,6 +14,10 @@ use rand::rngs::OsRng;
// TODO: These should be loaded from config file // TODO: These should be loaded from config file
pub const REQUIRE_BRIDGE_TOKEN: bool = true; 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 /// Get Julian date
pub fn today() -> u32 { pub fn today() -> u32 {
time::OffsetDateTime::now_utc() time::OffsetDateTime::now_utc()
@ -197,7 +203,8 @@ pub struct PositiveUserReport {
pub fingerprint: [u8; 20], pub fingerprint: [u8; 20],
/// token from the bridge indicating it was reached /// token from the bridge indicating it was reached
bridge_token: Option<BridgeToken>, bridge_token: Option<BridgeToken>,
// 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 /// user's country code, may be an empty string
pub country: String, pub country: String,
/// today's Julian date /// today's Julian date
@ -205,7 +212,7 @@ pub struct PositiveUserReport {
} }
impl PositiveUserReport { impl PositiveUserReport {
pub fn new(bridge_id: [u8; 20], bridge_token: Option<BridgeToken>, country: String) -> Self { pub fn new(bridge_id: [u8; 20], bridge_token: Option<BridgeToken>, lox_proof: positive_report::Request, country: String) -> Self {
let mut hasher = Sha1::new(); let mut hasher = Sha1::new();
hasher.update(bridge_id); hasher.update(bridge_id);
let fingerprint: [u8; 20] = hasher.finalize().into(); let fingerprint: [u8; 20] = hasher.finalize().into();
@ -213,11 +220,17 @@ impl PositiveUserReport {
Self { Self {
fingerprint, fingerprint,
bridge_token, bridge_token,
lox_proof,
country, country,
today, today,
} }
} }
pub fn from_lox_credential(bridge_id: [u8; 20], bridge_token: Option<BridgeToken>, 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 { fn verify(&self) -> bool {
// possibly include check that self.today is recent as well // possibly include check that self.today is recent as well
self.today <= today() self.today <= today()