|
@@ -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()
|