Skip to main content

ntex_tls/
types.rs

1//! Owned connection metadata returned through [`ntex_io::IoRef::query`].
2//!
3//! Queries return no value when a backend does not support the requested type
4//! or the negotiated session has no corresponding information. Reading a
5//! certificate is not a substitute for configuring certificate verification.
6
7use ntex_bytes::Bytes;
8
9/// The pre-shared-key identity reported by OpenSSL.
10///
11/// Available only when OpenSSL exposes an identity for the session. The rustls
12/// and Schannel filters do not implement this query.
13#[derive(Clone, Debug, PartialEq, Eq, Hash)]
14pub struct PskIdentity(
15    /// Identity bytes, not the secret key.
16    pub Bytes,
17);
18
19/// The DNS server name carried in the TLS SNI extension.
20///
21/// Server-side filters expose the name received from the client, when present.
22/// OpenSSL may also expose its configured client-side name. This is not the
23/// transport address or evidence that the peer is authorized to use the name.
24#[derive(Clone, Debug, PartialEq, Eq, Hash)]
25pub struct Servername(
26    /// Owned server name without a port.
27    pub String,
28);
29
30/// The peer's end-entity certificate in DER encoding.
31///
32/// Supported by all TLS backends. The query returns no value if no peer
33/// certificate is available, for example when client authentication is not used.
34#[derive(Clone, Debug, PartialEq, Eq, Hash)]
35pub struct PeerCertDer(
36    /// DER-encoded leaf certificate.
37    pub Bytes,
38);
39
40/// The certificates sent by the peer in DER encoding, the end-entity
41/// certificate first.
42///
43/// Supported by all TLS backends. OpenSSL normalizes its native chain to include
44/// the leaf on both sides; Schannel orders issuers after the leaf and retains
45/// unrelated supplied certificates at the end. The chain need not contain a
46/// root certificate and its presence does not establish trust.
47#[derive(Clone, Debug, PartialEq, Eq, Hash)]
48pub struct PeerCertChainDer(
49    /// DER-encoded certificates, with the peer's leaf first.
50    pub Vec<Bytes>,
51);
52
53/// The negotiated TLS protocol version.
54///
55/// Supported by all TLS backends. These variants describe metadata, not the
56/// protocol versions enabled by a backend's configuration.
57#[non_exhaustive]
58#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
59pub enum TlsVersion {
60    /// TLS 1.0.
61    Tls10,
62    /// TLS 1.1.
63    Tls11,
64    /// TLS 1.2.
65    Tls12,
66    /// TLS 1.3.
67    Tls13,
68}
69
70/// The negotiated cipher suite.
71///
72/// Supported by rustls, Schannel, and OpenSSL builds with cipher metadata
73/// support (OpenSSL 1.1.1 or newer). A known numeric identifier may have no
74/// corresponding name in the backend's lookup table.
75#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
76pub struct TlsCipher {
77    /// IANA cipher suite identifier, for example `0x1301`.
78    pub id: u16,
79    /// IANA name, for example `TLS_AES_128_GCM_SHA256`, when recognized.
80    pub name: Option<&'static str>,
81}