use tls_core::{
key::{Certificate, PublicKey},
msgs::{
codec::Codec,
enums::{NamedGroup, SignatureScheme},
handshake::{DigitallySignedStruct, Random, ServerECDHParams},
},
};
use hex::FromHex;
pub struct TestData {
pub ee: Certificate,
pub inter: Certificate,
pub ca: Certificate,
pub cr: Random,
pub sr: Random,
pub pubkey: PublicKey,
pub sig: Vec<u8>,
pub time: u64,
pub sig_scheme: SignatureScheme,
pub dns_name: String,
}
impl TestData {
pub fn kx_params(&self) -> Vec<u8> {
let mut params = Vec::new();
let ecdh_params = ServerECDHParams::new(NamedGroup::secp256r1, &self.pubkey.key);
ecdh_params.encode(&mut params);
params
}
pub fn dss(&self) -> DigitallySignedStruct {
DigitallySignedStruct::new(self.sig_scheme, self.sig.clone())
}
pub fn signature_msg(&self) -> Vec<u8> {
let mut msg = Vec::new();
msg.extend_from_slice(&self.cr.0);
msg.extend_from_slice(&self.sr.0);
msg.extend_from_slice(&self.kx_params());
msg
}
}
pub fn tlsnotary() -> TestData {
TestData {
ee: Certificate(include_bytes!("testdata/key_exchange/tlsnotary.org/ee.der").to_vec()),
inter: Certificate(
include_bytes!("testdata/key_exchange/tlsnotary.org/inter.der").to_vec(),
),
ca: Certificate(include_bytes!("testdata/key_exchange/tlsnotary.org/ca.der").to_vec()),
cr: Random(
<[u8; 32]>::from_hex(include_bytes!(
"testdata/key_exchange/tlsnotary.org/client_random"
))
.unwrap(),
),
sr: Random(
<[u8; 32]>::from_hex(include_bytes!(
"testdata/key_exchange/tlsnotary.org/server_random"
))
.unwrap(),
),
pubkey: PublicKey::new(
NamedGroup::secp256r1,
&Vec::<u8>::from_hex(include_bytes!("testdata/key_exchange/tlsnotary.org/pubkey"))
.unwrap(),
),
sig: Vec::<u8>::from_hex(include_bytes!(
"testdata/key_exchange/tlsnotary.org/signature"
))
.unwrap(),
time: 1671637529,
sig_scheme: SignatureScheme::RSA_PKCS1_SHA256,
dns_name: "tlsnotary.org".to_string(),
}
}
pub fn appliedzkp() -> TestData {
TestData {
ee: Certificate(include_bytes!("testdata/key_exchange/appliedzkp.org/ee.der").to_vec()),
inter: Certificate(
include_bytes!("testdata/key_exchange/appliedzkp.org/inter.der").to_vec(),
),
ca: Certificate(include_bytes!("testdata/key_exchange/appliedzkp.org/ca.der").to_vec()),
cr: Random(
<[u8; 32]>::from_hex(include_bytes!(
"testdata/key_exchange/appliedzkp.org/client_random"
))
.unwrap(),
),
sr: Random(
<[u8; 32]>::from_hex(include_bytes!(
"testdata/key_exchange/appliedzkp.org/server_random"
))
.unwrap(),
),
pubkey: PublicKey::new(
NamedGroup::secp256r1,
&Vec::<u8>::from_hex(include_bytes!(
"testdata/key_exchange/appliedzkp.org/pubkey"
))
.unwrap(),
),
sig: Vec::<u8>::from_hex(include_bytes!(
"testdata/key_exchange/appliedzkp.org/signature"
))
.unwrap(),
time: 1671637529,
sig_scheme: SignatureScheme::ECDSA_NISTP256_SHA256,
dns_name: "appliedzkp.org".to_string(),
}
}