/rust/registry/src/index.crates.io-1949cf8c6b5b557f/rustls-0.23.46/src/common_state.rs
Line | Count | Source |
1 | | use alloc::boxed::Box; |
2 | | use alloc::vec::Vec; |
3 | | |
4 | | use pki_types::CertificateDer; |
5 | | |
6 | | use crate::conn::kernel::KernelState; |
7 | | use crate::crypto::SupportedKxGroup; |
8 | | use crate::enums::{AlertDescription, ContentType, HandshakeType, ProtocolVersion}; |
9 | | use crate::error::{Error, InvalidMessage, PeerMisbehaved}; |
10 | | use crate::hash_hs::HandshakeHash; |
11 | | use crate::log::{debug, error, warn}; |
12 | | use crate::msgs::alert::AlertMessagePayload; |
13 | | use crate::msgs::base::Payload; |
14 | | use crate::msgs::codec::Codec; |
15 | | use crate::msgs::enums::{AlertLevel, KeyUpdateRequest}; |
16 | | use crate::msgs::fragmenter::MessageFragmenter; |
17 | | use crate::msgs::handshake::{CertificateChain, HandshakeMessagePayload, ProtocolName}; |
18 | | use crate::msgs::message::{ |
19 | | Message, MessagePayload, OutboundChunks, OutboundOpaqueMessage, OutboundPlainMessage, |
20 | | PlainMessage, |
21 | | }; |
22 | | use crate::record_layer::PreEncryptAction; |
23 | | use crate::suites::{PartiallyExtractedSecrets, SupportedCipherSuite}; |
24 | | #[cfg(feature = "tls12")] |
25 | | use crate::tls12::ConnectionSecrets; |
26 | | use crate::unbuffered::{EncryptError, InsufficientSizeError}; |
27 | | use crate::vecbuf::ChunkVecBuffer; |
28 | | use crate::{quic, record_layer}; |
29 | | |
30 | | /// Connection state common to both client and server connections. |
31 | | pub struct CommonState { |
32 | | pub(crate) negotiated_version: Option<ProtocolVersion>, |
33 | | pub(crate) handshake_kind: Option<HandshakeKind>, |
34 | | pub(crate) side: Side, |
35 | | pub(crate) record_layer: record_layer::RecordLayer, |
36 | | pub(crate) suite: Option<SupportedCipherSuite>, |
37 | | pub(crate) kx_state: KxState, |
38 | | pub(crate) alpn_protocol: Option<ProtocolName>, |
39 | | pub(crate) aligned_handshake: bool, |
40 | | pub(crate) may_send_application_data: bool, |
41 | | pub(crate) may_receive_application_data: bool, |
42 | | pub(crate) early_traffic: bool, |
43 | | sent_fatal_alert: bool, |
44 | | /// If we signaled end of stream. |
45 | | pub(crate) has_sent_close_notify: bool, |
46 | | /// If the peer has signaled end of stream. |
47 | | pub(crate) has_received_close_notify: bool, |
48 | | #[cfg(feature = "std")] |
49 | | pub(crate) has_seen_eof: bool, |
50 | | pub(crate) peer_certificates: Option<CertificateChain<'static>>, |
51 | | message_fragmenter: MessageFragmenter, |
52 | | pub(crate) received_plaintext: ChunkVecBuffer, |
53 | | pub(crate) sendable_tls: ChunkVecBuffer, |
54 | | queued_key_update_message: Option<Vec<u8>>, |
55 | | |
56 | | /// Protocol whose key schedule should be used. Unused for TLS < 1.3. |
57 | | pub(crate) protocol: Protocol, |
58 | | pub(crate) quic: quic::Quic, |
59 | | pub(crate) enable_secret_extraction: bool, |
60 | | temper_counters: TemperCounters, |
61 | | pub(crate) refresh_traffic_keys_pending: bool, |
62 | | pub(crate) fips: bool, |
63 | | pub(crate) tls13_tickets_received: u32, |
64 | | } |
65 | | |
66 | | impl CommonState { |
67 | 0 | pub(crate) fn new(side: Side) -> Self { |
68 | 0 | Self { |
69 | 0 | negotiated_version: None, |
70 | 0 | handshake_kind: None, |
71 | 0 | side, |
72 | 0 | record_layer: record_layer::RecordLayer::new(), |
73 | 0 | suite: None, |
74 | 0 | kx_state: KxState::default(), |
75 | 0 | alpn_protocol: None, |
76 | 0 | aligned_handshake: true, |
77 | 0 | may_send_application_data: false, |
78 | 0 | may_receive_application_data: false, |
79 | 0 | early_traffic: false, |
80 | 0 | sent_fatal_alert: false, |
81 | 0 | has_sent_close_notify: false, |
82 | 0 | has_received_close_notify: false, |
83 | 0 | #[cfg(feature = "std")] |
84 | 0 | has_seen_eof: false, |
85 | 0 | peer_certificates: None, |
86 | 0 | message_fragmenter: MessageFragmenter::default(), |
87 | 0 | received_plaintext: ChunkVecBuffer::new(Some(DEFAULT_RECEIVED_PLAINTEXT_LIMIT)), |
88 | 0 | sendable_tls: ChunkVecBuffer::new(Some(DEFAULT_BUFFER_LIMIT)), |
89 | 0 | queued_key_update_message: None, |
90 | 0 | protocol: Protocol::Tcp, |
91 | 0 | quic: quic::Quic::default(), |
92 | 0 | enable_secret_extraction: false, |
93 | 0 | temper_counters: TemperCounters::default(), |
94 | 0 | refresh_traffic_keys_pending: false, |
95 | 0 | fips: false, |
96 | 0 | tls13_tickets_received: 0, |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | /// Returns true if the caller should call [`Connection::write_tls`] as soon as possible. |
101 | | /// |
102 | | /// [`Connection::write_tls`]: crate::Connection::write_tls |
103 | 0 | pub fn wants_write(&self) -> bool { |
104 | 0 | !self.sendable_tls.is_empty() |
105 | 0 | } |
106 | | |
107 | | /// Returns true if the connection is currently performing the TLS handshake. |
108 | | /// |
109 | | /// During this time plaintext written to the connection is buffered in memory. After |
110 | | /// [`Connection::process_new_packets()`] has been called, this might start to return `false` |
111 | | /// while the final handshake packets still need to be extracted from the connection's buffers. |
112 | | /// |
113 | | /// [`Connection::process_new_packets()`]: crate::Connection::process_new_packets |
114 | 0 | pub fn is_handshaking(&self) -> bool { |
115 | 0 | !(self.may_send_application_data && self.may_receive_application_data) |
116 | 0 | } |
117 | | |
118 | | /// Retrieves the certificate chain or the raw public key used by the peer to authenticate. |
119 | | /// |
120 | | /// The order of the certificate chain is as it appears in the TLS |
121 | | /// protocol: the first certificate relates to the peer, the |
122 | | /// second certifies the first, the third certifies the second, and |
123 | | /// so on. |
124 | | /// |
125 | | /// When using raw public keys, the first and only element is the raw public key. |
126 | | /// |
127 | | /// This is made available for both full and resumed handshakes. |
128 | | /// |
129 | | /// For clients, this is the certificate chain or the raw public key of the server. |
130 | | /// |
131 | | /// For servers, this is the certificate chain or the raw public key of the client, |
132 | | /// if client authentication was completed. |
133 | | /// |
134 | | /// The return value is None until this value is available. |
135 | | /// |
136 | | /// Note: the return type of the 'certificate', when using raw public keys is `CertificateDer<'static>` |
137 | | /// even though this should technically be a `SubjectPublicKeyInfoDer<'static>`. |
138 | | /// This choice simplifies the API and ensures backwards compatibility. |
139 | 0 | pub fn peer_certificates(&self) -> Option<&[CertificateDer<'static>]> { |
140 | 0 | self.peer_certificates.as_deref() |
141 | 0 | } |
142 | | |
143 | | /// Retrieves the protocol agreed with the peer via ALPN. |
144 | | /// |
145 | | /// A return value of `None` after handshake completion |
146 | | /// means no protocol was agreed (because no protocols |
147 | | /// were offered or accepted by the peer). |
148 | 0 | pub fn alpn_protocol(&self) -> Option<&[u8]> { |
149 | 0 | self.get_alpn_protocol() |
150 | 0 | } |
151 | | |
152 | | /// Retrieves the ciphersuite agreed with the peer. |
153 | | /// |
154 | | /// This returns None until the ciphersuite is agreed. |
155 | 0 | pub fn negotiated_cipher_suite(&self) -> Option<SupportedCipherSuite> { |
156 | 0 | self.suite |
157 | 0 | } |
158 | | |
159 | | /// Retrieves the key exchange group agreed with the peer. |
160 | | /// |
161 | | /// This function may return `None` depending on the state of the connection, |
162 | | /// the type of handshake, and the protocol version. |
163 | | /// |
164 | | /// If [`CommonState::is_handshaking()`] is true this function will return `None`. |
165 | | /// Similarly, if the [`CommonState::handshake_kind()`] is [`HandshakeKind::Resumed`] |
166 | | /// and the [`CommonState::protocol_version()`] is TLS 1.2, then no key exchange will have |
167 | | /// occurred and this function will return `None`. |
168 | 0 | pub fn negotiated_key_exchange_group(&self) -> Option<&'static dyn SupportedKxGroup> { |
169 | 0 | match self.kx_state { |
170 | 0 | KxState::Complete(group) => Some(group), |
171 | 0 | _ => None, |
172 | | } |
173 | 0 | } |
174 | | |
175 | | /// Retrieves the protocol version agreed with the peer. |
176 | | /// |
177 | | /// This returns `None` until the version is agreed. |
178 | 0 | pub fn protocol_version(&self) -> Option<ProtocolVersion> { |
179 | 0 | self.negotiated_version |
180 | 0 | } |
181 | | |
182 | | /// Which kind of handshake was performed. |
183 | | /// |
184 | | /// This tells you whether the handshake was a resumption or not. |
185 | | /// |
186 | | /// This will return `None` before it is known which sort of |
187 | | /// handshake occurred. |
188 | 0 | pub fn handshake_kind(&self) -> Option<HandshakeKind> { |
189 | 0 | self.handshake_kind |
190 | 0 | } |
191 | | |
192 | 0 | pub(crate) fn is_tls13(&self) -> bool { |
193 | 0 | matches!(self.negotiated_version, Some(ProtocolVersion::TLSv1_3)) |
194 | 0 | } |
195 | | |
196 | 0 | pub(crate) fn process_main_protocol<Data>( |
197 | 0 | &mut self, |
198 | 0 | msg: Message<'_>, |
199 | 0 | mut state: Box<dyn State<Data>>, |
200 | 0 | data: &mut Data, |
201 | 0 | sendable_plaintext: Option<&mut ChunkVecBuffer>, |
202 | 0 | ) -> Result<Box<dyn State<Data>>, Error> { |
203 | | // For TLS1.2, outside of the handshake, send rejection alerts for |
204 | | // renegotiation requests. These can occur any time. |
205 | 0 | if self.may_receive_application_data && !self.is_tls13() { |
206 | 0 | let reject_ty = match self.side { |
207 | 0 | Side::Client => HandshakeType::HelloRequest, |
208 | 0 | Side::Server => HandshakeType::ClientHello, |
209 | | }; |
210 | 0 | if msg.is_handshake_type(reject_ty) { |
211 | 0 | self.temper_counters |
212 | 0 | .received_renegotiation_request()?; |
213 | 0 | self.send_warning_alert(AlertDescription::NoRenegotiation); |
214 | 0 | return Ok(state); |
215 | 0 | } |
216 | 0 | } |
217 | | |
218 | 0 | let mut cx = Context { |
219 | 0 | common: self, |
220 | 0 | data, |
221 | 0 | sendable_plaintext, |
222 | 0 | }; |
223 | 0 | match state.handle(&mut cx, msg) { |
224 | 0 | Ok(next) => { |
225 | 0 | state = next.into_owned(); |
226 | 0 | Ok(state) |
227 | | } |
228 | 0 | Err(e @ Error::InappropriateMessage { .. }) |
229 | 0 | | Err(e @ Error::InappropriateHandshakeMessage { .. }) => { |
230 | 0 | Err(self.send_fatal_alert(AlertDescription::UnexpectedMessage, e)) |
231 | | } |
232 | 0 | Err(e) => Err(e), |
233 | | } |
234 | 0 | } Unexecuted instantiation: <rustls::common_state::CommonState>::process_main_protocol::<rustls::client::client_conn::ClientConnectionData> Unexecuted instantiation: <rustls::common_state::CommonState>::process_main_protocol::<rustls::server::server_conn::ServerConnectionData> |
235 | | |
236 | | /// Ask for a TLS 1.3 key update before encrypting `payload`, if one of its records would |
237 | | /// take the last sequence number allowed by the current keys. |
238 | | /// |
239 | | /// The key update then takes that sequence number instead. |
240 | 0 | pub(crate) fn request_key_update_for(&mut self, payload: OutboundChunks<'_>) { |
241 | 0 | let records = self |
242 | 0 | .message_fragmenter |
243 | 0 | .fragment_payload( |
244 | 0 | ContentType::ApplicationData, |
245 | 0 | ProtocolVersion::TLSv1_2, |
246 | 0 | payload, |
247 | 0 | ) |
248 | 0 | .len(); |
249 | | |
250 | 0 | if records > 0 |
251 | 0 | && self.negotiated_version == Some(ProtocolVersion::TLSv1_3) |
252 | 0 | && self.record_layer.write_seq() > 0 |
253 | 0 | && self |
254 | 0 | .record_layer |
255 | 0 | .pre_encrypt_action(records as u64) |
256 | 0 | != PreEncryptAction::Nothing |
257 | 0 | { |
258 | 0 | // driven by caller, as we don't have the `State` here |
259 | 0 | self.refresh_traffic_keys_pending = true; |
260 | 0 | } |
261 | 0 | } |
262 | | |
263 | 0 | pub(crate) fn write_plaintext( |
264 | 0 | &mut self, |
265 | 0 | payload: OutboundChunks<'_>, |
266 | 0 | outgoing_tls: &mut [u8], |
267 | 0 | ) -> Result<usize, EncryptError> { |
268 | 0 | if payload.is_empty() { |
269 | 0 | return Ok(0); |
270 | 0 | } |
271 | | |
272 | 0 | let fragments = self |
273 | 0 | .message_fragmenter |
274 | 0 | .fragment_payload( |
275 | 0 | ContentType::ApplicationData, |
276 | 0 | ProtocolVersion::TLSv1_2, |
277 | 0 | payload.clone(), |
278 | | ); |
279 | | |
280 | 0 | for f in 0..fragments.len() { |
281 | 0 | match self |
282 | 0 | .record_layer |
283 | 0 | .pre_encrypt_action(f as u64) |
284 | | { |
285 | 0 | PreEncryptAction::Nothing => {} |
286 | 0 | PreEncryptAction::RefreshOrClose => match self.negotiated_version { |
287 | 0 | Some(ProtocolVersion::TLSv1_3) => { |
288 | 0 | // driven by caller, as we don't have the `State` here |
289 | 0 | self.refresh_traffic_keys_pending = true; |
290 | 0 | } |
291 | | _ => { |
292 | 0 | error!( |
293 | 0 | "traffic keys exhausted, closing connection to prevent security failure" |
294 | | ); |
295 | 0 | self.send_close_notify(); |
296 | 0 | return Err(EncryptError::EncryptExhausted); |
297 | | } |
298 | | }, |
299 | | PreEncryptAction::Refuse => { |
300 | 0 | return Err(EncryptError::EncryptExhausted); |
301 | | } |
302 | | } |
303 | | } |
304 | | |
305 | 0 | self.perhaps_write_key_update(); |
306 | | |
307 | 0 | self.check_required_size(outgoing_tls, fragments)?; |
308 | | |
309 | 0 | let fragments = self |
310 | 0 | .message_fragmenter |
311 | 0 | .fragment_payload( |
312 | 0 | ContentType::ApplicationData, |
313 | 0 | ProtocolVersion::TLSv1_2, |
314 | 0 | payload, |
315 | | ); |
316 | | |
317 | 0 | Ok(self.write_fragments(outgoing_tls, fragments)) |
318 | 0 | } |
319 | | |
320 | | // Changing the keys must not span any fragmented handshake |
321 | | // messages. Otherwise the defragmented messages will have |
322 | | // been protected with two different record layer protections, |
323 | | // which is illegal. Not mentioned in RFC. |
324 | 0 | pub(crate) fn check_aligned_handshake(&mut self) -> Result<(), Error> { |
325 | 0 | if !self.aligned_handshake { |
326 | 0 | Err(self.send_fatal_alert( |
327 | 0 | AlertDescription::UnexpectedMessage, |
328 | 0 | PeerMisbehaved::KeyEpochWithPendingFragment, |
329 | 0 | )) |
330 | | } else { |
331 | 0 | Ok(()) |
332 | | } |
333 | 0 | } |
334 | | |
335 | | /// Fragment `m`, encrypt the fragments, and then queue |
336 | | /// the encrypted fragments for sending. |
337 | 0 | pub(crate) fn send_msg_encrypt(&mut self, m: PlainMessage) { |
338 | 0 | let iter = self |
339 | 0 | .message_fragmenter |
340 | 0 | .fragment_message(&m); |
341 | 0 | for m in iter { |
342 | 0 | self.send_single_fragment(m); |
343 | 0 | } |
344 | 0 | } |
345 | | |
346 | | /// Like send_msg_encrypt, but operate on an appdata directly. |
347 | | /// |
348 | | /// If `stop_for_key_update` is true, this stops before a TLS 1.3 record that would take |
349 | | /// the last sequence number allowed by the current keys, so that the caller can first send |
350 | | /// a `key_update` request with that sequence number. In that case, the return value is the |
351 | | /// number of bytes sent so far. |
352 | 0 | fn send_appdata_encrypt( |
353 | 0 | &mut self, |
354 | 0 | payload: OutboundChunks<'_>, |
355 | 0 | limit: Limit, |
356 | 0 | stop_for_key_update: bool, |
357 | 0 | ) -> usize { |
358 | | // Here, the limit on sendable_tls applies to encrypted data, |
359 | | // but we're respecting it for plaintext data -- so we'll |
360 | | // be out by whatever the cipher+record overhead is. That's a |
361 | | // constant and predictable amount, so it's not a terrible issue. |
362 | 0 | let len = match limit { |
363 | | #[cfg(feature = "std")] |
364 | 0 | Limit::Yes => self |
365 | 0 | .sendable_tls |
366 | 0 | .apply_limit(payload.len()), |
367 | 0 | Limit::No => payload.len(), |
368 | | }; |
369 | | |
370 | 0 | let iter = self |
371 | 0 | .message_fragmenter |
372 | 0 | .fragment_payload( |
373 | 0 | ContentType::ApplicationData, |
374 | 0 | ProtocolVersion::TLSv1_2, |
375 | 0 | payload.split_at(len).0, |
376 | | ); |
377 | | |
378 | | // Check the record limit for the last fragment before encrypting any of them, so |
379 | | // that a write crossing the limit is not sent in part. |
380 | 0 | if let Some(last) = (iter.len() as u64).checked_sub(1) { |
381 | 0 | if !self.check_pre_encrypt_action(last) { |
382 | 0 | return len; |
383 | 0 | } |
384 | 0 | } |
385 | | |
386 | 0 | let mut sent = 0; |
387 | 0 | for m in iter { |
388 | | // The key update takes the last sequence number allowed by the current keys, |
389 | | // unless they have not been used yet (as updating them would not help then). |
390 | 0 | if stop_for_key_update |
391 | 0 | && self.negotiated_version == Some(ProtocolVersion::TLSv1_3) |
392 | 0 | && self.record_layer.write_seq() > 0 |
393 | 0 | && self.record_layer.pre_encrypt_action(1) != PreEncryptAction::Nothing |
394 | | { |
395 | | // driven by caller, as we don't have the `State` here |
396 | 0 | self.refresh_traffic_keys_pending = true; |
397 | 0 | return sent; |
398 | 0 | } |
399 | | |
400 | 0 | sent += m.payload.len(); |
401 | 0 | self.send_single_fragment(m); |
402 | | } |
403 | | |
404 | 0 | len |
405 | 0 | } |
406 | | |
407 | 0 | fn send_single_fragment(&mut self, m: OutboundPlainMessage<'_>) { |
408 | 0 | if m.typ == ContentType::Alert { |
409 | | // Alerts are always sendable -- never quashed by a PreEncryptAction. |
410 | 0 | let em = self.record_layer.encrypt_outgoing(m); |
411 | 0 | self.queue_tls_message(em); |
412 | 0 | return; |
413 | 0 | } |
414 | | |
415 | 0 | if !self.check_pre_encrypt_action(0) { |
416 | 0 | return; |
417 | 0 | } |
418 | | |
419 | 0 | let em = self.record_layer.encrypt_outgoing(m); |
420 | 0 | self.queue_tls_message(em); |
421 | 0 | } |
422 | | |
423 | | /// Take the remedial action needed before encrypting the record `add` records after the next. |
424 | | /// |
425 | | /// Returns `false` if that record must not be encrypted. |
426 | 0 | fn check_pre_encrypt_action(&mut self, add: u64) -> bool { |
427 | 0 | match self |
428 | 0 | .record_layer |
429 | 0 | .pre_encrypt_action(add) |
430 | | { |
431 | 0 | PreEncryptAction::Nothing => true, |
432 | | |
433 | | // Close connection once we start to run out of |
434 | | // sequence space. |
435 | 0 | PreEncryptAction::RefreshOrClose => match self.negotiated_version { |
436 | | Some(ProtocolVersion::TLSv1_3) => { |
437 | | // driven by caller, as we don't have the `State` here |
438 | 0 | self.refresh_traffic_keys_pending = true; |
439 | 0 | true |
440 | | } |
441 | | _ => { |
442 | 0 | error!( |
443 | 0 | "traffic keys exhausted, closing connection to prevent security failure" |
444 | | ); |
445 | 0 | self.send_close_notify(); |
446 | 0 | false |
447 | | } |
448 | | }, |
449 | | |
450 | | // Refuse to wrap counter at all costs. This |
451 | | // is basically untestable unfortunately. |
452 | 0 | PreEncryptAction::Refuse => false, |
453 | | } |
454 | 0 | } |
455 | | |
456 | 0 | fn send_plain_non_buffering( |
457 | 0 | &mut self, |
458 | 0 | payload: OutboundChunks<'_>, |
459 | 0 | limit: Limit, |
460 | 0 | stop_for_key_update: bool, |
461 | 0 | ) -> usize { |
462 | 0 | debug_assert!(self.may_send_application_data); |
463 | 0 | debug_assert!(self.record_layer.is_encrypting()); |
464 | | |
465 | 0 | if payload.is_empty() { |
466 | | // Don't send empty fragments. |
467 | 0 | return 0; |
468 | 0 | } |
469 | | |
470 | 0 | self.send_appdata_encrypt(payload, limit, stop_for_key_update) |
471 | 0 | } |
472 | | |
473 | | /// Mark the connection as ready to send application data. |
474 | | /// |
475 | | /// Also flush `sendable_plaintext` if it is `Some`. |
476 | 0 | pub(crate) fn start_outgoing_traffic( |
477 | 0 | &mut self, |
478 | 0 | sendable_plaintext: &mut Option<&mut ChunkVecBuffer>, |
479 | 0 | ) { |
480 | 0 | self.may_send_application_data = true; |
481 | 0 | if let Some(sendable_plaintext) = sendable_plaintext { |
482 | 0 | self.flush_plaintext(sendable_plaintext); |
483 | 0 | } |
484 | 0 | } |
485 | | |
486 | | /// Mark the connection as ready to send and receive application data. |
487 | | /// |
488 | | /// Also flush `sendable_plaintext` if it is `Some`. |
489 | 0 | pub(crate) fn start_traffic(&mut self, sendable_plaintext: &mut Option<&mut ChunkVecBuffer>) { |
490 | 0 | self.may_receive_application_data = true; |
491 | 0 | self.start_outgoing_traffic(sendable_plaintext); |
492 | 0 | } |
493 | | |
494 | | /// Send any buffered plaintext. Plaintext is buffered if |
495 | | /// written during handshake. |
496 | 0 | fn flush_plaintext(&mut self, sendable_plaintext: &mut ChunkVecBuffer) { |
497 | 0 | if !self.may_send_application_data { |
498 | 0 | return; |
499 | 0 | } |
500 | | |
501 | 0 | while let Some(buf) = sendable_plaintext.pop() { |
502 | 0 | self.send_plain_non_buffering(buf.as_slice().into(), Limit::No, false); |
503 | 0 | } |
504 | 0 | } |
505 | | |
506 | | // Put m into sendable_tls for writing. |
507 | 0 | fn queue_tls_message(&mut self, m: OutboundOpaqueMessage) { |
508 | 0 | self.perhaps_write_key_update(); |
509 | 0 | self.sendable_tls.append(m.encode()); |
510 | 0 | } |
511 | | |
512 | 0 | pub(crate) fn perhaps_write_key_update(&mut self) { |
513 | 0 | if let Some(message) = self.queued_key_update_message.take() { |
514 | 0 | self.sendable_tls.append(message); |
515 | 0 | } |
516 | 0 | } |
517 | | |
518 | | /// Send a raw TLS message, fragmenting it if needed. |
519 | 0 | pub(crate) fn send_msg(&mut self, m: Message<'_>, must_encrypt: bool) { |
520 | | { |
521 | 0 | if let Protocol::Quic = self.protocol { |
522 | 0 | if let MessagePayload::Alert(alert) = m.payload { |
523 | 0 | self.quic.alert = Some(alert.description); |
524 | 0 | } else { |
525 | 0 | debug_assert!( |
526 | 0 | matches!( |
527 | 0 | m.payload, |
528 | | MessagePayload::Handshake { .. } | MessagePayload::HandshakeFlight(_) |
529 | | ), |
530 | 0 | "QUIC uses TLS for the cryptographic handshake only" |
531 | | ); |
532 | 0 | let mut bytes = Vec::new(); |
533 | 0 | m.payload.encode(&mut bytes); |
534 | 0 | self.quic |
535 | 0 | .hs_queue |
536 | 0 | .push_back((must_encrypt, bytes)); |
537 | | } |
538 | 0 | return; |
539 | 0 | } |
540 | | } |
541 | 0 | if !must_encrypt { |
542 | 0 | let msg = &m.into(); |
543 | 0 | let iter = self |
544 | 0 | .message_fragmenter |
545 | 0 | .fragment_message(msg); |
546 | 0 | for m in iter { |
547 | 0 | self.queue_tls_message(m.to_unencrypted_opaque()); |
548 | 0 | } |
549 | 0 | } else { |
550 | 0 | self.send_msg_encrypt(m.into()); |
551 | 0 | } |
552 | 0 | } |
553 | | |
554 | 0 | pub(crate) fn take_received_plaintext(&mut self, bytes: Payload<'_>) { |
555 | 0 | self.temper_counters.received_app_data(); |
556 | 0 | self.received_plaintext |
557 | 0 | .append(bytes.into_vec()); |
558 | 0 | } |
559 | | |
560 | | #[cfg(feature = "tls12")] |
561 | 0 | pub(crate) fn start_encryption_tls12(&mut self, secrets: &ConnectionSecrets, side: Side) { |
562 | 0 | let (dec, enc) = secrets.make_cipher_pair(side); |
563 | 0 | self.record_layer |
564 | 0 | .prepare_message_encrypter( |
565 | 0 | enc, |
566 | 0 | secrets |
567 | 0 | .suite() |
568 | 0 | .common |
569 | 0 | .confidentiality_limit, |
570 | | ); |
571 | 0 | self.record_layer |
572 | 0 | .prepare_message_decrypter(dec); |
573 | 0 | } |
574 | | |
575 | 0 | pub(crate) fn missing_extension(&mut self, why: PeerMisbehaved) -> Error { |
576 | 0 | self.send_fatal_alert(AlertDescription::MissingExtension, why) |
577 | 0 | } |
578 | | |
579 | 0 | fn send_warning_alert(&mut self, desc: AlertDescription) { |
580 | 0 | warn!("Sending warning alert {desc:?}"); |
581 | 0 | self.send_warning_alert_no_log(desc); |
582 | 0 | } |
583 | | |
584 | 0 | pub(crate) fn process_alert(&mut self, alert: &AlertMessagePayload) -> Result<(), Error> { |
585 | | // Reject unknown AlertLevels. |
586 | 0 | if let AlertLevel::Unknown(_) = alert.level { |
587 | 0 | return Err(self.send_fatal_alert( |
588 | 0 | AlertDescription::IllegalParameter, |
589 | 0 | Error::AlertReceived(alert.description), |
590 | 0 | )); |
591 | 0 | } |
592 | | |
593 | | // If we get a CloseNotify, make a note to declare EOF to our |
594 | | // caller. But do not treat unauthenticated alerts like this. |
595 | 0 | if self.may_receive_application_data && alert.description == AlertDescription::CloseNotify { |
596 | 0 | self.has_received_close_notify = true; |
597 | 0 | return Ok(()); |
598 | 0 | } |
599 | | |
600 | | // Warnings are nonfatal for TLS1.2, but outlawed in TLS1.3 |
601 | | // (except, for no good reason, user_cancelled). |
602 | 0 | let err = Error::AlertReceived(alert.description); |
603 | 0 | if alert.level == AlertLevel::Warning { |
604 | 0 | self.temper_counters |
605 | 0 | .received_warning_alert()?; |
606 | 0 | if self.is_tls13() && alert.description != AlertDescription::UserCanceled { |
607 | 0 | return Err(self.send_fatal_alert(AlertDescription::DecodeError, err)); |
608 | 0 | } |
609 | | |
610 | | // Some implementations send pointless `user_canceled` alerts, don't log them |
611 | | // in release mode (https://bugs.openjdk.org/browse/JDK-8323517). |
612 | 0 | if alert.description != AlertDescription::UserCanceled || cfg!(debug_assertions) { |
613 | 0 | warn!("TLS alert warning received: {alert:?}"); |
614 | 0 | } |
615 | | |
616 | 0 | return Ok(()); |
617 | 0 | } |
618 | | |
619 | 0 | Err(err) |
620 | 0 | } |
621 | | |
622 | 0 | pub(crate) fn send_cert_verify_error_alert(&mut self, err: Error) -> Error { |
623 | 0 | self.send_fatal_alert( |
624 | 0 | match &err { |
625 | 0 | Error::InvalidCertificate(e) => e.clone().into(), |
626 | 0 | Error::PeerMisbehaved(_) => AlertDescription::IllegalParameter, |
627 | 0 | _ => AlertDescription::HandshakeFailure, |
628 | | }, |
629 | 0 | err, |
630 | | ) |
631 | 0 | } |
632 | | |
633 | 0 | pub(crate) fn send_fatal_alert( |
634 | 0 | &mut self, |
635 | 0 | desc: AlertDescription, |
636 | 0 | err: impl Into<Error>, |
637 | 0 | ) -> Error { |
638 | 0 | debug_assert!(!self.sent_fatal_alert); |
639 | 0 | let m = Message::build_alert(AlertLevel::Fatal, desc); |
640 | 0 | self.send_msg(m, self.record_layer.is_encrypting()); |
641 | 0 | self.sent_fatal_alert = true; |
642 | 0 | err.into() |
643 | 0 | } Unexecuted instantiation: <rustls::common_state::CommonState>::send_fatal_alert::<rustls::error::InvalidMessage> Unexecuted instantiation: <rustls::common_state::CommonState>::send_fatal_alert::<rustls::error::PeerMisbehaved> Unexecuted instantiation: <rustls::common_state::CommonState>::send_fatal_alert::<rustls::error::PeerIncompatible> Unexecuted instantiation: <rustls::common_state::CommonState>::send_fatal_alert::<rustls::error::Error> |
644 | | |
645 | | /// Queues a `close_notify` warning alert to be sent in the next |
646 | | /// [`Connection::write_tls`] call. This informs the peer that the |
647 | | /// connection is being closed. |
648 | | /// |
649 | | /// Does nothing if any `close_notify` or fatal alert was already sent. |
650 | | /// |
651 | | /// [`Connection::write_tls`]: crate::Connection::write_tls |
652 | 0 | pub fn send_close_notify(&mut self) { |
653 | 0 | if self.sent_fatal_alert { |
654 | 0 | return; |
655 | 0 | } |
656 | 0 | debug!("Sending warning alert {:?}", AlertDescription::CloseNotify); |
657 | 0 | self.sent_fatal_alert = true; |
658 | 0 | self.has_sent_close_notify = true; |
659 | 0 | self.send_warning_alert_no_log(AlertDescription::CloseNotify); |
660 | 0 | } |
661 | | |
662 | 0 | pub(crate) fn eager_send_close_notify( |
663 | 0 | &mut self, |
664 | 0 | outgoing_tls: &mut [u8], |
665 | 0 | ) -> Result<usize, EncryptError> { |
666 | 0 | self.send_close_notify(); |
667 | 0 | self.check_required_size(outgoing_tls, [].into_iter())?; |
668 | 0 | Ok(self.write_fragments(outgoing_tls, [].into_iter())) |
669 | 0 | } |
670 | | |
671 | 0 | fn send_warning_alert_no_log(&mut self, desc: AlertDescription) { |
672 | 0 | let m = Message::build_alert(AlertLevel::Warning, desc); |
673 | 0 | self.send_msg(m, self.record_layer.is_encrypting()); |
674 | 0 | } |
675 | | |
676 | 0 | fn check_required_size<'a>( |
677 | 0 | &self, |
678 | 0 | outgoing_tls: &mut [u8], |
679 | 0 | fragments: impl Iterator<Item = OutboundPlainMessage<'a>>, |
680 | 0 | ) -> Result<(), EncryptError> { |
681 | 0 | let mut required_size = self.sendable_tls.len(); |
682 | | |
683 | 0 | for m in fragments { |
684 | 0 | required_size += m.encoded_len(&self.record_layer); |
685 | 0 | } |
686 | | |
687 | 0 | if required_size > outgoing_tls.len() { |
688 | 0 | return Err(EncryptError::InsufficientSize(InsufficientSizeError { |
689 | 0 | required_size, |
690 | 0 | })); |
691 | 0 | } |
692 | | |
693 | 0 | Ok(()) |
694 | 0 | } Unexecuted instantiation: <rustls::common_state::CommonState>::check_required_size::<core::array::iter::IntoIter<rustls::msgs::message::outbound::OutboundPlainMessage, 0>> Unexecuted instantiation: <rustls::common_state::CommonState>::check_required_size::<core::iter::adapters::map::Map<rustls::msgs::fragmenter::Chunker, <rustls::msgs::fragmenter::MessageFragmenter>::fragment_payload::{closure#0}>> |
695 | | |
696 | 0 | fn write_fragments<'a>( |
697 | 0 | &mut self, |
698 | 0 | outgoing_tls: &mut [u8], |
699 | 0 | fragments: impl Iterator<Item = OutboundPlainMessage<'a>>, |
700 | 0 | ) -> usize { |
701 | 0 | let mut written = 0; |
702 | | |
703 | | // Any pre-existing encrypted messages in `sendable_tls` must |
704 | | // be output before encrypting any of the `fragments`. |
705 | 0 | while let Some(message) = self.sendable_tls.pop() { |
706 | 0 | let len = message.len(); |
707 | 0 | outgoing_tls[written..written + len].copy_from_slice(&message); |
708 | 0 | written += len; |
709 | 0 | } |
710 | | |
711 | 0 | for m in fragments { |
712 | 0 | let em = self |
713 | 0 | .record_layer |
714 | 0 | .encrypt_outgoing(m) |
715 | 0 | .encode(); |
716 | 0 |
|
717 | 0 | let len = em.len(); |
718 | 0 | outgoing_tls[written..written + len].copy_from_slice(&em); |
719 | 0 | written += len; |
720 | 0 | } |
721 | | |
722 | 0 | written |
723 | 0 | } Unexecuted instantiation: <rustls::common_state::CommonState>::write_fragments::<core::array::iter::IntoIter<rustls::msgs::message::outbound::OutboundPlainMessage, 0>> Unexecuted instantiation: <rustls::common_state::CommonState>::write_fragments::<core::iter::adapters::map::Map<rustls::msgs::fragmenter::Chunker, <rustls::msgs::fragmenter::MessageFragmenter>::fragment_payload::{closure#0}>> |
724 | | |
725 | 0 | pub(crate) fn set_max_fragment_size(&mut self, new: Option<usize>) -> Result<(), Error> { |
726 | 0 | self.message_fragmenter |
727 | 0 | .set_max_fragment_size(new) |
728 | 0 | } |
729 | | |
730 | 0 | pub(crate) fn get_alpn_protocol(&self) -> Option<&[u8]> { |
731 | 0 | self.alpn_protocol |
732 | 0 | .as_ref() |
733 | 0 | .map(AsRef::as_ref) |
734 | 0 | } |
735 | | |
736 | | /// Returns true if the caller should call [`Connection::read_tls`] as soon |
737 | | /// as possible. |
738 | | /// |
739 | | /// If there is pending plaintext data to read with [`Connection::reader`], |
740 | | /// this returns false. If your application respects this mechanism, |
741 | | /// only one full TLS message will be buffered by rustls. |
742 | | /// |
743 | | /// [`Connection::reader`]: crate::Connection::reader |
744 | | /// [`Connection::read_tls`]: crate::Connection::read_tls |
745 | 0 | pub fn wants_read(&self) -> bool { |
746 | | // We want to read more data all the time, except when we have unprocessed plaintext. |
747 | | // This provides back-pressure to the TCP buffers. We also don't want to read more after |
748 | | // the peer has sent us a close notification. |
749 | | // |
750 | | // In the handshake case we don't have readable plaintext before the handshake has |
751 | | // completed, but also don't want to read if we still have sendable tls. |
752 | 0 | self.received_plaintext.is_empty() |
753 | 0 | && !self.has_received_close_notify |
754 | 0 | && (self.may_send_application_data || self.sendable_tls.is_empty()) |
755 | 0 | } |
756 | | |
757 | 0 | pub(crate) fn current_io_state(&self) -> IoState { |
758 | 0 | IoState { |
759 | 0 | tls_bytes_to_write: self.sendable_tls.len(), |
760 | 0 | plaintext_bytes_to_read: self.received_plaintext.len(), |
761 | 0 | peer_has_closed: self.has_received_close_notify, |
762 | 0 | } |
763 | 0 | } |
764 | | |
765 | 0 | pub(crate) fn is_quic(&self) -> bool { |
766 | 0 | self.protocol == Protocol::Quic |
767 | 0 | } |
768 | | |
769 | 0 | pub(crate) fn should_update_key( |
770 | 0 | &mut self, |
771 | 0 | key_update_request: &KeyUpdateRequest, |
772 | 0 | ) -> Result<bool, Error> { |
773 | 0 | self.temper_counters |
774 | 0 | .received_key_update_request()?; |
775 | | |
776 | 0 | match key_update_request { |
777 | 0 | KeyUpdateRequest::UpdateNotRequested => Ok(false), |
778 | 0 | KeyUpdateRequest::UpdateRequested => Ok(self.queued_key_update_message.is_none()), |
779 | 0 | _ => Err(self.send_fatal_alert( |
780 | 0 | AlertDescription::IllegalParameter, |
781 | 0 | InvalidMessage::InvalidKeyUpdate, |
782 | 0 | )), |
783 | | } |
784 | 0 | } |
785 | | |
786 | 0 | pub(crate) fn enqueue_key_update_notification(&mut self) { |
787 | 0 | let message = PlainMessage::from(Message::build_key_update_notify()); |
788 | 0 | self.queued_key_update_message = Some( |
789 | 0 | self.record_layer |
790 | 0 | .encrypt_outgoing(message.borrow_outbound()) |
791 | 0 | .encode(), |
792 | 0 | ); |
793 | 0 | } |
794 | | |
795 | 0 | pub(crate) fn received_tls13_change_cipher_spec(&mut self) -> Result<(), Error> { |
796 | 0 | self.temper_counters |
797 | 0 | .received_tls13_change_cipher_spec() |
798 | 0 | } |
799 | | } |
800 | | |
801 | | #[cfg(feature = "std")] |
802 | | impl CommonState { |
803 | | /// Send plaintext application data, fragmenting and |
804 | | /// encrypting it as it goes out. |
805 | | /// |
806 | | /// If internal buffers are too small, or if the traffic keys must be |
807 | | /// updated first, this function will not accept all the data. |
808 | 0 | pub(crate) fn buffer_plaintext( |
809 | 0 | &mut self, |
810 | 0 | payload: OutboundChunks<'_>, |
811 | 0 | sendable_plaintext: &mut ChunkVecBuffer, |
812 | 0 | ) -> usize { |
813 | 0 | self.perhaps_write_key_update(); |
814 | 0 | self.send_plain(payload, Limit::Yes, sendable_plaintext) |
815 | 0 | } |
816 | | |
817 | 0 | pub(crate) fn send_early_plaintext(&mut self, data: &[u8]) -> usize { |
818 | 0 | debug_assert!(self.early_traffic); |
819 | 0 | debug_assert!(self.record_layer.is_encrypting()); |
820 | | |
821 | 0 | if data.is_empty() { |
822 | | // Don't send empty fragments. |
823 | 0 | return 0; |
824 | 0 | } |
825 | | |
826 | 0 | self.send_appdata_encrypt(data.into(), Limit::Yes, false) |
827 | 0 | } |
828 | | |
829 | | /// Encrypt and send some plaintext `data`. `limit` controls |
830 | | /// whether the per-connection buffer limits apply. |
831 | | /// |
832 | | /// Returns the number of bytes written from `data`: this might |
833 | | /// be less than `data.len()` if buffer limits were exceeded. |
834 | 0 | fn send_plain( |
835 | 0 | &mut self, |
836 | 0 | payload: OutboundChunks<'_>, |
837 | 0 | limit: Limit, |
838 | 0 | sendable_plaintext: &mut ChunkVecBuffer, |
839 | 0 | ) -> usize { |
840 | 0 | if !self.may_send_application_data { |
841 | | // If we haven't completed handshaking, buffer |
842 | | // plaintext to send once we do. |
843 | 0 | let len = match limit { |
844 | 0 | Limit::Yes => sendable_plaintext.append_limited_copy(payload), |
845 | 0 | Limit::No => sendable_plaintext.append(payload.to_vec()), |
846 | | }; |
847 | 0 | return len; |
848 | 0 | } |
849 | | |
850 | 0 | self.send_plain_non_buffering(payload, limit, true) |
851 | 0 | } |
852 | | } |
853 | | |
854 | | /// Describes which sort of handshake happened. |
855 | | #[derive(Debug, PartialEq, Clone, Copy)] |
856 | | pub enum HandshakeKind { |
857 | | /// A full handshake. |
858 | | /// |
859 | | /// This is the typical TLS connection initiation process when resumption is |
860 | | /// not yet unavailable, and the initial `ClientHello` was accepted by the server. |
861 | | Full, |
862 | | |
863 | | /// A full TLS1.3 handshake, with an extra round-trip for a `HelloRetryRequest`. |
864 | | /// |
865 | | /// The server can respond with a `HelloRetryRequest` if the initial `ClientHello` |
866 | | /// is unacceptable for several reasons, the most likely if no supported key |
867 | | /// shares were offered by the client. |
868 | | FullWithHelloRetryRequest, |
869 | | |
870 | | /// A resumed handshake. |
871 | | /// |
872 | | /// Resumed handshakes involve fewer round trips and less cryptography than |
873 | | /// full ones, but can only happen when the peers have previously done a full |
874 | | /// handshake together, and then remember data about it. |
875 | | Resumed, |
876 | | } |
877 | | |
878 | | /// Values of this structure are returned from [`Connection::process_new_packets`] |
879 | | /// and tell the caller the current I/O state of the TLS connection. |
880 | | /// |
881 | | /// [`Connection::process_new_packets`]: crate::Connection::process_new_packets |
882 | | #[derive(Debug, Eq, PartialEq)] |
883 | | pub struct IoState { |
884 | | tls_bytes_to_write: usize, |
885 | | plaintext_bytes_to_read: usize, |
886 | | peer_has_closed: bool, |
887 | | } |
888 | | |
889 | | impl IoState { |
890 | | /// How many bytes could be written by [`Connection::write_tls`] if called |
891 | | /// right now. A non-zero value implies [`CommonState::wants_write`]. |
892 | | /// |
893 | | /// [`Connection::write_tls`]: crate::Connection::write_tls |
894 | 0 | pub fn tls_bytes_to_write(&self) -> usize { |
895 | 0 | self.tls_bytes_to_write |
896 | 0 | } |
897 | | |
898 | | /// How many plaintext bytes could be obtained via [`std::io::Read`] |
899 | | /// without further I/O. |
900 | 0 | pub fn plaintext_bytes_to_read(&self) -> usize { |
901 | 0 | self.plaintext_bytes_to_read |
902 | 0 | } |
903 | | |
904 | | /// True if the peer has sent us a close_notify alert. This is |
905 | | /// the TLS mechanism to securely half-close a TLS connection, |
906 | | /// and signifies that the peer will not send any further data |
907 | | /// on this connection. |
908 | | /// |
909 | | /// This is also signalled via returning `Ok(0)` from |
910 | | /// [`std::io::Read`], after all the received bytes have been |
911 | | /// retrieved. |
912 | 0 | pub fn peer_has_closed(&self) -> bool { |
913 | 0 | self.peer_has_closed |
914 | 0 | } |
915 | | } |
916 | | |
917 | | pub(crate) trait State<Data>: Send + Sync { |
918 | | fn handle<'m>( |
919 | | self: Box<Self>, |
920 | | cx: &mut Context<'_, Data>, |
921 | | message: Message<'m>, |
922 | | ) -> Result<Box<dyn State<Data> + 'm>, Error> |
923 | | where |
924 | | Self: 'm; |
925 | | |
926 | 0 | fn export_keying_material( |
927 | 0 | &self, |
928 | 0 | _output: &mut [u8], |
929 | 0 | _label: &[u8], |
930 | 0 | _context: Option<&[u8]>, |
931 | 0 | ) -> Result<(), Error> { |
932 | 0 | Err(Error::HandshakeNotComplete) |
933 | 0 | } Unexecuted instantiation: <rustls::client::tls13::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectEncryptedExtensions as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::hs::ExpectServerHello as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::hs::ExpectServerHelloOrHelloRetryRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls12::ExpectClientKx as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls12::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls12::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls12::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls12::ExpectCcs as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls13::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls13::ExpectEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls13::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls13::ExpectAndSkipRejectedEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectNewTicket as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectServerDone as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatus as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectServerDoneOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatusOrServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::client::tls12::ExpectCcs as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::server_conn::Accepting as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material Unexecuted instantiation: <rustls::server::hs::ExpectClientHello as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::export_keying_material |
934 | | |
935 | 0 | fn extract_secrets(&self) -> Result<PartiallyExtractedSecrets, Error> { |
936 | 0 | Err(Error::HandshakeNotComplete) |
937 | 0 | } Unexecuted instantiation: <rustls::client::tls13::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectQuicTraffic as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectEncryptedExtensions as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::hs::ExpectServerHello as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::hs::ExpectServerHelloOrHelloRetryRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls12::ExpectClientKx as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls12::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls12::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls12::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls12::ExpectCcs as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectQuicTraffic as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectAndSkipRejectedEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectNewTicket as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectServerDone as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatus as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectServerDoneOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatusOrServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::client::tls12::ExpectCcs as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::server_conn::Accepting as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets Unexecuted instantiation: <rustls::server::hs::ExpectClientHello as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::extract_secrets |
938 | | |
939 | 0 | fn send_key_update_request(&mut self, _common: &mut CommonState) -> Result<(), Error> { |
940 | 0 | Err(Error::HandshakeNotComplete) |
941 | 0 | } Unexecuted instantiation: <rustls::client::tls13::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectQuicTraffic as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectEncryptedExtensions as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::hs::ExpectServerHello as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::hs::ExpectServerHelloOrHelloRetryRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls12::ExpectTraffic as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls12::ExpectClientKx as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls12::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls12::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls12::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls12::ExpectCcs as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectQuicTraffic as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectAndSkipRejectedEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectTraffic as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectNewTicket as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectServerDone as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatus as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectServerDoneOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatusOrServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::client::tls12::ExpectCcs as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::server_conn::Accepting as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request Unexecuted instantiation: <rustls::server::hs::ExpectClientHello as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::send_key_update_request |
942 | | |
943 | 0 | fn handle_decrypt_error(&self) {}Unexecuted instantiation: <rustls::client::tls13::ExpectTraffic as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectQuicTraffic as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectEncryptedExtensions as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::hs::ExpectServerHello as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::hs::ExpectServerHelloOrHelloRetryRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls12::ExpectTraffic as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls12::ExpectClientKx as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls12::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls12::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls12::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls12::ExpectCcs as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectTraffic as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectQuicTraffic as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectAndSkipRejectedEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectTraffic as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectNewTicket as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectServerDone as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatus as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectServerDoneOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatusOrServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::client::tls12::ExpectCcs as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::server_conn::Accepting as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error Unexecuted instantiation: <rustls::server::hs::ExpectClientHello as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::handle_decrypt_error |
944 | | |
945 | 0 | fn into_external_state(self: Box<Self>) -> Result<Box<dyn KernelState + 'static>, Error> { |
946 | 0 | Err(Error::HandshakeNotComplete) |
947 | 0 | } Unexecuted instantiation: <rustls::client::tls13::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectEncryptedExtensions as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls13::ExpectCertificateOrCompressedCertificateOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::hs::ExpectServerHello as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::hs::ExpectServerHelloOrHelloRetryRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls12::ExpectClientKx as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls12::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls12::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls12::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls12::ExpectCcs as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectFinished as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectQuicTraffic as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateVerify as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectAndSkipRejectedEarlyData as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::tls13::ExpectCertificateOrCompressedCertificate as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectFinished as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectNewTicket as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectServerDone as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectCertificate as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatus as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateRequest as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectServerDoneOrCertReq as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectCertificateStatusOrServerKx as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::client::tls12::ExpectCcs as rustls::common_state::State<rustls::client::client_conn::ClientConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::server_conn::Accepting as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state Unexecuted instantiation: <rustls::server::hs::ExpectClientHello as rustls::common_state::State<rustls::server::server_conn::ServerConnectionData>>::into_external_state |
948 | | |
949 | | fn into_owned(self: Box<Self>) -> Box<dyn State<Data> + 'static>; |
950 | | } |
951 | | |
952 | | pub(crate) struct Context<'a, Data> { |
953 | | pub(crate) common: &'a mut CommonState, |
954 | | pub(crate) data: &'a mut Data, |
955 | | /// Buffered plaintext. This is `Some` if any plaintext was written during handshake and `None` |
956 | | /// otherwise. |
957 | | pub(crate) sendable_plaintext: Option<&'a mut ChunkVecBuffer>, |
958 | | } |
959 | | |
960 | | /// Side of the connection. |
961 | | #[derive(Clone, Copy, Debug, PartialEq)] |
962 | | pub enum Side { |
963 | | /// A client initiates the connection. |
964 | | Client, |
965 | | /// A server waits for a client to connect. |
966 | | Server, |
967 | | } |
968 | | |
969 | | impl Side { |
970 | 0 | pub(crate) fn peer(&self) -> Self { |
971 | 0 | match self { |
972 | 0 | Self::Client => Self::Server, |
973 | 0 | Self::Server => Self::Client, |
974 | | } |
975 | 0 | } |
976 | | } |
977 | | |
978 | | #[derive(Copy, Clone, Eq, PartialEq, Debug)] |
979 | | pub(crate) enum Protocol { |
980 | | Tcp, |
981 | | Quic, |
982 | | } |
983 | | |
984 | | impl Protocol { |
985 | 0 | pub(crate) fn supports_version(&self, version: ProtocolVersion) -> bool { |
986 | 0 | match self { |
987 | 0 | Self::Quic => version == ProtocolVersion::TLSv1_3, |
988 | 0 | Self::Tcp => true, |
989 | | } |
990 | 0 | } |
991 | | } |
992 | | |
993 | | enum Limit { |
994 | | #[cfg(feature = "std")] |
995 | | Yes, |
996 | | No, |
997 | | } |
998 | | |
999 | | /// Tracking technically-allowed protocol actions |
1000 | | /// that we limit to avoid denial-of-service vectors. |
1001 | | struct TemperCounters { |
1002 | | allowed_warning_alerts: u8, |
1003 | | allowed_renegotiation_requests: u8, |
1004 | | allowed_key_update_requests: u8, |
1005 | | allowed_middlebox_ccs: u8, |
1006 | | } |
1007 | | |
1008 | | impl TemperCounters { |
1009 | 0 | fn received_warning_alert(&mut self) -> Result<(), Error> { |
1010 | 0 | match self.allowed_warning_alerts { |
1011 | 0 | 0 => Err(PeerMisbehaved::TooManyWarningAlertsReceived.into()), |
1012 | | _ => { |
1013 | 0 | self.allowed_warning_alerts -= 1; |
1014 | 0 | Ok(()) |
1015 | | } |
1016 | | } |
1017 | 0 | } |
1018 | | |
1019 | 0 | fn received_renegotiation_request(&mut self) -> Result<(), Error> { |
1020 | 0 | match self.allowed_renegotiation_requests { |
1021 | 0 | 0 => Err(PeerMisbehaved::TooManyRenegotiationRequests.into()), |
1022 | | _ => { |
1023 | 0 | self.allowed_renegotiation_requests -= 1; |
1024 | 0 | Ok(()) |
1025 | | } |
1026 | | } |
1027 | 0 | } |
1028 | | |
1029 | 0 | fn received_key_update_request(&mut self) -> Result<(), Error> { |
1030 | 0 | match self.allowed_key_update_requests { |
1031 | 0 | 0 => Err(PeerMisbehaved::TooManyKeyUpdateRequests.into()), |
1032 | | _ => { |
1033 | 0 | self.allowed_key_update_requests -= 1; |
1034 | 0 | Ok(()) |
1035 | | } |
1036 | | } |
1037 | 0 | } |
1038 | | |
1039 | 0 | fn received_tls13_change_cipher_spec(&mut self) -> Result<(), Error> { |
1040 | 0 | match self.allowed_middlebox_ccs { |
1041 | 0 | 0 => Err(PeerMisbehaved::IllegalMiddleboxChangeCipherSpec.into()), |
1042 | | _ => { |
1043 | 0 | self.allowed_middlebox_ccs -= 1; |
1044 | 0 | Ok(()) |
1045 | | } |
1046 | | } |
1047 | 0 | } |
1048 | | |
1049 | 0 | fn received_app_data(&mut self) { |
1050 | 0 | self.allowed_key_update_requests = Self::INITIAL_KEY_UPDATE_REQUESTS; |
1051 | 0 | } |
1052 | | |
1053 | | // cf. BoringSSL `kMaxKeyUpdates` |
1054 | | // <https://github.com/google/boringssl/blob/dec5989b793c56ad4dd32173bd2d8595ca78b398/ssl/tls13_both.cc#L35-L38> |
1055 | | const INITIAL_KEY_UPDATE_REQUESTS: u8 = 32; |
1056 | | } |
1057 | | |
1058 | | impl Default for TemperCounters { |
1059 | 0 | fn default() -> Self { |
1060 | 0 | Self { |
1061 | 0 | // cf. BoringSSL `kMaxWarningAlerts` |
1062 | 0 | // <https://github.com/google/boringssl/blob/dec5989b793c56ad4dd32173bd2d8595ca78b398/ssl/tls_record.cc#L137-L139> |
1063 | 0 | allowed_warning_alerts: 4, |
1064 | 0 |
|
1065 | 0 | // we rebuff renegotiation requests with a `NoRenegotiation` warning alerts. |
1066 | 0 | // a second request after this is fatal. |
1067 | 0 | allowed_renegotiation_requests: 1, |
1068 | 0 |
|
1069 | 0 | allowed_key_update_requests: Self::INITIAL_KEY_UPDATE_REQUESTS, |
1070 | 0 |
|
1071 | 0 | // At most two CCS are allowed: one after each ClientHello (recall a second |
1072 | 0 | // ClientHello happens after a HelloRetryRequest). |
1073 | 0 | // |
1074 | 0 | // note BoringSSL allows up to 32. |
1075 | 0 | allowed_middlebox_ccs: 2, |
1076 | 0 | } |
1077 | 0 | } |
1078 | | } |
1079 | | |
1080 | | #[derive(Debug, Default)] |
1081 | | pub(crate) enum KxState { |
1082 | | #[default] |
1083 | | None, |
1084 | | Start(&'static dyn SupportedKxGroup), |
1085 | | Complete(&'static dyn SupportedKxGroup), |
1086 | | } |
1087 | | |
1088 | | impl KxState { |
1089 | 0 | pub(crate) fn complete(&mut self) { |
1090 | 0 | debug_assert!(matches!(self, Self::Start(_))); |
1091 | 0 | if let Self::Start(group) = self { |
1092 | 0 | *self = Self::Complete(*group); |
1093 | 0 | } |
1094 | 0 | } |
1095 | | } |
1096 | | |
1097 | | pub(crate) struct HandshakeFlight<'a, const TLS13: bool> { |
1098 | | pub(crate) transcript: &'a mut HandshakeHash, |
1099 | | body: Vec<u8>, |
1100 | | } |
1101 | | |
1102 | | impl<'a, const TLS13: bool> HandshakeFlight<'a, TLS13> { |
1103 | 0 | pub(crate) fn new(transcript: &'a mut HandshakeHash) -> Self { |
1104 | 0 | Self { |
1105 | 0 | transcript, |
1106 | 0 | body: Vec::new(), |
1107 | 0 | } |
1108 | 0 | } Unexecuted instantiation: <rustls::common_state::HandshakeFlight<false>>::new Unexecuted instantiation: <rustls::common_state::HandshakeFlight<true>>::new |
1109 | | |
1110 | 0 | pub(crate) fn add(&mut self, hs: HandshakeMessagePayload<'_>) { |
1111 | 0 | let start_len = self.body.len(); |
1112 | 0 | hs.encode(&mut self.body); |
1113 | 0 | self.transcript |
1114 | 0 | .add(&self.body[start_len..]); |
1115 | 0 | } Unexecuted instantiation: <rustls::common_state::HandshakeFlight<false>>::add Unexecuted instantiation: <rustls::common_state::HandshakeFlight<true>>::add |
1116 | | |
1117 | 0 | pub(crate) fn finish(self, common: &mut CommonState) { |
1118 | 0 | common.send_msg( |
1119 | | Message { |
1120 | 0 | version: match TLS13 { |
1121 | 0 | true => ProtocolVersion::TLSv1_3, |
1122 | 0 | false => ProtocolVersion::TLSv1_2, |
1123 | | }, |
1124 | 0 | payload: MessagePayload::HandshakeFlight(Payload::new(self.body)), |
1125 | | }, |
1126 | | TLS13, |
1127 | | ); |
1128 | 0 | } Unexecuted instantiation: <rustls::common_state::HandshakeFlight<false>>::finish Unexecuted instantiation: <rustls::common_state::HandshakeFlight<true>>::finish |
1129 | | } |
1130 | | |
1131 | | #[cfg(feature = "tls12")] |
1132 | | pub(crate) type HandshakeFlightTls12<'a> = HandshakeFlight<'a, false>; |
1133 | | pub(crate) type HandshakeFlightTls13<'a> = HandshakeFlight<'a, true>; |
1134 | | |
1135 | | const DEFAULT_RECEIVED_PLAINTEXT_LIMIT: usize = 16 * 1024; |
1136 | | pub(crate) const DEFAULT_BUFFER_LIMIT: usize = 64 * 1024; |