tlspuffin/tls/
fn_transcript.rs

1#![allow(clippy::ptr_arg)]
2#![allow(dead_code)]
3
4use puffin::algebra::error::FnError;
5
6use crate::claims::{
7    Finished, Transcript, TranscriptCertificate, TranscriptClientFinished,
8    TranscriptServerFinished, TranscriptServerHello,
9};
10use crate::tls::rustls::hash_hs::HandshakeHash;
11use crate::tls::rustls::msgs::enums::CipherSuite;
12use crate::tls::rustls::msgs::handshake::Random;
13use crate::tls::rustls::tls13;
14
15pub fn fn_server_hello_transcript(claim: &TranscriptServerHello) -> Result<HandshakeHash, FnError> {
16    _fn_transcript::<TranscriptServerHello>(claim)
17}
18
19pub fn fn_client_finished_transcript(
20    claim: &TranscriptClientFinished,
21) -> Result<HandshakeHash, FnError> {
22    _fn_transcript::<TranscriptClientFinished>(claim)
23}
24
25pub fn fn_server_finished_transcript(
26    claim: &TranscriptServerFinished,
27) -> Result<HandshakeHash, FnError> {
28    _fn_transcript::<TranscriptServerFinished>(claim)
29}
30
31pub fn fn_certificate_transcript(claim: &TranscriptCertificate) -> Result<HandshakeHash, FnError> {
32    _fn_transcript::<TranscriptCertificate>(claim)
33}
34
35fn _fn_transcript<T: Transcript>(claim: &T) -> Result<HandshakeHash, FnError> {
36    let algorithm = tls13::TLS13_AES_128_GCM_SHA256.hash_algorithm();
37
38    let hash = HandshakeHash::new_override(Vec::from(claim.as_slice()), algorithm);
39    Ok(hash)
40}
41
42/// This function is meant to be used in post-execution decryption recipes but not by the attacker
43pub fn fn_finished_get_cipher(claim: &Finished) -> Result<CipherSuite, FnError> {
44    Ok(CipherSuite::from(claim.chosen_cipher))
45}
46
47/// This function is meant to be used in post-execution decryption recipes but not by the attacker
48pub fn fn_finished_get_secret(claim: &Finished) -> Result<Vec<u8>, FnError> {
49    let secret = Vec::from(claim.master_secret.as_slice());
50
51    Ok(secret)
52}
53
54/// This function is meant to be used in post-execution decryption recipes but not by the attacker
55pub fn fn_finished_get_handshake_secret(claim: &Finished) -> Result<Vec<u8>, FnError> {
56    let secret = Vec::from(claim.handshake_secret.as_slice());
57
58    Ok(secret)
59}
60
61/// This function is meant to be used in post-execution decryption recipes but not by the attacker
62pub fn fn_finished_get_server_random(claim: &Finished) -> Result<Random, FnError> {
63    let payload: [u8; 32] = claim.server_random[0..32].try_into().unwrap();
64    Ok(Random(payload))
65}
66
67/// This function is meant to be used in post-execution decryption recipes but not by the attacker
68pub fn fn_finished_get_client_random(claim: &Finished) -> Result<Random, FnError> {
69    let payload: [u8; 32] = claim.client_random[0..32].try_into().unwrap();
70    Ok(Random(payload))
71}