pub struct CommonState {Show 26 fields
pub(crate) negotiated_version: Option<ProtocolVersion>,
pub(crate) handshake_kind: Option<HandshakeKind>,
pub(crate) side: Side,
pub(crate) record_layer: RecordLayer,
pub(crate) suite: Option<SupportedCipherSuite>,
pub(crate) kx_state: KxState,
pub(crate) alpn_protocol: Option<Vec<u8>>,
pub(crate) aligned_handshake: bool,
pub(crate) may_send_application_data: bool,
pub(crate) may_receive_application_data: bool,
pub(crate) early_traffic: bool,
sent_fatal_alert: bool,
pub(crate) has_sent_close_notify: bool,
pub(crate) has_received_close_notify: bool,
pub(crate) has_seen_eof: bool,
pub(crate) peer_certificates: Option<CertificateChain<'static>>,
message_fragmenter: MessageFragmenter,
pub(crate) received_plaintext: ChunkVecBuffer,
pub(crate) sendable_tls: ChunkVecBuffer,
queued_key_update_message: Option<Vec<u8>>,
pub(crate) protocol: Protocol,
pub(crate) quic: Quic,
pub(crate) enable_secret_extraction: bool,
temper_counters: TemperCounters,
pub(crate) refresh_traffic_keys_pending: bool,
pub(crate) fips: bool,
}
Expand description
Connection state common to both client and server connections.
Fields§
§negotiated_version: Option<ProtocolVersion>
§handshake_kind: Option<HandshakeKind>
§side: Side
§record_layer: RecordLayer
§suite: Option<SupportedCipherSuite>
§kx_state: KxState
§alpn_protocol: Option<Vec<u8>>
§aligned_handshake: bool
§may_send_application_data: bool
§may_receive_application_data: bool
§early_traffic: bool
§sent_fatal_alert: bool
§has_sent_close_notify: bool
If we signaled end of stream.
has_received_close_notify: bool
If the peer has signaled end of stream.
has_seen_eof: bool
§peer_certificates: Option<CertificateChain<'static>>
§message_fragmenter: MessageFragmenter
§received_plaintext: ChunkVecBuffer
§sendable_tls: ChunkVecBuffer
§queued_key_update_message: Option<Vec<u8>>
§protocol: Protocol
Protocol whose key schedule should be used. Unused for TLS < 1.3.
quic: Quic
§enable_secret_extraction: bool
§temper_counters: TemperCounters
§refresh_traffic_keys_pending: bool
§fips: bool
Implementations§
Source§impl CommonState
impl CommonState
pub(crate) fn new(side: Side) -> Self
Sourcepub fn wants_write(&self) -> bool
pub fn wants_write(&self) -> bool
Returns true if the caller should call Connection::write_tls
as soon as possible.
Sourcepub fn is_handshaking(&self) -> bool
pub fn is_handshaking(&self) -> bool
Returns true if the connection is currently performing the TLS handshake.
During this time plaintext written to the connection is buffered in memory. After
Connection::process_new_packets()
has been called, this might start to return false
while the final handshake packets still need to be extracted from the connection’s buffers.
Sourcepub fn peer_certificates(&self) -> Option<&[CertificateDer<'static>]>
pub fn peer_certificates(&self) -> Option<&[CertificateDer<'static>]>
Retrieves the certificate chain or the raw public key used by the peer to authenticate.
The order of the certificate chain is as it appears in the TLS protocol: the first certificate relates to the peer, the second certifies the first, the third certifies the second, and so on.
When using raw public keys, the first and only element is the raw public key.
This is made available for both full and resumed handshakes.
For clients, this is the certificate chain or the raw public key of the server.
For servers, this is the certificate chain or the raw public key of the client, if client authentication was completed.
The return value is None until this value is available.
Note: the return type of the ‘certificate’, when using raw public keys is CertificateDer<'static>
even though this should technically be a SubjectPublicKeyInfoDer<'static>
.
This choice simplifies the API and ensures backwards compatibility.
Sourcepub fn alpn_protocol(&self) -> Option<&[u8]>
pub fn alpn_protocol(&self) -> Option<&[u8]>
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 ciphersuite agreed with the peer.
This returns None until the ciphersuite 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 CommonState::handshake_kind()
is HandshakeKind::Resumed
and the CommonState::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.
pub(crate) fn is_tls13(&self) -> bool
pub(crate) fn process_main_protocol<Data>( &mut self, msg: Message<'_>, state: Box<dyn State<Data>>, data: &mut Data, sendable_plaintext: Option<&mut ChunkVecBuffer>, ) -> Result<Box<dyn State<Data>>, Error>
pub(crate) fn write_plaintext( &mut self, payload: OutboundChunks<'_>, outgoing_tls: &mut [u8], ) -> Result<usize, EncryptError>
pub(crate) fn check_aligned_handshake(&mut self) -> Result<(), Error>
Sourcepub(crate) fn send_msg_encrypt(&mut self, m: PlainMessage)
pub(crate) fn send_msg_encrypt(&mut self, m: PlainMessage)
Fragment m
, encrypt the fragments, and then queue
the encrypted fragments for sending.
Sourcefn send_appdata_encrypt(
&mut self,
payload: OutboundChunks<'_>,
limit: Limit,
) -> usize
fn send_appdata_encrypt( &mut self, payload: OutboundChunks<'_>, limit: Limit, ) -> usize
Like send_msg_encrypt, but operate on an appdata directly.
fn send_single_fragment(&mut self, m: OutboundPlainMessage<'_>)
fn send_plain_non_buffering( &mut self, payload: OutboundChunks<'_>, limit: Limit, ) -> usize
Sourcepub(crate) fn start_outgoing_traffic(
&mut self,
sendable_plaintext: &mut Option<&mut ChunkVecBuffer>,
)
pub(crate) fn start_outgoing_traffic( &mut self, sendable_plaintext: &mut Option<&mut ChunkVecBuffer>, )
Mark the connection as ready to send application data.
Also flush sendable_plaintext
if it is Some
.
Sourcepub(crate) fn start_traffic(
&mut self,
sendable_plaintext: &mut Option<&mut ChunkVecBuffer>,
)
pub(crate) fn start_traffic( &mut self, sendable_plaintext: &mut Option<&mut ChunkVecBuffer>, )
Mark the connection as ready to send and receive application data.
Also flush sendable_plaintext
if it is Some
.
Sourcefn flush_plaintext(&mut self, sendable_plaintext: &mut ChunkVecBuffer)
fn flush_plaintext(&mut self, sendable_plaintext: &mut ChunkVecBuffer)
Send any buffered plaintext. Plaintext is buffered if written during handshake.
fn queue_tls_message(&mut self, m: OutboundOpaqueMessage)
pub(crate) fn perhaps_write_key_update(&mut self)
Sourcepub(crate) fn send_msg(&mut self, m: Message<'_>, must_encrypt: bool)
pub(crate) fn send_msg(&mut self, m: Message<'_>, must_encrypt: bool)
Send a raw TLS message, fragmenting it if needed.
pub(crate) fn take_received_plaintext(&mut self, bytes: Payload<'_>)
pub(crate) fn start_encryption_tls12( &mut self, secrets: &ConnectionSecrets, side: Side, )
pub(crate) fn missing_extension(&mut self, why: PeerMisbehaved) -> Error
fn send_warning_alert(&mut self, desc: AlertDescription)
pub(crate) fn process_alert( &mut self, alert: &AlertMessagePayload, ) -> Result<(), Error>
pub(crate) fn send_cert_verify_error_alert(&mut self, err: Error) -> Error
pub(crate) fn send_fatal_alert( &mut self, desc: AlertDescription, err: impl Into<Error>, ) -> Error
Sourcepub fn send_close_notify(&mut self)
pub fn send_close_notify(&mut self)
Queues a close_notify
warning alert to be sent in the next
Connection::write_tls
call. This informs the peer that the
connection is being closed.
Does nothing if any close_notify
or fatal alert was already sent.
pub(crate) fn eager_send_close_notify( &mut self, outgoing_tls: &mut [u8], ) -> Result<usize, EncryptError>
fn send_warning_alert_no_log(&mut self, desc: AlertDescription)
fn check_required_size<'a>( &self, outgoing_tls: &mut [u8], fragments: impl Iterator<Item = OutboundPlainMessage<'a>>, ) -> Result<(), EncryptError>
fn write_fragments<'a>( &mut self, outgoing_tls: &mut [u8], fragments: impl Iterator<Item = OutboundPlainMessage<'a>>, ) -> usize
pub(crate) fn set_max_fragment_size( &mut self, new: Option<usize>, ) -> Result<(), Error>
pub(crate) fn get_alpn_protocol(&self) -> Option<&[u8]>
Sourcepub fn wants_read(&self) -> bool
pub fn wants_read(&self) -> bool
Returns true if the caller should call Connection::read_tls
as soon
as possible.
If there is pending plaintext data to read with Connection::reader
,
this returns false. If your application respects this mechanism,
only one full TLS message will be buffered by rustls.
pub(crate) fn current_io_state(&self) -> IoState
pub(crate) fn is_quic(&self) -> bool
pub(crate) fn should_update_key( &mut self, key_update_request: &KeyUpdateRequest, ) -> Result<bool, Error>
pub(crate) fn enqueue_key_update_notification(&mut self)
pub(crate) fn received_tls13_change_cipher_spec(&mut self) -> Result<(), Error>
Source§impl CommonState
impl CommonState
Sourcepub(crate) fn buffer_plaintext(
&mut self,
payload: OutboundChunks<'_>,
sendable_plaintext: &mut ChunkVecBuffer,
) -> usize
pub(crate) fn buffer_plaintext( &mut self, payload: OutboundChunks<'_>, sendable_plaintext: &mut ChunkVecBuffer, ) -> usize
Send plaintext application data, fragmenting and encrypting it as it goes out.
If internal buffers are too small, this function will not accept all the data.
pub(crate) fn send_early_plaintext(&mut self, data: &[u8]) -> usize
Sourcefn send_plain(
&mut self,
payload: OutboundChunks<'_>,
limit: Limit,
sendable_plaintext: &mut ChunkVecBuffer,
) -> usize
fn send_plain( &mut self, payload: OutboundChunks<'_>, limit: Limit, sendable_plaintext: &mut ChunkVecBuffer, ) -> usize
Encrypt and send some plaintext data
. limit
controls
whether the per-connection buffer limits apply.
Returns the number of bytes written from data
: this might
be less than data.len()
if buffer limits were exceeded.