pub struct ServerConnection { /* private fields */ }Expand description
This represents a single TLS server connection.
Send TLS-protected data to the peer using the io::Write trait implementation.
Read data from the peer using the io::Read trait implementation.
Implementations§
Source§impl ServerConnection
impl ServerConnection
Sourcepub fn new(config: Arc<ServerConfig>) -> Result<Self, Error>
pub fn new(config: Arc<ServerConfig>) -> Result<Self, Error>
Make a new ServerConnection. config controls how
we behave in the TLS protocol.
Sourcepub fn server_name(&self) -> Option<&DnsName<'_>>
pub fn server_name(&self) -> Option<&DnsName<'_>>
Retrieves the server name, if any, used to select the certificate and private key.
This returns None until some time after the client’s server name indication
(SNI) extension value is processed during the handshake. It will never be
None when the connection is ready to send or process application data,
unless the client does not support SNI.
This is useful for application protocols that need to enforce that the
server name matches an application layer protocol hostname. For
example, HTTP/1.1 servers commonly expect the Host: header field of
every request on a connection to match the hostname in the SNI extension
when the client provides the SNI extension.
The server name is also used to match sessions during session resumption.
Sourcepub fn received_resumption_data(&self) -> Option<&[u8]>
pub fn received_resumption_data(&self) -> Option<&[u8]>
Application-controlled portion of the resumption ticket supplied by the client, if any.
Recovered from the prior session’s set_resumption_data. Integrity is guaranteed by rustls.
Returns Some if and only if a valid resumption ticket has been received from the client.
Sourcepub fn set_resumption_data(&mut self, data: &[u8]) -> Result<(), Error>
pub fn set_resumption_data(&mut self, data: &[u8]) -> Result<(), Error>
Set the resumption data to embed in future resumption tickets supplied to the client.
Defaults to the empty byte string. Must be less than 2^15 bytes to allow room for other
data. Should be called while is_handshaking returns true to ensure all transmitted
resumption tickets are affected.
Integrity will be assured by rustls, but the data will be visible to the client. If secrecy from the client is desired, encrypt the data separately.
Sourcepub fn early_data(&mut self) -> Option<ReadEarlyData<'_>>
pub fn early_data(&mut self) -> Option<ReadEarlyData<'_>>
Returns an io::Read implementer you can read bytes from that are
received from a client as TLS1.3 0RTT/“early” data, during the handshake.
This returns None in many circumstances, such as :
- Early data is disabled if
ServerConfig::max_early_data_sizeis zero (the default). - The session negotiated with the client is not TLS1.3.
- The client just doesn’t support early data.
- The connection doesn’t resume an existing session.
- The client hasn’t sent a full ClientHello yet.
Sourcepub fn dangerous_extract_secrets(self) -> Result<ExtractedSecrets, Error>
pub fn dangerous_extract_secrets(self) -> Result<ExtractedSecrets, Error>
Extract secrets, so they can be used when configuring kTLS, for example. Should be used with care as it exposes secret key material.
Methods from Deref<Target = ConnectionOutputs>§
Sourcepub fn peer_identity(&self) -> Option<&Identity<'static>>
pub fn peer_identity(&self) -> Option<&Identity<'static>>
Retrieves the certificate chain or the raw public key used by the peer to authenticate.
This is made available for both full and resumed handshakes.
For clients, this is the identity of the server. For servers, this is the identity of the client, if client authentication was completed.
The return value is None until this value is available.
Sourcepub fn alpn_protocol(&self) -> Option<&ApplicationProtocol<'static>>
pub fn alpn_protocol(&self) -> Option<&ApplicationProtocol<'static>>
Retrieves the protocol agreed with the peer via ALPN.
A return value of None after handshake completion
means no protocol was agreed (because no protocols
were offered or accepted by the peer).
Sourcepub fn negotiated_cipher_suite(&self) -> Option<SupportedCipherSuite>
pub fn negotiated_cipher_suite(&self) -> Option<SupportedCipherSuite>
Retrieves the cipher suite agreed with the peer.
This returns None until the cipher suite is agreed.
Sourcepub fn negotiated_key_exchange_group(
&self,
) -> Option<&'static dyn SupportedKxGroup>
pub fn negotiated_key_exchange_group( &self, ) -> Option<&'static dyn SupportedKxGroup>
Retrieves the key exchange group agreed with the peer.
This function may return None depending on the state of the connection,
the type of handshake, and the protocol version.
If CommonState::is_handshaking() is true this function will return None.
Similarly, if the ConnectionOutputs::handshake_kind() is HandshakeKind::Resumed
and the ConnectionOutputs::protocol_version() is TLS 1.2, then no key exchange will have
occurred and this function will return None.
Sourcepub fn protocol_version(&self) -> Option<ProtocolVersion>
pub fn protocol_version(&self) -> Option<ProtocolVersion>
Retrieves the protocol version agreed with the peer.
This returns None until the version is agreed.
Sourcepub fn handshake_kind(&self) -> Option<HandshakeKind>
pub fn handshake_kind(&self) -> Option<HandshakeKind>
Which kind of handshake was performed.
This tells you whether the handshake was a resumption or not.
This will return None before it is known which sort of
handshake occurred.
Trait Implementations§
Source§impl Connection for ServerConnection
impl Connection for ServerConnection
Source§fn read_tls(&mut self, rd: &mut dyn Read) -> Result<usize, Error>
fn read_tls(&mut self, rd: &mut dyn Read) -> Result<usize, Error>
rd into the internal buffer. Read moreSource§fn write_tls(&mut self, wr: &mut dyn Write) -> Result<usize, Error>
fn write_tls(&mut self, wr: &mut dyn Write) -> Result<usize, Error>
wr. Read moreSource§fn wants_read(&self) -> bool
fn wants_read(&self) -> bool
Connection::read_tls as soon
as possible. Read moreSource§fn wants_write(&self) -> bool
fn wants_write(&self) -> bool
Connection::write_tls as soon as possible.Source§fn process_new_packets(&mut self) -> Result<IoState, Error>
fn process_new_packets(&mut self) -> Result<IoState, Error>
Connection::read_tls. Read moreSource§fn exporter(&mut self) -> Result<KeyingMaterialExporter, Error>
fn exporter(&mut self) -> Result<KeyingMaterialExporter, Error>
Source§fn dangerous_extract_secrets(self) -> Result<ExtractedSecrets, Error>
fn dangerous_extract_secrets(self) -> Result<ExtractedSecrets, Error>
Source§fn set_buffer_limit(&mut self, limit: Option<usize>)
fn set_buffer_limit(&mut self, limit: Option<usize>)
Connection::writer. Read moreSource§fn set_plaintext_buffer_limit(&mut self, limit: Option<usize>)
fn set_plaintext_buffer_limit(&mut self, limit: Option<usize>)
Source§fn refresh_traffic_keys(&mut self) -> Result<(), Error>
fn refresh_traffic_keys(&mut self) -> Result<(), Error>
key_update message to refresh a connection’s keys. Read moreSource§fn send_close_notify(&mut self)
fn send_close_notify(&mut self)
close_notify warning alert to be sent in the next
Connection::write_tls call. This informs the peer that the
connection is being closed. Read more