Commit 1e6e634e authored by onyinyang's avatar onyinyang 🔒
Browse files

Implement uCMZ for update_cred

parent 2d2cc6a0
Loading
Loading
Loading
Loading
+9 −1
Changes for crates/lox-distributor/src/request_handler.rs: 9 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -763,12 +763,20 @@ mod tests {
                e.to_string()
            ),
        };

        let old_keys = pubkeys_obj.lox_pub;
        // Rotate Keys
        th.rotate_lox_keys();

        // Get pubkeys
        pubkey_request = lc.pubkeys();
        pubkey_response = handle(th.context.clone(), pubkey_request).await.unwrap();
        pubkeys = body_to_string(pubkey_response).await;
        pubkeys_obj = serde_json::from_str(&pubkeys).unwrap();

        // Test Upgrade Cred
        let update_cred_request =
            match proto::update_cred::request(&new_migrated_cred, &pubkeys_obj.lox_pub) {
            match proto::update_cred::request(&new_migrated_cred, &old_keys, &pubkeys_obj.lox_pub) {
                Ok(update_cred_request) => update_cred_request,
                Err(e) => panic!(
                    "Error: Proof error from update credential {:?}",
+78 −323

File changed.

Preview size limit exceeded, changes collapsed.

+19 −6
Changes for crates/lox-library/src/tests.rs: 19 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ impl TestHarness {
        let (req, state) = update_cred::request(
            cred,
            &self.ba.old_keys.lox_keys.clone().last().unwrap().pub_key,
            &self.ba.lox_pub,
        )
        .unwrap();
        let encoded: Vec<u8> = bincode::serialize(&req).unwrap();
@@ -777,7 +778,7 @@ fn test_update_cred() {
    let cred = th.open_invite().1 .0;

    // Attempt to update credential with new keys before next request
    let (up_req, _upstate) = update_cred::request(&cred, &th.ba.lox_pub).unwrap();
    let (up_req, _upstate) = update_cred::request(&cred, &th.ba.lox_pub, &th.ba.lox_pub).unwrap();
    let encoded: Vec<u8> = bincode::serialize(&up_req).unwrap();
    let decoded = bincode::deserialize(&encoded[..]).unwrap();
    let promresp = th.ba.handle_update_cred(decoded);
@@ -789,6 +790,8 @@ fn test_update_cred() {
    // Time passes
    th.advance_days(47);

    let mut old_key = th.ba.lox_pub.clone();

    // Rotate Keys
    th.ba.rotate_lox_keys();

@@ -804,10 +807,10 @@ fn test_update_cred() {
    );

    // Update credential with new keys before next request
    let (perf_stat, up_cred) = th.update_cred(&cred);
    let (_, up_cred) = th.update_cred(&cred);

    // Attempt Update credential with used credential
    let (upreq, _upstate) = update_cred::request(&cred, &th.ba.lox_pub).unwrap();
    let (upreq, _upstate) = update_cred::request(&cred, &old_key, &th.ba.lox_pub).unwrap();
    let encoded: Vec<u8> = bincode::serialize(&upreq).unwrap();
    let decoded = bincode::deserialize(&encoded[..]).unwrap();
    let promresp = th.ba.handle_update_cred(decoded);
@@ -819,26 +822,36 @@ fn test_update_cred() {
    // Successfully go up to level 1 with updated credential
    let (_, migcred) = th.trust_promotion(&up_cred);
    println!("--Trust Promotion to 1--\n");
    print_test_results(perf_stat);

    let (_perf_stat, cred1) = th.level0_migration(&up_cred, &migcred);
    println!("--New Level 1 Credential--\n");
    assert!(scalar_u32(&cred1.trust_level).unwrap() == 1);

    // Attempt to update credential with new keys before next request
    let (up_req, _upstate) = update_cred::request(&cred1, &th.ba.lox_pub).unwrap();
    let (up_req, _upstate) = update_cred::request(&cred1, &old_key, &th.ba.lox_pub).unwrap();
    let encoded: Vec<u8> = bincode::serialize(&up_req).unwrap();
    let mut decoded = bincode::deserialize(&encoded[..]).unwrap();
    let mut promresp = th.ba.handle_update_cred(decoded);
    assert!(promresp.is_err(), "Before another key rotation, credential update requests should fail due to verification with wrong pubkey");

    old_key = th.ba.lox_pub.clone();
    // Rotate Keys
    th.ba.rotate_lox_keys();
    decoded = bincode::deserialize(&encoded[..]).unwrap();
    promresp = th.ba.handle_update_cred(decoded);
    assert!(
        promresp.is_err(),
        "An updated credential prepared before the key rotation shouldn't work after the key rotation"
    );

    // Updated request should once again work
    let (up_req, _upstate) = update_cred::request(&cred1, &old_key, &th.ba.lox_pub).unwrap();
    let encoded: Vec<u8> = bincode::serialize(&up_req).unwrap();
    decoded = bincode::deserialize(&encoded[..]).unwrap();
    promresp = th.ba.handle_update_cred(decoded);
    assert!(
        promresp.is_ok(),
        "The credential update request should succeed after key rotation"
        "After key rotation, update cred should verify with correct keys"
    );
}

+9 −5

File changed.

Preview size limit exceeded, changes collapsed.