rustls

Undocumented in source.

Members

Aliases

rustls_client_hello_callback
alias rustls_client_hello_callback = rustls_certified_key* function(rustls_client_hello_userdata userdata, const rustls_client_hello* hello)

Prototype of a callback that can be installed by the application at the rustls_server_config. This callback will be invoked by a rustls_connection once the TLS client hello message has been received. userdata will be set based on rustls_connection_set_userdata. hello gives the value of the available client announcements, as interpreted by rustls. See the definition of rustls_client_hello for details.

rustls_client_hello_userdata
alias rustls_client_hello_userdata = void*

Any context information the callback will receive when invoked.

rustls_io_result
alias rustls_io_result = int

A return value for a function that may return either success (0) or a non-zero value representing an error. The values should match socket error numbers for your operating system - for example, the integers for ETIMEDOUT, EAGAIN, or similar.

rustls_log_callback
alias rustls_log_callback = void function(void* userdata, const rustls_log_params* params)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
rustls_log_level
alias rustls_log_level = size_t
Undocumented in source.
rustls_read_callback
alias rustls_read_callback = rustls_io_result function(void* userdata, ubyte* buf, size_t n, size_t* out_n)

A callback for rustls_connection_read_tls. An implementation of this callback should attempt to read up to n bytes from the network, storing them in buf. If any bytes were stored, the implementation should set out_n to the number of bytes stored and return 0. If there was an error, the implementation should return a nonzero rustls_io_result, which will be passed through to the caller. On POSIX systems, returning errno is convenient. On other systems, any appropriate error code works. It's best to make one read attempt to the network per call. Additional reads will be triggered by subsequent calls to one of the _read_tls methods. userdata is set to the value provided to rustls_connection_set_userdata. In most cases that should be a struct that contains, at a minimum, a file descriptor. The buf and out_n pointers are borrowed and should not be retained across calls.

rustls_session_store_get_callback
alias rustls_session_store_get_callback = uint function(rustls_session_store_userdata userdata, const rustls_slice_bytes* key, int remove_after, ubyte* buf, size_t count, size_t* out_n)

Prototype of a callback that can be installed by the application at the rustls_server_config or rustls_client_config. This callback will be invoked by a TLS session when looking up the data for a TLS session id. userdata will be supplied based on rustls_{client,server}_session_set_userdata.

rustls_session_store_put_callback
alias rustls_session_store_put_callback = uint function(rustls_session_store_userdata userdata, const rustls_slice_bytes* key, const rustls_slice_bytes* val)

Prototype of a callback that can be installed by the application at the rustls_server_config or rustls_client_config. This callback will be invoked by a TLS session when a TLS session has been created and an id for later use is handed to the client/has been received from the server. userdata will be supplied based on rustls_{client,server}_session_set_userdata.

rustls_session_store_userdata
alias rustls_session_store_userdata = void*

Any context information the callback will receive when invoked.

rustls_verify_server_cert_callback
alias rustls_verify_server_cert_callback = uint function(rustls_verify_server_cert_user_data userdata, const rustls_verify_server_cert_params* params)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
rustls_verify_server_cert_user_data
alias rustls_verify_server_cert_user_data = void*

User-provided input to a custom certificate verifier callback. See rustls_client_config_builder_dangerous_set_certificate_verifier().

rustls_write_callback
alias rustls_write_callback = rustls_io_result function(void* userdata, const ubyte* buf, size_t n, size_t* out_n)

A callback for rustls_connection_write_tls. An implementation of this callback should attempt to write the n bytes in buf to the network. If any bytes were written, the implementation should set out_n to the number of bytes stored and return 0. If there was an error, the implementation should return a nonzero rustls_io_result, which will be passed through to the caller. On POSIX systems, returning errno is convenient. On other systems, any appropriate error code works. It's best to make one write attempt to the network per call. Additional writes will be triggered by subsequent calls to rustls_connection_write_tls. userdata is set to the value provided to rustls_connection_set_userdata. In most cases that should be a struct that contains, at a minimum, a file descriptor. The buf and out_n pointers are borrowed and should not be retained across calls.

rustls_write_vectored_callback
alias rustls_write_vectored_callback = rustls_io_result function(void* userdata, const rustls_iovec* iov, size_t count, size_t* out_n)

A callback for rustls_connection_write_tls_vectored. An implementation of this callback should attempt to write the bytes in the given count iovecs to the network. If any bytes were written, the implementation should set out_n to the number of bytes written and return 0. If there was an error, the implementation should return a nonzero rustls_io_result, which will be passed through to the caller. On POSIX systems, returning errno is convenient. On other systems, any appropriate error code works. It's best to make one write attempt to the network per call. Additional write will be triggered by subsequent calls to one of the _write_tls methods. userdata is set to the value provided to rustls_*_session_set_userdata. In most cases that should be a struct that contains, at a minimum, a file descriptor. The buf and out_n pointers are borrowed and should not be retained across calls.

Enums

rustls_result
enum rustls_result
Undocumented in source.
rustls_tls_version
enum rustls_tls_version

Definitions of known TLS protocol versions.

Functions

rustls_all_ciphersuites_get_entry
const(rustls_supported_ciphersuite)* rustls_all_ciphersuites_get_entry(size_t i)

Get a pointer to a member of rustls' list of supported cipher suites. This will return non-NULL for i < rustls_all_ciphersuites_len(). The returned pointer is valid for the lifetime of the program and may be used directly when building a ClientConfig or ServerConfig.

rustls_all_ciphersuites_len
size_t rustls_all_ciphersuites_len()

Return the length of rustls' list of supported cipher suites.

rustls_certificate_get_der
rustls_result rustls_certificate_get_der(rustls_certificate* cert, ubyte** out_der_data, size_t* out_der_len)

Get the DER data of the certificate itself. The data is owned by the certificate and has the same lifetime.

rustls_certified_key_build
rustls_result rustls_certified_key_build(ubyte* cert_chain, size_t cert_chain_len, ubyte* private_key, size_t private_key_len, rustls_certified_key** certified_key_out)

Build a rustls_certified_key from a certificate chain and a private key. cert_chain must point to a buffer of cert_chain_len bytes, containing a series of PEM-encoded certificates, with the end-entity (leaf) certificate first.

rustls_certified_key_clone_with_ocsp
rustls_result rustls_certified_key_clone_with_ocsp(rustls_certified_key* certified_key, rustls_slice_bytes* ocsp_response, rustls_certified_key** cloned_key_out)

Create a copy of the rustls_certified_key with the given OCSP response data as DER encoded bytes. The OCSP response may be given as NULL to clear any possibly present OCSP data from the cloned key. The cloned key is independent from its original and needs to be freed by the application.

rustls_certified_key_free
void rustls_certified_key_free(rustls_certified_key* key)

"Free" a certified_key previously returned from rustls_certified_key_build. Since certified_key is actually an atomically reference-counted pointer, extant certified_key may still hold an internal reference to the Rust object. However, C code must consider this pointer unusable after "free"ing it. Calling with NULL is fine. Must not be called twice with the same value.

rustls_certified_key_get_certificate
const(rustls_certificate)* rustls_certified_key_get_certificate(rustls_certified_key* certified_key, size_t i)

Return the i-th rustls_certificate in the rustls_certified_key. 0 gives the end-entity certificate. 1 and higher give certificates from the chain. Indexes higher than the last available certificate return NULL.

rustls_client_cert_verifier_free
void rustls_client_cert_verifier_free(rustls_client_cert_verifier* verifier)

"Free" a verifier previously returned from rustls_client_cert_verifier_new. Since rustls_client_cert_verifier is actually an atomically reference-counted pointer, extant server_configs may still hold an internal reference to the Rust object. However, C code must consider this pointer unusable after "free"ing it. Calling with NULL is fine. Must not be called twice with the same value.

rustls_client_cert_verifier_new
const(rustls_client_cert_verifier)* rustls_client_cert_verifier_new(rustls_root_cert_store* store)

Create a new client certificate verifier for the root store. The verifier can be used in several rustls_server_config instances. Must be freed by the application when no longer needed. See the documentation of rustls_client_cert_verifier_free for details about lifetime. This copies the contents of the rustls_root_cert_store. It does not take ownership of the pointed-to memory.

rustls_client_cert_verifier_optional_free
void rustls_client_cert_verifier_optional_free(rustls_client_cert_verifier_optional* verifier)

"Free" a verifier previously returned from rustls_client_cert_verifier_optional_new. Since rustls_client_cert_verifier_optional is actually an atomically reference-counted pointer, extant server_configs may still hold an internal reference to the Rust object. However, C code must consider this pointer unusable after "free"ing it. Calling with NULL is fine. Must not be called twice with the same value.

rustls_client_cert_verifier_optional_new
const(rustls_client_cert_verifier_optional)* rustls_client_cert_verifier_optional_new(rustls_root_cert_store* store)

Create a new rustls_client_cert_verifier_optional for the root store. The verifier can be used in several rustls_server_config instances. Must be freed by the application when no longer needed. See the documentation of rustls_client_cert_verifier_optional_free for details about lifetime. This copies the contents of the rustls_root_cert_store. It does not take ownership of the pointed-to data.

rustls_client_config_builder_build
const(rustls_client_config)* rustls_client_config_builder_build(rustls_client_config_builder* builder)

Turn a *rustls_client_config_builder (mutable) into a const *rustls_client_config (read-only).

rustls_client_config_builder_dangerous_set_certificate_verifier
rustls_result rustls_client_config_builder_dangerous_set_certificate_verifier(rustls_client_config_builder* config_builder, rustls_verify_server_cert_callback callback)

Set a custom server certificate verifier.

rustls_client_config_builder_free
void rustls_client_config_builder_free(rustls_client_config_builder* config)

"Free" a client_config_builder without building it into a rustls_client_config. Normally builders are built into rustls_client_config via rustls_client_config_builder_build and may not be free'd or otherwise used afterwards. Use free only when the building of a config has to be aborted before a config was created.

rustls_client_config_builder_load_roots_from_file
rustls_result rustls_client_config_builder_load_roots_from_file(rustls_client_config_builder* config_builder, char* filename)

Add trusted root certificates from the named file, which should contain PEM-formatted certificates.

rustls_client_config_builder_new
rustls_client_config_builder* rustls_client_config_builder_new()

Create a rustls_client_config_builder. Caller owns the memory and must eventually call rustls_client_config_builder_build, then free the resulting rustls_client_config. This uses rustls safe default values for the cipher suites, key exchange groups and protocol versions. This starts out with no trusted roots. Caller must add roots with rustls_client_config_builder_load_roots_from_file or provide a custom verifier.

rustls_client_config_builder_new_custom
rustls_result rustls_client_config_builder_new_custom(rustls_supported_ciphersuite** cipher_suites, size_t cipher_suites_len, ushort* tls_versions, size_t tls_versions_len, rustls_client_config_builder** builder_out)

Create a rustls_client_config_builder. Caller owns the memory and must eventually call rustls_client_config_builder_build, then free the resulting rustls_client_config. Specify cipher suites in preference order; the cipher_suites parameter must point to an array containing len pointers to rustls_supported_ciphersuite previously obtained from rustls_all_ciphersuites_get_entry(), or to a provided array, RUSTLS_DEFAULT_CIPHER_SUITES or RUSTLS_ALL_CIPHER_SUITES. Set the TLS protocol versions to use when negotiating a TLS session.

rustls_client_config_builder_set_alpn_protocols
rustls_result rustls_client_config_builder_set_alpn_protocols(rustls_client_config_builder* builder, rustls_slice_bytes* protocols, size_t len)

Set the ALPN protocol list to the given protocols. protocols must point to a buffer of rustls_slice_bytes (built by the caller) with len elements. Each element of the buffer must be a rustls_slice_bytes whose data field points to a single ALPN protocol ID. Standard ALPN protocol IDs are defined at <https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids>.

rustls_client_config_builder_set_certified_key
rustls_result rustls_client_config_builder_set_certified_key(rustls_client_config_builder* builder, rustls_certified_key** certified_keys, size_t certified_keys_len)

Provide the configuration a list of certificates where the connection will select the first one that is compatible with the server's signature verification capabilities. Clients that want to support both ECDSA and RSA certificates will want the ECSDA to go first in the list.

rustls_client_config_builder_set_enable_sni
void rustls_client_config_builder_set_enable_sni(rustls_client_config_builder* config, bool enable)

Enable or disable SNI. <https://docs.rs/rustls/0.20.0/rustls/struct.ClientConfig.html#structfield.enable_sni>

rustls_client_config_builder_use_roots
rustls_result rustls_client_config_builder_use_roots(rustls_client_config_builder* config_builder, rustls_root_cert_store* roots)

Use the trusted root certificates from the provided store.

rustls_client_config_free
void rustls_client_config_free(rustls_client_config* config)

"Free" a rustls_client_config previously returned from rustls_client_config_builder_build. Since rustls_client_config is actually an atomically reference-counted pointer, extant client connections may still hold an internal reference to the Rust object. However, C code must consider this pointer unusable after "free"ing it. Calling with NULL is fine. Must not be called twice with the same value.

rustls_client_connection_new
rustls_result rustls_client_connection_new(rustls_client_config* config, char* hostname, rustls_connection** conn_out)

Create a new rustls_connection containing a client connection and return it in the output parameter out. If this returns an error code, the memory pointed to by conn_out remains unchanged. If this returns a non-error, the memory pointed to by conn_out is modified to point at a valid rustls_connection. The caller now owns the rustls_connection and must call rustls_connection_free when done with it.

rustls_client_hello_select_certified_key
rustls_result rustls_client_hello_select_certified_key(rustls_client_hello* hello, rustls_certified_key** certified_keys, size_t certified_keys_len, rustls_certified_key** out_key)

Select a rustls_certified_key from the list that matches the cryptographic parameters of a TLS client hello. Note that this does not do any SNI matching. The input certificates should already have been filtered to ones matching the SNI from the client hello.

rustls_connection_free
void rustls_connection_free(rustls_connection* conn)

Free a rustls_connection. Calling with NULL is fine. Must not be called twice with the same value.

rustls_connection_get_alpn_protocol
void rustls_connection_get_alpn_protocol(rustls_connection* conn, ubyte** protocol_out, size_t* protocol_out_len)

Get the ALPN protocol that was negotiated, if any. Stores a pointer to a borrowed buffer of bytes, and that buffer's len, in the output parameters. The borrow lives as long as the connection. If the connection is still handshaking, or no ALPN protocol was negotiated, stores NULL and 0 in the output parameters. The provided pointer is valid until the next mutating function call affecting the connection. A mutating function call is one where the first argument has type struct rustls_connection * (as opposed to const struct rustls_connection *). <https://www.iana.org/assignments/tls-parameters/> <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.alpn_protocol>

rustls_connection_get_negotiated_ciphersuite
const(rustls_supported_ciphersuite)* rustls_connection_get_negotiated_ciphersuite(rustls_connection* conn)

Retrieves the cipher suite agreed with the peer. This returns NULL until the ciphersuite is agreed. The returned pointer lives as long as the program. <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.negotiated_cipher_suite>

rustls_connection_get_peer_certificate
const(rustls_certificate)* rustls_connection_get_peer_certificate(rustls_connection* conn, size_t i)

Return the i-th certificate provided by the peer. Index 0 is the end entity certificate. Higher indexes are certificates in the chain. Requesting an index higher than what is available returns NULL. The returned pointer is valid until the next mutating function call affecting the connection. A mutating function call is one where the first argument has type struct rustls_connection * (as opposed to const struct rustls_connection *). <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.peer_certificates>

rustls_connection_get_protocol_version
ushort rustls_connection_get_protocol_version(rustls_connection* conn)

Return the TLS protocol version that has been negotiated. Before this has been decided during the handshake, this will return 0. Otherwise, the u16 version number as defined in the relevant RFC is returned. <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.protocol_version> <https://docs.rs/rustls/0.20.0/rustls/internal/msgs/enums/enum.ProtocolVersion.html>

rustls_connection_is_handshaking
bool rustls_connection_is_handshaking(rustls_connection* conn)

<https://docs.rs/rustls/0.20.0/rustls/struct.CommonState.html#method.is_handshaking>

rustls_connection_process_new_packets
rustls_result rustls_connection_process_new_packets(rustls_connection* conn)

Decrypt any available ciphertext from the internal buffer and put it into the internal plaintext buffer, potentially making bytes available for rustls_connection_read(). <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.process_new_packets>

rustls_connection_read
rustls_result rustls_connection_read(rustls_connection* conn, ubyte* buf, size_t count, size_t* out_n)

Read up to count plaintext bytes from the rustls_connection into buf. On success, store the number of bytes read in *out_n (this may be less than count). A success with *out_n set to 0 means "all bytes currently available have been read, but more bytes may become available after subsequent calls to rustls_connection_read_tls and rustls_connection_process_new_packets."

rustls_connection_read_2
rustls_result rustls_connection_read_2(rustls_connection* conn, ubyte* buf, size_t count, size_t* out_n)

Read up to count plaintext bytes from the rustls_connection into buf. On success, store the number of bytes read in *out_n (this may be less than count). A success with *out_n set to 0 means "all bytes currently available have been read, but more bytes may become available after subsequent calls to rustls_connection_read_tls and rustls_connection_process_new_packets."

rustls_connection_read_tls
rustls_io_result rustls_connection_read_tls(rustls_connection* conn, rustls_read_callback callback, void* userdata, size_t* out_n)

Read some TLS bytes from the network into internal buffers. The actual network I/O is performed by callback, which you provide. Rustls will invoke your callback with a suitable buffer to store the read bytes into. You don't have to fill it up, just fill with as many bytes as you get in one syscall. The userdata parameter is passed through directly to callback. Note that this is distinct from the userdata parameter set with rustls_connection_set_userdata. Returns 0 for success, or an errno value on error. Passes through return values from callback. See rustls_read_callback for more details. <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.read_tls>

rustls_connection_send_close_notify
void rustls_connection_send_close_notify(rustls_connection* conn)

Queues a close_notify fatal alert to be sent in the next write_tls call. <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.send_close_notify>

rustls_connection_set_buffer_limit
void rustls_connection_set_buffer_limit(rustls_connection* conn, size_t n)

Sets a limit on the internal buffers used to buffer unsent plaintext (prior to completing the TLS handshake) and unsent TLS records. By default, there is no limit. The limit can be set at any time, even if the current buffer use is higher. <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.set_buffer_limit>

rustls_connection_set_log_callback
void rustls_connection_set_log_callback(rustls_connection* conn, rustls_log_callback cb)

Set the logging callback for this connection. The log callback will be invoked with the userdata parameter previously set by rustls_connection_set_userdata, or NULL if no userdata was set.

rustls_connection_set_userdata
void rustls_connection_set_userdata(rustls_connection* conn, void* userdata)

Set the userdata pointer associated with this connection. This will be passed to any callbacks invoked by the connection, if you've set up callbacks in the config. The pointed-to data must outlive the connection.

rustls_connection_wants_read
bool rustls_connection_wants_read(rustls_connection* conn)

<https://docs.rs/rustls/0.20.0/rustls/struct.CommonState.html#method.wants_read>

rustls_connection_wants_write
bool rustls_connection_wants_write(rustls_connection* conn)

<https://docs.rs/rustls/0.20.0/rustls/struct.CommonState.html#method.wants_write>

rustls_connection_write
rustls_result rustls_connection_write(rustls_connection* conn, ubyte* buf, size_t count, size_t* out_n)

Write up to count plaintext bytes from buf into the rustls_connection. This will increase the number of output bytes available to rustls_connection_write_tls. On success, store the number of bytes actually written in *out_n (this may be less than count). <https://docs.rs/rustls/0.20.0/rustls/struct.Writer.html#method.write>

rustls_connection_write_tls
rustls_io_result rustls_connection_write_tls(rustls_connection* conn, rustls_write_callback callback, void* userdata, size_t* out_n)

Write some TLS bytes to the network. The actual network I/O is performed by callback, which you provide. Rustls will invoke your callback with a suitable buffer containing TLS bytes to send. You don't have to write them all, just as many as you can in one syscall. The userdata parameter is passed through directly to callback. Note that this is distinct from the userdata parameter set with rustls_connection_set_userdata. Returns 0 for success, or an errno value on error. Passes through return values from callback. See rustls_write_callback for more details. <https://docs.rs/rustls/0.20.0/rustls/enum.Connection.html#method.write_tls>

rustls_connection_write_tls_vectored
rustls_io_result rustls_connection_write_tls_vectored(rustls_connection* conn, rustls_write_vectored_callback callback, void* userdata, size_t* out_n)

Write all available TLS bytes to the network. The actual network I/O is performed by callback, which you provide. Rustls will invoke your callback with an array of rustls_slice_bytes, each containing a buffer with TLS bytes to send. You don't have to write them all, just as many as you are willing. The userdata parameter is passed through directly to callback. Note that this is distinct from the userdata parameter set with rustls_connection_set_userdata. Returns 0 for success, or an errno value on error. Passes through return values from callback. See rustls_write_callback for more details. <https://docs.rs/rustls/0.20.0/rustls/struct.Writer.html#method.write_vectored>

rustls_default_ciphersuites_get_entry
const(rustls_supported_ciphersuite)* rustls_default_ciphersuites_get_entry(size_t i)

Get a pointer to a member of rustls' list of supported cipher suites. This will return non-NULL for i < rustls_default_ciphersuites_len(). The returned pointer is valid for the lifetime of the program and may be used directly when building a ClientConfig or ServerConfig.

rustls_default_ciphersuites_len
size_t rustls_default_ciphersuites_len()

Return the length of rustls' list of default cipher suites.

rustls_error
void rustls_error(uint result, char* buf, size_t len, size_t* out_n)

After a rustls function returns an error, you may call this to get a pointer to a buffer containing a detailed error message. The contents of the error buffer will be out_n bytes long, UTF-8 encoded, and not NUL-terminated.

rustls_log_level_str
rustls_str rustls_log_level_str(rustls_log_level level)

Return a rustls_str containing the stringified version of a log level.

rustls_result_is_cert_error
bool rustls_result_is_cert_error(uint result)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
rustls_root_cert_store_add_pem
rustls_result rustls_root_cert_store_add_pem(rustls_root_cert_store* store, ubyte* pem, size_t pem_len, bool strict)

Add one or more certificates to the root cert store using PEM encoded data.

rustls_root_cert_store_free
void rustls_root_cert_store_free(rustls_root_cert_store* store)

Free a rustls_root_cert_store previously returned from rustls_root_cert_store_builder_build. Calling with NULL is fine. Must not be called twice with the same value.

rustls_root_cert_store_new
rustls_root_cert_store* rustls_root_cert_store_new()

Create a rustls_root_cert_store. Caller owns the memory and must eventually call rustls_root_cert_store_free. The store starts out empty. Caller must add root certificates with rustls_root_cert_store_add_pem. <https://docs.rs/rustls/0.20.0/rustls/struct.RootCertStore.html#method.empty>

rustls_server_config_builder_build
const(rustls_server_config)* rustls_server_config_builder_build(rustls_server_config_builder* builder)

Turn a *rustls_server_config_builder (mutable) into a const *rustls_server_config (read-only).

rustls_server_config_builder_free
void rustls_server_config_builder_free(rustls_server_config_builder* config)

"Free" a server_config_builder without building it into a rustls_server_config. Normally builders are built into rustls_server_configs via rustls_server_config_builder_build and may not be free'd or otherwise used afterwards. Use free only when the building of a config has to be aborted before a config was created.

rustls_server_config_builder_new
rustls_server_config_builder* rustls_server_config_builder_new()

Create a rustls_server_config_builder. Caller owns the memory and must eventually call rustls_server_config_builder_build, then free the resulting rustls_server_config. This uses rustls safe default values for the cipher suites, key exchange groups and protocol versions.

rustls_server_config_builder_new_custom
rustls_result rustls_server_config_builder_new_custom(rustls_supported_ciphersuite** cipher_suites, size_t cipher_suites_len, ushort* tls_versions, size_t tls_versions_len, rustls_server_config_builder** builder_out)

Create a rustls_server_config_builder. Caller owns the memory and must eventually call rustls_server_config_builder_build, then free the resulting rustls_server_config. Specify cipher suites in preference order; the cipher_suites parameter must point to an array containing len pointers to rustls_supported_ciphersuite previously obtained from rustls_all_ciphersuites_get_entry(). Set the TLS protocol versions to use when negotiating a TLS session.

rustls_server_config_builder_set_alpn_protocols
rustls_result rustls_server_config_builder_set_alpn_protocols(rustls_server_config_builder* builder, rustls_slice_bytes* protocols, size_t len)

Set the ALPN protocol list to the given protocols. protocols must point to a buffer of rustls_slice_bytes (built by the caller) with len elements. Each element of the buffer must point to a slice of bytes that contains a single ALPN protocol from <https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids>.

rustls_server_config_builder_set_certified_keys
rustls_result rustls_server_config_builder_set_certified_keys(rustls_server_config_builder* builder, rustls_certified_key** certified_keys, size_t certified_keys_len)

Provide the configuration a list of certificates where the connection will select the first one that is compatible with the client's signature verification capabilities. Servers that want to support both ECDSA and RSA certificates will want the ECSDA to go first in the list.

rustls_server_config_builder_set_client_verifier
void rustls_server_config_builder_set_client_verifier(rustls_server_config_builder* builder, rustls_client_cert_verifier* verifier)

Create a rustls_server_config_builder for TLS sessions that require valid client certificates. The passed rustls_client_cert_verifier may be used in several builders. For memory lifetime, see rustls_server_config_builder_new.

rustls_server_config_builder_set_client_verifier_optional
void rustls_server_config_builder_set_client_verifier_optional(rustls_server_config_builder* builder, rustls_client_cert_verifier_optional* verifier)

Create a rustls_server_config_builder for TLS sessions that accept valid client certificates, but do not require them. The passed rustls_client_cert_verifier_optional may be used in several builders. For memory lifetime, see rustls_server_config_builder_new.

rustls_server_config_builder_set_hello_callback
rustls_result rustls_server_config_builder_set_hello_callback(rustls_server_config_builder* builder, rustls_client_hello_callback callback)

Register a callback to be invoked when a connection created from this config sees a TLS ClientHello message. If userdata has been set with rustls_connection_set_userdata, it will be passed to the callback. Otherwise the userdata param passed to the callback will be NULL.

rustls_server_config_builder_set_ignore_client_order
rustls_result rustls_server_config_builder_set_ignore_client_order(rustls_server_config_builder* builder, bool ignore)

With ignore != 0, the server will ignore the client ordering of cipher suites, aka preference, during handshake and respect its own ordering as configured. <https://docs.rs/rustls/0.20.0/rustls/struct.ServerConfig.html#structfield.ignore_client_order>

rustls_server_config_builder_set_persistence
rustls_result rustls_server_config_builder_set_persistence(rustls_server_config_builder* builder, rustls_session_store_get_callback get_cb, rustls_session_store_put_callback put_cb)

Register callbacks for persistence of TLS session IDs and secrets. Both keys and values are highly sensitive data, containing enough information to break the security of the connections involved.

rustls_server_config_free
void rustls_server_config_free(rustls_server_config* config)

"Free" a rustls_server_config previously returned from rustls_server_config_builder_build. Since rustls_server_config is actually an atomically reference-counted pointer, extant server connections may still hold an internal reference to the Rust object. However, C code must consider this pointer unusable after "free"ing it. Calling with NULL is fine. Must not be called twice with the same value.

rustls_server_connection_get_sni_hostname
rustls_result rustls_server_connection_get_sni_hostname(rustls_connection* conn, ubyte* buf, size_t count, size_t* out_n)

Copy the SNI hostname to buf which can hold up to count bytes, and the length of that hostname in out_n. The string is stored in UTF-8 with no terminating NUL byte. Returns RUSTLS_RESULT_INSUFFICIENT_SIZE if the SNI hostname is longer than count. Returns Ok with *out_n == 0 if there is no SNI hostname available on this connection because it hasn't been processed yet, or because the client did not send SNI. <https://docs.rs/rustls/0.20.0/rustls/server/struct.ServerConnection.html#method.sni_hostname>

rustls_server_connection_new
rustls_result rustls_server_connection_new(rustls_server_config* config, rustls_connection** conn_out)

Create a new rustls_connection containing a server connection, and return it in the output parameter out. If this returns an error code, the memory pointed to by conn_out remains unchanged. If this returns a non-error, the memory pointed to by conn_out is modified to point at a valid rustls_connection. The caller now owns the rustls_connection and must call rustls_connection_free when done with it.

rustls_slice_slice_bytes_get
rustls_slice_bytes rustls_slice_slice_bytes_get(rustls_slice_slice_bytes* input, size_t n)

Retrieve the nth element from the input slice of slices. If the input pointer is NULL, or n is greater than the length of the rustls_slice_slice_bytes, returns rustls_slice_bytes{NULL, 0}.

rustls_slice_slice_bytes_len
size_t rustls_slice_slice_bytes_len(rustls_slice_slice_bytes* input)

Return the length of the outer slice. If the input pointer is NULL, returns 0.

rustls_slice_str_get
rustls_str rustls_slice_str_get(rustls_slice_str* input, size_t n)

Retrieve the nth element from the input slice of &strs. If the input pointer is NULL, or n is greater than the length of the rustls_slice_str, returns rustls_str{NULL, 0}.

rustls_slice_str_len
size_t rustls_slice_str_len(rustls_slice_str* input)

Return the length of the outer slice. If the input pointer is NULL, returns 0.

rustls_supported_ciphersuite_get_name
rustls_str rustls_supported_ciphersuite_get_name(rustls_supported_ciphersuite* supported_ciphersuite)

Returns the name of the ciphersuite as a rustls_str. If the provided ciphersuite is invalid, the rustls_str will contain the empty string. The lifetime of the rustls_str is the lifetime of the program, it does not need to be freed.

rustls_supported_ciphersuite_get_suite
ushort rustls_supported_ciphersuite_get_suite(rustls_supported_ciphersuite* supported_ciphersuite)

Return a 16-bit unsigned integer corresponding to this cipher suite's assignment from <https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4>. The bytes from the assignment are interpreted in network order.

rustls_version
rustls_str rustls_version()

Returns a static string containing the rustls-ffi version as well as the rustls version. The string is alive for the lifetime of the program and does not need to be freed.

Structs

rustls_certificate
struct rustls_certificate

An X.509 certificate, as used in rustls. Corresponds to Certificate in the Rust API. <https://docs.rs/rustls/0.20.0/rustls/struct.Certificate.html>

rustls_certified_key
struct rustls_certified_key

The complete chain of certificates to send during a TLS handshake, plus a private key that matches the end-entity (leaf) certificate. Corresponds to CertifiedKey in the Rust API. <https://docs.rs/rustls/0.20.0/rustls/sign/struct.CertifiedKey.html>

rustls_client_cert_verifier
struct rustls_client_cert_verifier

A verifier of client certificates that requires all certificates to be trusted based on a given rustls_root_cert_store. Usable in building server configurations. Connections without such a client certificate will not be accepted.

rustls_client_cert_verifier_optional
struct rustls_client_cert_verifier_optional

Alternative to rustls_client_cert_verifier that allows connections with or without a client certificate. If the client offers a certificate, it will be verified (and rejected if it is not valid). If the client does not offer a certificate, the connection will succeed.

rustls_client_config
struct rustls_client_config

A client config that is done being constructed and is now read-only. Under the hood, this object corresponds to an Arc<ClientConfig>. <https://docs.rs/rustls/0.20.0/rustls/struct.ClientConfig.html>

rustls_client_config_builder
struct rustls_client_config_builder

A client config being constructed. A builder can be modified by, e.g. rustls_client_config_builder_load_roots_from_file. Once you're done configuring settings, call rustls_client_config_builder_build to turn it into a *rustls_client_config. This object is not safe for concurrent mutation. Under the hood, it corresponds to a Box<ClientConfig>. <https://docs.rs/rustls/0.20.0/rustls/struct.ConfigBuilder.html>

rustls_client_hello
struct rustls_client_hello

The TLS Client Hello information provided to a ClientHelloCallback function. sni_name is the SNI servername provided by the client. If the client did not provide an SNI, the length of this rustls_string will be 0. The signature_schemes carries the values supplied by the client or, should the client not use this TLS extension, the default schemes in the rustls library. See: <https://docs.rs/rustls/0.20.0/rustls/internal/msgs/enums/enum.SignatureScheme.html>. alpn carries the list of ALPN protocol names that the client proposed to the server. Again, the length of this list will be 0 if none were supplied.

rustls_connection
struct rustls_connection
Undocumented in source.
rustls_iovec
struct rustls_iovec

An alias for struct iovec from uio.h (on Unix) or WSABUF on Windows. You should cast const struct rustls_iovec * to const struct iovec * on Unix, or const *LPWSABUF on Windows. See [std::io::IoSlice] for details on interoperability with platform specific vectored IO.

rustls_log_params
struct rustls_log_params
Undocumented in source.
rustls_root_cert_store
struct rustls_root_cert_store

A root certificate store. <https://docs.rs/rustls/0.20.0/rustls/struct.RootCertStore.html>

rustls_server_config
struct rustls_server_config

A server config that is done being constructed and is now read-only. Under the hood, this object corresponds to an Arc<ServerConfig>. <https://docs.rs/rustls/0.20.0/rustls/struct.ServerConfig.html>

rustls_server_config_builder
struct rustls_server_config_builder

A server config being constructed. A builder can be modified by, e.g. rustls_server_config_builder_load_native_roots. Once you're done configuring settings, call rustls_server_config_builder_build to turn it into a *const rustls_server_config. This object is not safe for concurrent mutation. <https://docs.rs/rustls/0.20.0/rustls/struct.ConfigBuilder.html>

rustls_slice_bytes
struct rustls_slice_bytes

A read-only view on a Rust byte slice.

rustls_slice_slice_bytes
struct rustls_slice_slice_bytes

A read-only view of a slice of Rust byte slices.

rustls_slice_str
struct rustls_slice_str

A read-only view of a slice of multiple Rust &str's (that is, multiple strings). Like rustls_str, this guarantees that each string contains UTF-8 and no NUL bytes. Strings are not NUL-terminated.

rustls_slice_u16
struct rustls_slice_u16

A read-only view on a Rust slice of 16-bit integers in platform endianness.

rustls_str
struct rustls_str

A read-only view on a Rust &str. The contents are guaranteed to be valid UTF-8. As an additional guarantee on top of Rust's normal UTF-8 guarantee, a rustls_str is guaranteed not to contain internal NUL bytes, so it is safe to interpolate into a C string or compare using strncmp. Keep in mind that it is not NUL-terminated.

rustls_supported_ciphersuite
struct rustls_supported_ciphersuite

A cipher suite supported by rustls.

rustls_verify_server_cert_params
struct rustls_verify_server_cert_params

Input to a custom certificate verifier callback. See rustls_client_config_builder_dangerous_set_certificate_verifier().

Variables

RUSTLS_ALL_CIPHER_SUITES
rustls_supported_ciphersuite[9]* RUSTLS_ALL_CIPHER_SUITES;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
RUSTLS_ALL_CIPHER_SUITES_LEN
size_t RUSTLS_ALL_CIPHER_SUITES_LEN;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
RUSTLS_ALL_VERSIONS
ushort[2] RUSTLS_ALL_VERSIONS;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
RUSTLS_ALL_VERSIONS_LEN
size_t RUSTLS_ALL_VERSIONS_LEN;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
RUSTLS_DEFAULT_CIPHER_SUITES
rustls_supported_ciphersuite[9]* RUSTLS_DEFAULT_CIPHER_SUITES;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
RUSTLS_DEFAULT_CIPHER_SUITES_LEN
size_t RUSTLS_DEFAULT_CIPHER_SUITES_LEN;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
RUSTLS_DEFAULT_VERSIONS
ushort[2] RUSTLS_DEFAULT_VERSIONS;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
RUSTLS_DEFAULT_VERSIONS_LEN
size_t RUSTLS_DEFAULT_VERSIONS_LEN;
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Meta