1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#![deny(unsafe_code)]
#![warn(
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
unused_qualifications
)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "std")]
extern crate core;
#[cfg(feature = "alloc")]
#[macro_use]
extern crate alloc;
mod error;
pub use error::*;
use ockam_core::AsyncTryClone;
pub const SHA256_SIZE: usize = 32;
pub const AES_GCM_TAGSIZE: usize = 16;
pub trait XXVault:
SecretVault + Hasher + AsymmetricVault + SymmetricVault + AsyncTryClone + Send + Sync + 'static
{
}
impl<D> XXVault for D where
D: SecretVault
+ Hasher
+ AsymmetricVault
+ SymmetricVault
+ AsyncTryClone
+ Send
+ Sync
+ 'static
{
}
mod initiator;
mod state;
pub use initiator::*;
mod responder;
pub use responder::*;
mod new_key_exchanger;
pub use new_key_exchanger::*;
use ockam_core::vault::{AsymmetricVault, Hasher, SecretVault, SymmetricVault};
#[cfg(test)]
mod tests {
use super::*;
use ockam_key_exchange_core::{KeyExchanger, NewKeyExchanger};
use ockam_vault_sync_core::Vault;
#[allow(non_snake_case)]
#[test]
fn full_flow__correct_credentials__keys_should_match() {
let (mut ctx, mut exec) = ockam_node::start_node();
exec.execute(async move {
let mut vault = Vault::create();
let key_exchanger = XXNewKeyExchanger::new(vault.async_try_clone().await.unwrap());
let mut initiator = key_exchanger.initiator().await.unwrap();
let mut responder = key_exchanger.responder().await.unwrap();
loop {
if !initiator.is_complete().await.unwrap() {
let m = initiator.generate_request(&[]).await.unwrap();
let _ = responder.handle_response(&m).await.unwrap();
}
if !responder.is_complete().await.unwrap() {
let m = responder.generate_request(&[]).await.unwrap();
let _ = initiator.handle_response(&m).await.unwrap();
}
if initiator.is_complete().await.unwrap() && responder.is_complete().await.unwrap()
{
break;
}
}
let initiator = initiator.finalize().await.unwrap();
let responder = responder.finalize().await.unwrap();
assert_eq!(initiator.h(), responder.h());
let s1 = vault.secret_export(initiator.encrypt_key()).await.unwrap();
let s2 = vault.secret_export(responder.decrypt_key()).await.unwrap();
assert_eq!(s1, s2);
let s1 = vault.secret_export(initiator.decrypt_key()).await.unwrap();
let s2 = vault.secret_export(responder.encrypt_key()).await.unwrap();
assert_eq!(s1, s2);
ctx.stop().await.unwrap();
})
.unwrap();
}
}