Sfoglia il codice sorgente

Add Lox proof for positive reports

Vecna 4 mesi fa
parent
commit
76dd724613
2 ha cambiato i file con 17 aggiunte e 4 eliminazioni
  1. 2 2
      Cargo.toml
  2. 15 2
      src/lib.rs

+ 2 - 2
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"

+ 15 - 2
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<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
     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<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();
         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<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 {
         // possibly include check that self.today is recent as well
         self.today <= today()