All the API functions except cy_tls_init cy_tls_deinit cy_tls_load_global_root_ca_certificates and cy_tls_release_global_root_ca_certificates are thread-safe.
All the API functions are blocking API functions.
Functions | |
cy_rslt_t | cy_tls_init (void) |
Does general allocation and initialization of resources needed for the library. More... | |
cy_rslt_t | cy_tls_deinit (void) |
Releases the resources allocated in the cy_tls_init function. More... | |
cy_rslt_t | cy_tls_load_global_root_ca_certificates (const char *trusted_ca_certificates, const uint32_t cert_length) |
Initializes the global trusted RootCA certificates used for verifying certificates received during TLS handshake. More... | |
cy_rslt_t | cy_tls_release_global_root_ca_certificates (void) |
Releases the resources allocated by the cy_tls_load_global_root_ca_certificates API function. More... | |
cy_rslt_t | cy_tls_create_identity (const char *certificate_data, const uint32_t certificate_len, const char *private_key, uint32_t private_key_len, void **tls_identity) |
Creates an identity structure from the supplied certificate and private key. More... | |
cy_rslt_t | cy_tls_delete_identity (void *tls_identity) |
Releases resources allocated by the cy_tls_create_identity API function. More... | |
cy_rslt_t | cy_tls_create_context (cy_tls_context_t *context, cy_tls_params_t *params) |
Creates a TLS context structure from the input parameters. More... | |
cy_rslt_t | cy_tls_connect (cy_tls_context_t context, cy_tls_endpoint_type_t endpoint, uint32_t timeout) |
Performs a TLS handshake and connects to the server. More... | |
cy_rslt_t | cy_tls_send (cy_tls_context_t context, const unsigned char *data, uint32_t length, uint32_t timeout, uint32_t *bytes_sent) |
Encrypts the given data and sends it over a secure connection. More... | |
cy_rslt_t | cy_tls_recv (cy_tls_context_t context, unsigned char *buffer, uint32_t length, uint32_t timeout, uint32_t *bytes_received) |
Reads the encrypted data from the network, decrypts the data, and then stores it in the given buffer. More... | |
cy_rslt_t | cy_tls_delete_context (cy_tls_context_t context) |
Releases the resources allocated for the TLS connection. More... | |
cy_rslt_t | cy_tls_config_cert_profile_param (cy_tls_md_type_t mds_type, cy_tls_rsa_min_key_len_t rsa_bit_len) |
Configures a custom certificate profile using the message digest and RSA min key length. More... | |
cy_rslt_t | cy_tls_is_certificate_valid_x509 (const char *certificate_data, const uint32_t certificate_len) |
Checks if given buffer is in valid certificate format. More... | |
cy_rslt_t cy_tls_init | ( | void | ) |
Does general allocation and initialization of resources needed for the library.
This API function must be called before using any other context-based TLS API functions.
cy_rslt_t cy_tls_deinit | ( | void | ) |
Releases the resources allocated in the cy_tls_init function.
cy_rslt_t cy_tls_load_global_root_ca_certificates | ( | const char * | trusted_ca_certificates, |
const uint32_t | cert_length | ||
) |
Initializes the global trusted RootCA certificates used for verifying certificates received during TLS handshake.
This function parses the RootCA certificate chain and converts it to the underlying TLS stack format. It also stores the converted RootCA in its internal memory. This function overrides previously loaded RootCA certificates.
[in] | trusted_ca_certificates | A chain of x509 certificates in PEM or DER format. It should be a null-terminated string. This chain of certificates comprise the public keys of the signing authorities. During the handshake, these public keys are used to verify the authenticity of the peer. |
[in] | cert_length | Length of the trusted RootCA certificates excluding the 'null' terminator. The buffer pointed by trusted_ca_certificates is treated as a byte stream. |
cy_rslt_t cy_tls_release_global_root_ca_certificates | ( | void | ) |
Releases the resources allocated by the cy_tls_load_global_root_ca_certificates API function.
cy_rslt_t cy_tls_create_identity | ( | const char * | certificate_data, |
const uint32_t | certificate_len, | ||
const char * | private_key, | ||
uint32_t | private_key_len, | ||
void ** | tls_identity | ||
) |
Creates an identity structure from the supplied certificate and private key.
[in] | certificate_data | x509 certificate in PEM format. It should be a null-terminated string. |
[in] | certificate_len | Length of the certificate excluding the 'null' terminator. |
[in] | private_key | Private key in PEM format. It should be a null-terminated string. |
[in] | private_key_len | Length of the private key excluding the 'null' terminator. |
[out] | tls_identity | Pointer to a memory location containing the certificate and key in the underlying TLS stack format. |
cy_rslt_t cy_tls_delete_identity | ( | void * | tls_identity | ) |
Releases resources allocated by the cy_tls_create_identity API function.
[in] | tls_identity | Pointer to a memory location containing the certificate and key in the underlying TLS stack format. |
cy_rslt_t cy_tls_create_context | ( | cy_tls_context_t * | context, |
cy_tls_params_t * | params | ||
) |
Creates a TLS context structure from the input parameters.
It allocates a TLS context structure and stores the RootCA, TLS identity, send/receive callback functions, server name to be used in the SNI extension, protocol list to be added to the ALPN extension, and user context. TLS parameters provided by the user are used in later cy_tls API function calls. The memory holding the parameters should not be freed until completely done with using cy_tls API functions.
[out] | context | Context handle returned by the TLS layer. |
[in] | params | TLS parameters specified by the caller such as the server certificate. |
cy_rslt_t cy_tls_connect | ( | cy_tls_context_t | context, |
cy_tls_endpoint_type_t | endpoint, | ||
uint32_t | timeout | ||
) |
Performs a TLS handshake and connects to the server.
RootCA certificate will be used for peer certificate verification as below:
Device certificate & keys will be loaded as below:
[in] | context | Context handle for the TLS Layer created using cy_tls_create_context. |
[in] | endpoint | Endpoint type for the TLS handshake. |
[in] | timeout | Maximum amount of time to wait in milliseconds to complete TLS connection. |
cy_rslt_t cy_tls_send | ( | cy_tls_context_t | context, |
const unsigned char * | data, | ||
uint32_t | length, | ||
uint32_t | timeout, | ||
uint32_t * | bytes_sent | ||
) |
Encrypts the given data and sends it over a secure connection.
[in] | context | Context handle for TLS Layer created using cy_tls_create_context. |
[in] | data | Byte array of data to be encrypted and then sent to the network. |
[in] | length | Length in bytes of the write buffer. |
[in] | timeout | Maximum amount of time to wait in milliseconds to complete send operation. |
[out] | bytes_sent | Number of bytes sent. |
cy_rslt_t cy_tls_recv | ( | cy_tls_context_t | context, |
unsigned char * | buffer, | ||
uint32_t | length, | ||
uint32_t | timeout, | ||
uint32_t * | bytes_received | ||
) |
Reads the encrypted data from the network, decrypts the data, and then stores it in the given buffer.
[in] | context | Context handle for the TLS Layer created using cy_tls_create_context. |
[out] | buffer | Byte array to store the decrypted data received from the network. |
[in] | length | Length in bytes of the read buffer. |
[in] | timeout | Maximum amount of time to wait in milliseconds to complete receive operation. |
[out] | bytes_received | Number of bytes received. |
cy_rslt_t cy_tls_delete_context | ( | cy_tls_context_t | context | ) |
Releases the resources allocated for the TLS connection.
[in] | context | Context handle returned by the TLS Layer created using cy_tls_create_context. |
cy_rslt_t cy_tls_config_cert_profile_param | ( | cy_tls_md_type_t | mds_type, |
cy_tls_rsa_min_key_len_t | rsa_bit_len | ||
) |
Configures a custom certificate profile using the message digest and RSA min key length.
[in] | mds_type | Message digest type. |
[in] | rsa_bit_len | Minimum RSA key length in bits. |
cy_rslt_t cy_tls_is_certificate_valid_x509 | ( | const char * | certificate_data, |
const uint32_t | certificate_len | ||
) |
Checks if given buffer is in valid certificate format.
[in] | certificate_data | x509 certificate in PEM format. It should be a null-terminated string. |
[in] | certificate_len | Length of the certificate excluding the 'null' terminator. |