Debian Codegraph @

crt/s2n/tests/pcap/src/client_hello.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 use crate::handshake_message::HandshakeMessage;
5 use anyhow::*;
6 use std::option::Option;
7
8 #[derive(Debug, Clone, Default)]
9 pub struct ClientHello(HandshakeMessage);
10
11 impl ClientHello {
12 /// ClientHello message type, as defined in the TLS RFC.
13 /// See https://datatracker.ietf.org/doc/html/rfc8446#section-4
14 const MESSAGE_TYPE: u8 = 1;
15
16 const JA3_HASH: &'static str = "tls.handshake.ja3";
17 pub fn ja3_hash(&self) -> Option<String> {
18 self.0.packet.metadata(Self::JA3_HASH).map(str::to_owned)
19 }
20
21 const JA3_STR: &'static str = "tls.handshake.ja3_full";
22 pub fn ja3_string(&self) -> Option<String> {
23 self.0.packet.metadata(Self::JA3_STR).map(str::to_owned)
24 }
25
26 const JA4_HASH: &'static str = "tls.handshake.ja4";
27 pub fn ja4_hash(&self) -> Option<String> {
28 self.0.packet.metadata(Self::JA4_HASH).map(str::to_owned)
29 }
30
31 const JA4_STR: &'static str = "tls.handshake.ja4_r";
32 pub fn ja4_string(&self) -> Option<String> {
33 self.0.packet.metadata(Self::JA4_STR).map(str::to_owned)
34 }
35
36 pub fn message(&self) -> &HandshakeMessage {
37 &self.0
38 }
39 }
40
41 impl crate::handshake_message::Builder {
42 pub fn build_client_hellos(mut self) -> Result<Vec<ClientHello>> {
43 self.set_type(ClientHello::MESSAGE_TYPE);
44 let client_hellos = self.build()?.into_iter().map(ClientHello).collect();
45 Ok(client_hellos)
46 }
47 }
48
49 #[cfg(test)]
50 mod tests {
51 use super::*;
52 use crate::handshake_message::Builder;
53
54 #[test]
55 fn multiple_hellos() -> Result<()> {
56 let mut builder = Builder::default();
57 builder.set_capture_file("data/multiple_hellos.pcap");
58 let hellos = builder.build_client_hellos().unwrap();
59 assert_eq!(hellos.len(), 5);
60 Ok(())
61 }
62
63 #[test]
64 fn from_pcaps() -> Result<()> {
65 let pcaps = crate::all_pcaps();
66 for pcap in pcaps {
67 let mut builder = Builder::default();
68 builder.set_capture_file(&pcap);
69 let hellos = builder.build_client_hellos().unwrap();
70 assert!(!hellos.is_empty());
71 }
72 Ok(())
73 }
74 }