| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
use crate::{ |
| 5 |
harness::{TlsConfigBuilder, TlsConfigBuilderPair}, |
| 6 |
TlsConnPair, TlsConnection, |
| 7 |
}; |
| 8 |
|
| 9 |
|
| 10 |
pub fn handshake<C, B>() |
| 11 |
where |
| 12 |
C: TlsConnection, |
| 13 |
B: TlsConfigBuilder<Config = C::Config>, |
| 14 |
{ |
| 15 |
let mut conn_pair: TlsConnPair<C, C> = { |
| 16 |
let config_pair: TlsConfigBuilderPair<B, B> = TlsConfigBuilderPair::default(); |
| 17 |
config_pair.connection_pair() |
| 18 |
}; |
| 19 |
conn_pair.handshake().unwrap(); |
| 20 |
conn_pair.round_trip_transfer(&mut [0]).unwrap(); |
| 21 |
conn_pair.shutdown().unwrap(); |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
pub fn transfer<C, B>() |
| 26 |
where |
| 27 |
C: TlsConnection, |
| 28 |
B: TlsConfigBuilder<Config = C::Config>, |
| 29 |
{ |
| 30 |
let mut conn_pair: TlsConnPair<C, C> = { |
| 31 |
let config_pair: TlsConfigBuilderPair<B, B> = TlsConfigBuilderPair::default(); |
| 32 |
config_pair.connection_pair() |
| 33 |
}; |
| 34 |
conn_pair.handshake().unwrap(); |
| 35 |
let mut data = [0; 1_000_000]; |
| 36 |
conn_pair.round_trip_transfer(&mut data).unwrap(); |
| 37 |
conn_pair.shutdown().unwrap(); |
| 38 |
} |
| 39 |
|
| 40 |
#[cfg(test)] |
| 41 |
mod tests { |
| 42 |
use super::*; |
| 43 |
use brass_aphid_wire_decryption::decryption::key_manager::KeyManager; |
| 44 |
use brass_aphid_wire_messages::iana; |
| 45 |
use openssl::ssl::SslContextBuilder; |
| 46 |
|
| 47 |
use crate::{ |
| 48 |
cohort::{OpenSslConnection, S2NConnection}, |
| 49 |
TlsConnPair, |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
#[test] |
| 55 |
fn tls13_decryption() { |
| 56 |
let key_manager = KeyManager::new(); |
| 57 |
let mut pair: TlsConnPair<OpenSslConnection, S2NConnection> = { |
| 58 |
let mut configs = |
| 59 |
TlsConfigBuilderPair::<SslContextBuilder, s2n_tls::config::Builder>::default(); |
| 60 |
configs |
| 61 |
.server |
| 62 |
.set_security_policy(&s2n_tls::security::DEFAULT) |
| 63 |
.unwrap(); |
| 64 |
key_manager.enable_s2n_logging(&mut configs.server); |
| 65 |
configs.client.set_groups_list("x448:secp256r1").unwrap(); |
| 66 |
configs.connection_pair() |
| 67 |
}; |
| 68 |
pair.io.enable_recording(); |
| 69 |
pair.io.enable_decryption(key_manager.clone()); |
| 70 |
|
| 71 |
pair.handshake().unwrap(); |
| 72 |
pair.shutdown().unwrap(); |
| 73 |
|
| 74 |
let transcript = pair.io.decrypter.borrow(); |
| 75 |
let transcript = transcript.as_ref().unwrap().transcript(); |
| 76 |
let ch = transcript.client_hellos().first().unwrap().clone(); |
| 77 |
let client_key_shares = ch.key_share().unwrap(); |
| 78 |
let client_supported_groups = ch.supported_groups().unwrap(); |
| 79 |
|
| 80 |
|
| 81 |
assert_eq!(client_key_shares, vec![iana::constants::x448]); |
| 82 |
assert_eq!( |
| 83 |
client_supported_groups, |
| 84 |
vec![iana::constants::x448, iana::constants::secp256r1] |
| 85 |
); |
| 86 |
|
| 87 |
|
| 88 |
let sh = transcript.server_hello(); |
| 89 |
let selected_group = sh.selected_group().unwrap().unwrap(); |
| 90 |
assert_eq!(selected_group, iana::constants::secp256r1); |
| 91 |
|
| 92 |
|
| 93 |
assert!(transcript.hello_retry_request().is_some()); |
| 94 |
} |
| 95 |
} |