/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tls-parser-0.11.0/src/tls.rs
Line | Count | Source |
1 | | //! # TLS parser |
2 | | //! Parsing functions for the TLS protocol, supporting versions 1.0 to 1.3 |
3 | | |
4 | | use alloc::{vec, vec::Vec}; |
5 | | use core::convert::AsRef; |
6 | | use core::fmt; |
7 | | use core::ops::Deref; |
8 | | use nom::branch::alt; |
9 | | use nom::bytes::streaming::take; |
10 | | use nom::combinator::{complete, cond, map, map_parser, opt, verify}; |
11 | | use nom::error::{make_error, ErrorKind}; |
12 | | use nom::multi::{length_count, length_data, many0, many1}; |
13 | | use nom::number::streaming::{be_u16, be_u24, be_u32, be_u8}; |
14 | | use nom_derive::*; |
15 | | use rusticata_macros::newtype_enum; |
16 | | |
17 | | use crate::tls_alert::*; |
18 | | use crate::tls_ciphers::*; |
19 | | use crate::tls_ec::ECPoint; |
20 | | |
21 | | pub use nom::{Err, IResult}; |
22 | | |
23 | | /// Max record size (RFC8446 5.1) |
24 | | pub const MAX_RECORD_LEN: u16 = 1 << 14; |
25 | | |
26 | | /// Handshake type |
27 | | /// |
28 | | /// Handshake types are defined in [RFC5246](https://tools.ietf.org/html/rfc5246) and |
29 | | /// the [IANA HandshakeType |
30 | | /// Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-7) |
31 | 0 | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] Unexecuted instantiation: <tls_parser::tls::TlsHandshakeType as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsHandshakeType as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls::TlsHandshakeType as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsHandshakeType as nom_derive::traits::Parse<&[u8]>>::parse_le |
32 | | pub struct TlsHandshakeType(pub u8); |
33 | | |
34 | | newtype_enum! { |
35 | | impl debug TlsHandshakeType { |
36 | | HelloRequest = 0x00, |
37 | | ClientHello = 0x01, |
38 | | ServerHello = 0x02, |
39 | | HelloVerifyRequest = 0x03, |
40 | | NewSessionTicket = 0x04, |
41 | | EndOfEarlyData = 0x05, |
42 | | HelloRetryRequest = 0x06, |
43 | | EncryptedExtensions = 0x08, |
44 | | Certificate = 0x0b, |
45 | | ServerKeyExchange = 0x0c, |
46 | | CertificateRequest = 0x0d, |
47 | | ServerDone = 0x0e, |
48 | | CertificateVerify = 0x0f, |
49 | | ClientKeyExchange = 0x10, |
50 | | Finished = 0x14, |
51 | | CertificateURL = 0x15, |
52 | | CertificateStatus = 0x16, |
53 | | KeyUpdate = 0x18, |
54 | | |
55 | | NextProtocol = 0x43, |
56 | | } |
57 | | } |
58 | | |
59 | | impl From<TlsHandshakeType> for u8 { |
60 | 0 | fn from(v: TlsHandshakeType) -> u8 { |
61 | 0 | v.0 |
62 | 0 | } Unexecuted instantiation: <u8 as core::convert::From<tls_parser::tls::TlsHandshakeType>>::from Unexecuted instantiation: <u8 as core::convert::From<tls_parser::tls::TlsHandshakeType>>::from |
63 | | } |
64 | | |
65 | | /// TLS version |
66 | | /// |
67 | | /// Only the TLS version defined in the TLS message header is meaningful, the |
68 | | /// version defined in the record should be ignored or set to TLS 1.0 |
69 | 52.7k | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] <tls_parser::tls::TlsVersion as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 69 | 44.4k | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] |
Unexecuted instantiation: <tls_parser::tls::TlsVersion as nom_derive::traits::Parse<&[u8]>>::parse_le <tls_parser::tls::TlsVersion as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 69 | 8.28k | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] |
Unexecuted instantiation: <tls_parser::tls::TlsVersion as nom_derive::traits::Parse<&[u8]>>::parse_le |
70 | | pub struct TlsVersion(pub u16); |
71 | | |
72 | | newtype_enum! { |
73 | | impl debug TlsVersion { |
74 | | Ssl30 = 0x0300, |
75 | | Tls10 = 0x0301, |
76 | | Tls11 = 0x0302, |
77 | | Tls12 = 0x0303, |
78 | | Tls13 = 0x0304, |
79 | | |
80 | | Tls13Draft18 = 0x7f12, |
81 | | Tls13Draft19 = 0x7f13, |
82 | | Tls13Draft20 = 0x7f14, |
83 | | Tls13Draft21 = 0x7f15, |
84 | | Tls13Draft22 = 0x7f16, |
85 | | Tls13Draft23 = 0x7f17, |
86 | | |
87 | | DTls10 = 0xfeff, |
88 | | DTls11 = 0xfefe, |
89 | | DTls12 = 0xfefd, |
90 | | } |
91 | | } |
92 | | |
93 | | impl From<TlsVersion> for u16 { |
94 | 796k | fn from(v: TlsVersion) -> u16 { |
95 | 796k | v.0 |
96 | 796k | } <u16 as core::convert::From<tls_parser::tls::TlsVersion>>::from Line | Count | Source | 94 | 365k | fn from(v: TlsVersion) -> u16 { | 95 | 365k | v.0 | 96 | 365k | } |
<u16 as core::convert::From<tls_parser::tls::TlsVersion>>::from Line | Count | Source | 94 | 431k | fn from(v: TlsVersion) -> u16 { | 95 | 431k | v.0 | 96 | 431k | } |
|
97 | | } |
98 | | |
99 | | impl fmt::LowerHex for TlsVersion { |
100 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
101 | 0 | write!(f, "{:x}", self.0) |
102 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsVersion as core::fmt::LowerHex>::fmt Unexecuted instantiation: <tls_parser::tls::TlsVersion as core::fmt::LowerHex>::fmt |
103 | | } |
104 | | |
105 | | /// Heartbeat type, as defined in [RFC6520](https://tools.ietf.org/html/rfc6520) section 3 |
106 | 1.66k | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] <tls_parser::tls::TlsHeartbeatMessageType as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 106 | 1.06k | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] |
Unexecuted instantiation: <tls_parser::tls::TlsHeartbeatMessageType as nom_derive::traits::Parse<&[u8]>>::parse_le <tls_parser::tls::TlsHeartbeatMessageType as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 106 | 601 | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] |
Unexecuted instantiation: <tls_parser::tls::TlsHeartbeatMessageType as nom_derive::traits::Parse<&[u8]>>::parse_le |
107 | | pub struct TlsHeartbeatMessageType(pub u8); |
108 | | |
109 | | newtype_enum! { |
110 | | impl debug TlsHeartbeatMessageType { |
111 | | HeartBeatRequest = 0x1, |
112 | | HeartBeatResponse = 0x2, |
113 | | } |
114 | | } |
115 | | |
116 | | impl From<TlsHeartbeatMessageType> for u8 { |
117 | 0 | fn from(v: TlsHeartbeatMessageType) -> u8 { |
118 | 0 | v.0 |
119 | 0 | } Unexecuted instantiation: <u8 as core::convert::From<tls_parser::tls::TlsHeartbeatMessageType>>::from Unexecuted instantiation: <u8 as core::convert::From<tls_parser::tls::TlsHeartbeatMessageType>>::from |
120 | | } |
121 | | |
122 | | /// Content type, as defined in IANA TLS ContentType registry |
123 | 0 | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] Unexecuted instantiation: <tls_parser::tls::TlsRecordType as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsRecordType as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls::TlsRecordType as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsRecordType as nom_derive::traits::Parse<&[u8]>>::parse_le |
124 | | pub struct TlsRecordType(pub u8); |
125 | | |
126 | | newtype_enum! { |
127 | | impl debug TlsRecordType { |
128 | | ChangeCipherSpec = 0x14, |
129 | | Alert = 0x15, |
130 | | Handshake = 0x16, |
131 | | ApplicationData = 0x17, |
132 | | Heartbeat = 0x18, |
133 | | } |
134 | | } |
135 | | |
136 | | impl From<TlsRecordType> for u8 { |
137 | 6.44k | fn from(v: TlsRecordType) -> u8 { |
138 | 6.44k | v.0 |
139 | 6.44k | } <u8 as core::convert::From<tls_parser::tls::TlsRecordType>>::from Line | Count | Source | 137 | 2.94k | fn from(v: TlsRecordType) -> u8 { | 138 | 2.94k | v.0 | 139 | 2.94k | } |
<u8 as core::convert::From<tls_parser::tls::TlsRecordType>>::from Line | Count | Source | 137 | 3.50k | fn from(v: TlsRecordType) -> u8 { | 138 | 3.50k | v.0 | 139 | 3.50k | } |
|
140 | | } |
141 | | |
142 | 0 | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as nom_derive::traits::Parse<&[u8]>>::parse_le |
143 | | pub struct TlsCompressionID(pub u8); |
144 | | |
145 | | newtype_enum! { |
146 | | impl debug TlsCompressionID { |
147 | | Null = 0x00, |
148 | | } |
149 | | } |
150 | | |
151 | | impl From<TlsCompressionID> for u8 { |
152 | 0 | fn from(c: TlsCompressionID) -> u8 { |
153 | 0 | c.0 |
154 | 0 | } Unexecuted instantiation: <u8 as core::convert::From<tls_parser::tls::TlsCompressionID>>::from Unexecuted instantiation: <u8 as core::convert::From<tls_parser::tls::TlsCompressionID>>::from |
155 | | } |
156 | | |
157 | | impl Deref for TlsCompressionID { |
158 | | type Target = u8; |
159 | 0 | fn deref(&self) -> &Self::Target { |
160 | 0 | &self.0 |
161 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as core::ops::deref::Deref>::deref Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as core::ops::deref::Deref>::deref |
162 | | } |
163 | | |
164 | | impl AsRef<u8> for TlsCompressionID { |
165 | 0 | fn as_ref(&self) -> &u8 { |
166 | 0 | &self.0 |
167 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as core::convert::AsRef<u8>>::as_ref Unexecuted instantiation: <tls_parser::tls::TlsCompressionID as core::convert::AsRef<u8>>::as_ref |
168 | | } |
169 | | |
170 | 0 | #[derive(Clone, Copy, PartialEq, Eq, NomBE)] Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as nom_derive::traits::Parse<&[u8]>>::parse_le Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as nom_derive::traits::Parse<&[u8]>>::parse_be Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as nom_derive::traits::Parse<&[u8]>>::parse_le |
171 | | pub struct TlsCipherSuiteID(pub u16); |
172 | | |
173 | | impl TlsCipherSuiteID { |
174 | 0 | pub fn get_ciphersuite(self) -> Option<&'static TlsCipherSuite> { |
175 | 0 | TlsCipherSuite::from_id(self.0) |
176 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID>::get_ciphersuite Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID>::get_ciphersuite |
177 | | } |
178 | | |
179 | | impl From<TlsCipherSuiteID> for u16 { |
180 | 103M | fn from(c: TlsCipherSuiteID) -> u16 { |
181 | 103M | c.0 |
182 | 103M | } <u16 as core::convert::From<tls_parser::tls::TlsCipherSuiteID>>::from Line | Count | Source | 180 | 48.6M | fn from(c: TlsCipherSuiteID) -> u16 { | 181 | 48.6M | c.0 | 182 | 48.6M | } |
<u16 as core::convert::From<tls_parser::tls::TlsCipherSuiteID>>::from Line | Count | Source | 180 | 55.0M | fn from(c: TlsCipherSuiteID) -> u16 { | 181 | 55.0M | c.0 | 182 | 55.0M | } |
|
183 | | } |
184 | | |
185 | | impl Deref for TlsCipherSuiteID { |
186 | | type Target = u16; |
187 | 0 | fn deref(&self) -> &Self::Target { |
188 | 0 | &self.0 |
189 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::ops::deref::Deref>::deref Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::ops::deref::Deref>::deref |
190 | | } |
191 | | |
192 | | impl AsRef<u16> for TlsCipherSuiteID { |
193 | 0 | fn as_ref(&self) -> &u16 { |
194 | 0 | &self.0 |
195 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::convert::AsRef<u16>>::as_ref Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::convert::AsRef<u16>>::as_ref |
196 | | } |
197 | | |
198 | | impl fmt::Display for TlsCipherSuiteID { |
199 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
200 | 0 | write!(f, "{}", self.0) |
201 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::fmt::Display>::fmt Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::fmt::Display>::fmt |
202 | | } |
203 | | |
204 | | impl fmt::Debug for TlsCipherSuiteID { |
205 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
206 | 0 | match TlsCipherSuite::from_id(self.0) { |
207 | 0 | Some(c) => write!(f, "0x{:04x}({})", self.0, c.name), |
208 | 0 | None => write!(f, "0x{:04x}(Unknown cipher)", self.0), |
209 | | } |
210 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::fmt::Debug>::fmt Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::fmt::Debug>::fmt |
211 | | } |
212 | | |
213 | | impl fmt::LowerHex for TlsCipherSuiteID { |
214 | 0 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
215 | 0 | write!(f, "{:x}", self.0) |
216 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::fmt::LowerHex>::fmt Unexecuted instantiation: <tls_parser::tls::TlsCipherSuiteID as core::fmt::LowerHex>::fmt |
217 | | } |
218 | | |
219 | | /// A trait that both TLS & DTLS satisfy |
220 | | pub trait ClientHello<'a> { |
221 | | /// TLS version of message |
222 | | fn version(&self) -> TlsVersion; |
223 | | fn rand_data(&self) -> &'a [u8]; |
224 | | fn session_id(&self) -> Option<&'a [u8]>; |
225 | | /// A list of ciphers supported by client |
226 | | fn ciphers(&self) -> &Vec<TlsCipherSuiteID>; |
227 | 0 | fn cipher_suites(&self) -> Vec<Option<&'static TlsCipherSuite>> { |
228 | 0 | self.ciphers() |
229 | 0 | .iter() |
230 | 0 | .map(|&x| x.get_ciphersuite()) Unexecuted instantiation: <_ as tls_parser::tls::ClientHello>::cipher_suites::{closure#0}Unexecuted instantiation: <_ as tls_parser::tls::ClientHello>::cipher_suites::{closure#0} |
231 | 0 | .collect() |
232 | 0 | } Unexecuted instantiation: <_ as tls_parser::tls::ClientHello>::cipher_suites Unexecuted instantiation: <_ as tls_parser::tls::ClientHello>::cipher_suites |
233 | | /// A list of compression methods supported by client |
234 | | fn comp(&self) -> &Vec<TlsCompressionID>; |
235 | | fn ext(&self) -> Option<&'a [u8]>; |
236 | | } |
237 | | |
238 | | /// TLS Client Hello (from TLS 1.0 to TLS 1.2) |
239 | | /// |
240 | | /// Some fields are unparsed (for performance reasons), for ex to parse `ext`, |
241 | | /// call the `parse_tls_extensions` function. |
242 | | #[derive(Clone, PartialEq)] |
243 | | pub struct TlsClientHelloContents<'a> { |
244 | | /// TLS version of message |
245 | | pub version: TlsVersion, |
246 | | pub rand_time: u32, |
247 | | pub rand_data: &'a [u8], |
248 | | pub session_id: Option<&'a [u8]>, |
249 | | /// A list of ciphers supported by client |
250 | | pub ciphers: Vec<TlsCipherSuiteID>, |
251 | | /// A list of compression methods supported by client |
252 | | pub comp: Vec<TlsCompressionID>, |
253 | | |
254 | | pub ext: Option<&'a [u8]>, |
255 | | } |
256 | | |
257 | | impl<'a> TlsClientHelloContents<'a> { |
258 | 89.9k | pub fn new( |
259 | 89.9k | v: u16, |
260 | 89.9k | rt: u32, |
261 | 89.9k | rd: &'a [u8], |
262 | 89.9k | sid: Option<&'a [u8]>, |
263 | 89.9k | c: Vec<TlsCipherSuiteID>, |
264 | 89.9k | co: Vec<TlsCompressionID>, |
265 | 89.9k | e: Option<&'a [u8]>, |
266 | 89.9k | ) -> Self { |
267 | 89.9k | TlsClientHelloContents { |
268 | 89.9k | version: TlsVersion(v), |
269 | 89.9k | rand_time: rt, |
270 | 89.9k | rand_data: rd, |
271 | 89.9k | session_id: sid, |
272 | 89.9k | ciphers: c, |
273 | 89.9k | comp: co, |
274 | 89.9k | ext: e, |
275 | 89.9k | } |
276 | 89.9k | } <tls_parser::tls::TlsClientHelloContents>::new Line | Count | Source | 258 | 40.3k | pub fn new( | 259 | 40.3k | v: u16, | 260 | 40.3k | rt: u32, | 261 | 40.3k | rd: &'a [u8], | 262 | 40.3k | sid: Option<&'a [u8]>, | 263 | 40.3k | c: Vec<TlsCipherSuiteID>, | 264 | 40.3k | co: Vec<TlsCompressionID>, | 265 | 40.3k | e: Option<&'a [u8]>, | 266 | 40.3k | ) -> Self { | 267 | 40.3k | TlsClientHelloContents { | 268 | 40.3k | version: TlsVersion(v), | 269 | 40.3k | rand_time: rt, | 270 | 40.3k | rand_data: rd, | 271 | 40.3k | session_id: sid, | 272 | 40.3k | ciphers: c, | 273 | 40.3k | comp: co, | 274 | 40.3k | ext: e, | 275 | 40.3k | } | 276 | 40.3k | } |
<tls_parser::tls::TlsClientHelloContents>::new Line | Count | Source | 258 | 49.6k | pub fn new( | 259 | 49.6k | v: u16, | 260 | 49.6k | rt: u32, | 261 | 49.6k | rd: &'a [u8], | 262 | 49.6k | sid: Option<&'a [u8]>, | 263 | 49.6k | c: Vec<TlsCipherSuiteID>, | 264 | 49.6k | co: Vec<TlsCompressionID>, | 265 | 49.6k | e: Option<&'a [u8]>, | 266 | 49.6k | ) -> Self { | 267 | 49.6k | TlsClientHelloContents { | 268 | 49.6k | version: TlsVersion(v), | 269 | 49.6k | rand_time: rt, | 270 | 49.6k | rand_data: rd, | 271 | 49.6k | session_id: sid, | 272 | 49.6k | ciphers: c, | 273 | 49.6k | comp: co, | 274 | 49.6k | ext: e, | 275 | 49.6k | } | 276 | 49.6k | } |
|
277 | | |
278 | 0 | pub fn get_version(&self) -> TlsVersion { |
279 | 0 | self.version |
280 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents>::get_version Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents>::get_version |
281 | | |
282 | 0 | pub fn get_ciphers(&self) -> Vec<Option<&'static TlsCipherSuite>> { |
283 | 0 | self.ciphers.iter().map(|&x| x.get_ciphersuite()).collect() Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents>::get_ciphers::{closure#0}Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents>::get_ciphers::{closure#0} |
284 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents>::get_ciphers Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents>::get_ciphers |
285 | | } |
286 | | |
287 | | impl<'a> ClientHello<'a> for TlsClientHelloContents<'a> { |
288 | 0 | fn version(&self) -> TlsVersion { |
289 | 0 | self.version |
290 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::version Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::version |
291 | | |
292 | 0 | fn rand_data(&self) -> &'a [u8] { |
293 | 0 | self.rand_data |
294 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::rand_data Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::rand_data |
295 | | |
296 | 0 | fn session_id(&self) -> Option<&'a [u8]> { |
297 | 0 | self.session_id |
298 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::session_id Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::session_id |
299 | | |
300 | 0 | fn ciphers(&self) -> &Vec<TlsCipherSuiteID> { |
301 | 0 | &self.ciphers |
302 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::ciphers Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::ciphers |
303 | | |
304 | 0 | fn comp(&self) -> &Vec<TlsCompressionID> { |
305 | 0 | &self.comp |
306 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::comp Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::comp |
307 | | |
308 | 0 | fn ext(&self) -> Option<&'a [u8]> { |
309 | 0 | self.ext |
310 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::ext Unexecuted instantiation: <tls_parser::tls::TlsClientHelloContents as tls_parser::tls::ClientHello>::ext |
311 | | } |
312 | | |
313 | | /// TLS Server Hello (from TLS 1.0 to TLS 1.2) |
314 | | #[derive(Clone, PartialEq)] |
315 | | pub struct TlsServerHelloContents<'a> { |
316 | | pub version: TlsVersion, |
317 | | pub rand_time: u32, |
318 | | pub rand_data: &'a [u8], |
319 | | pub session_id: Option<&'a [u8]>, |
320 | | pub cipher: TlsCipherSuiteID, |
321 | | pub compression: TlsCompressionID, |
322 | | |
323 | | pub ext: Option<&'a [u8]>, |
324 | | } |
325 | | |
326 | | /// TLS Server Hello (TLS 1.3 draft 18) |
327 | | #[derive(Clone, PartialEq)] |
328 | | pub struct TlsServerHelloV13Draft18Contents<'a> { |
329 | | pub version: TlsVersion, |
330 | | pub random: &'a [u8], |
331 | | pub cipher: TlsCipherSuiteID, |
332 | | |
333 | | pub ext: Option<&'a [u8]>, |
334 | | } |
335 | | |
336 | | /// TLS Hello Retry Request (TLS 1.3) |
337 | | #[derive(Clone, PartialEq)] |
338 | | pub struct TlsHelloRetryRequestContents<'a> { |
339 | | pub version: TlsVersion, |
340 | | pub cipher: TlsCipherSuiteID, |
341 | | |
342 | | pub ext: Option<&'a [u8]>, |
343 | | } |
344 | | |
345 | | impl<'a> TlsServerHelloContents<'a> { |
346 | 10.7k | pub fn new( |
347 | 10.7k | v: u16, |
348 | 10.7k | rt: u32, |
349 | 10.7k | rd: &'a [u8], |
350 | 10.7k | sid: Option<&'a [u8]>, |
351 | 10.7k | c: u16, |
352 | 10.7k | co: u8, |
353 | 10.7k | e: Option<&'a [u8]>, |
354 | 10.7k | ) -> Self { |
355 | 10.7k | TlsServerHelloContents { |
356 | 10.7k | version: TlsVersion(v), |
357 | 10.7k | rand_time: rt, |
358 | 10.7k | rand_data: rd, |
359 | 10.7k | session_id: sid, |
360 | 10.7k | cipher: TlsCipherSuiteID(c), |
361 | 10.7k | compression: TlsCompressionID(co), |
362 | 10.7k | ext: e, |
363 | 10.7k | } |
364 | 10.7k | } <tls_parser::tls::TlsServerHelloContents>::new Line | Count | Source | 346 | 3.51k | pub fn new( | 347 | 3.51k | v: u16, | 348 | 3.51k | rt: u32, | 349 | 3.51k | rd: &'a [u8], | 350 | 3.51k | sid: Option<&'a [u8]>, | 351 | 3.51k | c: u16, | 352 | 3.51k | co: u8, | 353 | 3.51k | e: Option<&'a [u8]>, | 354 | 3.51k | ) -> Self { | 355 | 3.51k | TlsServerHelloContents { | 356 | 3.51k | version: TlsVersion(v), | 357 | 3.51k | rand_time: rt, | 358 | 3.51k | rand_data: rd, | 359 | 3.51k | session_id: sid, | 360 | 3.51k | cipher: TlsCipherSuiteID(c), | 361 | 3.51k | compression: TlsCompressionID(co), | 362 | 3.51k | ext: e, | 363 | 3.51k | } | 364 | 3.51k | } |
<tls_parser::tls::TlsServerHelloContents>::new Line | Count | Source | 346 | 7.20k | pub fn new( | 347 | 7.20k | v: u16, | 348 | 7.20k | rt: u32, | 349 | 7.20k | rd: &'a [u8], | 350 | 7.20k | sid: Option<&'a [u8]>, | 351 | 7.20k | c: u16, | 352 | 7.20k | co: u8, | 353 | 7.20k | e: Option<&'a [u8]>, | 354 | 7.20k | ) -> Self { | 355 | 7.20k | TlsServerHelloContents { | 356 | 7.20k | version: TlsVersion(v), | 357 | 7.20k | rand_time: rt, | 358 | 7.20k | rand_data: rd, | 359 | 7.20k | session_id: sid, | 360 | 7.20k | cipher: TlsCipherSuiteID(c), | 361 | 7.20k | compression: TlsCompressionID(co), | 362 | 7.20k | ext: e, | 363 | 7.20k | } | 364 | 7.20k | } |
|
365 | | |
366 | 0 | pub fn get_version(&self) -> TlsVersion { |
367 | 0 | self.version |
368 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsServerHelloContents>::get_version Unexecuted instantiation: <tls_parser::tls::TlsServerHelloContents>::get_version |
369 | | |
370 | 0 | pub fn get_cipher(&self) -> Option<&'static TlsCipherSuite> { |
371 | 0 | self.cipher.get_ciphersuite() |
372 | 0 | } Unexecuted instantiation: <tls_parser::tls::TlsServerHelloContents>::get_cipher Unexecuted instantiation: <tls_parser::tls::TlsServerHelloContents>::get_cipher |
373 | | } |
374 | | |
375 | | /// Session ticket, as defined in [RFC5077](https://tools.ietf.org/html/rfc5077) |
376 | | #[derive(Clone, Debug, PartialEq)] |
377 | | pub struct TlsNewSessionTicketContent<'a> { |
378 | | pub ticket_lifetime_hint: u32, |
379 | | pub ticket: &'a [u8], |
380 | | } |
381 | | |
382 | | /// A raw certificate, which should be a DER-encoded X.509 certificate. |
383 | | /// |
384 | | /// See [RFC5280](https://tools.ietf.org/html/rfc5280) for X509v3 certificate format. |
385 | | #[derive(Clone, PartialEq)] |
386 | | pub struct RawCertificate<'a> { |
387 | | pub data: &'a [u8], |
388 | | } |
389 | | |
390 | | /// The certificate chain, usually composed of the certificate, and all |
391 | | /// required certificate authorities. |
392 | | #[derive(Clone, Debug, PartialEq)] |
393 | | pub struct TlsCertificateContents<'a> { |
394 | | pub cert_chain: Vec<RawCertificate<'a>>, |
395 | | } |
396 | | |
397 | | /// Certificate request, as defined in [RFC5246](https://tools.ietf.org/html/rfc5246) section 7.4.4 |
398 | | /// |
399 | | /// Note: TLS 1.2 adds SignatureAndHashAlgorithm (chapter 7.4.4) but do not declare it in A.4.2 |
400 | | #[derive(Clone, Debug, PartialEq)] |
401 | | pub struct TlsCertificateRequestContents<'a> { |
402 | | pub cert_types: Vec<u8>, |
403 | | pub sig_hash_algs: Option<Vec<u16>>, |
404 | | /// A list of DER-encoded distinguished names. See |
405 | | /// [X.501](http://www.itu.int/rec/T-REC-X.501/en) |
406 | | pub unparsed_ca: Vec<&'a [u8]>, |
407 | | } |
408 | | |
409 | | /// Server key exchange parameters |
410 | | /// |
411 | | /// This is an opaque struct, since the content depends on the selected |
412 | | /// key exchange method. |
413 | | #[derive(Clone, PartialEq)] |
414 | | pub struct TlsServerKeyExchangeContents<'a> { |
415 | | pub parameters: &'a [u8], |
416 | | } |
417 | | |
418 | | /// Client key exchange parameters |
419 | | /// |
420 | | /// Content depends on the selected key exchange method. |
421 | | #[derive(Clone, PartialEq)] |
422 | | pub enum TlsClientKeyExchangeContents<'a> { |
423 | | Dh(&'a [u8]), |
424 | | Ecdh(ECPoint<'a>), |
425 | | Unknown(&'a [u8]), |
426 | | } |
427 | | |
428 | | /// Certificate status response, as defined in [RFC6066](https://tools.ietf.org/html/rfc6066) section 8 |
429 | | #[derive(Clone, Debug, PartialEq)] |
430 | | pub struct TlsCertificateStatusContents<'a> { |
431 | | pub status_type: u8, |
432 | | pub blob: &'a [u8], |
433 | | } |
434 | | |
435 | | /// Next protocol response, defined in |
436 | | /// [draft-agl-tls-nextprotoneg-03](https://tools.ietf.org/html/draft-agl-tls-nextprotoneg-03) |
437 | | #[derive(Clone, Debug, PartialEq)] |
438 | | pub struct TlsNextProtocolContent<'a> { |
439 | | pub selected_protocol: &'a [u8], |
440 | | pub padding: &'a [u8], |
441 | | } |
442 | | |
443 | | /// Key update request (TLS 1.3) |
444 | | #[derive(Copy, Clone, PartialEq, Eq)] |
445 | | pub struct KeyUpdateRequest(pub u8); |
446 | | |
447 | | newtype_enum! { |
448 | | impl KeyUpdateRequest { |
449 | | NotRequested = 0x0, |
450 | | Requested = 0x1, |
451 | | } |
452 | | } |
453 | | |
454 | | /// Generic handshake message |
455 | | #[derive(Clone, Debug, PartialEq)] |
456 | | pub enum TlsMessageHandshake<'a> { |
457 | | HelloRequest, |
458 | | ClientHello(TlsClientHelloContents<'a>), |
459 | | ServerHello(TlsServerHelloContents<'a>), |
460 | | ServerHelloV13Draft18(TlsServerHelloV13Draft18Contents<'a>), |
461 | | NewSessionTicket(TlsNewSessionTicketContent<'a>), |
462 | | EndOfEarlyData, |
463 | | HelloRetryRequest(TlsHelloRetryRequestContents<'a>), |
464 | | Certificate(TlsCertificateContents<'a>), |
465 | | ServerKeyExchange(TlsServerKeyExchangeContents<'a>), |
466 | | CertificateRequest(TlsCertificateRequestContents<'a>), |
467 | | ServerDone(&'a [u8]), |
468 | | CertificateVerify(&'a [u8]), |
469 | | ClientKeyExchange(TlsClientKeyExchangeContents<'a>), |
470 | | Finished(&'a [u8]), |
471 | | CertificateStatus(TlsCertificateStatusContents<'a>), |
472 | | NextProtocol(TlsNextProtocolContent<'a>), |
473 | | KeyUpdate(u8), |
474 | | } |
475 | | |
476 | | /// TLS application data |
477 | | /// |
478 | | /// Since this message can only be sent after the handshake, data is |
479 | | /// stored as opaque. |
480 | | #[derive(Clone, Debug, PartialEq)] |
481 | | pub struct TlsMessageApplicationData<'a> { |
482 | | pub blob: &'a [u8], |
483 | | } |
484 | | |
485 | | /// TLS heartbeat message, as defined in [RFC6520](https://tools.ietf.org/html/rfc6520) |
486 | | /// |
487 | | /// Heartbeat messages should not be sent during handshake, but in practise |
488 | | /// they can (and this caused heartbleed). |
489 | | #[derive(Clone, Debug, PartialEq)] |
490 | | pub struct TlsMessageHeartbeat<'a> { |
491 | | pub heartbeat_type: TlsHeartbeatMessageType, |
492 | | pub payload_len: u16, |
493 | | pub payload: &'a [u8], |
494 | | } |
495 | | |
496 | | /// TLS record header |
497 | 5.55k | #[derive(Clone, Copy, PartialEq, NomBE)] <tls_parser::tls::TlsRecordHeader as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 497 | 1.37k | #[derive(Clone, Copy, PartialEq, NomBE)] |
Unexecuted instantiation: <tls_parser::tls::TlsRecordHeader as nom_derive::traits::Parse<&[u8]>>::parse_le <tls_parser::tls::TlsRecordHeader as nom_derive::traits::Parse<&[u8]>>::parse_be Line | Count | Source | 497 | 4.17k | #[derive(Clone, Copy, PartialEq, NomBE)] |
Unexecuted instantiation: <tls_parser::tls::TlsRecordHeader as nom_derive::traits::Parse<&[u8]>>::parse_le |
498 | | pub struct TlsRecordHeader { |
499 | | pub record_type: TlsRecordType, |
500 | | pub version: TlsVersion, |
501 | | pub len: u16, |
502 | | } |
503 | | |
504 | | /// TLS plaintext message |
505 | | /// |
506 | | /// Plaintext records can only be found during the handshake. |
507 | | #[derive(Clone, Debug, PartialEq)] |
508 | | pub enum TlsMessage<'a> { |
509 | | Handshake(TlsMessageHandshake<'a>), |
510 | | ChangeCipherSpec, |
511 | | Alert(TlsMessageAlert), |
512 | | ApplicationData(TlsMessageApplicationData<'a>), |
513 | | Heartbeat(TlsMessageHeartbeat<'a>), |
514 | | } |
515 | | |
516 | | /// TLS plaintext record |
517 | | /// |
518 | | /// A TLS record can contain multiple messages (sharing the same record type). |
519 | | /// Plaintext records can only be found during the handshake. |
520 | | #[derive(Clone, Debug, PartialEq)] |
521 | | pub struct TlsPlaintext<'a> { |
522 | | pub hdr: TlsRecordHeader, |
523 | | pub msg: Vec<TlsMessage<'a>>, |
524 | | } |
525 | | |
526 | | /// TLS encrypted data |
527 | | /// |
528 | | /// This struct only contains an opaque pointer (data are encrypted). |
529 | | #[derive(Clone, Debug, PartialEq)] |
530 | | pub struct TlsEncryptedContent<'a> { |
531 | | pub blob: &'a [u8], |
532 | | } |
533 | | |
534 | | /// Encrypted TLS record (containing opaque data) |
535 | | #[derive(Clone, Debug, PartialEq)] |
536 | | pub struct TlsEncrypted<'a> { |
537 | | pub hdr: TlsRecordHeader, |
538 | | pub msg: TlsEncryptedContent<'a>, |
539 | | } |
540 | | |
541 | | /// Tls Record with raw (unparsed) data |
542 | | /// |
543 | | /// Use `parse_tls_raw_record` to parse content |
544 | | #[derive(Clone, Debug, PartialEq)] |
545 | | pub struct TlsRawRecord<'a> { |
546 | | pub hdr: TlsRecordHeader, |
547 | | pub data: &'a [u8], |
548 | | } |
549 | | |
550 | 100k | pub(crate) fn parse_cipher_suites(i: &[u8], len: usize) -> IResult<&[u8], Vec<TlsCipherSuiteID>> { |
551 | 100k | if len == 0 { |
552 | 68.9k | return Ok((i, Vec::new())); |
553 | 31.0k | } |
554 | 31.0k | if len % 2 == 1 || len > i.len() { |
555 | 1.25k | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); |
556 | 29.7k | } |
557 | 29.7k | let v = (&i[..len]) |
558 | 29.7k | .chunks(2) |
559 | 9.74M | .map(|chunk| TlsCipherSuiteID((chunk[0] as u16) << 8 | chunk[1] as u16)) tls_parser::tls::parse_cipher_suites::{closure#0}Line | Count | Source | 559 | 4.39M | .map(|chunk| TlsCipherSuiteID((chunk[0] as u16) << 8 | chunk[1] as u16)) |
tls_parser::tls::parse_cipher_suites::{closure#0}Line | Count | Source | 559 | 5.35M | .map(|chunk| TlsCipherSuiteID((chunk[0] as u16) << 8 | chunk[1] as u16)) |
|
560 | 29.7k | .collect(); |
561 | 29.7k | Ok((&i[len..], v)) |
562 | 100k | } tls_parser::tls::parse_cipher_suites Line | Count | Source | 550 | 43.0k | pub(crate) fn parse_cipher_suites(i: &[u8], len: usize) -> IResult<&[u8], Vec<TlsCipherSuiteID>> { | 551 | 43.0k | if len == 0 { | 552 | 29.0k | return Ok((i, Vec::new())); | 553 | 14.0k | } | 554 | 14.0k | if len % 2 == 1 || len > i.len() { | 555 | 727 | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); | 556 | 13.2k | } | 557 | 13.2k | let v = (&i[..len]) | 558 | 13.2k | .chunks(2) | 559 | 13.2k | .map(|chunk| TlsCipherSuiteID((chunk[0] as u16) << 8 | chunk[1] as u16)) | 560 | 13.2k | .collect(); | 561 | 13.2k | Ok((&i[len..], v)) | 562 | 43.0k | } |
tls_parser::tls::parse_cipher_suites Line | Count | Source | 550 | 56.9k | pub(crate) fn parse_cipher_suites(i: &[u8], len: usize) -> IResult<&[u8], Vec<TlsCipherSuiteID>> { | 551 | 56.9k | if len == 0 { | 552 | 39.9k | return Ok((i, Vec::new())); | 553 | 17.0k | } | 554 | 17.0k | if len % 2 == 1 || len > i.len() { | 555 | 531 | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); | 556 | 16.4k | } | 557 | 16.4k | let v = (&i[..len]) | 558 | 16.4k | .chunks(2) | 559 | 16.4k | .map(|chunk| TlsCipherSuiteID((chunk[0] as u16) << 8 | chunk[1] as u16)) | 560 | 16.4k | .collect(); | 561 | 16.4k | Ok((&i[len..], v)) | 562 | 56.9k | } |
|
563 | | |
564 | 91.5k | pub(crate) fn parse_compressions_algs( |
565 | 91.5k | i: &[u8], |
566 | 91.5k | len: usize, |
567 | 91.5k | ) -> IResult<&[u8], Vec<TlsCompressionID>> { |
568 | 91.5k | if len == 0 { |
569 | 78.6k | return Ok((i, Vec::new())); |
570 | 12.9k | } |
571 | 12.9k | if len > i.len() { |
572 | 1.54k | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); |
573 | 11.3k | } |
574 | 456k | let v = (&i[..len]).iter().map(|&it| TlsCompressionID(it)).collect(); tls_parser::tls::parse_compressions_algs::{closure#0}Line | Count | Source | 574 | 228k | let v = (&i[..len]).iter().map(|&it| TlsCompressionID(it)).collect(); |
tls_parser::tls::parse_compressions_algs::{closure#0}Line | Count | Source | 574 | 228k | let v = (&i[..len]).iter().map(|&it| TlsCompressionID(it)).collect(); |
|
575 | 11.3k | Ok((&i[len..], v)) |
576 | 91.5k | } tls_parser::tls::parse_compressions_algs Line | Count | Source | 564 | 40.7k | pub(crate) fn parse_compressions_algs( | 565 | 40.7k | i: &[u8], | 566 | 40.7k | len: usize, | 567 | 40.7k | ) -> IResult<&[u8], Vec<TlsCompressionID>> { | 568 | 40.7k | if len == 0 { | 569 | 35.2k | return Ok((i, Vec::new())); | 570 | 5.49k | } | 571 | 5.49k | if len > i.len() { | 572 | 466 | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); | 573 | 5.03k | } | 574 | 5.03k | let v = (&i[..len]).iter().map(|&it| TlsCompressionID(it)).collect(); | 575 | 5.03k | Ok((&i[len..], v)) | 576 | 40.7k | } |
tls_parser::tls::parse_compressions_algs Line | Count | Source | 564 | 50.7k | pub(crate) fn parse_compressions_algs( | 565 | 50.7k | i: &[u8], | 566 | 50.7k | len: usize, | 567 | 50.7k | ) -> IResult<&[u8], Vec<TlsCompressionID>> { | 568 | 50.7k | if len == 0 { | 569 | 43.3k | return Ok((i, Vec::new())); | 570 | 7.43k | } | 571 | 7.43k | if len > i.len() { | 572 | 1.07k | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); | 573 | 6.35k | } | 574 | 6.35k | let v = (&i[..len]).iter().map(|&it| TlsCompressionID(it)).collect(); | 575 | 6.35k | Ok((&i[len..], v)) | 576 | 50.7k | } |
|
577 | | |
578 | 3.36k | pub(crate) fn parse_tls_versions(i: &[u8]) -> IResult<&[u8], Vec<TlsVersion>> { |
579 | 3.36k | let len = i.len(); |
580 | 3.36k | if len == 0 { |
581 | 523 | return Ok((i, Vec::new())); |
582 | 2.83k | } |
583 | 2.83k | if len % 2 == 1 || len > i.len() { |
584 | 396 | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); |
585 | 2.44k | } |
586 | 2.44k | let v = (&i[..len]) |
587 | 2.44k | .chunks(2) |
588 | 512k | .map(|chunk| TlsVersion((chunk[0] as u16) << 8 | chunk[1] as u16)) tls_parser::tls::parse_tls_versions::{closure#0}Line | Count | Source | 588 | 219k | .map(|chunk| TlsVersion((chunk[0] as u16) << 8 | chunk[1] as u16)) |
tls_parser::tls::parse_tls_versions::{closure#0}Line | Count | Source | 588 | 292k | .map(|chunk| TlsVersion((chunk[0] as u16) << 8 | chunk[1] as u16)) |
|
589 | 2.44k | .collect(); |
590 | 2.44k | Ok((&i[len..], v)) |
591 | 3.36k | } tls_parser::tls::parse_tls_versions Line | Count | Source | 578 | 1.77k | pub(crate) fn parse_tls_versions(i: &[u8]) -> IResult<&[u8], Vec<TlsVersion>> { | 579 | 1.77k | let len = i.len(); | 580 | 1.77k | if len == 0 { | 581 | 318 | return Ok((i, Vec::new())); | 582 | 1.46k | } | 583 | 1.46k | if len % 2 == 1 || len > i.len() { | 584 | 195 | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); | 585 | 1.26k | } | 586 | 1.26k | let v = (&i[..len]) | 587 | 1.26k | .chunks(2) | 588 | 1.26k | .map(|chunk| TlsVersion((chunk[0] as u16) << 8 | chunk[1] as u16)) | 589 | 1.26k | .collect(); | 590 | 1.26k | Ok((&i[len..], v)) | 591 | 1.77k | } |
tls_parser::tls::parse_tls_versions Line | Count | Source | 578 | 1.58k | pub(crate) fn parse_tls_versions(i: &[u8]) -> IResult<&[u8], Vec<TlsVersion>> { | 579 | 1.58k | let len = i.len(); | 580 | 1.58k | if len == 0 { | 581 | 205 | return Ok((i, Vec::new())); | 582 | 1.37k | } | 583 | 1.37k | if len % 2 == 1 || len > i.len() { | 584 | 201 | return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); | 585 | 1.17k | } | 586 | 1.17k | let v = (&i[..len]) | 587 | 1.17k | .chunks(2) | 588 | 1.17k | .map(|chunk| TlsVersion((chunk[0] as u16) << 8 | chunk[1] as u16)) | 589 | 1.17k | .collect(); | 590 | 1.17k | Ok((&i[len..], v)) | 591 | 1.58k | } |
|
592 | | |
593 | 396k | fn parse_certs(i: &[u8]) -> IResult<&[u8], Vec<RawCertificate>> { |
594 | 396k | many0(complete(map(length_data(be_u24), |data| RawCertificate { |
595 | 476k | data, |
596 | 476k | })))(i) tls_parser::tls::parse_certs::{closure#0}Line | Count | Source | 595 | 342k | data, | 596 | 342k | })))(i) |
tls_parser::tls::parse_certs::{closure#0}Line | Count | Source | 595 | 134k | data, | 596 | 134k | })))(i) |
|
597 | 396k | } tls_parser::tls::parse_certs Line | Count | Source | 593 | 229k | fn parse_certs(i: &[u8]) -> IResult<&[u8], Vec<RawCertificate>> { | 594 | 229k | many0(complete(map(length_data(be_u24), |data| RawCertificate { | 595 | | data, | 596 | 229k | })))(i) | 597 | 229k | } |
tls_parser::tls::parse_certs Line | Count | Source | 593 | 167k | fn parse_certs(i: &[u8]) -> IResult<&[u8], Vec<RawCertificate>> { | 594 | 167k | many0(complete(map(length_data(be_u24), |data| RawCertificate { | 595 | | data, | 596 | 167k | })))(i) | 597 | 167k | } |
|
598 | | |
599 | | /// Read TLS record header |
600 | | /// |
601 | | /// This function is used to get the record header. |
602 | | /// After calling this function, caller can read the expected number of bytes and use |
603 | | /// `parse_tls_record_with_header` to parse content. |
604 | | #[inline] |
605 | 703k | pub fn parse_tls_record_header(i: &[u8]) -> IResult<&[u8], TlsRecordHeader> { |
606 | 703k | TlsRecordHeader::parse(i) |
607 | 703k | } tls_parser::tls::parse_tls_record_header Line | Count | Source | 605 | 417k | pub fn parse_tls_record_header(i: &[u8]) -> IResult<&[u8], TlsRecordHeader> { | 606 | 417k | TlsRecordHeader::parse(i) | 607 | 417k | } |
tls_parser::tls::parse_tls_record_header Line | Count | Source | 605 | 285k | pub fn parse_tls_record_header(i: &[u8]) -> IResult<&[u8], TlsRecordHeader> { | 606 | 285k | TlsRecordHeader::parse(i) | 607 | 285k | } |
|
608 | | |
609 | | #[allow(clippy::unnecessary_wraps)] |
610 | 190k | fn parse_tls_handshake_msg_hello_request(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
611 | 190k | Ok((i, TlsMessageHandshake::HelloRequest)) |
612 | 190k | } tls_parser::tls::parse_tls_handshake_msg_hello_request Line | Count | Source | 610 | 161k | fn parse_tls_handshake_msg_hello_request(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 611 | 161k | Ok((i, TlsMessageHandshake::HelloRequest)) | 612 | 161k | } |
tls_parser::tls::parse_tls_handshake_msg_hello_request Line | Count | Source | 610 | 28.8k | fn parse_tls_handshake_msg_hello_request(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 611 | 28.8k | Ok((i, TlsMessageHandshake::HelloRequest)) | 612 | 28.8k | } |
|
613 | | |
614 | 124k | fn parse_tls_handshake_msg_client_hello(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
615 | 124k | let (i, version) = be_u16(i)?; |
616 | 120k | let (i, rand_time) = be_u32(i)?; |
617 | 114k | let (i, rand_data) = take(28usize)(i)?; // 28 as 32 (aligned) - 4 (time) |
618 | 109k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; tls_parser::tls::parse_tls_handshake_msg_client_hello::{closure#0}Line | Count | Source | 618 | 45.0k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; |
tls_parser::tls::parse_tls_handshake_msg_client_hello::{closure#0}Line | Count | Source | 618 | 59.1k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; |
|
619 | 102k | let (i, sid) = cond(sidlen > 0, take(sidlen as usize))(i)?; |
620 | 101k | let (i, ciphers_len) = be_u16(i)?; |
621 | 100k | let (i, ciphers) = parse_cipher_suites(i, ciphers_len as usize)?; |
622 | 98.7k | let (i, comp_len) = be_u8(i)?; |
623 | 91.5k | let (i, comp) = parse_compressions_algs(i, comp_len as usize)?; |
624 | 89.9k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; |
625 | 89.9k | let content = |
626 | 89.9k | TlsClientHelloContents::new(version, rand_time, rand_data, sid, ciphers, comp, ext); |
627 | 89.9k | Ok((i, TlsMessageHandshake::ClientHello(content))) |
628 | 124k | } tls_parser::tls::parse_tls_handshake_msg_client_hello Line | Count | Source | 614 | 58.0k | fn parse_tls_handshake_msg_client_hello(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 615 | 58.0k | let (i, version) = be_u16(i)?; | 616 | 55.2k | let (i, rand_time) = be_u32(i)?; | 617 | 53.2k | let (i, rand_data) = take(28usize)(i)?; // 28 as 32 (aligned) - 4 (time) | 618 | 49.4k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; | 619 | 44.4k | let (i, sid) = cond(sidlen > 0, take(sidlen as usize))(i)?; | 620 | 43.7k | let (i, ciphers_len) = be_u16(i)?; | 621 | 43.0k | let (i, ciphers) = parse_cipher_suites(i, ciphers_len as usize)?; | 622 | 42.2k | let (i, comp_len) = be_u8(i)?; | 623 | 40.7k | let (i, comp) = parse_compressions_algs(i, comp_len as usize)?; | 624 | 40.3k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 625 | 40.3k | let content = | 626 | 40.3k | TlsClientHelloContents::new(version, rand_time, rand_data, sid, ciphers, comp, ext); | 627 | 40.3k | Ok((i, TlsMessageHandshake::ClientHello(content))) | 628 | 58.0k | } |
tls_parser::tls::parse_tls_handshake_msg_client_hello Line | Count | Source | 614 | 66.0k | fn parse_tls_handshake_msg_client_hello(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 615 | 66.0k | let (i, version) = be_u16(i)?; | 616 | 64.8k | let (i, rand_time) = be_u32(i)?; | 617 | 61.6k | let (i, rand_data) = take(28usize)(i)?; // 28 as 32 (aligned) - 4 (time) | 618 | 59.5k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; | 619 | 58.4k | let (i, sid) = cond(sidlen > 0, take(sidlen as usize))(i)?; | 620 | 57.6k | let (i, ciphers_len) = be_u16(i)?; | 621 | 56.9k | let (i, ciphers) = parse_cipher_suites(i, ciphers_len as usize)?; | 622 | 56.4k | let (i, comp_len) = be_u8(i)?; | 623 | 50.7k | let (i, comp) = parse_compressions_algs(i, comp_len as usize)?; | 624 | 49.6k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 625 | 49.6k | let content = | 626 | 49.6k | TlsClientHelloContents::new(version, rand_time, rand_data, sid, ciphers, comp, ext); | 627 | 49.6k | Ok((i, TlsMessageHandshake::ClientHello(content))) | 628 | 66.0k | } |
|
629 | | |
630 | 40.1k | fn parse_tls_handshake_msg_server_hello_tlsv12(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
631 | 40.1k | map( |
632 | 40.1k | parse_tls_server_hello_tlsv12, |
633 | 40.1k | TlsMessageHandshake::ServerHello, |
634 | 40.1k | )(i) |
635 | 40.1k | } tls_parser::tls::parse_tls_handshake_msg_server_hello_tlsv12 Line | Count | Source | 630 | 26.8k | fn parse_tls_handshake_msg_server_hello_tlsv12(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 631 | 26.8k | map( | 632 | 26.8k | parse_tls_server_hello_tlsv12, | 633 | 26.8k | TlsMessageHandshake::ServerHello, | 634 | 26.8k | )(i) | 635 | 26.8k | } |
tls_parser::tls::parse_tls_handshake_msg_server_hello_tlsv12 Line | Count | Source | 630 | 13.3k | fn parse_tls_handshake_msg_server_hello_tlsv12(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 631 | 13.3k | map( | 632 | 13.3k | parse_tls_server_hello_tlsv12, | 633 | 13.3k | TlsMessageHandshake::ServerHello, | 634 | 13.3k | )(i) | 635 | 13.3k | } |
|
636 | | |
637 | 40.1k | pub(crate) fn parse_tls_server_hello_tlsv12(i: &[u8]) -> IResult<&[u8], TlsServerHelloContents> { |
638 | 40.1k | let (i, version) = be_u16(i)?; |
639 | 40.1k | let (i, rand_time) = be_u32(i)?; |
640 | 21.5k | let (i, rand_data) = take(28usize)(i)?; // 28 as 32 (aligned) - 4 (time) |
641 | 17.6k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; tls_parser::tls::parse_tls_server_hello_tlsv12::{closure#0}Line | Count | Source | 641 | 6.55k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; |
tls_parser::tls::parse_tls_server_hello_tlsv12::{closure#0}Line | Count | Source | 641 | 10.3k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; |
|
642 | 15.7k | let (i, sid) = cond(sidlen > 0, take(sidlen as usize))(i)?; |
643 | 14.7k | let (i, cipher) = be_u16(i)?; |
644 | 13.5k | let (i, comp) = be_u8(i)?; |
645 | 10.7k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; |
646 | 10.7k | let content = |
647 | 10.7k | TlsServerHelloContents::new(version, rand_time, rand_data, sid, cipher, comp, ext); |
648 | 10.7k | Ok((i, content)) |
649 | 40.1k | } tls_parser::tls::parse_tls_server_hello_tlsv12 Line | Count | Source | 637 | 26.8k | pub(crate) fn parse_tls_server_hello_tlsv12(i: &[u8]) -> IResult<&[u8], TlsServerHelloContents> { | 638 | 26.8k | let (i, version) = be_u16(i)?; | 639 | 26.8k | let (i, rand_time) = be_u32(i)?; | 640 | 9.28k | let (i, rand_data) = take(28usize)(i)?; // 28 as 32 (aligned) - 4 (time) | 641 | 6.94k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; | 642 | 6.16k | let (i, sid) = cond(sidlen > 0, take(sidlen as usize))(i)?; | 643 | 5.76k | let (i, cipher) = be_u16(i)?; | 644 | 5.24k | let (i, comp) = be_u8(i)?; | 645 | 3.51k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 646 | 3.51k | let content = | 647 | 3.51k | TlsServerHelloContents::new(version, rand_time, rand_data, sid, cipher, comp, ext); | 648 | 3.51k | Ok((i, content)) | 649 | 26.8k | } |
tls_parser::tls::parse_tls_server_hello_tlsv12 Line | Count | Source | 637 | 13.3k | pub(crate) fn parse_tls_server_hello_tlsv12(i: &[u8]) -> IResult<&[u8], TlsServerHelloContents> { | 638 | 13.3k | let (i, version) = be_u16(i)?; | 639 | 13.3k | let (i, rand_time) = be_u32(i)?; | 640 | 12.2k | let (i, rand_data) = take(28usize)(i)?; // 28 as 32 (aligned) - 4 (time) | 641 | 10.7k | let (i, sidlen) = verify(be_u8, |&n| n <= 32)(i)?; | 642 | 9.57k | let (i, sid) = cond(sidlen > 0, take(sidlen as usize))(i)?; | 643 | 8.93k | let (i, cipher) = be_u16(i)?; | 644 | 8.29k | let (i, comp) = be_u8(i)?; | 645 | 7.20k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 646 | 7.20k | let content = | 647 | 7.20k | TlsServerHelloContents::new(version, rand_time, rand_data, sid, cipher, comp, ext); | 648 | 7.20k | Ok((i, content)) | 649 | 13.3k | } |
|
650 | | |
651 | 6.99k | fn parse_tls_handshake_msg_server_hello_tlsv13draft18( |
652 | 6.99k | i: &[u8], |
653 | 6.99k | ) -> IResult<&[u8], TlsMessageHandshake> { |
654 | 6.99k | let (i, version) = TlsVersion::parse(i)?; |
655 | 6.99k | let (i, random) = take(32usize)(i)?; |
656 | 4.53k | let (i, cipher) = map(be_u16, TlsCipherSuiteID)(i)?; |
657 | 3.76k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; |
658 | 3.76k | let content = TlsServerHelloV13Draft18Contents { |
659 | 3.76k | version, |
660 | 3.76k | random, |
661 | 3.76k | cipher, |
662 | 3.76k | ext, |
663 | 3.76k | }; |
664 | 3.76k | Ok((i, TlsMessageHandshake::ServerHelloV13Draft18(content))) |
665 | 6.99k | } tls_parser::tls::parse_tls_handshake_msg_server_hello_tlsv13draft18 Line | Count | Source | 651 | 3.29k | fn parse_tls_handshake_msg_server_hello_tlsv13draft18( | 652 | 3.29k | i: &[u8], | 653 | 3.29k | ) -> IResult<&[u8], TlsMessageHandshake> { | 654 | 3.29k | let (i, version) = TlsVersion::parse(i)?; | 655 | 3.29k | let (i, random) = take(32usize)(i)?; | 656 | 2.36k | let (i, cipher) = map(be_u16, TlsCipherSuiteID)(i)?; | 657 | 1.97k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 658 | 1.97k | let content = TlsServerHelloV13Draft18Contents { | 659 | 1.97k | version, | 660 | 1.97k | random, | 661 | 1.97k | cipher, | 662 | 1.97k | ext, | 663 | 1.97k | }; | 664 | 1.97k | Ok((i, TlsMessageHandshake::ServerHelloV13Draft18(content))) | 665 | 3.29k | } |
tls_parser::tls::parse_tls_handshake_msg_server_hello_tlsv13draft18 Line | Count | Source | 651 | 3.70k | fn parse_tls_handshake_msg_server_hello_tlsv13draft18( | 652 | 3.70k | i: &[u8], | 653 | 3.70k | ) -> IResult<&[u8], TlsMessageHandshake> { | 654 | 3.70k | let (i, version) = TlsVersion::parse(i)?; | 655 | 3.70k | let (i, random) = take(32usize)(i)?; | 656 | 2.17k | let (i, cipher) = map(be_u16, TlsCipherSuiteID)(i)?; | 657 | 1.78k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 658 | 1.78k | let content = TlsServerHelloV13Draft18Contents { | 659 | 1.78k | version, | 660 | 1.78k | random, | 661 | 1.78k | cipher, | 662 | 1.78k | ext, | 663 | 1.78k | }; | 664 | 1.78k | Ok((i, TlsMessageHandshake::ServerHelloV13Draft18(content))) | 665 | 3.70k | } |
|
666 | | |
667 | 49.7k | fn parse_tls_handshake_msg_server_hello(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
668 | 49.7k | let (_, version) = be_u16(i)?; |
669 | 48.6k | match version { |
670 | 6.99k | 0x7f12 => parse_tls_handshake_msg_server_hello_tlsv13draft18(i), |
671 | 26.3k | 0x0303 => parse_tls_handshake_msg_server_hello_tlsv12(i), |
672 | 6.18k | 0x0302 => parse_tls_handshake_msg_server_hello_tlsv12(i), |
673 | 7.67k | 0x0301 => parse_tls_handshake_msg_server_hello_tlsv12(i), |
674 | | // 0x0300 => call!(parse_tls_handshake_msg_server_hello_sslv3(i), |
675 | 1.45k | _ => Err(Err::Error(make_error(i, ErrorKind::Tag))), |
676 | | } |
677 | 49.7k | } tls_parser::tls::parse_tls_handshake_msg_server_hello Line | Count | Source | 667 | 31.3k | fn parse_tls_handshake_msg_server_hello(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 668 | 31.3k | let (_, version) = be_u16(i)?; | 669 | 30.8k | match version { | 670 | 3.29k | 0x7f12 => parse_tls_handshake_msg_server_hello_tlsv13draft18(i), | 671 | 19.2k | 0x0303 => parse_tls_handshake_msg_server_hello_tlsv12(i), | 672 | 3.11k | 0x0302 => parse_tls_handshake_msg_server_hello_tlsv12(i), | 673 | 4.41k | 0x0301 => parse_tls_handshake_msg_server_hello_tlsv12(i), | 674 | | // 0x0300 => call!(parse_tls_handshake_msg_server_hello_sslv3(i), | 675 | 718 | _ => Err(Err::Error(make_error(i, ErrorKind::Tag))), | 676 | | } | 677 | 31.3k | } |
tls_parser::tls::parse_tls_handshake_msg_server_hello Line | Count | Source | 667 | 18.3k | fn parse_tls_handshake_msg_server_hello(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 668 | 18.3k | let (_, version) = be_u16(i)?; | 669 | 17.7k | match version { | 670 | 3.70k | 0x7f12 => parse_tls_handshake_msg_server_hello_tlsv13draft18(i), | 671 | 7.01k | 0x0303 => parse_tls_handshake_msg_server_hello_tlsv12(i), | 672 | 3.06k | 0x0302 => parse_tls_handshake_msg_server_hello_tlsv12(i), | 673 | 3.26k | 0x0301 => parse_tls_handshake_msg_server_hello_tlsv12(i), | 674 | | // 0x0300 => call!(parse_tls_handshake_msg_server_hello_sslv3(i), | 675 | 732 | _ => Err(Err::Error(make_error(i, ErrorKind::Tag))), | 676 | | } | 677 | 18.3k | } |
|
678 | | |
679 | | // RFC 5077 Stateless TLS Session Resumption |
680 | 2.66k | fn parse_tls_handshake_msg_newsessionticket( |
681 | 2.66k | i: &[u8], |
682 | 2.66k | len: usize, |
683 | 2.66k | ) -> IResult<&[u8], TlsMessageHandshake> { |
684 | 2.66k | if len < 4 { |
685 | 1.08k | return Err(Err::Error(make_error(i, ErrorKind::Verify))); |
686 | 1.58k | } |
687 | 1.58k | let (i, ticket_lifetime_hint) = be_u32(i)?; |
688 | 1.58k | let (i, ticket) = take(len - 4)(i)?; |
689 | 1.58k | let content = TlsNewSessionTicketContent { |
690 | 1.58k | ticket_lifetime_hint, |
691 | 1.58k | ticket, |
692 | 1.58k | }; |
693 | 1.58k | Ok((i, TlsMessageHandshake::NewSessionTicket(content))) |
694 | 2.66k | } tls_parser::tls::parse_tls_handshake_msg_newsessionticket Line | Count | Source | 680 | 1.32k | fn parse_tls_handshake_msg_newsessionticket( | 681 | 1.32k | i: &[u8], | 682 | 1.32k | len: usize, | 683 | 1.32k | ) -> IResult<&[u8], TlsMessageHandshake> { | 684 | 1.32k | if len < 4 { | 685 | 426 | return Err(Err::Error(make_error(i, ErrorKind::Verify))); | 686 | 895 | } | 687 | 895 | let (i, ticket_lifetime_hint) = be_u32(i)?; | 688 | 895 | let (i, ticket) = take(len - 4)(i)?; | 689 | 895 | let content = TlsNewSessionTicketContent { | 690 | 895 | ticket_lifetime_hint, | 691 | 895 | ticket, | 692 | 895 | }; | 693 | 895 | Ok((i, TlsMessageHandshake::NewSessionTicket(content))) | 694 | 1.32k | } |
tls_parser::tls::parse_tls_handshake_msg_newsessionticket Line | Count | Source | 680 | 1.34k | fn parse_tls_handshake_msg_newsessionticket( | 681 | 1.34k | i: &[u8], | 682 | 1.34k | len: usize, | 683 | 1.34k | ) -> IResult<&[u8], TlsMessageHandshake> { | 684 | 1.34k | if len < 4 { | 685 | 657 | return Err(Err::Error(make_error(i, ErrorKind::Verify))); | 686 | 690 | } | 687 | 690 | let (i, ticket_lifetime_hint) = be_u32(i)?; | 688 | 690 | let (i, ticket) = take(len - 4)(i)?; | 689 | 690 | let content = TlsNewSessionTicketContent { | 690 | 690 | ticket_lifetime_hint, | 691 | 690 | ticket, | 692 | 690 | }; | 693 | 690 | Ok((i, TlsMessageHandshake::NewSessionTicket(content))) | 694 | 1.34k | } |
|
695 | | |
696 | 48.2k | fn parse_tls_handshake_msg_hello_retry_request(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
697 | 48.2k | let (i, version) = TlsVersion::parse(i)?; |
698 | 7.09k | let (i, cipher) = map(be_u16, TlsCipherSuiteID)(i)?; |
699 | 5.36k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; |
700 | 5.36k | let content = TlsHelloRetryRequestContents { |
701 | 5.36k | version, |
702 | 5.36k | cipher, |
703 | 5.36k | ext, |
704 | 5.36k | }; |
705 | 5.36k | Ok((i, TlsMessageHandshake::HelloRetryRequest(content))) |
706 | 48.2k | } tls_parser::tls::parse_tls_handshake_msg_hello_retry_request Line | Count | Source | 696 | 43.5k | fn parse_tls_handshake_msg_hello_retry_request(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 697 | 43.5k | let (i, version) = TlsVersion::parse(i)?; | 698 | 3.05k | let (i, cipher) = map(be_u16, TlsCipherSuiteID)(i)?; | 699 | 2.22k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 700 | 2.22k | let content = TlsHelloRetryRequestContents { | 701 | 2.22k | version, | 702 | 2.22k | cipher, | 703 | 2.22k | ext, | 704 | 2.22k | }; | 705 | 2.22k | Ok((i, TlsMessageHandshake::HelloRetryRequest(content))) | 706 | 43.5k | } |
tls_parser::tls::parse_tls_handshake_msg_hello_retry_request Line | Count | Source | 696 | 4.73k | fn parse_tls_handshake_msg_hello_retry_request(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 697 | 4.73k | let (i, version) = TlsVersion::parse(i)?; | 698 | 4.04k | let (i, cipher) = map(be_u16, TlsCipherSuiteID)(i)?; | 699 | 3.13k | let (i, ext) = opt(complete(length_data(be_u16)))(i)?; | 700 | 3.13k | let content = TlsHelloRetryRequestContents { | 701 | 3.13k | version, | 702 | 3.13k | cipher, | 703 | 3.13k | ext, | 704 | 3.13k | }; | 705 | 3.13k | Ok((i, TlsMessageHandshake::HelloRetryRequest(content))) | 706 | 4.73k | } |
|
707 | | |
708 | 406k | pub(crate) fn parse_tls_certificate(i: &[u8]) -> IResult<&[u8], TlsCertificateContents> { |
709 | 406k | let (i, cert_len) = be_u24(i)?; |
710 | 403k | let (i, cert_chain) = map_parser(take(cert_len as usize), parse_certs)(i)?; |
711 | 396k | let content = TlsCertificateContents { cert_chain }; |
712 | 396k | Ok((i, content)) |
713 | 406k | } tls_parser::tls::parse_tls_certificate Line | Count | Source | 708 | 235k | pub(crate) fn parse_tls_certificate(i: &[u8]) -> IResult<&[u8], TlsCertificateContents> { | 709 | 235k | let (i, cert_len) = be_u24(i)?; | 710 | 235k | let (i, cert_chain) = map_parser(take(cert_len as usize), parse_certs)(i)?; | 711 | 229k | let content = TlsCertificateContents { cert_chain }; | 712 | 229k | Ok((i, content)) | 713 | 235k | } |
tls_parser::tls::parse_tls_certificate Line | Count | Source | 708 | 170k | pub(crate) fn parse_tls_certificate(i: &[u8]) -> IResult<&[u8], TlsCertificateContents> { | 709 | 170k | let (i, cert_len) = be_u24(i)?; | 710 | 168k | let (i, cert_chain) = map_parser(take(cert_len as usize), parse_certs)(i)?; | 711 | 167k | let content = TlsCertificateContents { cert_chain }; | 712 | 167k | Ok((i, content)) | 713 | 170k | } |
|
714 | | |
715 | 406k | fn parse_tls_handshake_msg_certificate(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
716 | 406k | map(parse_tls_certificate, TlsMessageHandshake::Certificate)(i) |
717 | 406k | } tls_parser::tls::parse_tls_handshake_msg_certificate Line | Count | Source | 715 | 235k | fn parse_tls_handshake_msg_certificate(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 716 | 235k | map(parse_tls_certificate, TlsMessageHandshake::Certificate)(i) | 717 | 235k | } |
tls_parser::tls::parse_tls_handshake_msg_certificate Line | Count | Source | 715 | 170k | fn parse_tls_handshake_msg_certificate(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 716 | 170k | map(parse_tls_certificate, TlsMessageHandshake::Certificate)(i) | 717 | 170k | } |
|
718 | | |
719 | 82.5k | fn parse_tls_handshake_msg_serverkeyexchange( |
720 | 82.5k | i: &[u8], |
721 | 82.5k | len: usize, |
722 | 82.5k | ) -> IResult<&[u8], TlsMessageHandshake> { |
723 | 82.5k | map(take(len), |ext| { |
724 | 82.5k | TlsMessageHandshake::ServerKeyExchange(TlsServerKeyExchangeContents { parameters: ext }) |
725 | 82.5k | })(i) tls_parser::tls::parse_tls_handshake_msg_serverkeyexchange::{closure#0}Line | Count | Source | 723 | 688 | map(take(len), |ext| { | 724 | 688 | TlsMessageHandshake::ServerKeyExchange(TlsServerKeyExchangeContents { parameters: ext }) | 725 | 688 | })(i) |
tls_parser::tls::parse_tls_handshake_msg_serverkeyexchange::{closure#0}Line | Count | Source | 723 | 81.8k | map(take(len), |ext| { | 724 | 81.8k | TlsMessageHandshake::ServerKeyExchange(TlsServerKeyExchangeContents { parameters: ext }) | 725 | 81.8k | })(i) |
|
726 | 82.5k | } tls_parser::tls::parse_tls_handshake_msg_serverkeyexchange Line | Count | Source | 719 | 688 | fn parse_tls_handshake_msg_serverkeyexchange( | 720 | 688 | i: &[u8], | 721 | 688 | len: usize, | 722 | 688 | ) -> IResult<&[u8], TlsMessageHandshake> { | 723 | 688 | map(take(len), |ext| { | 724 | | TlsMessageHandshake::ServerKeyExchange(TlsServerKeyExchangeContents { parameters: ext }) | 725 | 688 | })(i) | 726 | 688 | } |
tls_parser::tls::parse_tls_handshake_msg_serverkeyexchange Line | Count | Source | 719 | 81.8k | fn parse_tls_handshake_msg_serverkeyexchange( | 720 | 81.8k | i: &[u8], | 721 | 81.8k | len: usize, | 722 | 81.8k | ) -> IResult<&[u8], TlsMessageHandshake> { | 723 | 81.8k | map(take(len), |ext| { | 724 | | TlsMessageHandshake::ServerKeyExchange(TlsServerKeyExchangeContents { parameters: ext }) | 725 | 81.8k | })(i) | 726 | 81.8k | } |
|
727 | | |
728 | 4.22k | fn parse_tls_handshake_msg_serverdone(i: &[u8], len: usize) -> IResult<&[u8], TlsMessageHandshake> { |
729 | 4.22k | map(take(len), TlsMessageHandshake::ServerDone)(i) |
730 | 4.22k | } tls_parser::tls::parse_tls_handshake_msg_serverdone Line | Count | Source | 728 | 1.08k | fn parse_tls_handshake_msg_serverdone(i: &[u8], len: usize) -> IResult<&[u8], TlsMessageHandshake> { | 729 | 1.08k | map(take(len), TlsMessageHandshake::ServerDone)(i) | 730 | 1.08k | } |
tls_parser::tls::parse_tls_handshake_msg_serverdone Line | Count | Source | 728 | 3.14k | fn parse_tls_handshake_msg_serverdone(i: &[u8], len: usize) -> IResult<&[u8], TlsMessageHandshake> { | 729 | 3.14k | map(take(len), TlsMessageHandshake::ServerDone)(i) | 730 | 3.14k | } |
|
731 | | |
732 | 1.78k | fn parse_tls_handshake_msg_certificateverify( |
733 | 1.78k | i: &[u8], |
734 | 1.78k | len: usize, |
735 | 1.78k | ) -> IResult<&[u8], TlsMessageHandshake> { |
736 | 1.78k | map(take(len), TlsMessageHandshake::CertificateVerify)(i) |
737 | 1.78k | } tls_parser::tls::parse_tls_handshake_msg_certificateverify Line | Count | Source | 732 | 876 | fn parse_tls_handshake_msg_certificateverify( | 733 | 876 | i: &[u8], | 734 | 876 | len: usize, | 735 | 876 | ) -> IResult<&[u8], TlsMessageHandshake> { | 736 | 876 | map(take(len), TlsMessageHandshake::CertificateVerify)(i) | 737 | 876 | } |
tls_parser::tls::parse_tls_handshake_msg_certificateverify Line | Count | Source | 732 | 904 | fn parse_tls_handshake_msg_certificateverify( | 733 | 904 | i: &[u8], | 734 | 904 | len: usize, | 735 | 904 | ) -> IResult<&[u8], TlsMessageHandshake> { | 736 | 904 | map(take(len), TlsMessageHandshake::CertificateVerify)(i) | 737 | 904 | } |
|
738 | | |
739 | 4.44k | pub(crate) fn parse_tls_clientkeyexchange( |
740 | 4.44k | len: usize, |
741 | 4.44k | ) -> impl FnMut(&[u8]) -> IResult<&[u8], TlsClientKeyExchangeContents> { |
742 | 4.44k | move |i| map(take(len), TlsClientKeyExchangeContents::Unknown)(i) tls_parser::tls::parse_tls_clientkeyexchange::{closure#0}Line | Count | Source | 742 | 2.43k | move |i| map(take(len), TlsClientKeyExchangeContents::Unknown)(i) |
tls_parser::tls::parse_tls_clientkeyexchange::{closure#0}Line | Count | Source | 742 | 2.01k | move |i| map(take(len), TlsClientKeyExchangeContents::Unknown)(i) |
|
743 | 4.44k | } tls_parser::tls::parse_tls_clientkeyexchange Line | Count | Source | 739 | 2.43k | pub(crate) fn parse_tls_clientkeyexchange( | 740 | 2.43k | len: usize, | 741 | 2.43k | ) -> impl FnMut(&[u8]) -> IResult<&[u8], TlsClientKeyExchangeContents> { | 742 | | move |i| map(take(len), TlsClientKeyExchangeContents::Unknown)(i) | 743 | 2.43k | } |
tls_parser::tls::parse_tls_clientkeyexchange Line | Count | Source | 739 | 2.01k | pub(crate) fn parse_tls_clientkeyexchange( | 740 | 2.01k | len: usize, | 741 | 2.01k | ) -> impl FnMut(&[u8]) -> IResult<&[u8], TlsClientKeyExchangeContents> { | 742 | | move |i| map(take(len), TlsClientKeyExchangeContents::Unknown)(i) | 743 | 2.01k | } |
|
744 | | |
745 | 4.44k | fn parse_tls_handshake_msg_clientkeyexchange( |
746 | 4.44k | i: &[u8], |
747 | 4.44k | len: usize, |
748 | 4.44k | ) -> IResult<&[u8], TlsMessageHandshake> { |
749 | 4.44k | map( |
750 | 4.44k | parse_tls_clientkeyexchange(len), |
751 | 4.44k | TlsMessageHandshake::ClientKeyExchange, |
752 | 4.44k | )(i) |
753 | 4.44k | } tls_parser::tls::parse_tls_handshake_msg_clientkeyexchange Line | Count | Source | 745 | 2.43k | fn parse_tls_handshake_msg_clientkeyexchange( | 746 | 2.43k | i: &[u8], | 747 | 2.43k | len: usize, | 748 | 2.43k | ) -> IResult<&[u8], TlsMessageHandshake> { | 749 | 2.43k | map( | 750 | 2.43k | parse_tls_clientkeyexchange(len), | 751 | 2.43k | TlsMessageHandshake::ClientKeyExchange, | 752 | 2.43k | )(i) | 753 | 2.43k | } |
tls_parser::tls::parse_tls_handshake_msg_clientkeyexchange Line | Count | Source | 745 | 2.01k | fn parse_tls_handshake_msg_clientkeyexchange( | 746 | 2.01k | i: &[u8], | 747 | 2.01k | len: usize, | 748 | 2.01k | ) -> IResult<&[u8], TlsMessageHandshake> { | 749 | 2.01k | map( | 750 | 2.01k | parse_tls_clientkeyexchange(len), | 751 | 2.01k | TlsMessageHandshake::ClientKeyExchange, | 752 | 2.01k | )(i) | 753 | 2.01k | } |
|
754 | | |
755 | 103k | fn parse_certrequest_nosigalg(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
756 | 103k | let (i, cert_types) = length_count(be_u8, be_u8)(i)?; |
757 | 99.7k | let (i, ca_len) = be_u16(i)?; |
758 | 6.76k | let (i, unparsed_ca) = |
759 | 16.5k | map_parser(take(ca_len as usize), many0(complete(length_data(be_u16))))(i)?; |
760 | 6.76k | let content = TlsCertificateRequestContents { |
761 | 6.76k | cert_types, |
762 | 6.76k | // sig_hash_algs: Some(sig_hash_algs), |
763 | 6.76k | sig_hash_algs: None, |
764 | 6.76k | unparsed_ca, |
765 | 6.76k | }; |
766 | 6.76k | Ok((i, TlsMessageHandshake::CertificateRequest(content))) |
767 | 103k | } tls_parser::tls::parse_certrequest_nosigalg Line | Count | Source | 755 | 96.1k | fn parse_certrequest_nosigalg(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 756 | 96.1k | let (i, cert_types) = length_count(be_u8, be_u8)(i)?; | 757 | 94.5k | let (i, ca_len) = be_u16(i)?; | 758 | 3.21k | let (i, unparsed_ca) = | 759 | 12.0k | map_parser(take(ca_len as usize), many0(complete(length_data(be_u16))))(i)?; | 760 | 3.21k | let content = TlsCertificateRequestContents { | 761 | 3.21k | cert_types, | 762 | 3.21k | // sig_hash_algs: Some(sig_hash_algs), | 763 | 3.21k | sig_hash_algs: None, | 764 | 3.21k | unparsed_ca, | 765 | 3.21k | }; | 766 | 3.21k | Ok((i, TlsMessageHandshake::CertificateRequest(content))) | 767 | 96.1k | } |
tls_parser::tls::parse_certrequest_nosigalg Line | Count | Source | 755 | 7.18k | fn parse_certrequest_nosigalg(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 756 | 7.18k | let (i, cert_types) = length_count(be_u8, be_u8)(i)?; | 757 | 5.17k | let (i, ca_len) = be_u16(i)?; | 758 | 3.54k | let (i, unparsed_ca) = | 759 | 4.50k | map_parser(take(ca_len as usize), many0(complete(length_data(be_u16))))(i)?; | 760 | 3.54k | let content = TlsCertificateRequestContents { | 761 | 3.54k | cert_types, | 762 | 3.54k | // sig_hash_algs: Some(sig_hash_algs), | 763 | 3.54k | sig_hash_algs: None, | 764 | 3.54k | unparsed_ca, | 765 | 3.54k | }; | 766 | 3.54k | Ok((i, TlsMessageHandshake::CertificateRequest(content))) | 767 | 7.18k | } |
|
768 | | |
769 | 106k | fn parse_certrequest_full(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
770 | 106k | let (i, cert_types) = length_count(be_u8, be_u8)(i)?; |
771 | 102k | let (i, sig_hash_algs_len) = be_u16(i)?; |
772 | 9.83k | let (i, sig_hash_algs) = |
773 | 19.6k | map_parser(take(sig_hash_algs_len as usize), many0(complete(be_u16)))(i)?; |
774 | 9.83k | let (i, ca_len) = be_u16(i)?; |
775 | 3.06k | let (i, unparsed_ca) = |
776 | 5.35k | map_parser(take(ca_len as usize), many0(complete(length_data(be_u16))))(i)?; |
777 | 3.06k | let content = TlsCertificateRequestContents { |
778 | 3.06k | cert_types, |
779 | 3.06k | sig_hash_algs: Some(sig_hash_algs), |
780 | 3.06k | unparsed_ca, |
781 | 3.06k | }; |
782 | 3.06k | Ok((i, TlsMessageHandshake::CertificateRequest(content))) |
783 | 106k | } tls_parser::tls::parse_certrequest_full Line | Count | Source | 769 | 97.0k | fn parse_certrequest_full(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 770 | 97.0k | let (i, cert_types) = length_count(be_u8, be_u8)(i)?; | 771 | 95.4k | let (i, sig_hash_algs_len) = be_u16(i)?; | 772 | 4.14k | let (i, sig_hash_algs) = | 773 | 12.9k | map_parser(take(sig_hash_algs_len as usize), many0(complete(be_u16)))(i)?; | 774 | 4.14k | let (i, ca_len) = be_u16(i)?; | 775 | 924 | let (i, unparsed_ca) = | 776 | 1.76k | map_parser(take(ca_len as usize), many0(complete(length_data(be_u16))))(i)?; | 777 | 924 | let content = TlsCertificateRequestContents { | 778 | 924 | cert_types, | 779 | 924 | sig_hash_algs: Some(sig_hash_algs), | 780 | 924 | unparsed_ca, | 781 | 924 | }; | 782 | 924 | Ok((i, TlsMessageHandshake::CertificateRequest(content))) | 783 | 97.0k | } |
tls_parser::tls::parse_certrequest_full Line | Count | Source | 769 | 9.32k | fn parse_certrequest_full(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 770 | 9.32k | let (i, cert_types) = length_count(be_u8, be_u8)(i)?; | 771 | 7.31k | let (i, sig_hash_algs_len) = be_u16(i)?; | 772 | 5.68k | let (i, sig_hash_algs) = | 773 | 6.64k | map_parser(take(sig_hash_algs_len as usize), many0(complete(be_u16)))(i)?; | 774 | 5.68k | let (i, ca_len) = be_u16(i)?; | 775 | 2.14k | let (i, unparsed_ca) = | 776 | 3.59k | map_parser(take(ca_len as usize), many0(complete(length_data(be_u16))))(i)?; | 777 | 2.14k | let content = TlsCertificateRequestContents { | 778 | 2.14k | cert_types, | 779 | 2.14k | sig_hash_algs: Some(sig_hash_algs), | 780 | 2.14k | unparsed_ca, | 781 | 2.14k | }; | 782 | 2.14k | Ok((i, TlsMessageHandshake::CertificateRequest(content))) | 783 | 9.32k | } |
|
784 | | |
785 | | #[inline] |
786 | 106k | fn parse_tls_handshake_msg_certificaterequest(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
787 | 106k | alt(( |
788 | 106k | complete(parse_certrequest_full), |
789 | 106k | complete(parse_certrequest_nosigalg), |
790 | 106k | ))(i) |
791 | 106k | } tls_parser::tls::parse_tls_handshake_msg_certificaterequest Line | Count | Source | 786 | 97.0k | fn parse_tls_handshake_msg_certificaterequest(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 787 | 97.0k | alt(( | 788 | 97.0k | complete(parse_certrequest_full), | 789 | 97.0k | complete(parse_certrequest_nosigalg), | 790 | 97.0k | ))(i) | 791 | 97.0k | } |
tls_parser::tls::parse_tls_handshake_msg_certificaterequest Line | Count | Source | 786 | 9.32k | fn parse_tls_handshake_msg_certificaterequest(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 787 | 9.32k | alt(( | 788 | 9.32k | complete(parse_certrequest_full), | 789 | 9.32k | complete(parse_certrequest_nosigalg), | 790 | 9.32k | ))(i) | 791 | 9.32k | } |
|
792 | | |
793 | 1.53k | fn parse_tls_handshake_msg_finished(i: &[u8], len: usize) -> IResult<&[u8], TlsMessageHandshake> { |
794 | 1.53k | map(take(len), TlsMessageHandshake::Finished)(i) |
795 | 1.53k | } tls_parser::tls::parse_tls_handshake_msg_finished Line | Count | Source | 793 | 396 | fn parse_tls_handshake_msg_finished(i: &[u8], len: usize) -> IResult<&[u8], TlsMessageHandshake> { | 794 | 396 | map(take(len), TlsMessageHandshake::Finished)(i) | 795 | 396 | } |
tls_parser::tls::parse_tls_handshake_msg_finished Line | Count | Source | 793 | 1.13k | fn parse_tls_handshake_msg_finished(i: &[u8], len: usize) -> IResult<&[u8], TlsMessageHandshake> { | 794 | 1.13k | map(take(len), TlsMessageHandshake::Finished)(i) | 795 | 1.13k | } |
|
796 | | |
797 | | // Defined in [RFC6066] |
798 | | // if status_type == 0, blob is a OCSPResponse, as defined in [RFC2560](https://tools.ietf.org/html/rfc2560) |
799 | | // Note that the OCSPResponse object is DER-encoded. |
800 | 10.6k | fn parse_tls_handshake_msg_certificatestatus(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
801 | 10.6k | let (i, status_type) = be_u8(i)?; |
802 | 9.17k | let (i, blob) = length_data(be_u24)(i)?; |
803 | 1.69k | let content = TlsCertificateStatusContents { status_type, blob }; |
804 | 1.69k | Ok((i, TlsMessageHandshake::CertificateStatus(content))) |
805 | 10.6k | } tls_parser::tls::parse_tls_handshake_msg_certificatestatus Line | Count | Source | 800 | 4.01k | fn parse_tls_handshake_msg_certificatestatus(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 801 | 4.01k | let (i, status_type) = be_u8(i)?; | 802 | 3.49k | let (i, blob) = length_data(be_u24)(i)?; | 803 | 1.00k | let content = TlsCertificateStatusContents { status_type, blob }; | 804 | 1.00k | Ok((i, TlsMessageHandshake::CertificateStatus(content))) | 805 | 4.01k | } |
tls_parser::tls::parse_tls_handshake_msg_certificatestatus Line | Count | Source | 800 | 6.62k | fn parse_tls_handshake_msg_certificatestatus(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 801 | 6.62k | let (i, status_type) = be_u8(i)?; | 802 | 5.68k | let (i, blob) = length_data(be_u24)(i)?; | 803 | 695 | let content = TlsCertificateStatusContents { status_type, blob }; | 804 | 695 | Ok((i, TlsMessageHandshake::CertificateStatus(content))) | 805 | 6.62k | } |
|
806 | | |
807 | | /// NextProtocol handshake message, as defined in |
808 | | /// [draft-agl-tls-nextprotoneg-03](https://tools.ietf.org/html/draft-agl-tls-nextprotoneg-03) |
809 | | /// Deprecated in favour of ALPN. |
810 | 9.67k | fn parse_tls_handshake_msg_next_protocol(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
811 | 9.67k | let (i, selected_protocol) = length_data(be_u8)(i)?; |
812 | 7.30k | let (i, padding) = length_data(be_u8)(i)?; |
813 | 2.52k | let next_proto = TlsNextProtocolContent { |
814 | 2.52k | selected_protocol, |
815 | 2.52k | padding, |
816 | 2.52k | }; |
817 | 2.52k | Ok((i, TlsMessageHandshake::NextProtocol(next_proto))) |
818 | 9.67k | } tls_parser::tls::parse_tls_handshake_msg_next_protocol Line | Count | Source | 810 | 4.35k | fn parse_tls_handshake_msg_next_protocol(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 811 | 4.35k | let (i, selected_protocol) = length_data(be_u8)(i)?; | 812 | 3.15k | let (i, padding) = length_data(be_u8)(i)?; | 813 | 1.06k | let next_proto = TlsNextProtocolContent { | 814 | 1.06k | selected_protocol, | 815 | 1.06k | padding, | 816 | 1.06k | }; | 817 | 1.06k | Ok((i, TlsMessageHandshake::NextProtocol(next_proto))) | 818 | 4.35k | } |
tls_parser::tls::parse_tls_handshake_msg_next_protocol Line | Count | Source | 810 | 5.31k | fn parse_tls_handshake_msg_next_protocol(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 811 | 5.31k | let (i, selected_protocol) = length_data(be_u8)(i)?; | 812 | 4.15k | let (i, padding) = length_data(be_u8)(i)?; | 813 | 1.46k | let next_proto = TlsNextProtocolContent { | 814 | 1.46k | selected_protocol, | 815 | 1.46k | padding, | 816 | 1.46k | }; | 817 | 1.46k | Ok((i, TlsMessageHandshake::NextProtocol(next_proto))) | 818 | 5.31k | } |
|
819 | | |
820 | 2.96k | fn parse_tls_handshake_msg_key_update(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { |
821 | 2.96k | map(be_u8, TlsMessageHandshake::KeyUpdate)(i) |
822 | 2.96k | } tls_parser::tls::parse_tls_handshake_msg_key_update Line | Count | Source | 820 | 1.37k | fn parse_tls_handshake_msg_key_update(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 821 | 1.37k | map(be_u8, TlsMessageHandshake::KeyUpdate)(i) | 822 | 1.37k | } |
tls_parser::tls::parse_tls_handshake_msg_key_update Line | Count | Source | 820 | 1.58k | fn parse_tls_handshake_msg_key_update(i: &[u8]) -> IResult<&[u8], TlsMessageHandshake> { | 821 | 1.58k | map(be_u8, TlsMessageHandshake::KeyUpdate)(i) | 822 | 1.58k | } |
|
823 | | |
824 | | /// Parse a TLS handshake message |
825 | 1.53M | pub fn parse_tls_message_handshake(i: &[u8]) -> IResult<&[u8], TlsMessage> { |
826 | 1.53M | let (i, ht) = be_u8(i)?; |
827 | 1.10M | let (i, hl) = be_u24(i)?; |
828 | 1.09M | let (i, raw_msg) = take(hl)(i)?; |
829 | 1.05M | let (_, msg) = match TlsHandshakeType(ht) { |
830 | 190k | TlsHandshakeType::HelloRequest => parse_tls_handshake_msg_hello_request(raw_msg), |
831 | 124k | TlsHandshakeType::ClientHello => parse_tls_handshake_msg_client_hello(raw_msg), |
832 | 49.7k | TlsHandshakeType::ServerHello => parse_tls_handshake_msg_server_hello(raw_msg), |
833 | | TlsHandshakeType::NewSessionTicket => { |
834 | 2.66k | parse_tls_handshake_msg_newsessionticket(raw_msg, hl as usize) |
835 | | } |
836 | 6.67k | TlsHandshakeType::EndOfEarlyData => Ok((raw_msg, TlsMessageHandshake::EndOfEarlyData)), |
837 | 48.2k | TlsHandshakeType::HelloRetryRequest => parse_tls_handshake_msg_hello_retry_request(raw_msg), |
838 | 406k | TlsHandshakeType::Certificate => parse_tls_handshake_msg_certificate(raw_msg), |
839 | | TlsHandshakeType::ServerKeyExchange => { |
840 | 82.5k | parse_tls_handshake_msg_serverkeyexchange(raw_msg, hl as usize) |
841 | | } |
842 | 106k | TlsHandshakeType::CertificateRequest => parse_tls_handshake_msg_certificaterequest(raw_msg), |
843 | 4.22k | TlsHandshakeType::ServerDone => parse_tls_handshake_msg_serverdone(raw_msg, hl as usize), |
844 | | TlsHandshakeType::CertificateVerify => { |
845 | 1.78k | parse_tls_handshake_msg_certificateverify(raw_msg, hl as usize) |
846 | | } |
847 | | TlsHandshakeType::ClientKeyExchange => { |
848 | 4.44k | parse_tls_handshake_msg_clientkeyexchange(raw_msg, hl as usize) |
849 | | } |
850 | 1.53k | TlsHandshakeType::Finished => parse_tls_handshake_msg_finished(raw_msg, hl as usize), |
851 | | // TlsHandshakeType::CertificateURL => parse_tls_handshake_msg_certificateurl(raw_msg), |
852 | 10.6k | TlsHandshakeType::CertificateStatus => parse_tls_handshake_msg_certificatestatus(raw_msg), |
853 | 2.96k | TlsHandshakeType::KeyUpdate => parse_tls_handshake_msg_key_update(raw_msg), |
854 | 9.67k | TlsHandshakeType::NextProtocol => parse_tls_handshake_msg_next_protocol(raw_msg), |
855 | 2.39k | _ => Err(Err::Error(make_error(i, ErrorKind::Switch))), |
856 | 239k | }?; |
857 | 815k | Ok((i, TlsMessage::Handshake(msg))) |
858 | 1.53M | } tls_parser::tls::parse_tls_message_handshake Line | Count | Source | 825 | 890k | pub fn parse_tls_message_handshake(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 826 | 890k | let (i, ht) = be_u8(i)?; | 827 | 669k | let (i, hl) = be_u24(i)?; | 828 | 665k | let (i, raw_msg) = take(hl)(i)?; | 829 | 650k | let (_, msg) = match TlsHandshakeType(ht) { | 830 | 161k | TlsHandshakeType::HelloRequest => parse_tls_handshake_msg_hello_request(raw_msg), | 831 | 58.0k | TlsHandshakeType::ClientHello => parse_tls_handshake_msg_client_hello(raw_msg), | 832 | 31.3k | TlsHandshakeType::ServerHello => parse_tls_handshake_msg_server_hello(raw_msg), | 833 | | TlsHandshakeType::NewSessionTicket => { | 834 | 1.32k | parse_tls_handshake_msg_newsessionticket(raw_msg, hl as usize) | 835 | | } | 836 | 5.40k | TlsHandshakeType::EndOfEarlyData => Ok((raw_msg, TlsMessageHandshake::EndOfEarlyData)), | 837 | 43.5k | TlsHandshakeType::HelloRetryRequest => parse_tls_handshake_msg_hello_retry_request(raw_msg), | 838 | 235k | TlsHandshakeType::Certificate => parse_tls_handshake_msg_certificate(raw_msg), | 839 | | TlsHandshakeType::ServerKeyExchange => { | 840 | 688 | parse_tls_handshake_msg_serverkeyexchange(raw_msg, hl as usize) | 841 | | } | 842 | 97.0k | TlsHandshakeType::CertificateRequest => parse_tls_handshake_msg_certificaterequest(raw_msg), | 843 | 1.08k | TlsHandshakeType::ServerDone => parse_tls_handshake_msg_serverdone(raw_msg, hl as usize), | 844 | | TlsHandshakeType::CertificateVerify => { | 845 | 876 | parse_tls_handshake_msg_certificateverify(raw_msg, hl as usize) | 846 | | } | 847 | | TlsHandshakeType::ClientKeyExchange => { | 848 | 2.43k | parse_tls_handshake_msg_clientkeyexchange(raw_msg, hl as usize) | 849 | | } | 850 | 396 | TlsHandshakeType::Finished => parse_tls_handshake_msg_finished(raw_msg, hl as usize), | 851 | | // TlsHandshakeType::CertificateURL => parse_tls_handshake_msg_certificateurl(raw_msg), | 852 | 4.01k | TlsHandshakeType::CertificateStatus => parse_tls_handshake_msg_certificatestatus(raw_msg), | 853 | 1.37k | TlsHandshakeType::KeyUpdate => parse_tls_handshake_msg_key_update(raw_msg), | 854 | 4.35k | TlsHandshakeType::NextProtocol => parse_tls_handshake_msg_next_protocol(raw_msg), | 855 | 887 | _ => Err(Err::Error(make_error(i, ErrorKind::Switch))), | 856 | 192k | }?; | 857 | 457k | Ok((i, TlsMessage::Handshake(msg))) | 858 | 890k | } |
tls_parser::tls::parse_tls_message_handshake Line | Count | Source | 825 | 647k | pub fn parse_tls_message_handshake(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 826 | 647k | let (i, ht) = be_u8(i)?; | 827 | 438k | let (i, hl) = be_u24(i)?; | 828 | 431k | let (i, raw_msg) = take(hl)(i)?; | 829 | 404k | let (_, msg) = match TlsHandshakeType(ht) { | 830 | 28.8k | TlsHandshakeType::HelloRequest => parse_tls_handshake_msg_hello_request(raw_msg), | 831 | 66.0k | TlsHandshakeType::ClientHello => parse_tls_handshake_msg_client_hello(raw_msg), | 832 | 18.3k | TlsHandshakeType::ServerHello => parse_tls_handshake_msg_server_hello(raw_msg), | 833 | | TlsHandshakeType::NewSessionTicket => { | 834 | 1.34k | parse_tls_handshake_msg_newsessionticket(raw_msg, hl as usize) | 835 | | } | 836 | 1.27k | TlsHandshakeType::EndOfEarlyData => Ok((raw_msg, TlsMessageHandshake::EndOfEarlyData)), | 837 | 4.73k | TlsHandshakeType::HelloRetryRequest => parse_tls_handshake_msg_hello_retry_request(raw_msg), | 838 | 170k | TlsHandshakeType::Certificate => parse_tls_handshake_msg_certificate(raw_msg), | 839 | | TlsHandshakeType::ServerKeyExchange => { | 840 | 81.8k | parse_tls_handshake_msg_serverkeyexchange(raw_msg, hl as usize) | 841 | | } | 842 | 9.32k | TlsHandshakeType::CertificateRequest => parse_tls_handshake_msg_certificaterequest(raw_msg), | 843 | 3.14k | TlsHandshakeType::ServerDone => parse_tls_handshake_msg_serverdone(raw_msg, hl as usize), | 844 | | TlsHandshakeType::CertificateVerify => { | 845 | 904 | parse_tls_handshake_msg_certificateverify(raw_msg, hl as usize) | 846 | | } | 847 | | TlsHandshakeType::ClientKeyExchange => { | 848 | 2.01k | parse_tls_handshake_msg_clientkeyexchange(raw_msg, hl as usize) | 849 | | } | 850 | 1.13k | TlsHandshakeType::Finished => parse_tls_handshake_msg_finished(raw_msg, hl as usize), | 851 | | // TlsHandshakeType::CertificateURL => parse_tls_handshake_msg_certificateurl(raw_msg), | 852 | 6.62k | TlsHandshakeType::CertificateStatus => parse_tls_handshake_msg_certificatestatus(raw_msg), | 853 | 1.58k | TlsHandshakeType::KeyUpdate => parse_tls_handshake_msg_key_update(raw_msg), | 854 | 5.31k | TlsHandshakeType::NextProtocol => parse_tls_handshake_msg_next_protocol(raw_msg), | 855 | 1.50k | _ => Err(Err::Error(make_error(i, ErrorKind::Switch))), | 856 | 46.8k | }?; | 857 | 357k | Ok((i, TlsMessage::Handshake(msg))) | 858 | 647k | } |
|
859 | | |
860 | | /// Parse a TLS changecipherspec message |
861 | | // XXX add extra verification hdr.len == 1 |
862 | 102k | pub fn parse_tls_message_changecipherspec(i: &[u8]) -> IResult<&[u8], TlsMessage> { |
863 | 102k | let (i, _) = verify(be_u8, |&tag| tag == 0x01)(i)?; tls_parser::tls::parse_tls_message_changecipherspec::{closure#0}Line | Count | Source | 863 | 72.4k | let (i, _) = verify(be_u8, |&tag| tag == 0x01)(i)?; |
tls_parser::tls::parse_tls_message_changecipherspec::{closure#0}Line | Count | Source | 863 | 25.7k | let (i, _) = verify(be_u8, |&tag| tag == 0x01)(i)?; |
|
864 | 79.5k | Ok((i, TlsMessage::ChangeCipherSpec)) |
865 | 102k | } tls_parser::tls::parse_tls_message_changecipherspec Line | Count | Source | 862 | 74.1k | pub fn parse_tls_message_changecipherspec(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 863 | 74.1k | let (i, _) = verify(be_u8, |&tag| tag == 0x01)(i)?; | 864 | 54.8k | Ok((i, TlsMessage::ChangeCipherSpec)) | 865 | 74.1k | } |
tls_parser::tls::parse_tls_message_changecipherspec Line | Count | Source | 862 | 27.8k | pub fn parse_tls_message_changecipherspec(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 863 | 27.8k | let (i, _) = verify(be_u8, |&tag| tag == 0x01)(i)?; | 864 | 24.6k | Ok((i, TlsMessage::ChangeCipherSpec)) | 865 | 27.8k | } |
|
866 | | |
867 | | /// Parse a TLS alert message |
868 | | // XXX add extra verification hdr.len == 2 |
869 | 682k | pub fn parse_tls_message_alert(i: &[u8]) -> IResult<&[u8], TlsMessage> { |
870 | 682k | let (i, alert) = TlsMessageAlert::parse(i)?; |
871 | 662k | Ok((i, TlsMessage::Alert(alert))) |
872 | 682k | } tls_parser::tls::parse_tls_message_alert Line | Count | Source | 869 | 50.6k | pub fn parse_tls_message_alert(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 870 | 50.6k | let (i, alert) = TlsMessageAlert::parse(i)?; | 871 | 47.4k | Ok((i, TlsMessage::Alert(alert))) | 872 | 50.6k | } |
tls_parser::tls::parse_tls_message_alert Line | Count | Source | 869 | 632k | pub fn parse_tls_message_alert(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 870 | 632k | let (i, alert) = TlsMessageAlert::parse(i)?; | 871 | 614k | Ok((i, TlsMessage::Alert(alert))) | 872 | 632k | } |
|
873 | | |
874 | | /// Parse a TLS applicationdata message |
875 | | /// |
876 | | /// Read the entire input as applicationdata |
877 | 26 | pub fn parse_tls_message_applicationdata(i: &[u8]) -> IResult<&[u8], TlsMessage> { |
878 | 26 | let msg = TlsMessage::ApplicationData(TlsMessageApplicationData { blob: i }); |
879 | 26 | Ok((&[], msg)) |
880 | 26 | } tls_parser::tls::parse_tls_message_applicationdata Line | Count | Source | 877 | 10 | pub fn parse_tls_message_applicationdata(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 878 | 10 | let msg = TlsMessage::ApplicationData(TlsMessageApplicationData { blob: i }); | 879 | 10 | Ok((&[], msg)) | 880 | 10 | } |
tls_parser::tls::parse_tls_message_applicationdata Line | Count | Source | 877 | 16 | pub fn parse_tls_message_applicationdata(i: &[u8]) -> IResult<&[u8], TlsMessage> { | 878 | 16 | let msg = TlsMessage::ApplicationData(TlsMessageApplicationData { blob: i }); | 879 | 16 | Ok((&[], msg)) | 880 | 16 | } |
|
881 | | |
882 | | /// Parse a TLS heartbeat message |
883 | 7.31k | pub fn parse_tls_message_heartbeat( |
884 | 7.31k | i: &[u8], |
885 | 7.31k | tls_plaintext_len: u16, |
886 | 7.31k | ) -> IResult<&[u8], Vec<TlsMessage>> { |
887 | 7.31k | let (i, heartbeat_type) = TlsHeartbeatMessageType::parse(i)?; |
888 | 5.65k | let (i, payload_len) = be_u16(i)?; |
889 | 3.68k | if tls_plaintext_len < 3 { |
890 | 0 | return Err(Err::Error(make_error(i, ErrorKind::Verify))); |
891 | 3.68k | } |
892 | 3.68k | let (i, payload) = take(payload_len as usize)(i)?; |
893 | 1.65k | let v = vec![TlsMessage::Heartbeat(TlsMessageHeartbeat { |
894 | 1.65k | heartbeat_type, |
895 | 1.65k | payload_len, |
896 | 1.65k | payload, |
897 | 1.65k | })]; |
898 | 1.65k | Ok((i, v)) |
899 | 7.31k | } tls_parser::tls::parse_tls_message_heartbeat Line | Count | Source | 883 | 3.12k | pub fn parse_tls_message_heartbeat( | 884 | 3.12k | i: &[u8], | 885 | 3.12k | tls_plaintext_len: u16, | 886 | 3.12k | ) -> IResult<&[u8], Vec<TlsMessage>> { | 887 | 3.12k | let (i, heartbeat_type) = TlsHeartbeatMessageType::parse(i)?; | 888 | 2.06k | let (i, payload_len) = be_u16(i)?; | 889 | 1.68k | if tls_plaintext_len < 3 { | 890 | 0 | return Err(Err::Error(make_error(i, ErrorKind::Verify))); | 891 | 1.68k | } | 892 | 1.68k | let (i, payload) = take(payload_len as usize)(i)?; | 893 | 602 | let v = vec![TlsMessage::Heartbeat(TlsMessageHeartbeat { | 894 | 602 | heartbeat_type, | 895 | 602 | payload_len, | 896 | 602 | payload, | 897 | 602 | })]; | 898 | 602 | Ok((i, v)) | 899 | 3.12k | } |
tls_parser::tls::parse_tls_message_heartbeat Line | Count | Source | 883 | 4.18k | pub fn parse_tls_message_heartbeat( | 884 | 4.18k | i: &[u8], | 885 | 4.18k | tls_plaintext_len: u16, | 886 | 4.18k | ) -> IResult<&[u8], Vec<TlsMessage>> { | 887 | 4.18k | let (i, heartbeat_type) = TlsHeartbeatMessageType::parse(i)?; | 888 | 3.58k | let (i, payload_len) = be_u16(i)?; | 889 | 1.99k | if tls_plaintext_len < 3 { | 890 | 0 | return Err(Err::Error(make_error(i, ErrorKind::Verify))); | 891 | 1.99k | } | 892 | 1.99k | let (i, payload) = take(payload_len as usize)(i)?; | 893 | 1.05k | let v = vec![TlsMessage::Heartbeat(TlsMessageHeartbeat { | 894 | 1.05k | heartbeat_type, | 895 | 1.05k | payload_len, | 896 | 1.05k | payload, | 897 | 1.05k | })]; | 898 | 1.05k | Ok((i, v)) | 899 | 4.18k | } |
|
900 | | |
901 | | /// Given data and a TLS record header, parse content. |
902 | | /// |
903 | | /// A record can contain multiple messages (with the same type). |
904 | | /// |
905 | | /// Note that message length is checked (not required for parser safety, but for |
906 | | /// strict protocol conformance). |
907 | | #[rustfmt::skip] |
908 | | #[allow(clippy::trivially_copy_pass_by_ref)] // TlsRecordHeader is only 6 bytes, but we prefer not breaking current API |
909 | 659k | pub fn parse_tls_record_with_header<'i, 'hdr>(i:&'i [u8], hdr:&'hdr TlsRecordHeader ) -> IResult<&'i [u8], Vec<TlsMessage<'i>>> { |
910 | 659k | match hdr.record_type { |
911 | 22.4k | TlsRecordType::ChangeCipherSpec => many1(complete(parse_tls_message_changecipherspec))(i), |
912 | 20.6k | TlsRecordType::Alert => many1(complete(parse_tls_message_alert))(i), |
913 | 608k | TlsRecordType::Handshake => many1(complete(parse_tls_message_handshake))(i), |
914 | 13 | TlsRecordType::ApplicationData => many1(complete(parse_tls_message_applicationdata))(i), |
915 | 7.31k | TlsRecordType::Heartbeat => parse_tls_message_heartbeat(i, hdr.len), |
916 | 183 | _ => Err(Err::Error(make_error(i, ErrorKind::Switch))) |
917 | | } |
918 | 659k | } tls_parser::tls::parse_tls_record_with_header Line | Count | Source | 909 | 407k | pub fn parse_tls_record_with_header<'i, 'hdr>(i:&'i [u8], hdr:&'hdr TlsRecordHeader ) -> IResult<&'i [u8], Vec<TlsMessage<'i>>> { | 910 | 407k | match hdr.record_type { | 911 | 19.2k | TlsRecordType::ChangeCipherSpec => many1(complete(parse_tls_message_changecipherspec))(i), | 912 | 3.17k | TlsRecordType::Alert => many1(complete(parse_tls_message_alert))(i), | 913 | 381k | TlsRecordType::Handshake => many1(complete(parse_tls_message_handshake))(i), | 914 | 5 | TlsRecordType::ApplicationData => many1(complete(parse_tls_message_applicationdata))(i), | 915 | 3.12k | TlsRecordType::Heartbeat => parse_tls_message_heartbeat(i, hdr.len), | 916 | 68 | _ => Err(Err::Error(make_error(i, ErrorKind::Switch))) | 917 | | } | 918 | 407k | } |
tls_parser::tls::parse_tls_record_with_header Line | Count | Source | 909 | 252k | pub fn parse_tls_record_with_header<'i, 'hdr>(i:&'i [u8], hdr:&'hdr TlsRecordHeader ) -> IResult<&'i [u8], Vec<TlsMessage<'i>>> { | 910 | 252k | match hdr.record_type { | 911 | 3.22k | TlsRecordType::ChangeCipherSpec => many1(complete(parse_tls_message_changecipherspec))(i), | 912 | 17.4k | TlsRecordType::Alert => many1(complete(parse_tls_message_alert))(i), | 913 | 227k | TlsRecordType::Handshake => many1(complete(parse_tls_message_handshake))(i), | 914 | 8 | TlsRecordType::ApplicationData => many1(complete(parse_tls_message_applicationdata))(i), | 915 | 4.18k | TlsRecordType::Heartbeat => parse_tls_message_heartbeat(i, hdr.len), | 916 | 115 | _ => Err(Err::Error(make_error(i, ErrorKind::Switch))) | 917 | | } | 918 | 252k | } |
|
919 | | |
920 | | /// Parse one packet only, as plaintext |
921 | | /// A single record can contain multiple messages, they must share the same record type |
922 | 703k | pub fn parse_tls_plaintext(i: &[u8]) -> IResult<&[u8], TlsPlaintext> { |
923 | 703k | let (i, hdr) = parse_tls_record_header(i)?; |
924 | 686k | if hdr.len > MAX_RECORD_LEN { |
925 | 349 | return Err(Err::Error(make_error(i, ErrorKind::TooLarge))); |
926 | 686k | } |
927 | 686k | let (i, msg) = map_parser(take(hdr.len as usize), |i| { |
928 | 659k | parse_tls_record_with_header(i, &hdr) |
929 | 686k | })(i)?; tls_parser::tls::parse_tls_plaintext::{closure#0}Line | Count | Source | 927 | 407k | let (i, msg) = map_parser(take(hdr.len as usize), |i| { | 928 | 407k | parse_tls_record_with_header(i, &hdr) | 929 | 407k | })(i)?; |
tls_parser::tls::parse_tls_plaintext::{closure#0}Line | Count | Source | 927 | 252k | let (i, msg) = map_parser(take(hdr.len as usize), |i| { | 928 | 252k | parse_tls_record_with_header(i, &hdr) | 929 | 252k | })(i)?; |
|
930 | 652k | Ok((i, TlsPlaintext { hdr, msg })) |
931 | 703k | } tls_parser::tls::parse_tls_plaintext Line | Count | Source | 922 | 417k | pub fn parse_tls_plaintext(i: &[u8]) -> IResult<&[u8], TlsPlaintext> { | 923 | 417k | let (i, hdr) = parse_tls_record_header(i)?; | 924 | 412k | if hdr.len > MAX_RECORD_LEN { | 925 | 118 | return Err(Err::Error(make_error(i, ErrorKind::TooLarge))); | 926 | 412k | } | 927 | 412k | let (i, msg) = map_parser(take(hdr.len as usize), |i| { | 928 | | parse_tls_record_with_header(i, &hdr) | 929 | 412k | })(i)?; | 930 | 404k | Ok((i, TlsPlaintext { hdr, msg })) | 931 | 417k | } |
tls_parser::tls::parse_tls_plaintext Line | Count | Source | 922 | 285k | pub fn parse_tls_plaintext(i: &[u8]) -> IResult<&[u8], TlsPlaintext> { | 923 | 285k | let (i, hdr) = parse_tls_record_header(i)?; | 924 | 274k | if hdr.len > MAX_RECORD_LEN { | 925 | 231 | return Err(Err::Error(make_error(i, ErrorKind::TooLarge))); | 926 | 273k | } | 927 | 273k | let (i, msg) = map_parser(take(hdr.len as usize), |i| { | 928 | | parse_tls_record_with_header(i, &hdr) | 929 | 273k | })(i)?; | 930 | 248k | Ok((i, TlsPlaintext { hdr, msg })) | 931 | 285k | } |
|
932 | | |
933 | | /// Parse one packet only, as encrypted content |
934 | 0 | pub fn parse_tls_encrypted(i: &[u8]) -> IResult<&[u8], TlsEncrypted> { |
935 | 0 | let (i, hdr) = parse_tls_record_header(i)?; |
936 | 0 | if hdr.len > MAX_RECORD_LEN { |
937 | 0 | return Err(Err::Error(make_error(i, ErrorKind::TooLarge))); |
938 | 0 | } |
939 | 0 | let (i, blob) = take(hdr.len as usize)(i)?; |
940 | 0 | let msg = TlsEncryptedContent { blob }; |
941 | 0 | Ok((i, TlsEncrypted { hdr, msg })) |
942 | 0 | } Unexecuted instantiation: tls_parser::tls::parse_tls_encrypted Unexecuted instantiation: tls_parser::tls::parse_tls_encrypted |
943 | | |
944 | | /// Read TLS record envelope, but do not decode data |
945 | | /// |
946 | | /// This function is used to get the record type, and to make sure the record is |
947 | | /// complete (not fragmented). |
948 | | /// After calling this function, use `parse_tls_record_with_header` to parse content. |
949 | 0 | pub fn parse_tls_raw_record(i: &[u8]) -> IResult<&[u8], TlsRawRecord> { |
950 | 0 | let (i, hdr) = parse_tls_record_header(i)?; |
951 | 0 | if hdr.len > MAX_RECORD_LEN { |
952 | 0 | return Err(Err::Error(make_error(i, ErrorKind::TooLarge))); |
953 | 0 | } |
954 | 0 | let (i, data) = take(hdr.len as usize)(i)?; |
955 | 0 | Ok((i, TlsRawRecord { hdr, data })) |
956 | 0 | } Unexecuted instantiation: tls_parser::tls::parse_tls_raw_record Unexecuted instantiation: tls_parser::tls::parse_tls_raw_record |
957 | | |
958 | | /// Parse one packet only, as plaintext |
959 | | /// This function is deprecated. Use `parse_tls_plaintext` instead. |
960 | | /// |
961 | | /// This function will be removed from API, as the name is not correct: it is |
962 | | /// not possible to parse TLS packets without knowing the TLS state. |
963 | | #[deprecated(since = "0.5.0", note = "Use parse_tls_plaintext")] |
964 | | #[inline] |
965 | 0 | pub fn tls_parser(i: &[u8]) -> IResult<&[u8], TlsPlaintext> { |
966 | 0 | parse_tls_plaintext(i) |
967 | 0 | } Unexecuted instantiation: tls_parser::tls::tls_parser Unexecuted instantiation: tls_parser::tls::tls_parser |
968 | | |
969 | | /// Parse one chunk of data, possibly containing multiple TLS plaintext records |
970 | | /// This function is deprecated. Use `parse_tls_plaintext` instead, checking if |
971 | | /// there are remaining bytes, and calling `parse_tls_plaintext` recursively. |
972 | | /// |
973 | | /// This function will be removed from API, as it should be replaced by a more |
974 | | /// useful one to handle fragmentation. |
975 | 0 | pub fn tls_parser_many(i: &[u8]) -> IResult<&[u8], Vec<TlsPlaintext>> { |
976 | 0 | many1(complete(parse_tls_plaintext))(i) |
977 | 0 | } Unexecuted instantiation: tls_parser::tls::tls_parser_many Unexecuted instantiation: tls_parser::tls::tls_parser_many |