1mod provider;
4
5pub use provider::FixtureEncodingProvider;
6
7use hex::FromHex;
8
9use crate::{
10 connection::{
11 Certificate, ConnectionInfo, HandshakeData, HandshakeDataV1_2, KeyType, ServerCertData,
12 ServerEphemKey, ServerName, ServerSignature, SignatureScheme, TlsVersion, TranscriptLength,
13 },
14 transcript::{
15 encoding::{EncoderSecret, EncodingProvider},
16 Transcript,
17 },
18};
19
20#[derive(Clone)]
22#[allow(missing_docs)]
23pub struct ConnectionFixture {
24 pub server_name: ServerName,
25 pub connection_info: ConnectionInfo,
26 pub server_cert_data: ServerCertData,
27}
28
29impl ConnectionFixture {
30 pub fn tlsnotary(transcript_length: TranscriptLength) -> Self {
32 ConnectionFixture {
33 server_name: ServerName::new("tlsnotary.org".to_string()),
34 connection_info: ConnectionInfo {
35 time: 1671637529,
36 version: TlsVersion::V1_2,
37 transcript_length,
38 },
39 server_cert_data: ServerCertData {
40 certs: vec![
41 Certificate(include_bytes!("fixtures/data/tlsnotary.org/ee.der").to_vec()),
42 Certificate(include_bytes!("fixtures/data/tlsnotary.org/inter.der").to_vec()),
43 Certificate(include_bytes!("fixtures/data/tlsnotary.org/ca.der").to_vec()),
44 ],
45 sig: ServerSignature {
46 scheme: SignatureScheme::RSA_PKCS1_SHA256,
47 sig: Vec::<u8>::from_hex(include_bytes!(
48 "fixtures/data/tlsnotary.org/signature"
49 ))
50 .unwrap(),
51 },
52 handshake: HandshakeData::V1_2(HandshakeDataV1_2 {
53 client_random: <[u8; 32]>::from_hex(include_bytes!(
54 "fixtures/data/tlsnotary.org/client_random"
55 ))
56 .unwrap(),
57 server_random: <[u8; 32]>::from_hex(include_bytes!(
58 "fixtures/data/tlsnotary.org/server_random"
59 ))
60 .unwrap(),
61 server_ephemeral_key: ServerEphemKey {
62 typ: KeyType::SECP256R1,
63 key: Vec::<u8>::from_hex(include_bytes!(
64 "fixtures/data/tlsnotary.org/pubkey"
65 ))
66 .unwrap(),
67 },
68 }),
69 },
70 }
71 }
72
73 pub fn appliedzkp(transcript_length: TranscriptLength) -> Self {
75 ConnectionFixture {
76 server_name: ServerName::new("appliedzkp.org".to_string()),
77 connection_info: ConnectionInfo {
78 time: 1671637529,
79 version: TlsVersion::V1_2,
80 transcript_length,
81 },
82 server_cert_data: ServerCertData {
83 certs: vec![
84 Certificate(include_bytes!("fixtures/data/appliedzkp.org/ee.der").to_vec()),
85 Certificate(include_bytes!("fixtures/data/appliedzkp.org/inter.der").to_vec()),
86 Certificate(include_bytes!("fixtures/data/appliedzkp.org/ca.der").to_vec()),
87 ],
88 sig: ServerSignature {
89 scheme: SignatureScheme::ECDSA_NISTP256_SHA256,
90 sig: Vec::<u8>::from_hex(include_bytes!(
91 "fixtures/data/appliedzkp.org/signature"
92 ))
93 .unwrap(),
94 },
95 handshake: HandshakeData::V1_2(HandshakeDataV1_2 {
96 client_random: <[u8; 32]>::from_hex(include_bytes!(
97 "fixtures/data/appliedzkp.org/client_random"
98 ))
99 .unwrap(),
100 server_random: <[u8; 32]>::from_hex(include_bytes!(
101 "fixtures/data/appliedzkp.org/server_random"
102 ))
103 .unwrap(),
104 server_ephemeral_key: ServerEphemKey {
105 typ: KeyType::SECP256R1,
106 key: Vec::<u8>::from_hex(include_bytes!(
107 "fixtures/data/appliedzkp.org/pubkey"
108 ))
109 .unwrap(),
110 },
111 }),
112 },
113 }
114 }
115
116 pub fn server_ephemeral_key(&self) -> &ServerEphemKey {
118 let HandshakeData::V1_2(HandshakeDataV1_2 {
119 server_ephemeral_key,
120 ..
121 }) = &self.server_cert_data.handshake;
122 server_ephemeral_key
123 }
124}
125
126pub fn encoding_provider(tx: &[u8], rx: &[u8]) -> impl EncodingProvider {
128 let secret = encoder_secret();
129 FixtureEncodingProvider::new(&secret, Transcript::new(tx, rx))
130}
131
132const SEED: [u8; 32] = [0; 32];
134
135const DELTA: [u8; 16] = [1; 16];
137
138pub fn encoder_secret() -> EncoderSecret {
140 EncoderSecret::new(SEED, DELTA)
141}
142
143pub fn encoder_secret_tampered_seed() -> EncoderSecret {
145 let mut seed = SEED;
146 seed[0] += 1;
147 EncoderSecret::new(seed, DELTA)
148}