Skip to content
Merged
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
10 changes: 5 additions & 5 deletions ooniauth-core/benches/bench_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn setup() -> (ThreadRng, UserState, ServerState) {
// For now we will only care about server functions, specially handling submit and
// registration, since those are the most important bottleneck for our backend
fn bench_registration(c: &mut Criterion) {
let (mut rng, user, mut server) = setup();
let (mut rng, user, server) = setup();

// Create the request
let (registration_req, _) = user.request(&mut rng).unwrap();
Expand All @@ -25,14 +25,14 @@ fn bench_registration(c: &mut Criterion) {
}

fn bench_submit(c: &mut Criterion) {
let (mut rng, mut user, mut server) = setup();
let (mut rng, mut user, server) = setup();

c.bench_function("server.handle_submit", |b| {
let (registration_req, reg_state) = user.request(&mut rng).unwrap();
let resp = server.open_registration(registration_req).unwrap();
user.handle_response(reg_state, resp)
.expect("Should handle response properly");
let today = server.today();
let today = ServerState::today();
let cc = "VE";
let asn = "AS1234";

Expand All @@ -52,8 +52,8 @@ fn bench_submit(c: &mut Criterion) {
black_box(&mut rng),
black_box(req.clone()),
black_box(&nym),
black_box(cc.into()),
black_box(asn.into()),
black_box(cc),
black_box(asn),
black_box(age_range.clone()),
black_box(msm_range.clone()),
)
Expand Down
15 changes: 14 additions & 1 deletion ooniauth-core/src/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ CMZ! { UserAuthCredential:
measurement_count
}

impl UserAuthCredential {
/// Set the public key and private key for this credential. Assumes the keypair is well-formed.
pub(crate) fn set_keypair(
&mut self,
privkey: CMZPrivkey<G>,
pubkey: CMZPubkey<G>,
) -> &mut Self {
self.privkey = privkey;
self.pubkey = pubkey;
self
}
}

muCMZProtocol! {open_registration,
,
UAC: UserAuthCredential { nym_id: J, age: S, measurement_count: I},
Expand Down Expand Up @@ -76,7 +89,7 @@ impl ServerState {
SESSION_ID,
recvreq,
|UAC: &mut UserAuthCredential| {
UAC.set_privkey(&self.sk);
UAC.set_keypair(self.sk.clone(), self.pp.clone());
UAC.measurement_count = Some(Scalar::ZERO);
UAC.age = Some(ServerState::today().into());
Ok(())
Expand Down
7 changes: 4 additions & 3 deletions ooniauth-core/src/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ impl ServerState {
};

let server_sk = self.sk.clone();
let server_pp = self.pp.clone();
match submit::handle(
rng,
SESSION_ID,
recvreq,
move |Old: &mut UserAuthCredential, New: &mut UserAuthCredential| {
// Set the private key for the credentials - this is essential for the protocol
Old.set_privkey(&server_sk);
New.set_privkey(&server_sk);
Old.set_keypair(server_sk.clone(), server_pp.clone());
New.set_keypair(server_sk.clone(), server_pp.clone());

// The protocol should populate Old and New from the client's proof
// We don't set the values here - they come from the client's proof
Expand Down Expand Up @@ -231,7 +232,7 @@ mod tests {
let rng = &mut rand::thread_rng();

// Setup server and user
let mut server_state = ServerState::new(rng);
let server_state = ServerState::new(rng);
let mut user_state = UserState::new(server_state.public_parameters());

// First do registration to get a credential
Expand Down