/* automatically generated by rust-bindgen 0.58.1 */
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#![allow(unused_imports, non_camel_case_types)]
use libc::{iovec, FILE};
extern "C" {
#[doc = " This function can be used instead of trying to resolve `s2n_errno` directly"]
#[doc = " in runtimes where thread-local variables may not be easily accessible."]
#[doc = ""]
#[doc = " @returns The address of the thread-local `s2n_errno` variable"]
pub fn s2n_errno_location() -> *mut ::libc::c_int;
}
pub mod s2n_error_type {
#[doc = " Used to help applications determine why an s2n-tls function failed."]
#[doc = ""]
#[doc = " This enum is optimized for use in C switch statements. Each value in the enum represents"]
#[doc = " an error \"category\"."]
#[doc = ""]
#[doc = " s2n-tls organizes errors into different \"types\" to allow applications to handle error"]
#[doc = " values without catching all possibilities. Applications using non-blocking I/O should check"]
#[doc = " the error type to determine if the I/O operation failed because it would block or for some other"]
#[doc = " error. To retrieve the type for a given error use `s2n_error_get_type()`. Applications should"]
#[doc = " perform any error handling logic using these high level types."]
#[doc = ""]
#[doc = " See the [Error Handling](https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md#error-handling) section for how the errors should be interpreted."]
pub type Type = ::libc::c_uint;
#[doc = " No error"]
pub const OK: Type = 0;
#[doc = " Underlying I/O operation failed, check system errno"]
pub const IO: Type = 1;
#[doc = " EOF"]
pub const CLOSED: Type = 2;
#[doc = " Underlying I/O operation would block"]
pub const BLOCKED: Type = 3;
#[doc = " Incoming Alert"]
pub const ALERT: Type = 4;
#[doc = " Failure in some part of the TLS protocol. Ex: CBC verification failure"]
pub const PROTO: Type = 5;
#[doc = " Error internal to s2n-tls. A precondition could have failed."]
pub const INTERNAL: Type = 6;
#[doc = " User input error. Ex: Providing an invalid cipher preference version"]
pub const USAGE: Type = 7;
}
extern "C" {
#[doc = " Gets the category of error from an error."]
#[doc = ""]
#[doc = " s2n-tls organizes errors into different \"types\" to allow applications to do logic on error values without catching all possibilities."]
#[doc = " Applications using non-blocking I/O should check error type to determine if the I/O operation failed because"]
#[doc = " it would block or for some other error."]
#[doc = ""]
#[doc = " @param error The error from s2n. Usually this is `s2n_errno`."]
#[doc = " @returns An s2n_error_type"]
pub fn s2n_error_get_type(error: ::libc::c_int) -> ::libc::c_int;
}
#[doc = " An opaque configuration object, used by clients and servers for holding cryptographic certificates, keys and preferences."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_config {
_unused: [u8; 0],
}
#[doc = " An opaque connection. Used to track each s2n connection."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_connection {
_unused: [u8; 0],
}
extern "C" {
#[doc = " Prevents S2N from calling `OPENSSL_crypto_init`/`OPENSSL_cleanup`/`EVP_cleanup` on OpenSSL versions"]
#[doc = " prior to 1.1.x. This allows applications or languages that also init OpenSSL to interoperate"]
#[doc = " with S2N."]
#[doc = ""]
#[doc = " @warning This function must be called BEFORE s2n_init() to have any effect. It will return an error"]
#[doc = " if s2n is already initialized."]
#[doc = ""]
#[doc = " @note If you disable this and are using a version of OpenSSL/libcrypto < 1.1.x, you will"]
#[doc = " be responsible for library init and cleanup (specifically `OPENSSL_add_all_algorithms()`"]
#[doc = " or `OPENSSL_crypto_init()`, and EVP_* APIs will not be usable unless the library is initialized."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_crypto_disable_init() -> ::libc::c_int;
}
extern "C" {
#[doc = " Prevents S2N from installing an atexit handler, which allows safe shutdown of S2N from within a"]
#[doc = " re-entrant shared library"]
#[doc = ""]
#[doc = " @warning This function must be called BEFORE s2n_init() to have any effect. It will return an error"]
#[doc = " if s2n is already initialized."]
#[doc = ""]
#[doc = " @note This will cause `s2n_cleanup` to do complete cleanup of s2n-tls when called from the main"]
#[doc = " thread (the thread `s2n_init` was called from)."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_disable_atexit() -> ::libc::c_int;
}
extern "C" {
#[doc = " Fetches the OpenSSL version s2n-tls was compiled with. This can be used by applications to validate at runtime"]
#[doc = " that the versions of s2n-tls and Openssl that they have loaded are correct."]
#[doc = ""]
#[doc = " @returns the version number of OpenSSL that s2n-tls was compiled with"]
pub fn s2n_get_openssl_version() -> ::libc::c_ulong;
}
extern "C" {
#[doc = " Initializes the s2n-tls library and should be called once in your application, before any other s2n-tls"]
#[doc = " functions are called. Failure to call s2n_init() will result in errors from other s2n-tls functions."]
#[doc = ""]
#[doc = " @warning This function is not thread safe and should only be called once."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_init() -> ::libc::c_int;
}
extern "C" {
#[doc = " Cleans up any internal resources used by s2n-tls. This function should be called from each thread or process"]
#[doc = " that is created subsequent to calling `s2n_init` when that thread or process is done calling other s2n-tls functions."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cleanup() -> ::libc::c_int;
}
extern "C" {
#[doc = " Create a new s2n_config object. This object can (and should) be associated with many connection objects."]
#[doc = ""]
#[doc = " @returns returns a new configuration object suitable for associating certs and keys."]
pub fn s2n_config_new() -> *mut s2n_config;
}
extern "C" {
#[doc = " Frees the memory associated with an `s2n_config` object."]
#[doc = ""]
#[doc = " @param config The configuration object being freed"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_free(config: *mut s2n_config) -> ::libc::c_int;
}
extern "C" {
#[doc = " Frees the DH params associated with an `s2n_config` object."]
#[doc = ""]
#[doc = " @param config The configuration object with DH params being freed"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_free_dhparams(config: *mut s2n_config) -> ::libc::c_int;
}
extern "C" {
#[doc = " Frees the certificate chain and key associated with an `s2n_config` object."]
#[doc = ""]
#[doc = " @param config The configuration object with DH params being freed"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_free_cert_chain_and_key(config: *mut s2n_config) -> ::libc::c_int;
}
#[doc = " Callback function type used to get the system time."]
#[doc = ""]
#[doc = " @param void* A pointer to arbitrary data for use within the callback"]
#[doc = " @param uint64_t* A pointer that the callback will set to the time in nanoseconds"]
#[doc = " The function should return 0 on success and -1 on failure."]
pub type s2n_clock_time_nanoseconds = ::core::option::Option<
unsafe extern "C" fn(arg1: *mut ::libc::c_void, arg2: *mut u64) -> ::libc::c_int,
>;
#[doc = " Cache callback function that allows the caller to retrieve SSL session data"]
#[doc = " from a cache."]
#[doc = ""]
#[doc = " The callback function takes six arguments:"]
#[doc = " a pointer to the s2n_connection object,"]
#[doc = " a pointer to arbitrary data for use within the callback,"]
#[doc = " a pointer to a key which can be used to retrieve the cached entry,"]
#[doc = " a 64 bit unsigned integer specifying the size of this key,"]
#[doc = " a pointer to a memory location where the value should be stored,"]
#[doc = " and a pointer to a 64 bit unsigned integer specifying the size of this value."]
#[doc = ""]
#[doc = " Initially *value_size will be set to the amount of space allocated for the value,"]
#[doc = " the callback should set *value_size to the actual size of the data returned."]
#[doc = " If there is insufficient space, -1 should be returned."]
#[doc = " If the cache is not ready to provide data for the request,"]
#[doc = " S2N_CALLBACK_BLOCKED should be returned."]
#[doc = ""]
#[doc = " This will cause s2n_negotiate() to return S2N_BLOCKED_ON_APPLICATION_INPUT."]
pub type s2n_cache_retrieve_callback = ::core::option::Option<
unsafe extern "C" fn(
conn: *mut s2n_connection,
arg1: *mut ::libc::c_void,
key: *const ::libc::c_void,
key_size: u64,
value: *mut ::libc::c_void,
value_size: *mut u64,
) -> ::libc::c_int,
>;
#[doc = " Cache callback function that allows the caller to store SSL session data in a"]
#[doc = " cache."]
#[doc = ""]
#[doc = " The callback function takes seven arguments:"]
#[doc = " a pointer to the s2n_connection object,"]
#[doc = " a pointer to arbitrary data for use within the callback,"]
#[doc = " a 64-bit unsigned integer specifying the number of seconds the session data may be stored for,"]
#[doc = " a pointer to a key which can be used to retrieve the cached entry,"]
#[doc = " a 64 bit unsigned integer specifying the size of this key,"]
#[doc = " a pointer to a value which should be stored,"]
#[doc = " and a 64 bit unsigned integer specified the size of this value."]
pub type s2n_cache_store_callback = ::core::option::Option<
unsafe extern "C" fn(
conn: *mut s2n_connection,
arg1: *mut ::libc::c_void,
ttl_in_seconds: u64,
key: *const ::libc::c_void,
key_size: u64,
value: *const ::libc::c_void,
value_size: u64,
) -> ::libc::c_int,
>;
#[doc = " Cache callback function that allows the caller to set a callback function"]
#[doc = " that will be used to delete SSL session data from a cache."]
#[doc = ""]
#[doc = " The callback function takes four arguments:"]
#[doc = " a pointer to s2n_connection object,"]
#[doc = " a pointer to arbitrary data for use within the callback,"]
#[doc = " a pointer to a key which can be used to delete the cached entry,"]
#[doc = " and a 64 bit unsigned integer specifying the size of this key."]
pub type s2n_cache_delete_callback = ::core::option::Option<
unsafe extern "C" fn(
conn: *mut s2n_connection,
arg1: *mut ::libc::c_void,
key: *const ::libc::c_void,
key_size: u64,
) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Allows the caller to set a callback function that will be used to get the"]
#[doc = " system time. The time returned should be the number of nanoseconds since the"]
#[doc = " Unix epoch (Midnight, January 1st, 1970)."]
#[doc = ""]
#[doc = " s2n-tls uses this clock for timestamps."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param clock_fn The wall clock time callback function"]
#[doc = " @param ctx An opaque pointer that the callback will be invoked with"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_wall_clock(
config: *mut s2n_config,
clock_fn: s2n_clock_time_nanoseconds,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Allows the caller to set a callback function that will be used to get"]
#[doc = " monotonic time. The monotonic time is the time since an arbitrary, unspecified"]
#[doc = " point. Unlike wall clock time, it MUST never move backwards."]
#[doc = ""]
#[doc = " s2n-tls uses this clock for timers."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param clock_fn The monotonic time callback function"]
#[doc = " @param ctx An opaque pointer that the callback will be invoked with"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_monotonic_clock(
config: *mut s2n_config,
clock_fn: s2n_clock_time_nanoseconds,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Translates an s2n_error code to a human readable string explaining the error."]
#[doc = ""]
#[doc = " @param error The error code to explain. Usually this is s2n_errno"]
#[doc = " @param lang The language to explain the error code. Pass \"EN\" or NULL for English."]
#[doc = " @returns The error string"]
pub fn s2n_strerror(error: ::libc::c_int, lang: *const ::libc::c_char)
-> *const ::libc::c_char;
}
extern "C" {
#[doc = " Translates an s2n_error code to a human readable string containing internal debug"]
#[doc = " information, including file name and line number. This function is useful when"]
#[doc = " reporting issues to the s2n-tls development team."]
#[doc = ""]
#[doc = " @param error The error code to explain. Usually this is s2n_errno"]
#[doc = " @param lang The language to explain the error code. Pass \"EN\" or NULL for English."]
#[doc = " @returns The error string"]
pub fn s2n_strerror_debug(
error: ::libc::c_int,
lang: *const ::libc::c_char,
) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Translates an s2n_error code to a human readable string."]
#[doc = ""]
#[doc = " @param error The error code to explain. Usually this is s2n_errno"]
#[doc = " @returns The error string"]
pub fn s2n_strerror_name(error: ::libc::c_int) -> *const ::libc::c_char;
}
#[doc = " Opaque stack trace structure."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_stacktrace {
_unused: [u8; 0],
}
extern "C" {
#[doc = " Checks if s2n stack trace captures are enabled."]
#[doc = ""]
#[doc = " @returns True if stack traces are enabled. False if they are disabled."]
pub fn s2n_stack_traces_enabled() -> bool;
}
extern "C" {
#[doc = " Configures the s2n stack trace captures option."]
#[doc = ""]
#[doc = " @param newval Boolean to determine if stack traces should be enabled. True to enable them. False to disable them."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_stack_traces_enabled_set(newval: bool) -> ::libc::c_int;
}
extern "C" {
#[doc = " Calculates the s2n stack trace."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_calculate_stacktrace() -> ::libc::c_int;
}
extern "C" {
#[doc = " Prints the s2n stack trace to a file. The file descriptor is expected to be"]
#[doc = " open and ready for writing."]
#[doc = ""]
#[doc = " @param fptr A pointer to the file s2n-tls should write the stack trace to."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_print_stacktrace(fptr: *mut FILE) -> ::libc::c_int;
}
extern "C" {
#[doc = " Clean up the memory used to contain the stack trace."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_free_stacktrace() -> ::libc::c_int;
}
extern "C" {
#[doc = " Export the s2n_stacktrace."]
#[doc = ""]
#[doc = " @param trace A pointer to the s2n_stacktrace to fill."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_get_stacktrace(trace: *mut s2n_stacktrace) -> ::libc::c_int;
}
extern "C" {
#[doc = " Allows the caller to set a callback function that will be used to store SSL"]
#[doc = " session data in a cache."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cache_store_callback The cache store callback function."]
#[doc = " @param data An opaque context pointer that the callback will be invoked with."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_cache_store_callback(
config: *mut s2n_config,
cache_store_callback: s2n_cache_store_callback,
data: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Allows the caller to set a callback function that will be used to retrieve SSL"]
#[doc = " session data from a cache."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cache_retrieve_callback The cache retrieve callback function."]
#[doc = " @param data An opaque context pointer that the callback will be invoked with."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_cache_retrieve_callback(
config: *mut s2n_config,
cache_retrieve_callback: s2n_cache_retrieve_callback,
data: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Allows the caller to set a callback function that will be used to delete SSL"]
#[doc = " session data from a cache."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cache_delete_callback The cache delete callback function."]
#[doc = " @param data An opaque context pointer that the callback will be invoked with."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_cache_delete_callback(
config: *mut s2n_config,
cache_delete_callback: s2n_cache_delete_callback,
data: *mut ::libc::c_void,
) -> ::libc::c_int;
}
#[doc = " Called when `s2n_init` is executed."]
pub type s2n_mem_init_callback = ::core::option::Option<unsafe extern "C" fn() -> ::libc::c_int>;
#[doc = " Will be called when `s2n_cleanup` is executed."]
pub type s2n_mem_cleanup_callback = ::core::option::Option<unsafe extern "C" fn() -> ::libc::c_int>;
#[doc = " A function that can allocate at least `requested` bytes of memory."]
#[doc = ""]
#[doc = " It stores the location of that memory in **\\*ptr** and the size of the allocated"]
#[doc = " data in **\\*allocated**. The function may choose to allocate more memory"]
#[doc = " than was requested. s2n-tls will consider all allocated memory available for"]
#[doc = " use, and will attempt to free all allocated memory when able."]
pub type s2n_mem_malloc_callback = ::core::option::Option<
unsafe extern "C" fn(
ptr: *mut *mut ::libc::c_void,
requested: u32,
allocated: *mut u32,
) -> ::libc::c_int,
>;
#[doc = " Frees memory allocated by s2n_mem_malloc_callback."]
pub type s2n_mem_free_callback = ::core::option::Option<
unsafe extern "C" fn(ptr: *mut ::libc::c_void, size: u32) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Allows the caller to override s2n-tls's internal memory handling functions."]
#[doc = ""]
#[doc = " @warning This function must be called before s2n_init()."]
#[doc = ""]
#[doc = " @param mem_init_callback The s2n_mem_init_callback"]
#[doc = " @param mem_cleanup_callback The s2n_mem_cleanup_callback"]
#[doc = " @param mem_malloc_callback The s2n_mem_malloc_callback"]
#[doc = " @param mem_free_callback The s2n_mem_free_callback"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_mem_set_callbacks(
mem_init_callback: s2n_mem_init_callback,
mem_cleanup_callback: s2n_mem_cleanup_callback,
mem_malloc_callback: s2n_mem_malloc_callback,
mem_free_callback: s2n_mem_free_callback,
) -> ::libc::c_int;
}
#[doc = " A callback function that will be called when s2n-tls is initialized."]
pub type s2n_rand_init_callback = ::core::option::Option<unsafe extern "C" fn() -> ::libc::c_int>;
#[doc = " A callback function that will be called when `s2n_cleanup` is executed."]
pub type s2n_rand_cleanup_callback =
::core::option::Option<unsafe extern "C" fn() -> ::libc::c_int>;
#[doc = " A callback function that will be used to provide entropy to the s2n-tls"]
#[doc = " random number generators."]
pub type s2n_rand_seed_callback = ::core::option::Option<
unsafe extern "C" fn(data: *mut ::libc::c_void, size: u32) -> ::libc::c_int,
>;
#[doc = " A callback function that will be used to mix in entropy every time the RNG"]
#[doc = " is invoked."]
pub type s2n_rand_mix_callback = ::core::option::Option<
unsafe extern "C" fn(data: *mut ::libc::c_void, size: u32) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Allows the caller to override s2n-tls's entropy functions."]
#[doc = ""]
#[doc = " @warning This function must be called before s2n_init()."]
#[doc = ""]
#[doc = " @param rand_init_callback The s2n_rand_init_callback"]
#[doc = " @param rand_cleanup_callback The s2n_rand_cleanup_callback"]
#[doc = " @param rand_seed_callback The s2n_rand_seed_callback"]
#[doc = " @param rand_mix_callback The s2n_rand_mix_callback"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_rand_set_callbacks(
rand_init_callback: s2n_rand_init_callback,
rand_cleanup_callback: s2n_rand_cleanup_callback,
rand_seed_callback: s2n_rand_seed_callback,
rand_mix_callback: s2n_rand_mix_callback,
) -> ::libc::c_int;
}
pub mod s2n_tls_extension_type {
#[doc = " TLS extensions supported by s2n-tls"]
pub type Type = ::libc::c_uint;
pub const SERVER_NAME: Type = 0;
pub const MAX_FRAG_LEN: Type = 1;
pub const OCSP_STAPLING: Type = 5;
pub const SUPPORTED_GROUPS: Type = 10;
pub const EC_POINT_FORMATS: Type = 11;
pub const SIGNATURE_ALGORITHMS: Type = 13;
pub const ALPN: Type = 16;
pub const CERTIFICATE_TRANSPARENCY: Type = 18;
pub const RENEGOTIATION_INFO: Type = 65281;
}
pub mod s2n_max_frag_len {
#[doc = " MFL configurations from https://datatracker.ietf.org/doc/html/rfc6066#section-4."]
pub type Type = ::libc::c_uint;
pub const LEN_512: Type = 1;
pub const LEN_1024: Type = 2;
pub const LEN_2048: Type = 3;
pub const LEN_4096: Type = 4;
}
#[doc = " Opaque certificate type."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_cert {
_unused: [u8; 0],
}
#[doc = " Opaque certificate chain and key type."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_cert_chain_and_key {
_unused: [u8; 0],
}
#[doc = " Opaque key type."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_pkey {
_unused: [u8; 0],
}
#[doc = " Opaque public key type."]
pub type s2n_cert_public_key = s2n_pkey;
#[doc = " Opaque private key type."]
pub type s2n_cert_private_key = s2n_pkey;
extern "C" {
#[doc = " Creates a new s2n_cert_chain_and_key object. This object can be associated"]
#[doc = " with many config objects. It is used to represent a certificate and key pair."]
#[doc = ""]
#[doc = " @returns A new object used to represent a certificate-chain/key pair"]
pub fn s2n_cert_chain_and_key_new() -> *mut s2n_cert_chain_and_key;
}
extern "C" {
#[doc = " Associates a certificate chain and private key with an `s2n_cert_chain_and_key` object."]
#[doc = ""]
#[doc = " `cert_chain_pem` should be a PEM encoded certificate chain, with the first"]
#[doc = " certificate in the chain being your leaf certificate. `private_key_pem`"]
#[doc = " should be a PEM encoded private key corresponding to the leaf certificate."]
#[doc = ""]
#[doc = " @note Prefer using s2n_cert_chain_and_key_load_pem_bytes."]
#[doc = ""]
#[doc = " @param chain_and_key The certificate chain and private key handle"]
#[doc = " @param chain_pem A byte array of a PEM encoded certificate chain."]
#[doc = " @param private_key_pem A byte array of a PEM encoded key."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cert_chain_and_key_load_pem(
chain_and_key: *mut s2n_cert_chain_and_key,
chain_pem: *const ::libc::c_char,
private_key_pem: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Associates a certificate chain and private key with an `s2n_cert_chain_and_key` object."]
#[doc = ""]
#[doc = " `cert_chain_pem` should be a PEM encoded certificate chain, with the first"]
#[doc = " certificate in the chain being your leaf certificate. `private_key_pem`"]
#[doc = " should be a PEM encoded private key corresponding to the leaf certificate."]
#[doc = ""]
#[doc = " @param chain_and_key The certificate chain and private key handle"]
#[doc = " @param chain_pem A byte array of a PEM encoded certificate chain."]
#[doc = " @param chain_pem_len Size of `chain_pem`"]
#[doc = " @param private_key_pem A byte array of a PEM encoded key."]
#[doc = " @param private_key_pem_len Size of `private_key_pem`"]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cert_chain_and_key_load_pem_bytes(
chain_and_key: *mut s2n_cert_chain_and_key,
chain_pem: *mut u8,
chain_pem_len: u32,
private_key_pem: *mut u8,
private_key_pem_len: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Associates a public certificate chain with a `s2n_cert_chain_and_key` object. It does"]
#[doc = " NOT set a private key, so the connection will need to be configured to"]
#[doc = " [offload private key operations](https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md#offloading-asynchronous-private-key-operations)."]
#[doc = ""]
#[doc = " @param chain_and_key The certificate chain and private key handle"]
#[doc = " @param chain_pem A byte array of a PEM encoded certificate chain."]
#[doc = " @param chain_pem_len Size of `chain_pem`"]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cert_chain_and_key_load_public_pem_bytes(
chain_and_key: *mut s2n_cert_chain_and_key,
chain_pem: *mut u8,
chain_pem_len: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Frees the memory associated with an `s2n_cert_chain_and_key` object."]
#[doc = ""]
#[doc = " @param cert_and_key The certificate chain and private key handle"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cert_chain_and_key_free(cert_and_key: *mut s2n_cert_chain_and_key) -> ::libc::c_int;
}
extern "C" {
#[doc = " Adds a context to the `s2n_cert_chain_and_key` object."]
#[doc = ""]
#[doc = " @param cert_and_key The certificate chain and private key handle"]
#[doc = " @param ctx An opaque pointer to user supplied data."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cert_chain_and_key_set_ctx(
cert_and_key: *mut s2n_cert_chain_and_key,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the user supplied context from the `s2n_cert_chain_and_key` object."]
#[doc = ""]
#[doc = " @param cert_and_key The certificate chain and private key handle"]
#[doc = " @returns The user supplied pointer from s2n_cert_chain_and_key_set_ctx()"]
pub fn s2n_cert_chain_and_key_get_ctx(
cert_and_key: *mut s2n_cert_chain_and_key,
) -> *mut ::libc::c_void;
}
extern "C" {
#[doc = " Get the private key from the `s2n_cert_chain_and_key` object."]
#[doc = ""]
#[doc = " @param cert_and_key The certificate chain and private key handle"]
#[doc = " @returns A pointer to the `s2n_cert_private_key`"]
pub fn s2n_cert_chain_and_key_get_private_key(
cert_and_key: *mut s2n_cert_chain_and_key,
) -> *mut s2n_cert_private_key;
}
extern "C" {
#[doc = " Set the raw OCSP stapling data for a certificate chain."]
#[doc = ""]
#[doc = " @param chain_and_key The certificate chain handle"]
#[doc = " @param data A pointer to the raw OCSP stapling data bytes. The data will be copied."]
#[doc = " @param length The length of the data bytes."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cert_chain_and_key_set_ocsp_data(
chain_and_key: *mut s2n_cert_chain_and_key,
data: *const u8,
length: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Set the signed certificate timestamp (SCT) for a certificate chain."]
#[doc = " This is used for Certificate Transparency."]
#[doc = ""]
#[doc = " @param chain_and_key The certificate chain handle"]
#[doc = " @param data A pointer to the SCT data. The data will be copied."]
#[doc = " @param length The length of the data bytes."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_cert_chain_and_key_set_sct_list(
chain_and_key: *mut s2n_cert_chain_and_key,
data: *const u8,
length: u32,
) -> ::libc::c_int;
}
#[doc = " A callback function that is invoked if s2n-tls cannot resolve a conflict between"]
#[doc = " two certificates with the same domain name. This function is invoked while certificates"]
#[doc = " are added to an `s2n_config`."]
#[doc = ""]
#[doc = " Currently, the only builtin resolution for domain name conflicts is certificate type(RSA,"]
#[doc = " ECDSA, etc). The callback should return a pointer to the `s2n_cert_chain_and_key` that"]
#[doc = " should be used for dns name `name`."]
#[doc = ""]
#[doc = " If NULL is returned, the first certificate will be used. Typically an application"]
#[doc = " will use properties like trust and expiry to implement tiebreaking."]
pub type s2n_cert_tiebreak_callback = ::core::option::Option<
unsafe extern "C" fn(
cert1: *mut s2n_cert_chain_and_key,
cert2: *mut s2n_cert_chain_and_key,
name: *mut u8,
name_len: u32,
) -> *mut s2n_cert_chain_and_key,
>;
extern "C" {
#[doc = " Sets the `s2n_cert_tiebreak_callback` for resolving domain name conflicts."]
#[doc = " If no callback is set, the first certificate added for a domain name will always be preferred."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cert_tiebreak_cb The pointer to the certificate tiebreak function"]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_cert_tiebreak_callback(
config: *mut s2n_config,
cert_tiebreak_cb: s2n_cert_tiebreak_callback,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Associates a certificate chain and private key with an `s2n_config` object."]
#[doc = " Using this API, only one cert chain of each type (like ECDSA or RSA) may be associated with a config."]
#[doc = " `cert_chain_pem` should be a PEM encoded certificate chain, with the first certificate"]
#[doc = " in the chain being your server's certificate. `private_key_pem` should be a"]
#[doc = " PEM encoded private key corresponding to the server certificate."]
#[doc = ""]
#[doc = " @deprecated Use s2n_config_add_cert_chain_and_key_to_store instead."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cert_chain_pem A byte array of a PEM encoded certificate chain."]
#[doc = " @param private_key_pem A byte array of a PEM encoded key."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure."]
pub fn s2n_config_add_cert_chain_and_key(
config: *mut s2n_config,
cert_chain_pem: *const ::libc::c_char,
private_key_pem: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " The preferred method of associating a certificate chain and private key pair with an `s2n_config` object."]
#[doc = " This method may be called multiple times to support multiple key types(RSA, ECDSA) and multiple domains."]
#[doc = " On the server side, the certificate selected will be based on the incoming SNI value and the"]
#[doc = " client's capabilities(supported ciphers)."]
#[doc = ""]
#[doc = " In the case of no certificate matching the client's SNI extension or if no SNI extension was sent by"]
#[doc = " the client, the certificate from the `first` call to `s2n_config_add_cert_chain_and_key_to_store`"]
#[doc = " will be selected."]
#[doc = ""]
#[doc = " @warning It is not recommended to free or modify the `cert_key_pair` as any subsequent changes will be"]
#[doc = " reflected in the config."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cert_key_pair The certificate chain and private key handle"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_add_cert_chain_and_key_to_store(
config: *mut s2n_config,
cert_key_pair: *mut s2n_cert_chain_and_key,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Explicitly sets certificate chain and private key pairs to be used as defaults for each auth"]
#[doc = " method (key type). A \"default\" certificate is used when there is not an SNI match with any other"]
#[doc = " configured certificate."]
#[doc = ""]
#[doc = " Only one certificate can be set as the default per auth method (one RSA default, one ECDSA default,"]
#[doc = " etc.). All previous default certificates will be cleared and re-set when this API is called."]
#[doc = ""]
#[doc = " This API is called for a specific `s2n_config` object. s2n-tls will attempt to automatically choose"]
#[doc = " default certificates for each auth method (key type) based on the order that `s2n_cert_chain_and_key`"]
#[doc = " are added to the `s2n_config` using one of the APIs listed above."]
#[doc = " `s2n_config_set_cert_chain_and_key_defaults` can be called at any time; s2n-tls will clear defaults"]
#[doc = " and no longer attempt to automatically choose any default certificates."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cert_key_pairs An array of certificate chain and private key handles"]
#[doc = " @param num_cert_key_pairs The amount of handles in cert_key_pairs"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_cert_chain_and_key_defaults(
config: *mut s2n_config,
cert_key_pairs: *mut *mut s2n_cert_chain_and_key,
num_cert_key_pairs: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Adds to the trust store from a CA file or directory containing trusted certificates."]
#[doc = " To completely override those locations, call s2n_config_wipe_trust_store() before calling"]
#[doc = " this function."]
#[doc = ""]
#[doc = " @note The trust store will be initialized with the common locations for the host"]
#[doc = " operating system by default."]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param ca_pem_filename A string for the file path of the CA PEM file."]
#[doc = " @param ca_dir A string for the directory of the CA PEM files."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_verification_ca_location(
config: *mut s2n_config,
ca_pem_filename: *const ::libc::c_char,
ca_dir: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Adds a PEM to the trust store. This will allocate memory, and load PEM into the"]
#[doc = " Trust Store. Note that the trust store will be initialized with the common locations"]
#[doc = " for the host operating system by default. To completely override those locations,"]
#[doc = " call s2n_config_wipe_trust_store before calling this function."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param pem The string value of the PEM certificate."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_add_pem_to_trust_store(
config: *mut s2n_config,
pem: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Clear the trust store."]
#[doc = ""]
#[doc = " Note that the trust store will be initialized with the common locations for"]
#[doc = " the host operating system by default. To completely override those locations,"]
#[doc = " call this before functions like `s2n_config_set_verification_ca_location()`"]
#[doc = " or `s2n_config_add_pem_to_trust_store()`"]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = ""]
#[doc = " @returns 0 on success and -1 on error"]
pub fn s2n_config_wipe_trust_store(config: *mut s2n_config) -> ::libc::c_int;
}
pub mod s2n_verify_after_sign {
pub type Type = ::libc::c_uint;
pub const VERIFY_AFTER_SIGN_DISABLED: Type = 0;
pub const VERIFY_AFTER_SIGN_ENABLED: Type = 1;
}
extern "C" {
#[doc = " Toggle whether generated signatures are verified before being sent."]
#[doc = ""]
#[doc = " Although signatures produced by the underlying libcrypto should always be valid,"]
#[doc = " hardware faults, bugs in the signing implementation, or other uncommon factors"]
#[doc = " can cause unexpected mistakes in the final signatures. Because these mistakes"]
#[doc = " can leak information about the private key, applications with low trust in their"]
#[doc = " hardware or libcrypto may want to verify signatures before sending them."]
#[doc = ""]
#[doc = " However, this feature will significantly impact handshake latency."]
#[doc = " Additionally, most libcrypto implementations already check for common errors in signatures."]
pub fn s2n_config_set_verify_after_sign(
config: *mut s2n_config,
mode: s2n_verify_after_sign::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Set a custom send buffer size."]
#[doc = ""]
#[doc = " This buffer is used to stage records for sending. By default,"]
#[doc = " enough memory is allocated to hold a single record of the maximum"]
#[doc = " size configured for the connection. With the default fragment size,"]
#[doc = " that is about 8K bytes."]
#[doc = ""]
#[doc = " Less memory can be allocated for the send buffer, but this will result in"]
#[doc = " smaller, more fragmented records and increased overhead. While the absolute"]
#[doc = " minimum size required is 1025 bytes, at least 2K bytes is recommended for"]
#[doc = " reasonable record sizes."]
#[doc = ""]
#[doc = " More memory can be allocated for the send buffer. This will result in s2n-tls"]
#[doc = " buffering multiple records before sending them, reducing system write calls."]
#[doc = " At least 17K bytes is recommended for this use case, or at least 35K bytes"]
#[doc = " if larger fragment sizes are used via `s2n_connection_prefer_throughput()`."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param size The desired custom buffer size."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_send_buffer_size(config: *mut s2n_config, size: u32) -> ::libc::c_int;
}
#[doc = " A callback function invoked (usually multiple times) during X.509 validation for each"]
#[doc = " name encountered in the leaf certificate."]
#[doc = ""]
#[doc = " Return 1 to trust that hostname or 0 to not trust the hostname."]
#[doc = ""]
#[doc = " If this function returns 1, then the certificate is considered trusted and that portion"]
#[doc = " of the X.509 validation will succeed."]
#[doc = ""]
#[doc = " If no hostname results in a 1 being returned, the certificate will be untrusted and the"]
#[doc = " validation will terminate immediately."]
#[doc = ""]
#[doc = " Data is a opaque user context set in s2n_config_set_verify_host_callback() or s2n_connection_set_verify_host_callback()."]
pub type s2n_verify_host_fn = ::core::option::Option<
unsafe extern "C" fn(
host_name: *const ::libc::c_char,
host_name_len: usize,
data: *mut ::libc::c_void,
) -> u8,
>;
extern "C" {
#[doc = " Sets the callback to use for verifying that a hostname from an X.509 certificate is trusted."]
#[doc = ""]
#[doc = " The default behavior is to require that the hostname match the server name set with s2n_set_server_name()."]
#[doc = " This will likely lead to all client certificates being rejected, so the callback will need to be overriden when using"]
#[doc = " client authentication."]
#[doc = ""]
#[doc = " This change will be inherited by s2n_connections using this config. If a separate callback for different connections"]
#[doc = " using the same config is desired, see s2n_connection_set_verify_host_callback()."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param data A user supplied opaque context to pass back to the callback"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_verify_host_callback(
config: *mut s2n_config,
arg1: s2n_verify_host_fn,
data: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Toggles whether or not to validate stapled OCSP responses."]
#[doc = ""]
#[doc = " 1 means OCSP responses will be validated when they are encountered, while 0 means this step will"]
#[doc = " be skipped."]
#[doc = ""]
#[doc = " The default value is 1 if the underlying libCrypto implementation supports OCSP."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param check_ocsp The desired OCSP response check configuration"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_check_stapled_ocsp_response(
config: *mut s2n_config,
check_ocsp: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Turns off all X.509 validation during the negotiation phase of the connection. This should only"]
#[doc = " be used for testing or debugging purposes."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_disable_x509_verification(config: *mut s2n_config) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the maximum allowed depth of a cert chain used for X509 validation. The default value is"]
#[doc = " 7. If this limit is exceeded, validation will fail if s2n_config_disable_x509_verification()"]
#[doc = " has not been called. 0 is an illegal value and will return an error."]
#[doc = " 1 means only a root certificate will be used."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param max_depth The number of allowed certificates in the certificate chain"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_max_cert_chain_depth(
config: *mut s2n_config,
max_depth: u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Associates a set of Diffie-Hellman parameters with an `s2n_config` object."]
#[doc = " @note `dhparams_pem` should be PEM encoded DH parameters."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param dhparams_pem A string containing the PEM encoded DH parameters."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_add_dhparams(
config: *mut s2n_config,
dhparams_pem: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the security policy that includes the cipher/kem/signature/ecc preferences and"]
#[doc = " protocol version."]
#[doc = ""]
#[doc = " See the [USAGE-GUIDE.md](https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md) for how to use security policies."]
pub fn s2n_config_set_cipher_preferences(
config: *mut s2n_config,
version: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Appends the provided application protocol to the preference list"]
#[doc = ""]
#[doc = " The data provided in `protocol` parameter will be copied into an internal buffer"]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param protocol A pointer to a byte array value"]
#[doc = " @param protocol_len The length of bytes that should be read from `protocol`. Note: this value cannot be 0, otherwise an error will be returned."]
pub fn s2n_config_append_protocol_preference(
config: *mut s2n_config,
protocol: *const u8,
protocol_len: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the application protocol preferences on an `s2n_config` object."]
#[doc = " `protocols` is a list in order of preference, with most preferred protocol first, and of"]
#[doc = " length `protocol_count`."]
#[doc = ""]
#[doc = " When acting as an `S2N_CLIENT` the protocol list is included in the Client Hello message"]
#[doc = " as the ALPN extension."]
#[doc = ""]
#[doc = " As an `S2N_SERVER`, the list is used to negotiate a mutual application protocol with the"]
#[doc = " client. After the negotiation for the connection has completed, the agreed upon protocol"]
#[doc = " can be retrieved with s2n_get_application_protocol()"]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param protocols The list of preferred protocols, in order of preference"]
#[doc = " @param protocol_count The size of the protocols list"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_protocol_preferences(
config: *mut s2n_config,
protocols: *const *const ::libc::c_char,
protocol_count: ::libc::c_int,
) -> ::libc::c_int;
}
pub mod s2n_status_request_type {
#[doc = " Enum used to define the type, if any, of certificate status request"]
#[doc = " an S2N_CLIENT should make during the handshake. The only supported status request type is"]
#[doc = " OCSP, `S2N_STATUS_REQUEST_OCSP`."]
pub type Type = ::libc::c_uint;
pub const NONE: Type = 0;
pub const OCSP: Type = 1;
}
extern "C" {
#[doc = " Sets up an S2N_CLIENT to request the server certificate status during an SSL handshake. If set"]
#[doc = " to S2N_STATUS_REQUEST_NONE, no status request is made."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param type The desired request status type"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_status_request_type(
config: *mut s2n_config,
type_: s2n_status_request_type::Type,
) -> ::libc::c_int;
}
pub mod s2n_ct_support_level {
#[doc = " Enum to set Certificate Transparency Support level."]
pub type Type = ::libc::c_uint;
pub const NONE: Type = 0;
pub const REQUEST: Type = 1;
}
extern "C" {
#[doc = " Set the Certificate Transparency Support level."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param level The desired Certificate Transparency Support configuration"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_ct_support_level(
config: *mut s2n_config,
level: s2n_ct_support_level::Type,
) -> ::libc::c_int;
}
pub mod s2n_alert_behavior {
#[doc = " Sets whether or not a connection should terminate on receiving a WARNING alert from its peer."]
#[doc = ""]
#[doc = " `alert_behavior` can take the following values:"]
#[doc = " - `S2N_ALERT_FAIL_ON_WARNINGS` default behavior: s2n-tls will terminate the connection if its peer sends a WARNING alert."]
#[doc = " - `S2N_ALERT_IGNORE_WARNINGS` - with the exception of `close_notify` s2n-tls will ignore all WARNING alerts and keep communicating with its peer. This setting is ignored in TLS1.3"]
#[doc = ""]
#[doc = " @note TLS1.3 terminates a connection for all alerts except user_canceled."]
#[doc = " @warning S2N_ALERT_FAIL_ON_WARNINGS is the recommended behavior. Past TLS protocol vulnerabilities have involved downgrading alerts to warnings."]
pub type Type = ::libc::c_uint;
pub const FAIL_ON_WARNINGS: Type = 0;
pub const IGNORE_WARNINGS: Type = 1;
}
extern "C" {
#[doc = " Sets the config's alert behavior based on the `s2n_alert_behavior` enum."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param alert_behavior The desired alert behavior."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_alert_behavior(
config: *mut s2n_config,
alert_behavior: s2n_alert_behavior::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the extension data in the `s2n_config` object for the specified extension."]
#[doc = " This method will clear any existing data that is set. If the data and length"]
#[doc = " parameters are set to NULL, no new data is set in the `s2n_config` object,"]
#[doc = " effectively clearing existing data."]
#[doc = ""]
#[doc = " @deprecated Use s2n_cert_chain_and_key_set_ocsp_data and s2n_cert_chain_and_key_set_sct_list instead."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param type The extension type"]
#[doc = " @param data Data for the extension"]
#[doc = " @param length Length of the `data` buffer"]
pub fn s2n_config_set_extension_data(
config: *mut s2n_config,
type_: s2n_tls_extension_type::Type,
data: *const u8,
length: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Allows the caller to set a TLS Maximum Fragment Length extension that will be used"]
#[doc = " to fragment outgoing messages. s2n-tls currently does not reject fragments larger"]
#[doc = " than the configured maximum when in server mode. The TLS negotiated maximum fragment"]
#[doc = " length overrides the preference set by the `s2n_connection_prefer_throughput` and"]
#[doc = " `s2n_connection_prefer_low_latency`."]
#[doc = ""]
#[doc = " @note Some TLS implementations do not respect their peer's max fragment length extension."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param mfl_code The selected MFL size"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_send_max_fragment_length(
config: *mut s2n_config,
mfl_code: s2n_max_frag_len::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Allows the server to opt-in to accept client's TLS maximum fragment length extension"]
#[doc = " requests. If this API is not called, and client requests the extension, server will ignore"]
#[doc = " the request and continue TLS handshake with default maximum fragment length of 8k bytes"]
#[doc = ""]
#[doc = " @note Some TLS implementations do not respect their peer's max fragment length extension."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_accept_max_fragment_length(config: *mut s2n_config) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the lifetime of the cached session state. The default value is 15 hours."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param lifetime_in_secs The desired lifetime of the session state in seconds"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_session_state_lifetime(
config: *mut s2n_config,
lifetime_in_secs: u64,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Enable or disable session resumption using session ticket."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param enabled The configuration object being updated. Set to 1 to enable. Set to 0 to disable."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_session_tickets_onoff(
config: *mut s2n_config,
enabled: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Enable or disable session caching."]
#[doc = ""]
#[doc = " @note Session caching will not be turned on unless all three session cache callbacks are set"]
#[doc = " prior to calling this function."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param enabled The configuration object being updated. Set to 1 to enable. Set to 0 to disable."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_session_cache_onoff(
config: *mut s2n_config,
enabled: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets how long a session ticket key will be in a state where it can be used for both encryption"]
#[doc = " and decryption of tickets on the server side."]
#[doc = ""]
#[doc = " @note The default value is 2 hours."]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param lifetime_in_secs The desired lifetime of decrypting and encrypting tickets in seconds"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_ticket_encrypt_decrypt_key_lifetime(
config: *mut s2n_config,
lifetime_in_secs: u64,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets how long a session ticket key will be in a state where it can used just for decryption of"]
#[doc = " already assigned tickets on the server side. Once decrypted, the session will resume and the"]
#[doc = " server will issue a new session ticket encrypted using a key in encrypt-decrypt state."]
#[doc = ""]
#[doc = " @note The default value is 13 hours."]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param lifetime_in_secs The desired lifetime of decrypting and encrypting tickets in seconds"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_ticket_decrypt_key_lifetime(
config: *mut s2n_config,
lifetime_in_secs: u64,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Adds session ticket key on the server side. It would be ideal to add new keys after every"]
#[doc = " (encrypt_decrypt_key_lifetime_in_nanos/2) nanos because this will allow for gradual and"]
#[doc = " linear transition of a key from encrypt-decrypt state to decrypt-only state."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param name Name of the session ticket key that should be randomly generated to avoid collisions"]
#[doc = " @param name_len Length of session ticket key name"]
#[doc = " @param key Key used to perform encryption/decryption of session ticket"]
#[doc = " @param key_len Length of the session ticket key"]
#[doc = " @param intro_time_in_seconds_from_epoch Time at which the session ticket key is introduced. If this is 0, then intro_time_in_seconds_from_epoch is set to now."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_add_ticket_crypto_key(
config: *mut s2n_config,
name: *const u8,
name_len: u32,
key: *mut u8,
key_len: u32,
intro_time_in_seconds_from_epoch: u64,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets user defined context on the `s2n_config` object."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param ctx A pointer to the user defined ctx."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_ctx(config: *mut s2n_config, ctx: *mut ::libc::c_void) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the user defined context from the `s2n_config` object."]
#[doc = " The context is set by calling s2n_config_set_ctx()"]
#[doc = ""]
#[doc = " @param config The configuration object being accessed"]
#[doc = " @param ctx A pointer to the user defined ctx."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_get_ctx(
config: *mut s2n_config,
ctx: *mut *mut ::libc::c_void,
) -> ::libc::c_int;
}
pub mod s2n_mode {
#[doc = " Used to declare connections as server or client type, respectively."]
pub type Type = ::libc::c_uint;
pub const SERVER: Type = 0;
pub const CLIENT: Type = 1;
}
extern "C" {
#[doc = " Creates a new connection object. Each s2n-tls SSL/TLS connection uses"]
#[doc = " one of these objects. These connection objects can be operated on by up"]
#[doc = " to two threads at a time, one sender and one receiver, but neither sending"]
#[doc = " nor receiving are atomic, so if these objects are being called by multiple"]
#[doc = " sender or receiver threads, you must perform your own locking to ensure"]
#[doc = " that only one sender or receiver is active at a time."]
#[doc = ""]
#[doc = " The `mode` parameters specifies if the caller is a server, or is a client."]
#[doc = " Connections objects are re-usable across many connections, and should be"]
#[doc = " re-used (to avoid deallocating and allocating memory). You should wipe"]
#[doc = " connections immediately after use."]
#[doc = ""]
#[doc = " @param mode The desired connection type"]
#[doc = " @returns A s2n_connection handle"]
pub fn s2n_connection_new(mode: s2n_mode::Type) -> *mut s2n_connection;
}
extern "C" {
#[doc = " Associates a configuration object with a connection."]
#[doc = ""]
#[doc = " @param conn The connection object being associated"]
#[doc = " @param config The configuration object being associated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_config(
conn: *mut s2n_connection,
config: *mut s2n_config,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets user defined context in `s2n_connection` object."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param ctx A pointer to the user defined context"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_ctx(
conn: *mut s2n_connection,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets user defined context from a `s2n_connection` object."]
#[doc = ""]
#[doc = " @param conn The connection object that contains the desired context"]
pub fn s2n_connection_get_ctx(conn: *mut s2n_connection) -> *mut ::libc::c_void;
}
#[doc = " The callback function takes a s2n-tls connection as input, which receives the ClientHello"]
#[doc = " and the context previously provided in `s2n_config_set_client_hello_cb`. The callback can"]
#[doc = " access any ClientHello information from the connection and use the `s2n_connection_set_config`"]
#[doc = " call to change the config of the connection."]
pub type s2n_client_hello_fn = ::core::option::Option<
unsafe extern "C" fn(conn: *mut s2n_connection, ctx: *mut ::libc::c_void) -> ::libc::c_int,
>;
pub mod s2n_client_hello_cb_mode {
#[doc = " Client Hello callback modes"]
#[doc = " - `S2N_CLIENT_HELLO_CB_BLOCKING` (default):"]
#[doc = " - In this mode s2n-tls expects the callback to complete its work and return the appropriate response code before the handshake continues. If any of the connection properties were changed based on the server_name extension the callback must either return a value greater than 0 or invoke `s2n_connection_server_name_extension_used`, otherwise the callback returns 0 to continue the handshake."]
#[doc = " - `S2N_CLIENT_HELLO_CB_NONBLOCKING`:"]
#[doc = " - In non-blocking mode, s2n-tls expects the callback to not complete its work. If the callback returns a response code of 0 s2n-tls will return `S2N_FAILURE` with `S2N_ERR_T_BLOCKED` error type and `s2n_blocked_status` set to `S2N_BLOCKED_ON_APPLICATION_INPUT`. The handshake is paused and further calls to `s2n_negotiate` will continue to return the same error until `s2n_client_hello_cb_done` is invoked for the `s2n_connection` to resume the handshake. This allows s2n-tls clients to process client_hello without blocking and then resume the handshake at a later time. If any of the connection properties were changed on the basis of the server_name extension then `s2n_connection_server_name_extension_used` must be invoked before marking the callback done."]
pub type Type = ::libc::c_uint;
pub const BLOCKING: Type = 0;
pub const NONBLOCKING: Type = 1;
}
extern "C" {
#[doc = " Allows the caller to set a callback function that will be called after ClientHello was parsed."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param client_hello_callback The client hello callback function"]
#[doc = " @param ctx A pointer to a user defined context that the Client Hello callback will be invoked with."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_client_hello_cb(
config: *mut s2n_config,
client_hello_callback: s2n_client_hello_fn,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the callback execution mode."]
#[doc = ""]
#[doc = " See s2n_client_hello_cb_mode for each mode's behavior."]
#[doc = ""]
#[doc = " @param config The configuration object being updated"]
#[doc = " @param cb_mode The desired callback mode"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_client_hello_cb_mode(
config: *mut s2n_config,
cb_mode: s2n_client_hello_cb_mode::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Marks the non-blocking callback as complete. Can be invoked from within the callback when"]
#[doc = " operating in non-blocking mode to continue the handshake."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_client_hello_cb_done(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Must be invoked if any of the connection properties were changed on the basis of the server_name"]
#[doc = " extension. This must be invoked before marking the Client Hello callback done."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_server_name_extension_used(conn: *mut s2n_connection) -> ::libc::c_int;
}
#[doc = " Opaque client hello handle"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_client_hello {
_unused: [u8; 0],
}
extern "C" {
#[doc = " Get the Client Hello from a s2n_connection."]
#[doc = ""]
#[doc = " Earliest point during the handshake when this structure is available for use is in the"]
#[doc = " client_hello_callback (see s2n_config_set_client_hello_cb())."]
#[doc = ""]
#[doc = " @param conn The connection object containing the client hello"]
#[doc = " @returns A handle to the s2n_client_hello structure holding the client hello message sent by the client during the handshake. NULL is returned if a Client Hello has not yet been received and parsed."]
pub fn s2n_connection_get_client_hello(conn: *mut s2n_connection) -> *mut s2n_client_hello;
}
extern "C" {
#[doc = " Function to determine the size of the raw Client Hello buffer."]
#[doc = ""]
#[doc = " Can be used to determine the necessary size of the `out` buffer for"]
#[doc = " s2n_client_hello_get_raw_message()"]
#[doc = ""]
#[doc = " @param ch The Client Hello handle"]
#[doc = " @returns The size of the ClientHello message received by the server"]
pub fn s2n_client_hello_get_raw_message_length(ch: *mut s2n_client_hello) -> isize;
}
extern "C" {
#[doc = " Copies `max_length` bytes of the ClientHello message into the `out` buffer."]
#[doc = " The ClientHello instrumented using this function will have the Random bytes"]
#[doc = " zero-ed out. For SSLv2 ClientHello messages, the raw message contains only"]
#[doc = " the cipher_specs, session_id and members portions of the hello message"]
#[doc = " (see [RFC5246](https://tools.ietf.org/html/rfc5246#appendix-E.2)). To access other"]
#[doc = " members, you may use s2n_connection_get_client_hello_version(),"]
#[doc = " s2n_connection_get_client_protocol_version() and s2n_connection_get_session_id_length()"]
#[doc = " accessors functions."]
#[doc = ""]
#[doc = " @param ch The Client Hello handle"]
#[doc = " @param out The destination buffer for the raw Client Hello"]
#[doc = " @param max_length The size of out in bytes"]
#[doc = " @returns The number of copied bytes"]
pub fn s2n_client_hello_get_raw_message(
ch: *mut s2n_client_hello,
out: *mut u8,
max_length: u32,
) -> isize;
}
extern "C" {
#[doc = " Function to determine the size of the Client Hello cipher suites."]
#[doc = " This can be used to allocate the `out` buffer for s2n_client_hello_get_cipher_suites()."]
#[doc = ""]
#[doc = " @param ch The Client Hello handle"]
#[doc = " @returns the number of bytes the cipher_suites takes on the ClientHello message received by the server"]
pub fn s2n_client_hello_get_cipher_suites_length(ch: *mut s2n_client_hello) -> isize;
}
extern "C" {
#[doc = " Copies into the `out` buffer `max_length` bytes of the cipher_suites on the ClientHello."]
#[doc = ""]
#[doc = " @param ch The Client Hello handle"]
#[doc = " @param out The destination buffer for the raw Client Hello cipher suites"]
#[doc = " @param max_length The size of out in bytes"]
#[doc = " @returns The number of copied bytes"]
pub fn s2n_client_hello_get_cipher_suites(
ch: *mut s2n_client_hello,
out: *mut u8,
max_length: u32,
) -> isize;
}
extern "C" {
#[doc = " Function to determine the size of the Client Hello extensions."]
#[doc = " This can be used to allocate the `out` buffer for s2n_client_hello_get_extensions()."]
#[doc = ""]
#[doc = " @param ch The Client Hello handle"]
#[doc = " @returns the number of bytes the extensions take in the ClientHello message received by the server"]
pub fn s2n_client_hello_get_extensions_length(ch: *mut s2n_client_hello) -> isize;
}
extern "C" {
#[doc = " Copies into the `out` buffer `max_length` bytes of the extensions in the ClientHello."]
#[doc = ""]
#[doc = " @param ch The Client Hello handle"]
#[doc = " @param out The destination buffer for the raw Client Hello extensions"]
#[doc = " @param max_length The size of out in bytes"]
#[doc = " @returns The number of copied bytes"]
pub fn s2n_client_hello_get_extensions(
ch: *mut s2n_client_hello,
out: *mut u8,
max_length: u32,
) -> isize;
}
extern "C" {
#[doc = " Query the ClientHello message received by the server. Use this function to allocate the `out` buffer for"]
#[doc = " other client hello extension functions."]
#[doc = ""]
#[doc = " @param ch A pointer to the Client Hello"]
#[doc = " @param extension_type Indicates the desired extension"]
#[doc = " @returns The number of bytes the given extension type takes"]
pub fn s2n_client_hello_get_extension_length(
ch: *mut s2n_client_hello,
extension_type: s2n_tls_extension_type::Type,
) -> isize;
}
extern "C" {
#[doc = " Copies into the `out` buffer `max_length` bytes of a given extension type on the ClientHello"]
#[doc = ""]
#[doc = " `ch` is a pointer to the `s2n_client_hello` of the `s2n_connection` which can be obtained using s2n_connection_get_client_hello()."]
#[doc = ""]
#[doc = " @param ch A pointer to the Client Hello"]
#[doc = " @param extension_type Indicates the desired extension"]
#[doc = " @param out A pointer to the buffer that s2n will write the client session id to. This buffer MUST be the size of `max_length`"]
#[doc = " @param max_length The size of `out`."]
#[doc = " @returns The number of copied bytes"]
pub fn s2n_client_hello_get_extension_by_id(
ch: *mut s2n_client_hello,
extension_type: s2n_tls_extension_type::Type,
out: *mut u8,
max_length: u32,
) -> isize;
}
extern "C" {
#[doc = " Used to check if a particular extension exists in the client hello."]
#[doc = ""]
#[doc = " `ch` is a pointer to the `s2n_client_hello` of the `s2n_connection` which can be obtained using s2n_connection_get_client_hello()."]
#[doc = ""]
#[doc = " @param ch A pointer to the client hello object"]
#[doc = " @param extension_iana The iana value of the extension"]
#[doc = " @param exists A pointer that will be set to whether or not the extension exists"]
pub fn s2n_client_hello_has_extension(
ch: *mut s2n_client_hello,
extension_iana: u16,
exists: *mut bool,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the the ClientHello session id length in bytes"]
#[doc = ""]
#[doc = " `ch` is a pointer to the `s2n_client_hello` of the `s2n_connection` which can be obtained using s2n_connection_get_client_hello()."]
#[doc = ""]
#[doc = " @param ch A pointer to the Client Hello"]
#[doc = " @param out_length An out pointer. s2n will set it's value to the size of the session_id in bytes."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_client_hello_get_session_id_length(
ch: *mut s2n_client_hello,
out_length: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Copies up to `max_length` bytes of the ClientHello session_id into the `out` buffer and stores the number of copied bytes in `out_length`."]
#[doc = ""]
#[doc = " Retrieve the session id as sent by the client in the ClientHello message. The session id on the `s2n_connection` may change later"]
#[doc = " when the server sends the ServerHello; see `s2n_connection_get_session_id` for how to get the final session id used for future session resumption."]
#[doc = ""]
#[doc = " Use s2n_client_hello_get_session_id_length() to get the the ClientHello session id length in bytes. `ch` is a pointer to the `s2n_client_hello`"]
#[doc = " of the `s2n_connection` which can be obtained using s2n_connection_get_client_hello()."]
#[doc = ""]
#[doc = " @param ch A pointer to the Client Hello"]
#[doc = " @param out A pointer to the buffer that s2n will write the client session id to. This buffer MUST be the size of `max_length`"]
#[doc = " @param out_length An out pointer. s2n will set it's value to the size of the session_id in bytes."]
#[doc = " @param max_length The size of `out`."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_client_hello_get_session_id(
ch: *mut s2n_client_hello,
out: *mut u8,
out_length: *mut u32,
max_length: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the file descriptor for a s2n connection."]
#[doc = ""]
#[doc = " @warning If the read end of the pipe is closed unexpectedly, writing to the pipe will raise a SIGPIPE signal."]
#[doc = " **s2n-tls does NOT handle SIGPIPE.** A SIGPIPE signal will cause the process to terminate unless it is handled"]
#[doc = " or ignored by the application."]
#[doc = " @note This file-descriptor should be active and connected"]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @param fd The new file descriptor"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_fd(conn: *mut s2n_connection, fd: ::libc::c_int) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the file descriptor for the read channel of an s2n connection."]
#[doc = ""]
#[doc = " @warning If the read end of the pipe is closed unexpectedly, writing to the pipe will raise a SIGPIPE signal."]
#[doc = " **s2n-tls does NOT handle SIGPIPE.** A SIGPIPE signal will cause the process to terminate unless it is handled"]
#[doc = " or ignored by the application."]
#[doc = " @note This file-descriptor should be active and connected"]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @param readfd The new read file descriptor"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_read_fd(
conn: *mut s2n_connection,
readfd: ::libc::c_int,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the assigned file descriptor for the write channel of an s2n connection."]
#[doc = ""]
#[doc = " @note This file-descriptor should be active and connected"]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @param writefd The new write file descriptor"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_write_fd(
conn: *mut s2n_connection,
writefd: ::libc::c_int,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the assigned file descriptor for the read channel of an s2n connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @param readfd pointer to place the used file descriptor."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_get_read_fd(
conn: *mut s2n_connection,
readfd: *mut ::libc::c_int,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the assigned file descriptor for the write channel of an s2n connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @param writefd pointer to place the used file descriptor."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_get_write_fd(
conn: *mut s2n_connection,
writefd: *mut ::libc::c_int,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Indicates to s2n that the connection is using corked IO."]
#[doc = ""]
#[doc = " @warning This API should only be used when using managed send IO."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_use_corked_io(conn: *mut s2n_connection) -> ::libc::c_int;
}
#[doc = " Function pointer for a user provided send callback."]
pub type s2n_recv_fn = ::core::option::Option<
unsafe extern "C" fn(io_context: *mut ::libc::c_void, buf: *mut u8, len: u32) -> ::libc::c_int,
>;
#[doc = " Function pointer for a user provided send callback."]
pub type s2n_send_fn = ::core::option::Option<
unsafe extern "C" fn(
io_context: *mut ::libc::c_void,
buf: *const u8,
len: u32,
) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Set a context containing anything needed in the recv callback function (for example,"]
#[doc = " a file descriptor), the buffer holding data to be sent or received, and the length of the buffer."]
#[doc = ""]
#[doc = " @note The `io_context` passed to the callbacks may be set separately using `s2n_connection_set_recv_ctx` and `s2n_connection_set_send_ctx`."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param ctx A user provided context that the callback will be invoked with"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_recv_ctx(
conn: *mut s2n_connection,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Set a context containing anything needed in the send callback function (for example,"]
#[doc = " a file descriptor), the buffer holding data to be sent or received, and the length of the buffer."]
#[doc = ""]
#[doc = " @note The `io_context` passed to the callbacks may be set separately using `s2n_connection_set_recv_ctx` and `s2n_connection_set_send_ctx`."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param ctx A user provided context that the callback will be invoked with"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_send_ctx(
conn: *mut s2n_connection,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Configure a connection to use a recv callback to receive data."]
#[doc = ""]
#[doc = " @note This callback may be blocking or nonblocking."]
#[doc = " @note The callback may receive less than the requested length. The function should return the number"]
#[doc = " of bytes received, or set errno and return an error code < 0."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param recv A recv callback function pointer"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_recv_cb(
conn: *mut s2n_connection,
recv: s2n_recv_fn,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Configure a connection to use a send callback to send data."]
#[doc = ""]
#[doc = " @note This callback may be blocking or nonblocking."]
#[doc = " @note The callback may send less than the requested length. The function should return the"]
#[doc = " number of bytes sent or set errno and return an error code < 0."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param send A send callback function pointer"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_send_cb(
conn: *mut s2n_connection,
send: s2n_send_fn,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Change the behavior of s2n-tls when sending data to prefer high throughput."]
#[doc = ""]
#[doc = " Connections preferring throughput will use"]
#[doc = " large record sizes that minimize overhead."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_prefer_throughput(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Change the behavior of s2n-tls when sending data to prefer low latency."]
#[doc = ""]
#[doc = " Connections preferring low latency will be encrypted"]
#[doc = " using small record sizes that can be decrypted sooner by the recipient."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_prefer_low_latency(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Configure the connection to free IO buffers when they are not currently in use."]
#[doc = ""]
#[doc = " This configuration can be used to minimize connection memory footprint size, at the cost"]
#[doc = " of more calls to alloc and free. Some of these costs can be mitigated by configuring s2n-tls"]
#[doc = " to use an allocator that includes thread-local caches or lock-free allocation patterns."]
#[doc = ""]
#[doc = " @param conn The connection object being update"]
#[doc = " @param enabled Set to `true` if dynamic buffers are enabled; `false` if disabled"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_dynamic_buffers(
conn: *mut s2n_connection,
enabled: bool,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Changes the behavior of s2n-tls when sending data to initially prefer records"]
#[doc = " small enough to fit in single ethernet frames."]
#[doc = ""]
#[doc = " When dynamic record sizing is active, the connection sends records small enough"]
#[doc = " to fit in a single standard 1500 byte ethernet frame. Otherwise, the connection"]
#[doc = " chooses record sizes according to the configured maximum fragment length."]
#[doc = ""]
#[doc = " Dynamic record sizing is active for the first resize_threshold bytes of a connection,"]
#[doc = " and is reactivated whenever timeout_threshold seconds pass without sending data."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param resize_threshold The number of bytes to send before changing the record size. Maximum 8MiB."]
#[doc = " @param timeout_threshold Reset record size back to a single segment after threshold seconds of inactivity"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_dynamic_record_threshold(
conn: *mut s2n_connection,
resize_threshold: u32,
timeout_threshold: u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the callback to use for verifying that a hostname from an X.509 certificate is trusted."]
#[doc = ""]
#[doc = " The default behavior is to require that the hostname match the server name set with s2n_set_server_name(). This will"]
#[doc = " likely lead to all client certificates being rejected, so the callback will need to be overriden when using client authentication."]
#[doc = ""]
#[doc = " If a single callback for different connections using the same config is desired, see s2n_config_set_verify_host_callback()."]
#[doc = ""]
#[doc = " @param conn A pointer to a s2n_connection object"]
#[doc = " @param host_fn A pointer to a callback function that s2n will invoke in order to verify the hostname of an X.509 certificate"]
#[doc = " @param data Opaque pointer to data that the verify host function will be invoked with"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_verify_host_callback(
conn: *mut s2n_connection,
host_fn: s2n_verify_host_fn,
data: *mut ::libc::c_void,
) -> ::libc::c_int;
}
pub mod s2n_blinding {
#[doc = " Used to opt-out of s2n-tls's built-in blinding. Blinding is a"]
#[doc = " mitigation against timing side-channels which in some cases can leak information"]
#[doc = " about encrypted data. By default s2n-tls will cause a thread to sleep between 10 and"]
#[doc = " 30 seconds whenever tampering is detected."]
#[doc = ""]
#[doc = " Setting the S2N_SELF_SERVICE_BLINDING option with s2n_connection_set_blinding()"]
#[doc = " turns off this behavior. This is useful for applications that are handling many connections"]
#[doc = " in a single thread. In that case, if s2n_recv() or s2n_negotiate() return an error,"]
#[doc = " self-service applications should call s2n_connection_get_delay() and pause"]
#[doc = " activity on the connection for the specified number of nanoseconds before calling"]
#[doc = " close() or shutdown()."]
pub type Type = ::libc::c_uint;
pub const BUILT_IN_BLINDING: Type = 0;
pub const SELF_SERVICE_BLINDING: Type = 1;
}
extern "C" {
#[doc = " Used to configure s2n-tls to either use built-in blinding (set blinding to S2N_BUILT_IN_BLINDING) or"]
#[doc = " self-service blinding (set blinding to S2N_SELF_SERVICE_BLINDING)."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param blinding The desired blinding mode for the connection"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_blinding(
conn: *mut s2n_connection,
blinding: s2n_blinding::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Query the connection object for the configured blinding delay."]
#[doc = " @param conn The connection object being updated"]
#[doc = " @returns the number of nanoseconds an application using self-service blinding should pause before calling close() or shutdown()."]
pub fn s2n_connection_get_delay(conn: *mut s2n_connection) -> u64;
}
extern "C" {
#[doc = " Sets the cipher preference override for the s2n_connection. Calling this function is not necessary"]
#[doc = " unless you want to set the cipher preferences on the connection to something different than what is in the s2n_config."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param version The human readable string representation of the security policy version."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_cipher_preferences(
conn: *mut s2n_connection,
version: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Appends the provided application protocol to the preference list"]
#[doc = ""]
#[doc = " The data provided in `protocol` parameter will be copied into an internal buffer"]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param protocol A pointer to a slice of bytes"]
#[doc = " @param protocol_len The length of bytes that should be read from `protocol`. Note: this value cannot be 0, otherwise an error will be returned."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_append_protocol_preference(
conn: *mut s2n_connection,
protocol: *const u8,
protocol_len: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the protocol preference override for the s2n_connection. Calling this function is not necessary unless you want"]
#[doc = " to set the protocol preferences on the connection to something different than what is in the s2n_config."]
#[doc = ""]
#[doc = " @param conn The connection object being updated"]
#[doc = " @param protocols A pointer to an array of protocol strings"]
#[doc = " @param protocol_count The number of protocols contained in protocols"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_protocol_preferences(
conn: *mut s2n_connection,
protocols: *const *const ::libc::c_char,
protocol_count: ::libc::c_int,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the server name for the connection."]
#[doc = ""]
#[doc = " It may be desirable for clients"]
#[doc = " to provide this information to facilitate secure connections to"]
#[doc = " servers that host multiple 'virtual' servers at a single underlying"]
#[doc = " network address."]
#[doc = ""]
#[doc = " @param conn The connection object being queried"]
#[doc = " @param server_name A pointer to a string containing the desired server name"]
#[doc = " @warning `server_name` must be a NULL terminated string."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_set_server_name(
conn: *mut s2n_connection,
server_name: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Query the connection for the selected server name."]
#[doc = ""]
#[doc = " This can be used by a server to determine which server name the client is using. This function returns the first ServerName entry"]
#[doc = " in the ServerNameList sent by the client. Subsequent entries are not returned."]
#[doc = ""]
#[doc = " @param conn The connection object being queried"]
#[doc = " @returns The server name associated with a connection, or NULL if none is found."]
pub fn s2n_get_server_name(conn: *mut s2n_connection) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Query the connection for the selected application protocol."]
#[doc = ""]
#[doc = " @param conn The connection object being queried"]
#[doc = " @returns The negotiated application protocol for a `s2n_connection`. In the event of no protocol being negotiated, NULL is returned."]
pub fn s2n_get_application_protocol(conn: *mut s2n_connection) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Query the connection for a buffer containing the OCSP response."]
#[doc = ""]
#[doc = " @param conn The connection object being queried"]
#[doc = " @param length A pointer that is set to the certificate transparency response buffer's size"]
#[doc = " @returns A pointer to the OCSP response sent by a server during the handshake. If no status response is received, NULL is returned."]
pub fn s2n_connection_get_ocsp_response(
conn: *mut s2n_connection,
length: *mut u32,
) -> *const u8;
}
extern "C" {
#[doc = " Query the connection for a buffer containing the Certificate Transparency response."]
#[doc = ""]
#[doc = " @param conn The connection object being queried"]
#[doc = " @param length A pointer that is set to the certificate transparency response buffer's size"]
#[doc = " @returns A pointer to the certificate transparency response buffer."]
pub fn s2n_connection_get_sct_list(conn: *mut s2n_connection, length: *mut u32) -> *const u8;
}
pub mod s2n_blocked_status {
#[doc = " Used in non-blocking mode to indicate in which direction s2n-tls became blocked on I/O before it"]
#[doc = " returned control to the caller. This allows an application to avoid retrying s2n-tls operations"]
#[doc = " until I/O is possible in that direction."]
pub type Type = ::libc::c_uint;
pub const NOT_BLOCKED: Type = 0;
pub const BLOCKED_ON_READ: Type = 1;
pub const BLOCKED_ON_WRITE: Type = 2;
pub const BLOCKED_ON_APPLICATION_INPUT: Type = 3;
pub const BLOCKED_ON_EARLY_DATA: Type = 4;
}
extern "C" {
#[doc = " Performs the initial \"handshake\" phase of a TLS connection and must be called before any s2n_recv() or s2n_send() calls."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param blocked A pointer which will be set to the blocked status."]
#[doc = " @returns S2N_SUCCESS if the handshake completed. S2N_FAILURE if the handshake encountered an error or is blocked."]
pub fn s2n_negotiate(
conn: *mut s2n_connection,
blocked: *mut s2n_blocked_status::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Writes and encrypts `size` of `buf` data to the associated connection. s2n_send() will return the number of bytes"]
#[doc = " written, and may indicate a partial write."]
#[doc = ""]
#[doc = " @note Partial writes are possible not just for non-blocking I/O, but also for connections aborted while active."]
#[doc = " @note Unlike OpenSSL, repeated calls to s2n_send() should not duplicate the original parameters, but should"]
#[doc = " update `buf` and `size` per the indication of size written. For example;"]
#[doc = " ```c"]
#[doc = " s2n_blocked_status blocked;"]
#[doc = " int written = 0;"]
#[doc = " char data[10];"]
#[doc = " do {"]
#[doc = " int w = s2n_send(conn, data + written, 10 - written, &blocked);"]
#[doc = " if (w < 0) {"]
#[doc = " break;"]
#[doc = " }"]
#[doc = " written += w;"]
#[doc = " } while (blocked != S2N_NOT_BLOCKED);"]
#[doc = " ```"]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param buf A pointer to a buffer that s2n will write data from"]
#[doc = " @param size The size of buf"]
#[doc = " @param blocked A pointer which will be set to the blocked status, as in s2n_negotiate()"]
#[doc = " @returns The number of bytes written, and may indicate a partial write"]
pub fn s2n_send(
conn: *mut s2n_connection,
buf: *const ::libc::c_void,
size: isize,
blocked: *mut s2n_blocked_status::Type,
) -> isize;
}
extern "C" {
#[doc = " Works in the same way as s2n_sendv_with_offset() except that the latter's `offs` parameter is implicitly assumed to be 0."]
#[doc = " Therefore in the partial write case, the caller would have to make sure that `bufs` and `count` fields are modified in a way that takes"]
#[doc = " the partial writes into account."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param bufs A pointer to a vector of buffers that s2n will write data from."]
#[doc = " @param count The number of buffers in `bufs`"]
#[doc = " @param blocked A pointer which will be set to the blocked status, as in s2n_negotiate()"]
#[doc = " @returns The number of bytes written, and may indicate a partial write."]
pub fn s2n_sendv(
conn: *mut s2n_connection,
bufs: *const iovec,
count: isize,
blocked: *mut s2n_blocked_status::Type,
) -> isize;
}
extern "C" {
#[doc = " Works in the same way as s2n_send() except that it accepts vectorized buffers. Will return the number of bytes written, and may indicate a partial write. Partial writes are possible not just for non-blocking I/O, but also for connections aborted while active."]
#[doc = ""]
#[doc = " @note Partial writes are possible not just for non-blocking I/O, but also for connections aborted while active."]
#[doc = ""]
#[doc = " @note Unlike OpenSSL, repeated calls to s2n_sendv_with_offset() should not duplicate the original parameters, but should update `bufs` and `count` per the indication of size written. For example;"]
#[doc = ""]
#[doc = " ```c"]
#[doc = " s2n_blocked_status blocked;"]
#[doc = " int written = 0;"]
#[doc = " char data[10];"]
#[doc = " struct iovec iov[1];"]
#[doc = " iov[0].iov_base = data;"]
#[doc = " iov[0].iov_len = 10;"]
#[doc = " do {"]
#[doc = " int w = s2n_sendv_with_offset(conn, iov, 1, written, &blocked);"]
#[doc = " if (w < 0) {"]
#[doc = " break;"]
#[doc = " }"]
#[doc = " written += w;"]
#[doc = " } while (blocked != S2N_NOT_BLOCKED);"]
#[doc = " ```"]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param bufs A pointer to a vector of buffers that s2n will write data from."]
#[doc = " @param count The number of buffers in `bufs`"]
#[doc = " @param offs The write cursor offset. This should be updated as data is written. See the example code."]
#[doc = " @param blocked A pointer which will be set to the blocked status, as in s2n_negotiate()"]
#[doc = " @returns The number of bytes written, and may indicate a partial write."]
pub fn s2n_sendv_with_offset(
conn: *mut s2n_connection,
bufs: *const iovec,
count: isize,
offs: isize,
blocked: *mut s2n_blocked_status::Type,
) -> isize;
}
extern "C" {
#[doc = " Decrypts and reads **size* to `buf` data from the associated"]
#[doc = " connection."]
#[doc = ""]
#[doc = " @note Unlike OpenSSL, repeated calls to `s2n_recv` should not duplicate the original parameters, but should update `buf` and `size` per the indication of size read. For example;"]
#[doc = " ```c"]
#[doc = " s2n_blocked_status blocked;"]
#[doc = " int bytes_read = 0;"]
#[doc = " char data[10];"]
#[doc = " do {"]
#[doc = " int r = s2n_recv(conn, data + bytes_read, 10 - bytes_read, &blocked);"]
#[doc = " if (r < 0) {"]
#[doc = " break;"]
#[doc = " }"]
#[doc = " bytes_read += r;"]
#[doc = " } while (blocked != S2N_NOT_BLOCKED);"]
#[doc = " ```"]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param buf A pointer to a buffer that s2n will place read data into."]
#[doc = " @param size Size of `buf`"]
#[doc = " @param blocked A pointer which will be set to the blocked status, as in s2n_negotiate()"]
#[doc = " @returns number of bytes read. 0 if the connection was shutdown by peer."]
pub fn s2n_recv(
conn: *mut s2n_connection,
buf: *mut ::libc::c_void,
size: isize,
blocked: *mut s2n_blocked_status::Type,
) -> isize;
}
extern "C" {
#[doc = " Allows users of s2n-tls to peek inside the data buffer of an s2n-tls connection to see if there more data to be read without actually reading it."]
#[doc = ""]
#[doc = " This is useful when using select() on the underlying s2n-tls file descriptor with a message based application layer protocol. As a single call"]
#[doc = " to s2n_recv may read all data off the underlying file descriptor, select() will be unable to tell you there if there is more application data"]
#[doc = " ready for processing already loaded into the s2n-tls buffer."]
#[doc = ""]
#[doc = " @note can then be used to determine if s2n_recv() needs to be called before more data comes in on the raw fd"]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @returns The number of bytes that can be read from the connection"]
pub fn s2n_peek(conn: *mut s2n_connection) -> u32;
}
extern "C" {
#[doc = " Wipes and releases buffers and memory allocated during the TLS handshake."]
#[doc = ""]
#[doc = " @note This function should be called after the handshake is successfully negotiated and logging or recording of handshake data is complete."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_free_handshake(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Wipes and free the `in` and `out` buffers associated with a connection."]
#[doc = ""]
#[doc = " @note This function may be called when a connection is"]
#[doc = " in keep-alive or idle state to reduce memory overhead of long lived connections."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_release_buffers(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Wipes an existing connection and allows it to be reused. Erases all data associated with a connection including"]
#[doc = " pending reads."]
#[doc = ""]
#[doc = " @note This function should be called after all I/O is completed and s2n_shutdown has been called."]
#[doc = " @note Reusing the same connection handle(s) is more performant than repeatedly calling s2n_connection_new() and s2n_connection_free()."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_wipe(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Frees the memory associated with an s2n_connection"]
#[doc = " handle. The handle is considered invalid after `s2n_connection_free` is used."]
#[doc = " s2n_connection_wipe() does not need to be called prior to this function. `s2n_connection_free` performs its own wipe"]
#[doc = " of sensitive data."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @returns 0 on success. -1 on failure"]
pub fn s2n_connection_free(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Attempts a closure at the TLS layer. Does not close the underlying transport. This call may block in either direction."]
#[doc = ""]
#[doc = " Unlike other TLS implementations, `s2n_shutdown` attempts a graceful shutdown by default. It will not return with success unless a close_notify alert is successfully"]
#[doc = " sent and received. As a result, `s2n_shutdown` may fail when interacting with a non-conformant TLS implementation."]
#[doc = ""]
#[doc = " Once `s2n_shutdown` is complete:"]
#[doc = " * The s2n_connection handle cannot be used for reading for writing."]
#[doc = " * The underlying transport can be closed. Most likely via `close()`."]
#[doc = " * The s2n_connection handle can be freed via s2n_connection_free() or reused via s2n_connection_wipe()"]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param blocked A pointer which will be set to the blocked status, as in s2n_negotiate()"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_shutdown(
conn: *mut s2n_connection,
blocked: *mut s2n_blocked_status::Type,
) -> ::libc::c_int;
}
pub mod s2n_cert_auth_type {
#[doc = " Used to declare what type of client certificate authentication to use."]
#[doc = ""]
#[doc = " Currently the default for s2n-tls is for neither the server side or the client side to use Client (aka Mutual) authentication."]
pub type Type = ::libc::c_uint;
pub const NONE: Type = 0;
pub const REQUIRED: Type = 1;
pub const OPTIONAL: Type = 2;
}
extern "C" {
#[doc = " Gets Client Certificate authentication method the s2n_config object is using."]
#[doc = ""]
#[doc = " @param config A pointer to a s2n_config object"]
#[doc = " @param client_auth_type A pointer to a client auth policy. This will be updated to the s2n_config value."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_get_client_auth_type(
config: *mut s2n_config,
client_auth_type: *mut s2n_cert_auth_type::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets whether or not a Client Certificate should be required to complete the TLS Connection."]
#[doc = ""]
#[doc = " If this is set to `S2N_CERT_AUTH_OPTIONAL` the server will request a client certificate but allow the client to not provide one."]
#[doc = " Rejecting a client certificate when using `S2N_CERT_AUTH_OPTIONAL` will terminate the handshake."]
#[doc = ""]
#[doc = " @param config A pointer to a s2n_config object"]
#[doc = " @param client_auth_type The client auth policy for the connection"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_client_auth_type(
config: *mut s2n_config,
client_auth_type: s2n_cert_auth_type::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets Client Certificate authentication method the s2n_connection object is using."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param client_auth_type A pointer to a client auth policy. This will be updated to the s2n_connection value."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_get_client_auth_type(
conn: *mut s2n_connection,
client_auth_type: *mut s2n_cert_auth_type::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets whether or not a Client Certificate should be required to complete the TLS Connection."]
#[doc = ""]
#[doc = " If this is set to `S2N_CERT_AUTH_OPTIONAL` the server will request a client certificate but allow the client to not provide one."]
#[doc = " Rejecting a client certificate when using `S2N_CERT_AUTH_OPTIONAL` will terminate the handshake."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param client_auth_type The client auth policy for the connection"]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_client_auth_type(
conn: *mut s2n_connection,
client_auth_type: s2n_cert_auth_type::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the client certificate chain and places it in the `der_cert_chain_out` buffer. `cert_chain_len` is updated"]
#[doc = " to match the size the chain buffer."]
#[doc = ""]
#[doc = " @warning The buffers share a lifetime with the s2n_connection object."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param der_cert_chain_out A uint8_t pointer. This will be updated to point to the client certificate chain."]
#[doc = " @param cert_chain_len A pointer to a uint32_t. This will be updated to match the size of the buffer `der_cert_chain_out` points to."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_get_client_cert_chain(
conn: *mut s2n_connection,
der_cert_chain_out: *mut *mut u8,
cert_chain_len: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the initial number of session tickets to send after a >=TLS1.3 handshake. The default value is one ticket."]
#[doc = ""]
#[doc = " @param config A pointer to the config object."]
#[doc = " @param num The number of session tickets that will be sent."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_config_set_initial_ticket_count(config: *mut s2n_config, num: u8) -> ::libc::c_int;
}
extern "C" {
#[doc = " Increases the number of session tickets to send after a >=TLS1.3 handshake."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection object."]
#[doc = " @param num The number of additional session tickets to send."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_add_new_tickets_to_send(
conn: *mut s2n_connection,
num: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the number of session tickets issued by the server."]
#[doc = ""]
#[doc = " In TLS1.3, this number can be up to the limit configured by s2n_config_set_initial_ticket_count"]
#[doc = " and s2n_connection_add_new_tickets_to_send. In earlier versions of TLS, this number will be either 0 or 1."]
#[doc = ""]
#[doc = " This method only works for server connections."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection object."]
#[doc = " @param num The number of additional session tickets sent."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_get_tickets_sent(
conn: *mut s2n_connection,
num: *mut u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the keying material lifetime for >=TLS1.3 session tickets so that one session doesn't get re-used ad infinitum."]
#[doc = " The default value is one week."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection object."]
#[doc = " @param lifetime_in_secs Lifetime of keying material in seconds."]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE on failure"]
pub fn s2n_connection_set_server_keying_material_lifetime(
conn: *mut s2n_connection,
lifetime_in_secs: u32,
) -> ::libc::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_session_ticket {
_unused: [u8; 0],
}
#[doc = " Callback function for receiving a session ticket."]
#[doc = ""]
#[doc = " This function will be called each time a session ticket is received, which may be multiple times for TLS1.3."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " `ctx` is a void pointer and the caller is responsible for ensuring it is cast to the correct type."]
#[doc = " `ticket` is valid only within the scope of this callback."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection object."]
#[doc = " @param ctx Context for the session ticket callback function."]
#[doc = " @param ticket Pointer to the received session ticket object."]
pub type s2n_session_ticket_fn = ::core::option::Option<
unsafe extern "C" fn(
conn: *mut s2n_connection,
ctx: *mut ::libc::c_void,
ticket: *mut s2n_session_ticket,
) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Sets a session ticket callback to be called when a client receives a new session ticket."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " `callback` MUST cast `ctx` into the same type of pointer that was originally created."]
#[doc = " `ctx` MUST be valid for the lifetime of the config, or until a different context is set."]
#[doc = ""]
#[doc = " @param config A pointer to the config object."]
#[doc = " @param callback The function that should be called when the callback is triggered."]
#[doc = " @param ctx The context to be passed when the callback is called."]
pub fn s2n_config_set_session_ticket_cb(
config: *mut s2n_config,
callback: s2n_session_ticket_fn,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the length of the session ticket from a session ticket object."]
#[doc = ""]
#[doc = " @param ticket Pointer to the session ticket object."]
#[doc = " @param data_len Pointer to be set to the length of the session ticket on success."]
pub fn s2n_session_ticket_get_data_len(
ticket: *mut s2n_session_ticket,
data_len: *mut usize,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the session ticket data from a session ticket object."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = " The entire session ticket will be copied into `data` on success. Therefore, `data` MUST have enough"]
#[doc = " memory to store the session ticket data."]
#[doc = ""]
#[doc = " @param ticket Pointer to the session ticket object."]
#[doc = " @param max_data_len Maximum length of data that can be written to the 'data' pointer."]
#[doc = " @param data Pointer to where the session ticket data will be stored."]
pub fn s2n_session_ticket_get_data(
ticket: *mut s2n_session_ticket,
max_data_len: usize,
data: *mut u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the lifetime in seconds of the session ticket from a session ticket object."]
#[doc = ""]
#[doc = " @param ticket Pointer to the session ticket object."]
#[doc = " @param session_lifetime Pointer to a variable where the lifetime of the session ticket will be stored."]
pub fn s2n_session_ticket_get_lifetime(
ticket: *mut s2n_session_ticket,
session_lifetime: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " De-serializes the session state and updates the connection accordingly."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param session A pointer to a buffer of size `length`"]
#[doc = " @param length The size of the `session` buffer"]
#[doc = ""]
#[doc = " @returns The number of copied bytes"]
pub fn s2n_connection_set_session(
conn: *mut s2n_connection,
session: *const u8,
length: usize,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Serializes the session state from connection and copies into the `session` buffer and returns the number of copied bytes"]
#[doc = ""]
#[doc = " @note This function is not recommended for > TLS 1.2 because in TLS1.3"]
#[doc = " servers can send multiple session tickets and this function will only"]
#[doc = " return the most recently received ticket."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param session A pointer to a buffer of size `max_length`"]
#[doc = " @param max_length The size of the `session` buffer"]
#[doc = ""]
#[doc = " @returns The number of copied bytes"]
pub fn s2n_connection_get_session(
conn: *mut s2n_connection,
session: *mut u8,
max_length: usize,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Retrieves a hint from the server indicating how long this ticket's lifetime is."]
#[doc = ""]
#[doc = " @note This function is not recommended for > TLS 1.2 because in TLS1.3"]
#[doc = " servers can send multiple session tickets and this function will only"]
#[doc = " return the most recently received ticket lifetime hint."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = ""]
#[doc = " @returns The session ticket lifetime hint in seconds from the server or -1 when session ticket was not used for resumption."]
pub fn s2n_connection_get_session_ticket_lifetime_hint(
conn: *mut s2n_connection,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Use this to query the serialized session state size before copying it into a buffer."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = ""]
#[doc = " @returns number of bytes needed to store serialized session state"]
pub fn s2n_connection_get_session_length(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the latest session id's length from the connection."]
#[doc = ""]
#[doc = " Use this to query the session id size before copying it into a buffer."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = ""]
#[doc = " @returns The latest session id length from the connection. Session id length will be 0 for TLS versions >= TLS1.3 as stateful session resumption has not yet been implemented in TLS1.3."]
pub fn s2n_connection_get_session_id_length(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the latest session id from the connection, copies it into the `session_id` buffer, and returns the number of copied bytes."]
#[doc = ""]
#[doc = " The session id may change between s2n receiving the ClientHello and sending the ServerHello, but this function will always describe the latest session id."]
#[doc = ""]
#[doc = " See s2n_client_hello_get_session_id() to get the session id as it was sent by the client in the ClientHello message."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param session_id A pointer to a buffer of size `max_length`"]
#[doc = " @param max_length The size of the `session_id` buffer"]
#[doc = ""]
#[doc = " @returns The number of copied bytes."]
pub fn s2n_connection_get_session_id(
conn: *mut s2n_connection,
session_id: *mut u8,
max_length: usize,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Check if the connection was resumed from an earlier handshake."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = ""]
#[doc = " @returns returns 1 if the handshake was abbreviated, otherwise returns 0"]
pub fn s2n_connection_is_session_resumed(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Check is the connection is OCSP stapled."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = ""]
#[doc = " @returns 1 if OCSP response was sent (if connection is in S2N_SERVER mode) or received (if connection is in S2N_CLIENT mode) during handshake, otherwise it returns 0."]
pub fn s2n_connection_is_ocsp_stapled(conn: *mut s2n_connection) -> ::libc::c_int;
}
pub mod s2n_tls_signature_algorithm {
#[doc = " TLS Signature Algorithms - RFC 5246 7.4.1.4.1"]
#[doc = " https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16"]
pub type Type = ::libc::c_uint;
pub const ANONYMOUS: Type = 0;
pub const RSA: Type = 1;
pub const ECDSA: Type = 3;
pub const RSA_PSS_RSAE: Type = 224;
pub const RSA_PSS_PSS: Type = 225;
}
pub mod s2n_tls_hash_algorithm {
#[doc = " TLS Hash Algorithms - https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1"]
#[doc = " https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-18"]
pub type Type = ::libc::c_uint;
pub const NONE: Type = 0;
pub const MD5: Type = 1;
pub const SHA1: Type = 2;
pub const SHA224: Type = 3;
pub const SHA256: Type = 4;
pub const SHA384: Type = 5;
pub const SHA512: Type = 6;
pub const MD5_SHA1: Type = 224;
}
extern "C" {
#[doc = " Get the connection's selected signature algorithm."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param chosen_alg A pointer to a s2n_tls_signature_algorithm object. This is an output parameter."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE if bad parameters are received."]
pub fn s2n_connection_get_selected_signature_algorithm(
conn: *mut s2n_connection,
chosen_alg: *mut s2n_tls_signature_algorithm::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the connection's selected digest algorithm."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param chosen_alg A pointer to a s2n_tls_hash_algorithm object. This is an output parameter."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE if bad parameters are received."]
pub fn s2n_connection_get_selected_digest_algorithm(
conn: *mut s2n_connection,
chosen_alg: *mut s2n_tls_hash_algorithm::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the client certificate's signature algorithm."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param chosen_alg A pointer to a s2n_tls_signature_algorithm object. This is an output parameter."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE if bad parameters are received."]
pub fn s2n_connection_get_selected_client_cert_signature_algorithm(
conn: *mut s2n_connection,
chosen_alg: *mut s2n_tls_signature_algorithm::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the client certificate's digest algorithm."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = " @param chosen_alg A pointer to a s2n_tls_hash_algorithm object. This is an output parameter."]
#[doc = ""]
#[doc = " @returns S2N_SUCCESS on success. S2N_FAILURE if bad parameters are received."]
pub fn s2n_connection_get_selected_client_cert_digest_algorithm(
conn: *mut s2n_connection,
chosen_alg: *mut s2n_tls_hash_algorithm::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the certificate used during the TLS handshake"]
#[doc = ""]
#[doc = " - If `conn` is a server connection, the certificate selected will depend on the"]
#[doc = " ServerName sent by the client and supported ciphers."]
#[doc = " - If `conn` is a client connection, the certificate sent in response to a CertificateRequest"]
#[doc = " message is returned. Currently s2n-tls supports loading only one certificate in client mode. Note that"]
#[doc = " not all TLS endpoints will request a certificate."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object"]
#[doc = ""]
#[doc = " @returns NULL if the certificate selection phase of the handshake has not completed or if a certificate was not requested by the peer"]
pub fn s2n_connection_get_selected_cert(
conn: *mut s2n_connection,
) -> *mut s2n_cert_chain_and_key;
}
extern "C" {
#[doc = " @param chain_and_key A pointer to the s2n_cert_chain_and_key object being read."]
#[doc = " @param cert_length This return value represents the length of the s2n certificate chain `chain_and_key`."]
#[doc = " @returns the length of the s2n certificate chain `chain_and_key`."]
pub fn s2n_cert_chain_get_length(
chain_and_key: *const s2n_cert_chain_and_key,
cert_length: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the certificate `out_cert` present at the index `cert_idx` of the certificate chain `chain_and_key`."]
#[doc = ""]
#[doc = " Note that the index of the leaf certificate is zero. If the certificate chain `chain_and_key` is NULL or the"]
#[doc = " certificate index value is not in the acceptable range for the input certificate chain, an error is returned."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " There is no memory allocation required for `out_cert` buffer prior to calling the `s2n_cert_chain_get_cert` API."]
#[doc = " The `out_cert` will contain the pointer to the s2n_cert initialized within the input s2n_cert_chain_and_key `chain_and_key`."]
#[doc = " The pointer to the output s2n certificate `out_cert` is valid until `chain_and_key` is freed up."]
#[doc = " If a caller wishes to persist the `out_cert` beyond the lifetime of `chain_and_key`, the contents would need to be"]
#[doc = " copied prior to freeing `chain_and_key`."]
#[doc = ""]
#[doc = " @param chain_and_key A pointer to the s2n_cert_chain_and_key object being read."]
#[doc = " @param out_cert A pointer to the output s2n_cert `out_cert` present at the index `cert_idx` of the certificate chain `chain_and_key`."]
#[doc = " @param cert_idx The certificate index for the requested certificate within the s2n certificate chain."]
pub fn s2n_cert_chain_get_cert(
chain_and_key: *const s2n_cert_chain_and_key,
out_cert: *mut *mut s2n_cert,
cert_idx: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the s2n certificate in DER format along with its length."]
#[doc = ""]
#[doc = " The API gets the s2n certificate `cert` in DER format. The certificate is returned in the `out_cert_der` buffer."]
#[doc = " Here, `cert_len` represents the length of the certificate."]
#[doc = ""]
#[doc = " A caller can use certificate parsing tools such as the ones provided by OpenSSL to parse the DER encoded certificate chain returned."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " The memory for the `out_cert_der` buffer is allocated and owned by s2n-tls."]
#[doc = " Since the size of the certificate can potentially be very large, a pointer to internal connection data is returned instead of"]
#[doc = " copying the contents into a caller-provided buffer."]
#[doc = ""]
#[doc = " The pointer to the output buffer `out_cert_der` is valid only while the connection exists."]
#[doc = " The `s2n_connection_free` API frees the memory associated with the out_cert_der buffer and after the `s2n_connection_wipe` API is"]
#[doc = " called the memory pointed by out_cert_der is invalid."]
#[doc = ""]
#[doc = " If a caller wishes to persist the `out_cert_der` beyond the lifetime of the connection, the contents would need to be"]
#[doc = " copied prior to the connection termination."]
#[doc = ""]
#[doc = " @param cert A pointer to the s2n_cert object being read."]
#[doc = " @param out_cert_der A pointer to the output buffer which will hold the s2n certificate `cert` in DER format."]
#[doc = " @param cert_length This return value represents the length of the certificate."]
pub fn s2n_cert_get_der(
cert: *const s2n_cert,
out_cert_der: *mut *const u8,
cert_length: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the validated peer certificate chain as a `s2n_cert_chain_and_key` opaque object."]
#[doc = ""]
#[doc = " The `s2n_cert_chain_and_key` parameter must be allocated by the caller using the `s2n_cert_chain_and_key_new` API"]
#[doc = " prior to this function call and must be empty. To free the memory associated with the `s2n_cert_chain_and_key` object use the"]
#[doc = " `s2n_cert_chain_and_key_free` API."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object being read."]
#[doc = " @param cert_chain The returned validated peer certificate chain `cert_chain` retrieved from the s2n connection."]
pub fn s2n_connection_get_peer_cert_chain(
conn: *const s2n_connection,
cert_chain: *mut s2n_cert_chain_and_key,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the length of the DER encoded extension value of the ASN.1 X.509 certificate extension."]
#[doc = ""]
#[doc = " @param cert A pointer to the s2n_cert object being read."]
#[doc = " @param oid A null-terminated cstring that contains the OID of the X.509 certificate extension to be read."]
#[doc = " @param ext_value_len This return value contains the length of DER encoded extension value of the ASN.1 X.509 certificate extension."]
pub fn s2n_cert_get_x509_extension_value_length(
cert: *mut s2n_cert,
oid: *const u8,
ext_value_len: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the DER encoding of an ASN.1 X.509 certificate extension value, it's length and a boolean critical."]
#[doc = ""]
#[doc = " @param cert A pointer to the s2n_cert object being read."]
#[doc = " @param oid A null-terminated cstring that contains the OID of the X.509 certificate extension to be read."]
#[doc = " @param ext_value A pointer to the output buffer which will hold the DER encoding of an ASN.1 X.509 certificate extension value returned."]
#[doc = " @param ext_value_len This value is both an input and output parameter and represents the length of the output buffer `ext_value`."]
#[doc = " When used as an input parameter, the caller must use this parameter to convey the maximum length of `ext_value`."]
#[doc = " When used as an output parameter, `ext_value_len` holds the actual length of the DER encoding of the ASN.1 X.509 certificate extension value returned."]
#[doc = " @param critical This return value contains the boolean value for `critical`."]
pub fn s2n_cert_get_x509_extension_value(
cert: *mut s2n_cert,
oid: *const u8,
ext_value: *mut u8,
ext_value_len: *mut u32,
critical: *mut bool,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the UTF8 String length of the ASN.1 X.509 certificate extension data."]
#[doc = ""]
#[doc = " @param extension_data A pointer to the DER encoded ASN.1 X.509 certificate extension value being read."]
#[doc = " @param extension_len represents the length of the input buffer `extension_data`."]
#[doc = " @param utf8_str_len This return value contains the UTF8 String length of the ASN.1 X.509 certificate extension data."]
pub fn s2n_cert_get_utf8_string_from_extension_data_length(
extension_data: *const u8,
extension_len: u32,
utf8_str_len: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the UTF8 String representation of the DER encoded ASN.1 X.509 certificate extension data."]
#[doc = ""]
#[doc = " @param extension_data A pointer to the DER encoded ASN.1 X.509 certificate extension value being read."]
#[doc = " @param extension_len represents the length of the input buffer `extension_data`."]
#[doc = " @param out_data A pointer to the output buffer which will hold the UTF8 String representation of the DER encoded ASN.1 X.509"]
#[doc = " certificate extension data returned."]
#[doc = " @param out_len This value is both an input and output parameter and represents the length of the output buffer `out_data`."]
#[doc = " When used as an input parameter, the caller must use this parameter to convey the maximum length of `out_data`."]
#[doc = " When used as an output parameter, `out_len` holds the actual length of UTF8 String returned."]
pub fn s2n_cert_get_utf8_string_from_extension_data(
extension_data: *const u8,
extension_len: u32,
out_data: *mut u8,
out_len: *mut u32,
) -> ::libc::c_int;
}
pub mod s2n_psk_hmac {
#[doc = " Pre-shared key (PSK) Hash Algorithm - RFC 8446 Section-2.2"]
pub type Type = ::libc::c_uint;
pub const SHA256: Type = 0;
pub const SHA384: Type = 1;
}
#[doc = " Opaque pre shared key handle"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_psk {
_unused: [u8; 0],
}
extern "C" {
#[doc = " Creates a new s2n external pre-shared key (PSK) object with `S2N_PSK_HMAC_SHA256` as the default"]
#[doc = " PSK hash algorithm. An external PSK is a key established outside of TLS using a secure mutually agreed upon mechanism."]
#[doc = ""]
#[doc = " Use `s2n_psk_free` to free the memory allocated to the s2n external PSK object created by this API."]
#[doc = ""]
#[doc = " @returns struct s2n_psk* Returns a pointer to the newly created external PSK object."]
pub fn s2n_external_psk_new() -> *mut s2n_psk;
}
extern "C" {
#[doc = " Frees the memory associated with the external PSK object."]
#[doc = ""]
#[doc = " @param psk Pointer to the PSK object to be freed."]
pub fn s2n_psk_free(psk: *mut *mut s2n_psk) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the identity for a given external PSK object."]
#[doc = " The identity is a unique identifier for the pre-shared secret."]
#[doc = " It is a non-secret value represented by raw bytes."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " The identity is transmitted over the network unencrypted and is a non-secret value."]
#[doc = " Do not include confidential information in the identity."]
#[doc = ""]
#[doc = " Note that the identity is copied into s2n-tls memory and the caller is responsible for"]
#[doc = " freeing the memory associated with the identity input."]
#[doc = ""]
#[doc = " @param psk A pointer to a PSK object to be updated with the identity."]
#[doc = " @param identity The identity in raw bytes format to be copied."]
#[doc = " @param identity_size The length of the PSK identity being set."]
pub fn s2n_psk_set_identity(
psk: *mut s2n_psk,
identity: *const u8,
identity_size: u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the out-of-band/externally provisioned secret for a given external PSK object."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " Note that the secret is copied into s2n-tls memory and the caller is responsible for"]
#[doc = " freeing the memory associated with the `secret` input."]
#[doc = ""]
#[doc = " Deriving a shared secret from a password or other low-entropy source"]
#[doc = " is not secure and is subject to dictionary attacks."]
#[doc = " See https://tools.ietf.org/rfc/rfc8446#section-2.2 for more information."]
#[doc = ""]
#[doc = " @param psk A pointer to a PSK object to be updated with the secret."]
#[doc = " @param secret The secret in raw bytes format to be copied."]
#[doc = " @param secret_size The length of the pre-shared secret being set."]
pub fn s2n_psk_set_secret(
psk: *mut s2n_psk,
secret: *const u8,
secret_size: u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the hash algorithm for a given external PSK object. The supported PSK hash"]
#[doc = " algorithms are as listed in the enum `s2n_psk_hmac` above."]
#[doc = ""]
#[doc = " @param psk A pointer to the external PSK object to be updated with the PSK hash algorithm."]
#[doc = " @param hmac The PSK hash algorithm being set."]
pub fn s2n_psk_set_hmac(psk: *mut s2n_psk, hmac: s2n_psk_hmac::Type) -> ::libc::c_int;
}
extern "C" {
#[doc = " Appends a PSK object to the list of PSKs supported by the s2n connection."]
#[doc = " If a PSK with a duplicate identity is found, an error is returned and the PSK is not added to the list."]
#[doc = " Note that a copy of `psk` is stored on the connection. The user is still responsible for freeing the"]
#[doc = " memory associated with `psk`."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object that contains the list of PSKs supported."]
#[doc = " @param psk A pointer to the `s2n_psk` object to be appended to the list of PSKs on the s2n connection."]
pub fn s2n_connection_append_psk(conn: *mut s2n_connection, psk: *mut s2n_psk)
-> ::libc::c_int;
}
pub mod s2n_psk_mode {
#[doc = " The list of PSK modes supported by s2n-tls for TLS versions >= TLS1.3."]
#[doc = " Currently s2n-tls supports two modes - `S2N_PSK_MODE_RESUMPTION`, which represents the PSKs established"]
#[doc = " using the previous connection via session resumption, and `S2N_PSK_MODE_EXTERNAL`, which represents PSKs"]
#[doc = " established out-of-band/externally using a secure mutually agreed upon mechanism."]
pub type Type = ::libc::c_uint;
pub const RESUMPTION: Type = 0;
pub const EXTERNAL: Type = 1;
}
extern "C" {
#[doc = " Sets the PSK mode on the s2n config object."]
#[doc = " The supported PSK modes are listed in the enum `s2n_psk_mode` above."]
#[doc = ""]
#[doc = " @param config A pointer to the s2n_config object being updated."]
#[doc = " @param mode The PSK mode to be set."]
pub fn s2n_config_set_psk_mode(
config: *mut s2n_config,
mode: s2n_psk_mode::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the PSK mode on the s2n connection object."]
#[doc = " The supported PSK modes are listed in the enum `s2n_psk_mode` above."]
#[doc = " This API overrides the PSK mode set on config for this connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object being updated."]
#[doc = " @param mode The PSK mode to be set."]
pub fn s2n_connection_set_psk_mode(
conn: *mut s2n_connection,
mode: s2n_psk_mode::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the negotiated PSK identity length from the s2n connection object. The negotiated PSK"]
#[doc = " refers to the chosen PSK by the server to be used for the connection."]
#[doc = ""]
#[doc = " This API can be used to determine if the negotiated PSK exists. If negotiated PSK exists a"]
#[doc = " call to this API returns a value greater than zero. If the negotiated PSK does not exist, the"]
#[doc = " value `0` is returned."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object that successfully negotiated a PSK connection."]
#[doc = " @param identity_length The length of the negotiated PSK identity."]
pub fn s2n_connection_get_negotiated_psk_identity_length(
conn: *mut s2n_connection,
identity_length: *mut u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the negotiated PSK identity from the s2n connection object."]
#[doc = " If the negotiated PSK does not exist, the PSK identity will not be obtained and no error will be returned."]
#[doc = " Prior to this API call, use `s2n_connection_get_negotiated_psk_identity_length` to determine if a"]
#[doc = " negotiated PSK exists or not."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " The negotiated PSK identity will be copied into the identity buffer on success."]
#[doc = " Therefore, the identity buffer must have enough memory to fit the identity length."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object."]
#[doc = " @param identity The negotiated PSK identity obtained from the s2n_connection object."]
#[doc = " @param max_identity_length The maximum length for the PSK identity. If the negotiated psk_identity length is"]
#[doc = " greater than this `max_identity_length` value an error will be returned."]
pub fn s2n_connection_get_negotiated_psk_identity(
conn: *mut s2n_connection,
identity: *mut u8,
max_identity_length: u16,
) -> ::libc::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_offered_psk {
_unused: [u8; 0],
}
extern "C" {
#[doc = " Creates a new s2n offered PSK object."]
#[doc = " An offered PSK object represents a single PSK sent by the client."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " Use `s2n_offered_psk_free` to free the memory allocated to the s2n offered PSK object created by this API."]
#[doc = ""]
#[doc = " @returns struct s2n_offered_psk* Returns a pointer to the newly created offered PSK object."]
pub fn s2n_offered_psk_new() -> *mut s2n_offered_psk;
}
extern "C" {
#[doc = " Frees the memory associated with the `s2n_offered_psk` object."]
#[doc = ""]
#[doc = " @param psk A pointer to the `s2n_offered_psk` object to be freed."]
pub fn s2n_offered_psk_free(psk: *mut *mut s2n_offered_psk) -> ::libc::c_int;
}
extern "C" {
#[doc = " Gets the PSK identity and PSK identity length for a given offered PSK object."]
#[doc = ""]
#[doc = " @param psk A pointer to the offered PSK object being read."]
#[doc = " @param identity The PSK identity being obtained."]
#[doc = " @param size The length of the PSK identity being obtained."]
pub fn s2n_offered_psk_get_identity(
psk: *mut s2n_offered_psk,
identity: *mut *mut u8,
size: *mut u16,
) -> ::libc::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_offered_psk_list {
_unused: [u8; 0],
}
extern "C" {
#[doc = " Checks whether the offered PSK list has an offered psk object next in line in the list."]
#[doc = " An offered PSK list contains all the PSKs offered by the client for the server to select."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " This API returns a pointer to the s2n-tls internal memory with limited lifetime."]
#[doc = " After the completion of `s2n_psk_selection_callback` this pointer is invalid."]
#[doc = ""]
#[doc = " @param psk_list A pointer to the offered PSK list being read."]
#[doc = " @returns bool A boolean value representing whether an offered psk object is present next in line in the offered PSK list."]
pub fn s2n_offered_psk_list_has_next(psk_list: *mut s2n_offered_psk_list) -> bool;
}
extern "C" {
#[doc = " Obtains the next offered PSK object from the list of offered PSKs. Use `s2n_offered_psk_list_has_next`"]
#[doc = " prior to this API call to ensure we have not reached the end of the list."]
#[doc = ""]
#[doc = " @param psk_list A pointer to the offered PSK list being read."]
#[doc = " @param psk A pointer to the next offered PSK object being obtained."]
pub fn s2n_offered_psk_list_next(
psk_list: *mut s2n_offered_psk_list,
psk: *mut s2n_offered_psk,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the offered PSK list to its original read state."]
#[doc = ""]
#[doc = " When `s2n_offered_psk_list_reread` is called, `s2n_offered_psk_list_next` will return the first PSK"]
#[doc = " in the offered PSK list."]
#[doc = ""]
#[doc = " @param psk_list A pointer to the offered PSK list being reread."]
pub fn s2n_offered_psk_list_reread(psk_list: *mut s2n_offered_psk_list) -> ::libc::c_int;
}
extern "C" {
#[doc = " Chooses a PSK from the offered PSK list to be used for the connection."]
#[doc = " This API matches the PSK identity received from the client against the server's known PSK identities"]
#[doc = " list, in order to choose the PSK to be used for the connection. If the PSK identity sent from the client"]
#[doc = " is NULL, no PSK is chosen for the connection. If the client offered PSK identity has no matching PSK identity"]
#[doc = " with the server, an error will be returned. Use this API along with the `s2n_psk_selection_callback` callback"]
#[doc = " to select a PSK identity."]
#[doc = ""]
#[doc = " @param psk_list A pointer to the server's known PSK list used to compare for a matching PSK with the client."]
#[doc = " @param psk A pointer to the client's PSK object used to compare with the server's known PSK identities."]
pub fn s2n_offered_psk_list_choose_psk(
psk_list: *mut s2n_offered_psk_list,
psk: *mut s2n_offered_psk,
) -> ::libc::c_int;
}
#[doc = " Callback function to select a PSK from a list of offered PSKs."]
#[doc = " Use this callback to implement custom PSK selection logic. The s2n-tls default PSK selection logic"]
#[doc = " chooses the first matching PSK from the list of offered PSKs sent by the client."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " `context` is a void pointer and the caller is responsible for ensuring it is cast to the correct type."]
#[doc = " After the completion of this callback, the pointer to `psk_list` is invalid."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n_connection object."]
#[doc = " @param context A pointer to a context for the caller to pass state to the callback, if needed."]
#[doc = " @param psk_list A pointer to the offered PSK list being read."]
pub type s2n_psk_selection_callback = ::core::option::Option<
unsafe extern "C" fn(
conn: *mut s2n_connection,
context: *mut ::libc::c_void,
psk_list: *mut s2n_offered_psk_list,
) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Sets the callback to select the matching PSK."]
#[doc = " If this callback is not set s2n-tls uses a default PSK selection logic that selects the first matching"]
#[doc = " server PSK."]
#[doc = ""]
#[doc = " @param config A pointer to the s2n_config object."]
#[doc = " @param cb The function that should be called when the callback is triggered."]
#[doc = " @param context A pointer to a context for the caller to pass state to the callback, if needed."]
pub fn s2n_config_set_psk_selection_callback(
config: *mut s2n_config,
cb: s2n_psk_selection_callback,
context: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the number of bytes the connection has received."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns return the number of bytes received by s2n-tls \"on the wire\""]
pub fn s2n_connection_get_wire_bytes_in(conn: *mut s2n_connection) -> u64;
}
extern "C" {
#[doc = " Get the number of bytes the connection has transmitted out."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns return the number of bytes transmitted out by s2n-tls \"on the wire\""]
pub fn s2n_connection_get_wire_bytes_out(conn: *mut s2n_connection) -> u64;
}
extern "C" {
#[doc = " Access the protocol version supported by the client of the connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns returns the protocol version number supported by the client_auth_type"]
pub fn s2n_connection_get_client_protocol_version(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Access the protocol version supported by the server of the connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns Returns the protocol version number supported by the server"]
pub fn s2n_connection_get_server_protocol_version(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Access the protocol version selected for the connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns The protocol version number actually used by s2n-tls for the connection"]
pub fn s2n_connection_get_actual_protocol_version(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Access the client hello protocol version for the connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns The protocol version used to send the initial client hello message."]
pub fn s2n_connection_get_client_hello_version(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Check if Client Auth was used for a connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns 1 if the handshake completed and Client Auth was negotiated during then"]
#[doc = " handshake."]
pub fn s2n_connection_client_cert_used(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " A function that provides a human readable string of the cipher suite that was chosen"]
#[doc = " for a connection."]
#[doc = ""]
#[doc = " @warning The string \"TLS_NULL_WITH_NULL_NULL\" is returned before the TLS handshake has been performed."]
#[doc = " This does not mean that the ciphersuite \"TLS_NULL_WITH_NULL_NULL\" will be used by the connection,"]
#[doc = " it is merely being used as a placeholder."]
#[doc = ""]
#[doc = " @note This function is only accurate after the TLS handshake."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @returns A string indicating the cipher suite negotiated by s2n in OpenSSL format."]
pub fn s2n_connection_get_cipher(conn: *mut s2n_connection) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Returns the IANA value for the connection's negotiated cipher suite."]
#[doc = ""]
#[doc = " The value is returned in the form of `first,second`, in order to closely match"]
#[doc = " the values defined in the [IANA Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#table-tls-parameters-4)."]
#[doc = " For example if the connection's negotiated cipher suite is `TLS_AES_128_GCM_SHA256`,"]
#[doc = " which is registered as `0x13,0x01`, then `first = 0x13` and `second = 0x01`."]
#[doc = ""]
#[doc = " This method will only succeed after the cipher suite has been negotiated with the peer."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection being read"]
#[doc = " @param first A pointer to a single byte, which will be updated with the first byte in the registered IANA value."]
#[doc = " @param second A pointer to a single byte, which will be updated with the second byte in the registered IANA value."]
#[doc = " @returns A POSIX error signal. If an error was returned, the values contained in `first` and `second` should be considered invalid."]
pub fn s2n_connection_get_cipher_iana_value(
conn: *mut s2n_connection,
first: *mut u8,
second: *mut u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Function to check if the cipher used by current connection is supported by the current"]
#[doc = " cipher preferences."]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @param version A string representing the security policy to check against."]
#[doc = " @returns 1 if the connection satisfies the cipher suite. 0 if the connection does not satisfy the cipher suite. -1 if there is an error."]
pub fn s2n_connection_is_valid_for_cipher_preferences(
conn: *mut s2n_connection,
version: *const ::libc::c_char,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Function to get the human readable elliptic curve name for the connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @returns A string indicating the elliptic curve used during ECDHE key exchange. The string \"NONE\" is returned if no curve was used."]
pub fn s2n_connection_get_curve(conn: *mut s2n_connection) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Function to get the human readable KEM name for the connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @returns A human readable string for the KEM group. If there is no KEM configured returns \"NONE\""]
pub fn s2n_connection_get_kem_name(conn: *mut s2n_connection) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Function to get the human readable KEM group name for the connection."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @returns A human readable string for the KEM group. If the connection is < TLS1.3 or there is no KEM group configured returns \"NONE\""]
pub fn s2n_connection_get_kem_group_name(conn: *mut s2n_connection) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Function to get the alert that caused a connection to close. s2n-tls considers all"]
#[doc = " TLS alerts fatal and shuts down a connection whenever one is received."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @returns The TLS alert code that caused a connection to be shut down"]
pub fn s2n_connection_get_alert(conn: *mut s2n_connection) -> ::libc::c_int;
}
extern "C" {
#[doc = " Function to return the last TLS handshake type that was processed. The returned format is a human readable string."]
#[doc = ""]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @returns A human-readable handshake type name, e.g. \"NEGOTIATED|FULL_HANDSHAKE|PERFECT_FORWARD_SECRECY\""]
pub fn s2n_connection_get_handshake_type_name(
conn: *mut s2n_connection,
) -> *const ::libc::c_char;
}
extern "C" {
#[doc = " Function to return the last TLS message that was processed. The returned format is a human readable string."]
#[doc = " @param conn A pointer to the s2n connection"]
#[doc = " @returns The last message name in the TLS state machine, e.g. \"SERVER_HELLO\", \"APPLICATION_DATA\"."]
pub fn s2n_connection_get_last_message_name(conn: *mut s2n_connection)
-> *const ::libc::c_char;
}
#[doc = " Opaque async private key operation handle"]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_async_pkey_op {
_unused: [u8; 0],
}
pub mod s2n_async_pkey_validation_mode {
#[doc = " Sets whether or not a connection should enforce strict signature validation during the"]
#[doc = " `s2n_async_pkey_op_apply` call."]
#[doc = ""]
#[doc = " `mode` can take the following values:"]
#[doc = " - `S2N_ASYNC_PKEY_VALIDATION_FAST` - default behavior: s2n-tls will perform only the minimum validation required for safe use of the asyn pkey operation."]
#[doc = " - `S2N_ASYNC_PKEY_VALIDATION_STRICT` - in addition to the previous checks, s2n-tls will also ensure that the signature created as a result of the async private key sign operation matches the public key on the connection."]
pub type Type = ::libc::c_uint;
pub const FAST: Type = 0;
pub const STRICT: Type = 1;
}
pub mod s2n_async_pkey_op_type {
#[doc = " The type of private key operation"]
pub type Type = ::libc::c_uint;
pub const DECRYPT: Type = 0;
pub const SIGN: Type = 1;
}
#[doc = " Callback function for handling private key operations"]
#[doc = ""]
#[doc = " Invoked every time an operation requiring the private key is encountered"]
#[doc = " during the handshake."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = " * `op` is owned by the application and MUST be freed."]
#[doc = ""]
#[doc = " @param conn Connection which triggered the callback"]
#[doc = " @param op An opaque object representing the private key operation"]
pub type s2n_async_pkey_fn = ::core::option::Option<
unsafe extern "C" fn(conn: *mut s2n_connection, op: *mut s2n_async_pkey_op) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Sets up the callback to invoke when private key operations occur."]
#[doc = ""]
#[doc = " @param config Config to set the callback"]
#[doc = " @param fn The function that should be called for each private key operation"]
pub fn s2n_config_set_async_pkey_callback(
config: *mut s2n_config,
fn_: s2n_async_pkey_fn,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Performs a private key operation using the given private key."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = " * Can only be called once. Any subsequent calls will produce a `S2N_ERR_T_USAGE` error."]
#[doc = " * Safe to call from inside s2n_async_pkey_fn"]
#[doc = " * Safe to call from a different thread, as long as no other thread is operating on `op`."]
#[doc = ""]
#[doc = " @param op An opaque object representing the private key operation"]
#[doc = " @param key The private key used for the operation. It can be extracted from"]
#[doc = " `conn` through the `s2n_connection_get_selected_cert` and `s2n_cert_chain_and_key_get_private_key` calls"]
pub fn s2n_async_pkey_op_perform(
op: *mut s2n_async_pkey_op,
key: *mut s2n_cert_private_key,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Finalizes a private key operation and unblocks the connection."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = " * `conn` must match the connection that originally triggered the callback."]
#[doc = " * Must be called after the operation is performed."]
#[doc = " * Can only be called once. Any subsequent calls will produce a `S2N_ERR_T_USAGE` error."]
#[doc = " * Safe to call from inside s2n_async_pkey_fn"]
#[doc = " * Safe to call from a different thread, as long as no other thread is operating on `op`."]
#[doc = ""]
#[doc = " @param op An opaque object representing the private key operation"]
#[doc = " @param conn The connection associated with the operation that should be unblocked"]
pub fn s2n_async_pkey_op_apply(
op: *mut s2n_async_pkey_op,
conn: *mut s2n_connection,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Frees the opaque structure representing a private key operation."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = " * MUST be called for every operation passed to s2n_async_pkey_fn"]
#[doc = " * Safe to call before or after the connection that created the operation is freed"]
#[doc = ""]
#[doc = " @param op An opaque object representing the private key operation"]
pub fn s2n_async_pkey_op_free(op: *mut s2n_async_pkey_op) -> ::libc::c_int;
}
extern "C" {
#[doc = " Configures whether or not s2n-tls will perform potentially expensive validation of"]
#[doc = " the results of a private key operation."]
#[doc = ""]
#[doc = " @param config Config to set the validation mode for"]
#[doc = " @param mode What level of validation to perform"]
pub fn s2n_config_set_async_pkey_validation_mode(
config: *mut s2n_config,
mode: s2n_async_pkey_validation_mode::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the type of the private key operation."]
#[doc = ""]
#[doc = " @param op An opaque object representing the private key operation"]
#[doc = " @param type A pointer to be set to the type"]
pub fn s2n_async_pkey_op_get_op_type(
op: *mut s2n_async_pkey_op,
type_: *mut s2n_async_pkey_op_type::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the size of the input to the private key operation."]
#[doc = ""]
#[doc = " @param op An opaque object representing the private key operation"]
#[doc = " @param data_len A pointer to be set to the size"]
pub fn s2n_async_pkey_op_get_input_size(
op: *mut s2n_async_pkey_op,
data_len: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Returns the input to the private key operation."]
#[doc = ""]
#[doc = " When signing, the input is the digest to sign."]
#[doc = " When decrypting, the input is the data to decrypt."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = " * `data` must be sufficiently large to contain the input."]
#[doc = " `s2n_async_pkey_op_get_input_size` can be called to determine how much memory is required."]
#[doc = " * s2n-tls does not take ownership of `data`."]
#[doc = " The application still owns the memory and must free it if necessary."]
#[doc = ""]
#[doc = " @param op An opaque object representing the private key operation"]
#[doc = " @param data A pointer to a buffer to copy the input into"]
#[doc = " @param data_len The maximum size of the `data` buffer"]
pub fn s2n_async_pkey_op_get_input(
op: *mut s2n_async_pkey_op,
data: *mut u8,
data_len: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the output of the private key operation."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = " * s2n-tls does not take ownership of `data`."]
#[doc = " The application still owns the memory and must free it if necessary."]
#[doc = ""]
#[doc = " @param op An opaque object representing the private key operation"]
#[doc = " @param data A pointer to a buffer containing the output"]
#[doc = " @param data_len The size of the `data` buffer"]
pub fn s2n_async_pkey_op_set_output(
op: *mut s2n_async_pkey_op,
data: *const u8,
data_len: u32,
) -> ::libc::c_int;
}
#[doc = " Callback function for handling key log events"]
#[doc = ""]
#[doc = " THIS SHOULD BE USED FOR DEBUGGING PURPOSES ONLY!"]
#[doc = ""]
#[doc = " Each log line is formatted with the"]
#[doc = " [NSS Key Log Format](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format)"]
#[doc = " without a newline."]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " * `ctx` MUST be cast into the same type of pointer that was originally created"]
#[doc = " * `logline` bytes MUST be copied or discarded before this function returns"]
#[doc = ""]
#[doc = " @param ctx Context for the callback"]
#[doc = " @param conn Connection for which the log line is being emitted"]
#[doc = " @param logline Pointer to the log line data"]
#[doc = " @param len Length of the log line data"]
pub type s2n_key_log_fn = ::core::option::Option<
unsafe extern "C" fn(
ctx: *mut ::libc::c_void,
conn: *mut s2n_connection,
logline: *mut u8,
len: usize,
) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Sets a key logging callback on the provided config"]
#[doc = ""]
#[doc = " THIS SHOULD BE USED FOR DEBUGGING PURPOSES ONLY!"]
#[doc = ""]
#[doc = " Setting this function enables configurations to emit secrets in the"]
#[doc = " [NSS Key Log Format](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format)"]
#[doc = ""]
#[doc = " # Safety"]
#[doc = ""]
#[doc = " * `callback` MUST cast `ctx` into the same type of pointer that was originally created"]
#[doc = " * `ctx` MUST live for at least as long as it is set on the config"]
#[doc = ""]
#[doc = " @param config Config to set the callback"]
#[doc = " @param callback The function that should be called for each secret log entry"]
#[doc = " @param ctx The context to be passed when the callback is called"]
pub fn s2n_config_set_key_log_cb(
config: *mut s2n_config,
callback: s2n_key_log_fn,
ctx: *mut ::libc::c_void,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " s2n_config_enable_cert_req_dss_legacy_compat adds a dss cert type in the server certificate request when being called."]
#[doc = " It only sends the dss cert type in the cert request but does not succeed the handshake if a dss cert is received."]
#[doc = " Please DO NOT call this api unless you know you actually need legacy DSS certificate type compatibility"]
#[doc = " @param config Config to enable legacy DSS certificates for"]
pub fn s2n_config_enable_cert_req_dss_legacy_compat(config: *mut s2n_config) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the maximum bytes of early data the server will accept."]
#[doc = ""]
#[doc = " The default maximum is 0. If the maximum is 0, the server rejects all early data requests."]
#[doc = " The config maximum can be overridden by the connection maximum or the maximum on an external pre-shared key."]
#[doc = ""]
#[doc = " @param config A pointer to the config"]
#[doc = " @param max_early_data_size The maximum early data that the server will accept"]
#[doc = " @returns A POSIX error signal. If successful, the maximum early data size was updated."]
pub fn s2n_config_set_server_max_early_data_size(
config: *mut s2n_config,
max_early_data_size: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the maximum bytes of early data the server will accept."]
#[doc = ""]
#[doc = " The default maximum is 0. If the maximum is 0, the server rejects all early data requests."]
#[doc = " The connection maximum can be overridden by the maximum on an external pre-shared key."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param max_early_data_size The maximum early data the server will accept"]
#[doc = " @returns A POSIX error signal. If successful, the maximum early data size was updated."]
pub fn s2n_connection_set_server_max_early_data_size(
conn: *mut s2n_connection,
max_early_data_size: u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the user context associated with early data on a server."]
#[doc = ""]
#[doc = " This context is passed to the `s2n_early_data_cb` callback to help decide whether to accept or reject early data."]
#[doc = ""]
#[doc = " Unlike most contexts, the early data context is a byte buffer instead of a void pointer."]
#[doc = " This is because we need to serialize the context into session tickets."]
#[doc = ""]
#[doc = " This API is intended for use with session resumption, and will not affect pre-shared keys."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param context A pointer to the user context data. This data will be copied."]
#[doc = " @param context_size The size of the data to read from the `context` pointer."]
#[doc = " @returns A POSIX error signal. If successful, the context was updated."]
pub fn s2n_connection_set_server_early_data_context(
conn: *mut s2n_connection,
context: *const u8,
context_size: u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Configures a particular pre-shared key to allow early data."]
#[doc = ""]
#[doc = " `max_early_data_size` must be set to the maximum early data accepted by the server."]
#[doc = ""]
#[doc = " In order to use early data, the cipher suite set on the pre-shared key must match the cipher suite"]
#[doc = " ultimately negotiated by the TLS handshake. Additionally, the cipher suite must have the same"]
#[doc = " hmac algorithm as the pre-shared key."]
#[doc = ""]
#[doc = " @param psk A pointer to the pre-shared key, created with `s2n_external_psk_new`."]
#[doc = " @param max_early_data_size The maximum early data that can be sent or received using this key."]
#[doc = " @param cipher_suite_first_byte The first byte in the registered IANA value of the associated cipher suite."]
#[doc = " @param cipher_suite_second_byte The second byte in the registered IANA value of the associated cipher suite."]
#[doc = " @returns A POSIX error signal. If successful, `psk` was updated."]
pub fn s2n_psk_configure_early_data(
psk: *mut s2n_psk,
max_early_data_size: u32,
cipher_suite_first_byte: u8,
cipher_suite_second_byte: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the optional `application_protocol` associated with the given pre-shared key."]
#[doc = ""]
#[doc = " In order to use early data, the `application_protocol` set on the pre-shared key must match"]
#[doc = " the `application_protocol` ultimately negotiated by the TLS handshake."]
#[doc = ""]
#[doc = " @param psk A pointer to the pre-shared key, created with `s2n_external_psk_new`."]
#[doc = " @param application_protocol A pointer to the associated application protocol data. This data will be copied."]
#[doc = " @param size The size of the data to read from the `application_protocol` pointer."]
#[doc = " @returns A POSIX error signal. If successful, the application protocol was set."]
pub fn s2n_psk_set_application_protocol(
psk: *mut s2n_psk,
application_protocol: *const u8,
size: u8,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Sets the optional user early data context associated with the given pre-shared key."]
#[doc = ""]
#[doc = " The early data context is passed to the `s2n_early_data_cb` callback to help decide whether"]
#[doc = " to accept or reject early data."]
#[doc = ""]
#[doc = " @param psk A pointer to the pre-shared key, created with `s2n_external_psk_new`."]
#[doc = " @param context A pointer to the associated user context data. This data will be copied."]
#[doc = " @param size The size of the data to read from the `context` pointer."]
#[doc = " @returns A POSIX error signal. If successful, the context was set."]
pub fn s2n_psk_set_early_data_context(
psk: *mut s2n_psk,
context: *const u8,
size: u16,
) -> ::libc::c_int;
}
pub mod s2n_early_data_status_t {
#[doc = " The status of early data on a connection."]
#[doc = ""]
#[doc = " S2N_EARLY_DATA_STATUS_OK: Early data is in progress."]
#[doc = " S2N_EARLY_DATA_STATUS_NOT_REQUESTED: The client did not request early data, so none was sent or received."]
#[doc = " S2N_EARLY_DATA_STATUS_REJECTED: The client requested early data, but the server rejected the request."]
#[doc = " Early data may have been sent, but was not received."]
#[doc = " S2N_EARLY_DATA_STATUS_END: All early data was successfully sent and received."]
pub type Type = ::libc::c_uint;
pub const OK: Type = 0;
pub const NOT_REQUESTED: Type = 1;
pub const REJECTED: Type = 2;
pub const END: Type = 3;
}
extern "C" {
#[doc = " Reports the current state of early data for a connection."]
#[doc = ""]
#[doc = " See `s2n_early_data_status_t` for all possible states."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param status A pointer which will be set to the current early data status"]
#[doc = " @returns A POSIX error signal."]
pub fn s2n_connection_get_early_data_status(
conn: *mut s2n_connection,
status: *mut s2n_early_data_status_t::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Reports the remaining size of the early data allowed by a connection."]
#[doc = ""]
#[doc = " If early data was rejected or not requested, the remaining early data size is 0."]
#[doc = " Otherwise, the remaining early data size is the maximum early data allowed by the connection,"]
#[doc = " minus the early data sent or received so far."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param allowed_early_data_size A pointer which will be set to the remaining early data currently allowed by `conn`"]
#[doc = " @returns A POSIX error signal."]
pub fn s2n_connection_get_remaining_early_data_size(
conn: *mut s2n_connection,
allowed_early_data_size: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Reports the maximum size of the early data allowed by a connection."]
#[doc = ""]
#[doc = " This is the maximum amount of early data that can ever be sent and received for a connection."]
#[doc = " It is not affected by the actual status of the early data, so can be non-zero even if early data"]
#[doc = " is rejected or not requested."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param max_early_data_size A pointer which will be set to the maximum early data allowed by `conn`"]
#[doc = " @returns A POSIX error signal."]
pub fn s2n_connection_get_max_early_data_size(
conn: *mut s2n_connection,
max_early_data_size: *mut u32,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Called by the client to begin negotiation and send early data."]
#[doc = ""]
#[doc = " See https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md#using-early-data--0rtt"]
#[doc = " for usage and examples. DO NOT USE unless you have considered the security issues and"]
#[doc = " implemented mitigation for anti-replay attacks."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param data A pointer to the early data to be sent"]
#[doc = " @param data_len The size of the early data to send"]
#[doc = " @param data_sent A pointer which will be set to the size of the early data sent"]
#[doc = " @param blocked A pointer which will be set to the blocked status, as in `s2n_negotiate`."]
#[doc = " @returns A POSIX error signal. The error should be handled as in `s2n_negotiate`."]
pub fn s2n_send_early_data(
conn: *mut s2n_connection,
data: *const u8,
data_len: isize,
data_sent: *mut isize,
blocked: *mut s2n_blocked_status::Type,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Called by the server to begin negotiation and accept any early data the client sends."]
#[doc = ""]
#[doc = " See https://github.com/aws/s2n-tls/blob/main/docs/USAGE-GUIDE.md#using-early-data--0rtt"]
#[doc = " for usage and examples. DO NOT USE unless you have considered the security issues and"]
#[doc = " implemented mitigation for anti-replay attacks."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param data A pointer to a buffer to store the early data received"]
#[doc = " @param max_data_len The size of the early data buffer"]
#[doc = " @param data_received A pointer which will be set to the size of the early data received"]
#[doc = " @param blocked A pointer which will be set to the blocked status, as in `s2n_negotiate`."]
#[doc = " @returns A POSIX error signal. The error should be handled as in `s2n_negotiate`."]
pub fn s2n_recv_early_data(
conn: *mut s2n_connection,
data: *mut u8,
max_data_len: isize,
data_received: *mut isize,
blocked: *mut s2n_blocked_status::Type,
) -> ::libc::c_int;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct s2n_offered_early_data {
_unused: [u8; 0],
}
#[doc = " A callback which can be implemented to accept or reject early data."]
#[doc = ""]
#[doc = " This callback is triggered only after the server has determined early data is otherwise acceptable according"]
#[doc = " to the TLS early data specification. Implementations therefore only need to cover application-specific checks,"]
#[doc = " not the standard TLS early data validation."]
#[doc = ""]
#[doc = " This callback can be synchronous or asynchronous. For asynchronous behavior, return success without"]
#[doc = " calling `s2n_offered_early_data_reject` or `s2n_offered_early_data_accept`. `early_data` will"]
#[doc = " still be a valid reference, and the connection will block until `s2n_offered_early_data_reject` or"]
#[doc = " `s2n_offered_early_data_accept` is called."]
#[doc = ""]
#[doc = " @param conn A pointer to the connection"]
#[doc = " @param early_data A pointer which can be used to access information about the proposed early data"]
#[doc = " and then accept or reject it."]
#[doc = " @returns A POSIX error signal. If unsuccessful, the connection will be closed with an error."]
pub type s2n_early_data_cb = ::core::option::Option<
unsafe extern "C" fn(
conn: *mut s2n_connection,
early_data: *mut s2n_offered_early_data,
) -> ::libc::c_int,
>;
extern "C" {
#[doc = " Set a callback to accept or reject early data."]
#[doc = ""]
#[doc = " @param config A pointer to the connection config"]
#[doc = " @param cb A pointer to the implementation of the callback."]
#[doc = " @returns A POSIX error signal. If successful, the callback was set."]
pub fn s2n_config_set_early_data_cb(
config: *mut s2n_config,
cb: s2n_early_data_cb,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the length of the early data context set by the user."]
#[doc = ""]
#[doc = " @param early_data A pointer to the early data information"]
#[doc = " @param context_len The length of the user context"]
#[doc = " @returns A POSIX error signal."]
pub fn s2n_offered_early_data_get_context_length(
early_data: *mut s2n_offered_early_data,
context_len: *mut u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Get the early data context set by the user."]
#[doc = ""]
#[doc = " @param early_data A pointer to the early data information"]
#[doc = " @param context A byte buffer to copy the user context into"]
#[doc = " @param max_len The size of `context`. Must be >= to the result of `s2n_offered_early_data_get_context_length`."]
#[doc = " @returns A POSIX error signal."]
pub fn s2n_offered_early_data_get_context(
early_data: *mut s2n_offered_early_data,
context: *mut u8,
max_len: u16,
) -> ::libc::c_int;
}
extern "C" {
#[doc = " Reject early data offered by the client."]
#[doc = ""]
#[doc = " @param early_data A pointer to the early data information"]
#[doc = " @returns A POSIX error signal. If success, the client's early data will be rejected."]
pub fn s2n_offered_early_data_reject(early_data: *mut s2n_offered_early_data) -> ::libc::c_int;
}
extern "C" {
#[doc = " Accept early data offered by the client."]
#[doc = ""]
#[doc = " @param early_data A pointer to the early data information"]
#[doc = " @returns A POSIX error signal. If success, the client's early data will be accepted."]
pub fn s2n_offered_early_data_accept(early_data: *mut s2n_offered_early_data) -> ::libc::c_int;
}