silk.tls.server_protocol.
Serve TLS 1.3 on a silk.net.tcp_server engine, with the certificate chain and private key
loaded from PEM text.
When to use#
Use TlsProtocol to run any silk.net.tcp_server protocol over TLS, as the HTTPS mode of
silk.http.serve does. Load the certificate chain and the private key one time with
TlsServerConfig.fromPem, and share the config across all connections and workers.
Details#
Each connection runs one silk.tls.server Server: the handshake, the record layer,
KeyUpdate and close_notify all come from it. The protocol decrypts the bytes that arrive and
gives them to the inner protocol, and encrypts what the inner protocol writes. When the inner
protocol closes the connection, it sends close_notify first. The server offers ALPN
http/1.1 without requiring it.
The private key is an ECDSA P-256 or P-384 key, in a PRIVATE KEY (PKCS #8) or
EC PRIVATE KEY (SEC 1) block.
Errors#
TlsConfigErrorfromTlsServerConfig.fromPemfor PEM text that it cannot use.A TLS error on a connection closes that connection without an alert.
OutOfMemoryErrorif a buffer cannot grow.
Gotchas#
The server does not check its own chain. Give the leaf certificate first. Secrets are not erased.
Import as TlsProtocol with import silk.tls.server_protocol { TlsProtocol }.
Public declarations: 4.
TlsConfigError#
pub enum TlsConfigErrorWhy TlsServerConfig.fromPem cannot use its input.
NoCertificate#
NoCertificateThe certificate text holds no CERTIFICATE block.
InvalidPem#
InvalidPemA PEM block is malformed, or its base64 is not valid.
UnsupportedKey#
UnsupportedKeyThe key text holds no PRIVATE KEY or EC PRIVATE KEY block with a P-256 or P-384 key.
ChainTooLarge#
ChainTooLargeThe chain is larger than the server allows.
InvalidCertificate#
InvalidCertificateThe leaf certificate cannot be decoded.
KeyMismatch#
KeyMismatchThe public key of the leaf certificate is not the public key of the private key.
Implementation Debug for TlsConfigError#
impl Debug for TlsConfigErrorOperation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites the name of the variant, such as NoCertificate.
TlsServerConfig#
pub struct TlsServerConfigThe certificate chain and the private key of a server. One config serves every connection and every worker.
Implementation TlsServerConfig#
impl TlsServerConfigAssociated function fromPem#
pub effect fn fromPem(certificates: &[u8], privateKey: &[u8]) -> TlsServerConfig
! TlsConfigError | OutOfMemoryError ? &mut AllocatorReads the certificate chain from the CERTIFICATE blocks of certificates, leaf first, and
the private key from the first PRIVATE KEY (PKCS #8) or EC PRIVATE KEY (SEC 1) block of
privateKey.
Details#
It makes one silk.tls.server Server to check the chain and the key, so a config that
loads serves every connection.
Errors#
NoCertificate,InvalidPem,UnsupportedKey,ChainTooLarge,InvalidCertificateorKeyMismatchfor input it cannot use.OutOfMemoryErrorif the chain cannot be stored.
TlsProtocol#
pub struct TlsProtocol<P>A silk.net.tcp_server protocol that serves TLS 1.3 and runs inner over the decrypted bytes.
Details#
For each connection it makes a silk.tls.server Server and the state of inner. Bytes that
arrive are decrypted and given to inner, and what inner writes is encrypted. When inner
closes the connection, the server sends close_notify first.
Implementation TlsProtocol<P>#
impl<P> TlsProtocol<P>Associated function make#
pub fn make(config: TlsServerConfig, inner: P) -> TlsProtocol<P>Returns a protocol that serves inner over TLS with config.
TlsSession#
pub struct TlsSession<S>The state of one connection of a TlsProtocol.
Implementation Protocol<TlsSession<S>> for TlsProtocol<P>#
impl<S, P: Protocol<S>> Protocol<TlsSession<S>> for TlsProtocol<P>Operation open#
effect fn open(self: &Self) -> TlsSession<S> ! OutOfMemoryError ? &mut AllocatorOperation receive#
effect fn receive(
self: &Self,
state: &mut TlsSession<S>,
input: &mut [u8],
ended: bool,
output: &mut List<u8>,
) -> Received ! OutOfMemoryError ? &mut AllocatorCategory: TLS and certificates.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.