|
|
@@ -67,7 +67,7 @@ muCMZProtocol! { trust_promotion<credential_expiry, eligibility_max_age>,
|
|
|
pub fn request(
|
|
|
rng: &mut (impl CryptoRng + RngCore),
|
|
|
L: Lox,
|
|
|
- mig_pubkeys: CMZPubkey<G>,
|
|
|
+ migkey_pubkeys: CMZPubkey<G>,
|
|
|
today: u32,
|
|
|
) -> Result<(trust_promotion::Request, trust_promotion::ClientState), CredentialError> {
|
|
|
cmz_group_init(G::hash_from_bytes::<Sha512>(b"CMZ Generator A"));
|
|
|
@@ -107,14 +107,10 @@ pub fn request(
|
|
|
credential_expiry: (eligibility_max_age - 511).into(),
|
|
|
eligibility_max_age: eligibility_max_age.into(),
|
|
|
};
|
|
|
-
|
|
|
- match trust_promotion::prepare(
|
|
|
- rng,
|
|
|
- SESSION_ID,
|
|
|
- &L,
|
|
|
- MigrationKey::using_pubkey(&mig_pubkeys),
|
|
|
- ¶ms,
|
|
|
- ) {
|
|
|
+ let mut M = MigrationKey::using_pubkey(&migkey_pubkeys);
|
|
|
+ M.lox_id = L.id;
|
|
|
+ M.from_bucket = L.bucket;
|
|
|
+ match trust_promotion::prepare(rng, SESSION_ID, &L, M, ¶ms) {
|
|
|
Ok(req_state) => Ok(req_state),
|
|
|
Err(e) => Err(CredentialError::CMZError(e)),
|
|
|
}
|
|
|
@@ -196,3 +192,54 @@ pub fn handle_response(
|
|
|
None => Err(CMZError::Unknown),
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+#[cfg(all(test, feature = "bridgeauth"))]
|
|
|
+mod tests {
|
|
|
+ use super::*;
|
|
|
+ use crate::mock_auth::TestHarness;
|
|
|
+ use crate::proto::{open_invite, trust_promotion};
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn test_trust_promotion() {
|
|
|
+ let mut th = TestHarness::new();
|
|
|
+ let rng = &mut rand::thread_rng();
|
|
|
+ let open_invitation_request = open_invite::request(rng, th.ba.lox_pub.clone());
|
|
|
+ assert!(
|
|
|
+ open_invitation_request.is_ok(),
|
|
|
+ "Open invitation request should succeed"
|
|
|
+ );
|
|
|
+ let (request, client_state) = open_invitation_request.unwrap();
|
|
|
+ let invite = th.bdb.invite();
|
|
|
+ let open_invitation_response = th.ba.open_invitation(request, &invite.unwrap());
|
|
|
+ assert!(
|
|
|
+ open_invitation_response.is_ok(),
|
|
|
+ "Open invitation response from server should succeed"
|
|
|
+ );
|
|
|
+ let (response, _) = open_invitation_response.unwrap();
|
|
|
+ let creds = open_invite::handle_response(client_state, response);
|
|
|
+ println!("{}", th.ba.today());
|
|
|
+ assert!(creds.is_ok(), "Handle response should succeed");
|
|
|
+ th.advance_days((UNTRUSTED_INTERVAL + 1).try_into().unwrap());
|
|
|
+ println!("{}", th.ba.today());
|
|
|
+ let trust_promo_request = trust_promotion::request(
|
|
|
+ rng,
|
|
|
+ creds.unwrap(),
|
|
|
+ th.ba.migrationkey_pub.clone(),
|
|
|
+ th.ba.today(),
|
|
|
+ );
|
|
|
+ assert!(
|
|
|
+ trust_promo_request.is_ok(),
|
|
|
+ "Trust Promotion request should succeed"
|
|
|
+ );
|
|
|
+ let (tp_request, tp_client_state) = trust_promo_request.unwrap();
|
|
|
+ let trust_promo_response = th.ba.handle_trust_promotion(tp_request);
|
|
|
+ assert!(
|
|
|
+ trust_promo_response.is_ok(),
|
|
|
+ "Trust promotion response from server should succeed"
|
|
|
+ );
|
|
|
+ let (response, enc) = trust_promo_response.unwrap();
|
|
|
+ let creds =
|
|
|
+ trust_promotion::handle_response(th.ba.migration_pub, tp_client_state, response, enc);
|
|
|
+ assert!(creds.is_ok(), "Handle response should succeed");
|
|
|
+ }
|
|
|
+}
|