Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 140 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ resolver = "2"
[patch.crates-io]
cmz = { path = "include/cmz" }
sigma-compiler-core = { path = "include/sigma-compiler/sigma-compiler-core" }
sigma-proofs = { path = "include/sigma-proofs" }
4 changes: 4 additions & 0 deletions ooniauth-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ subtle = "2.6.1"
thiserror = "2.0.12"
syn = "2.0.103"
hex = "0.4"
tracing = "0.1"

[dev-dependencies]
criterion = { version = "0.5"}
tracing-subscriber = { version = "0.3", features = ["env-filter", "registry"] }
tracing-forest = "0.1"

[[example]]
name = "basic_usage"
Expand All @@ -32,3 +35,4 @@ test = true
[[bench]]
name = "bench_server"
harness = false

14 changes: 14 additions & 0 deletions ooniauth-core/examples/basic_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ use std::time::Instant;

use hex;
use ooniauth_core::{scalar_u32, ServerState, UserState};
use tracing_forest::ForestLayer;
use tracing_forest::util::LevelFilter;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{EnvFilter, Registry};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize tracing with forest layer for runtime display
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy();

Registry::default()
.with(env_filter)
.with(ForestLayer::default())
.init();
let mut rng = rand::thread_rng();

println!("=== Anonymous Credential Example ===\n");
Expand Down
30 changes: 26 additions & 4 deletions ooniauth-core/src/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use curve25519_dalek::RistrettoPoint;
use group::{Group, GroupEncoding};
use rand::{CryptoRng, RngCore};
use sha2::Sha512;
use tracing::{instrument, trace, debug};

const SESSION_ID: &[u8] = b"submit";

Expand All @@ -24,6 +25,7 @@ muCMZProtocol!(submit<min_age_today, max_age, min_measurement_count,
);

impl UserState {
#[instrument(skip(self, rng))]
pub fn submit_request(
&self,
rng: &mut (impl RngCore + CryptoRng),
Expand All @@ -32,6 +34,8 @@ impl UserState {
age_range: std::ops::Range<u32>,
measurement_count_range: std::ops::Range<u32>,
) -> Result<((submit::Request, submit::ClientState), [u8; 32]), CredentialError> {
trace!("Starting submit request");
debug!("Age range: {:?}, Measurement count range: {:?}", age_range, measurement_count_range);
cmz_group_init(G::hash_from_bytes::<Sha512>(b"CMZ Generator A"));

// Get the current credential
Expand All @@ -45,8 +49,10 @@ impl UserState {

// Domain-specific generator and NYM computation
let domain_str = format!("ooni.org/{}/{}", probe_cc, probe_asn);
trace!("Computing DOMAIN for: {}", domain_str);
let DOMAIN = G::hash_from_bytes::<Sha512>(domain_str.as_bytes());
let NYM = Old.nym_id.unwrap() * DOMAIN;
debug!("NYM computed successfully");

// Ensure the credential timestamp is within the allowed range
let age: u32 = match scalar_u32(&Old.age.unwrap()) {
Expand Down Expand Up @@ -115,9 +121,16 @@ impl UserState {
NYM,
};

trace!("Preparing submit proof with params");
match submit::prepare(rng, SESSION_ID, &Old, New, &params) {
Ok(req_state) => Ok((req_state, NYM.compress().to_bytes())),
Err(_) => Err(CredentialError::CMZError(CMZError::CliProofFailed)),
Ok(req_state) => {
debug!("Submit request prepared successfully");
Ok((req_state, NYM.compress().to_bytes()))
}
Err(_) => {
debug!("Failed to prepare submit request");
Err(CredentialError::CMZError(CMZError::CliProofFailed))
}
}
}

Expand All @@ -139,6 +152,7 @@ impl UserState {
}

impl ServerState {
#[instrument(skip(self, rng, req))]
pub fn handle_submit(
&mut self,
rng: &mut (impl RngCore + CryptoRng),
Expand All @@ -149,6 +163,8 @@ impl ServerState {
age_range: std::ops::Range<u32>,
measurement_count_range: std::ops::Range<u32>,
) -> Result<submit::Reply, CMZError> {
trace!("Server handling submit request");
debug!("Age range: {:?}, Measurement count range: {:?}", age_range, measurement_count_range);
let reqbytes = req.as_bytes();

let recvreq = submit::Request::try_from(&reqbytes[..]).unwrap();
Expand Down Expand Up @@ -189,8 +205,14 @@ impl ServerState {
Ok(())
},
) {
Ok((response, (_old_cred, _new_cred))) => Ok(response),
Err(e) => Err(e),
Ok((response, (_old_cred, _new_cred))) => {
debug!("Submit request verified successfully");
Ok(response)
}
Err(e) => {
debug!("Submit request verification failed: {:?}", e);
Err(e)
}
}
}
}
Expand Down