|
|
@@ -14,22 +14,15 @@ The credential will have attributes:
|
|
|
*/
|
|
|
|
|
|
#[cfg(feature = "bridgeauth")]
|
|
|
-use super::super::bridge_table;
|
|
|
-#[cfg(feature = "bridgeauth")]
|
|
|
-use super::super::bridge_table::BridgeLine;
|
|
|
-#[cfg(feature = "bridgeauth")]
|
|
|
-use super::super::dup_filter::SeenType;
|
|
|
-#[cfg(feature = "bridgeauth")]
|
|
|
-use super::super::OPENINV_LENGTH;
|
|
|
-#[cfg(feature = "bridgeauth")]
|
|
|
-use super::super::{BridgeAuth, BridgeDb};
|
|
|
+use super::super::{
|
|
|
+ bridge_table::{self, BridgeLine},
|
|
|
+ dup_filter::SeenType,
|
|
|
+ BridgeAuth, BridgeDb, OPENINV_LENGTH,
|
|
|
+};
|
|
|
+use super::super::{Scalar, G};
|
|
|
use super::errors::CredentialError;
|
|
|
use crate::lox_creds::Lox;
|
|
|
use cmz::*;
|
|
|
-use curve25519_dalek::ristretto::RistrettoPoint as G;
|
|
|
-#[cfg(feature = "bridgeauth")]
|
|
|
-use curve25519_dalek::scalar::Scalar;
|
|
|
-use group::Group;
|
|
|
use rand_core::RngCore;
|
|
|
use sha2::Sha512;
|
|
|
|
|
|
@@ -47,8 +40,13 @@ pub fn request(
|
|
|
let mut rng = rand::thread_rng();
|
|
|
cmz_group_init(G::hash_from_bytes::<Sha512>(b"CMZ Generator A"));
|
|
|
|
|
|
- let L = Lox::using_pubkey(&pubkeys);
|
|
|
-
|
|
|
+ let mut L = Lox::using_pubkey(&pubkeys);
|
|
|
+ L.id = Some(Scalar::random(&mut rng));
|
|
|
+ L.bucket = Some(Scalar::ZERO);
|
|
|
+ L.trust_level = Some(Scalar::ZERO);
|
|
|
+ L.level_since = Some(Scalar::ZERO);
|
|
|
+ L.invites_remaining = Some(Scalar::ZERO);
|
|
|
+ L.blockages = Some(Scalar::ZERO);
|
|
|
match open_invitation::prepare(&mut rng, L) {
|
|
|
Ok(req_state) => Ok(req_state),
|
|
|
Err(e) => Err(CredentialError::CMZError(e)),
|
|
|
@@ -154,3 +152,29 @@ pub fn handle_response(
|
|
|
Err(_e) => Err(CMZError::Unknown),
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+#[cfg(all(test, feature = "bridgeauth"))]
|
|
|
+mod tests {
|
|
|
+ use super::*;
|
|
|
+ use crate::mock_auth::TestHarness;
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn test_open_invitation() {
|
|
|
+ let mut th = TestHarness::new();
|
|
|
+ let open_invitation_request = request(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, bridgeline) = open_invitation_response.unwrap();
|
|
|
+ let creds = handle_response(client_state, response);
|
|
|
+ assert!(creds.is_ok(), "Handle response should succeed");
|
|
|
+ }
|
|
|
+}
|