1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
use s2n_quic::provider::connection_close_formatter::{ConnectionClose, Context, Formatter};
use s2n_quic_core::{application, transport};
/// A formatter that passes transport errors through transparently.
///
/// This differs from the default [`Production`](s2n_quic_core::connection::close::Production) formatter
/// by preserving specific TLS alert codes (e.g., `CERTIFICATE_UNKNOWN`) over the wire.
/// Unlike the [`Development`](s2n_quic_core::connection::close::Development) formatter
/// this does clear the Reason Phrase field for early closure to remain compliant with RFC 9000.
///
/// This formatter is safe to use in controlled environments where both peers are
/// generally expected to be trusted infrastructure.
#[derive(Clone, Copy, Debug, Default)]
pub struct TransparentTransport;
impl Formatter for TransparentTransport {
fn format_transport_error(
&self,
_context: &Context,
error: transport::Error,
) -> ConnectionClose<'_> {
error.into()
}
fn format_application_error(
&self,
_context: &Context,
error: application::Error,
) -> ConnectionClose<'_> {
error.into()
}
fn format_early_transport_error(
&self,
context: &Context,
error: transport::Error,
) -> ConnectionClose<'_> {
Self.format_transport_error(context, error)
}
fn format_early_application_error(
&self,
_context: &Context,
_error: application::Error,
) -> ConnectionClose<'_> {
//= https://www.rfc-editor.org/rfc/rfc9000#section-10.2.3
//# Sending a CONNECTION_CLOSE of type 0x1d in an Initial or Handshake
//# packet could expose application state or be used to alter application
//# state. A CONNECTION_CLOSE of type 0x1d MUST be replaced by a
//# CONNECTION_CLOSE of type 0x1c when sending the frame in Initial or
//# Handshake packets. Otherwise, information about the application
//# state might be revealed. Endpoints MUST clear the value of the
//# Reason Phrase field and SHOULD use the APPLICATION_ERROR code when
//# converting to a CONNECTION_CLOSE of type 0x1c.
transport::Error::APPLICATION_ERROR.into()
}
}