Security handler module header file. More...
#include "mcl_core/mcl_core_common.h"
Go to the source code of this file.
Data Structures | |
struct | rsa_t |
struct | security_handler_t |
Security handler module header file.
This module presents security related operations.
Definition in file security_handler.h.
MCL_LOCAL mcl_error_t security_handler_base64_decode | ( | const char * | encoded_data, |
mcl_uint8_t ** | decoded_data, | ||
mcl_size_t * | decoded_data_size | ||
) |
Given a base64 zero-terminated string at encoded_data
, decode it and return a pointer in decoded_data
to a newly allocated memory area holding decoded data. Size of decoded data is returned in variable pointed by decoded_data_size
.
When decoded data length is 0, returns MCL_NULL in decoded_data
.
encoded_data | [in] Zero-terminated string which is base64 encoded and has to be decoded. |
decoded_data | [out] Newly allocated memory holding decoded data. |
decoded_data_size | [out] Size of decoded data. |
encoded_data
has invalid length (0 or not multiples of 4) or is invalidly encoded. Definition at line 118 of file security_handler.c.
References base64_decode(), MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.
MCL_LOCAL mcl_error_t security_handler_base64_encode | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
char ** | encoded_data | ||
) |
This function is used to encode the given data in base64 encoding format.
[in] | data | Data to be encoded. |
[in] | data_size | Data size. |
[out] | encoded_data | Encoded result. |
Definition at line 97 of file security_handler.c.
References base64_encode(), MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_OK, and string_util_strlen().
MCL_LOCAL mcl_error_t security_handler_base64_url_encode | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
char ** | encoded_data | ||
) |
This function is used to encode the given data in base64 URL encoding format.
[in] | data | Data to be encoded. |
[in] | data_size | Data size. |
[out] | encoded_data | Encoded result. |
Definition at line 131 of file security_handler.c.
References base64_url_encode(), MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_OK, and string_util_strlen().
Referenced by _calculate_signature(), and _get_header_and_payload_encoded_base64_url().
MCL_LOCAL void security_handler_destroy | ( | security_handler_t ** | security_handler | ) |
This function is used to destroy the security handler.
[in] | security_handler | Handler to be destroyed. |
Definition at line 177 of file security_handler.c.
References MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, and MCL_NULL.
Referenced by core_processor_destroy().
MCL_LOCAL mcl_error_t security_handler_generate_jti | ( | char ** | jti | ) |
This function is used to generate the jti nonce.
This generated jti nonce will be used inside of the authentication JWT.
[out] | jti | Generated jti string : 128 bit random number, base64 encoded. |
Definition at line 40 of file security_handler.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and random_generate_guid().
Referenced by _create_self_issued_jwt_payload().
MCL_LOCAL mcl_error_t security_handler_generate_rsa_key | ( | security_handler_t * | security_handler | ) |
This function is used to generate the RSA public/private key pairs.
Generated key pairs will be stored in the received handler.
[in] | security_handler | Handler to be used. |
Definition at line 152 of file security_handler.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, rsa_t::private_key, rsa_t::public_key, security_handler_t::rsa, and security_generate_rsa_key().
Referenced by _compose_rsa_key_rotation_json(), and _load_initial_credentials().
MCL_LOCAL mcl_error_t security_handler_hash_sha256 | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
mcl_uint8_t ** | hash, | ||
mcl_size_t * | hash_size | ||
) |
This function is used to generate the sha256 hash of the given data.
[in] | data | Data to be hashed. |
[in] | data_size | Size of data . |
[out] | hash | Generated hash result. |
[out] | hash_size | Length of the generated hash . |
Definition at line 52 of file security_handler.c.
References MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_OK, and security_hash_sha256().
MCL_LOCAL mcl_error_t security_handler_hmac_sha256 | ( | security_handler_t * | security_handler, |
const mcl_uint8_t * | data, | ||
mcl_size_t | data_size, | ||
mcl_uint8_t ** | hash, | ||
mcl_size_t * | hash_size | ||
) |
This function calculates HMAC SHA256 for given data with the authorization key of provided security_handler
.
[in] | security_handler | Security handler to use its authorization key. |
[in] | data | Data to calculate HMAC SHA256 for. |
[in] | data_size | Size of data . |
[out] | hash | A newly allocated memory which contains the result of HMAC SHA256. |
[out] | hash_size | Size of hash , which should be 32 bytes after SHA256 calculation. |
security_handler
is zero. Definition at line 73 of file security_handler.c.
References security_handler_t::client_secret, hmac_sha256(), MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_OK, and string_util_strlen().
Referenced by _calculate_signature().
MCL_LOCAL mcl_error_t security_handler_initialize | ( | security_handler_t ** | security_handler | ) |
This function creates and initializes an object of type security_handler_t.
[out] | security_handler | Handle to be created and initialized. |
Definition at line 18 of file security_handler.c.
References MCL_ASSERT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NEW, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by core_processor_initialize().
MCL_LOCAL mcl_error_t security_handler_rsa_sign | ( | char * | rsa_key, |
char * | data, | ||
mcl_size_t | data_size, | ||
mcl_uint8_t ** | signature, | ||
mcl_size_t * | signature_size | ||
) |
This function is used to sign data with RSA key.
Received key will be used to sign. Caller can use the generated RSA private key or the servers public key.
[in] | rsa_key | The key to be used in signing. |
[in] | data | The data to be signed. |
[in] | data_size | Size of the data. |
[out] | signature | Generated signature. |
[out] | signature_size | Size of signature. |
Definition at line 164 of file security_handler.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and security_rsa_sign().
Referenced by _calculate_signature().