Skip to main content

mbedtls_ssl_set_hostname

Function mbedtls_ssl_set_hostname 

Source
pub unsafe extern "C" fn mbedtls_ssl_set_hostname(
    ssl: *mut mbedtls_ssl_context,
    hostname: *const c_char,
) -> c_int
Expand description

\brief Set or reset the hostname to check against the received peer certificate. On a client, this also sets the ServerName TLS extension, if that extension is enabled. On a TLS 1.3 client, this also sets the server name in the session resumption ticket, if that feature is enabled.

\param ssl SSL context \param hostname The server hostname. This may be \c NULL to clear the hostname.

\note Maximum hostname length #MBEDTLS_SSL_MAX_HOST_NAME_LEN.

\note If the hostname is \c NULL on a client, then the server is not authenticated: it only needs to have a valid certificate, not a certificate matching its name. Therefore you should always call this function on a client, unless the connection is set up to only allow pre-shared keys, or in scenarios where server impersonation is not a concern. See the documentation of #MBEDTLS_ERR_SSL_CERTIFICATE_VERIFICATION_WITHOUT_HOSTNAME for more details.

\return 0 if successful, #MBEDTLS_ERR_SSL_ALLOC_FAILED on allocation failure, #MBEDTLS_ERR_SSL_BAD_INPUT_DATA on too long input hostname.

            Hostname set to the one provided on success (cleared
            when NULL). On allocation failure hostname is cleared.
            On too long input failure, old hostname is unchanged.