| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
use crate::{ |
| 17 |
capability_check::{required_capability, Capability}, |
| 18 |
utilities::certs::{self, CertMaterials}, |
| 19 |
}; |
| 20 |
use brass_aphid_wire_decryption::decryption::{key_manager::KeyManager, Mode}; |
| 21 |
use brass_aphid_wire_messages::{ |
| 22 |
iana::{self, SignatureScheme}, |
| 23 |
protocol::content_value::{ContentValue, HandshakeMessageValue}, |
| 24 |
}; |
| 25 |
use openssl::ssl::SslContextBuilder; |
| 26 |
use s2n_tls::security::{Policy, DEFAULT_PQ}; |
| 27 |
use tls_harness::{ |
| 28 |
cohort::{OpenSslConnection, S2NConnection}, |
| 29 |
harness::TlsConfigBuilderPair, |
| 30 |
TlsConnPair, |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
fn trial(server_policy: &Policy, cert_materials: &CertMaterials) -> SignatureScheme { |
| 36 |
let key_manager = KeyManager::new(); |
| 37 |
|
| 38 |
let mut pair: TlsConnPair<OpenSslConnection, S2NConnection> = { |
| 39 |
let mut configs = |
| 40 |
TlsConfigBuilderPair::<SslContextBuilder, s2n_tls::config::Builder>::default_without_certs(); |
| 41 |
|
| 42 |
configs.client.set_ca_file(&cert_materials.ca_path).unwrap(); |
| 43 |
|
| 44 |
configs.server.set_security_policy(server_policy).unwrap(); |
| 45 |
configs.server.set_max_blinding_delay(0).unwrap(); |
| 46 |
configs |
| 47 |
.server |
| 48 |
.load_pem(&cert_materials.server_chain(), &cert_materials.server_key()) |
| 49 |
.unwrap(); |
| 50 |
key_manager.enable_s2n_logging(&mut configs.server); |
| 51 |
|
| 52 |
configs.connection_pair() |
| 53 |
}; |
| 54 |
pair.io.enable_decryption(key_manager.clone()); |
| 55 |
|
| 56 |
pair.handshake().unwrap(); |
| 57 |
pair.shutdown().unwrap(); |
| 58 |
|
| 59 |
let cert_verify = { |
| 60 |
let transcript = pair.io.decrypter.borrow().as_ref().unwrap().transcript(); |
| 61 |
let transcript = transcript.content_transcript.lock().unwrap().clone(); |
| 62 |
transcript |
| 63 |
.into_iter() |
| 64 |
.find_map(|(sender, message)| { |
| 65 |
if let ContentValue::Handshake(HandshakeMessageValue::CertVerifyTls13(verify)) = |
| 66 |
message |
| 67 |
{ |
| 68 |
assert_eq!(sender, Mode::Server); |
| 69 |
Some(verify) |
| 70 |
} else { |
| 71 |
None |
| 72 |
} |
| 73 |
}) |
| 74 |
.unwrap() |
| 75 |
}; |
| 76 |
cert_verify.algorithm |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
#[test] |
| 83 |
fn signature_selection() { |
| 84 |
|
| 85 |
{ |
| 86 |
let secp256r1 = CertMaterials::from_permutation("ec_ecdsa_p256_sha256"); |
| 87 |
let secp521r1 = CertMaterials::from_permutation("ec_ecdsa_p521_sha512"); |
| 88 |
|
| 89 |
|
| 90 |
let policy = Policy::from_version("20240503").unwrap(); |
| 91 |
|
| 92 |
assert_eq!( |
| 93 |
trial(&policy, &secp256r1), |
| 94 |
iana::constants::ecdsa_secp256r1_sha256 |
| 95 |
); |
| 96 |
assert_eq!( |
| 97 |
trial(&policy, &secp521r1), |
| 98 |
iana::constants::ecdsa_secp521r1_sha512 |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
required_capability(&[Capability::MLDsa], || { |
| 104 |
assert_eq!( |
| 105 |
trial(&DEFAULT_PQ, &certs::ML_DSA_87), |
| 106 |
iana::constants::mldsa87 |
| 107 |
); |
| 108 |
assert_eq!( |
| 109 |
trial(&DEFAULT_PQ, &certs::ML_DSA_44), |
| 110 |
iana::constants::mldsa44 |
| 111 |
); |
| 112 |
}); |
| 113 |
} |