Security handler module header file. More...
#include "string_type.h"
Go to the source code of this file.
Data Structures | |
struct | rsa_t |
RSA Pair Struct holding public and private and session keys. More... | |
struct | security_handler_t |
Handle struct for security_handler module. More... | |
Functions | |
E_MCL_ERROR_CODE | security_handler_initialize (security_handler_t **security_handler) |
Initializer of security handler. More... | |
E_MCL_ERROR_CODE | security_handler_generate_jti (string_t **jti) |
To be used to generate the jti nonce. More... | |
E_MCL_ERROR_CODE | security_handler_hash_sha256 (const mcl_uint8_t *data, mcl_size_t data_size, mcl_uint8_t **hash, mcl_size_t *hash_size) |
To be used to generate the sha256 hash of the given data. More... | |
E_MCL_ERROR_CODE | 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) |
E_MCL_ERROR_CODE | security_handler_base64_url_encode (const mcl_uint8_t *data, mcl_size_t data_size, string_t **encoded_data) |
To be used to encode the given data in base64 URL encoding format. More... | |
E_MCL_ERROR_CODE | security_handler_base64_encode (const mcl_uint8_t *data, mcl_size_t data_size, string_t **encoded_data) |
To be used to encode the given data in base64 encoding format. More... | |
E_MCL_ERROR_CODE | security_handler_base64_decode (const string_t *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size) |
E_MCL_ERROR_CODE | security_handler_generate_rsa_key (security_handler_t *security_handler) |
To be used to generate the RSA public/private key pairs. More... | |
E_MCL_ERROR_CODE | security_handler_rsa_sign (char *rsa_key, char *data, mcl_size_t data_size, mcl_uint8_t **signature, mcl_size_t *signature_size) |
To be used to sign data with RSA key. More... | |
void | security_handler_destroy (security_handler_t **security_handler) |
To destroy the Security Handler. More... | |
Security handler module header file.
Definition in file security_handler.h.
E_MCL_ERROR_CODE security_handler_base64_decode | ( | const string_t * | 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 if the given encoded_data
is invalidly encoded. Definition at line 115 of file security_handler.c.
References base64_decode(), DEBUG_ENTRY, and DEBUG_LEAVE.
E_MCL_ERROR_CODE security_handler_base64_encode | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
string_t ** | encoded_data | ||
) |
To be 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(), DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_ERROR, and MCL_OK.
E_MCL_ERROR_CODE security_handler_base64_url_encode | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
string_t ** | encoded_data | ||
) |
To be 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 125 of file security_handler.c.
References base64_url_encode(), DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_ERROR, and MCL_OK.
Referenced by _calculate_signature(), and _get_header_and_payload_encoded_base64_url().
void security_handler_destroy | ( | security_handler_t ** | security_handler | ) |
To destroy the Security Handler.
Will release the resources of security handler. After destroy operation, handler shouldn't be used.
[in] | security_handler | Handler to be destroyed. |
Definition at line 164 of file security_handler.c.
References DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_FREE, MCL_NULL, and string_destroy().
Referenced by http_processor_destroy().
E_MCL_ERROR_CODE security_handler_generate_jti | ( | string_t ** | jti | ) |
To be 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 50 of file security_handler.c.
References DEBUG_ENTRY, DEBUG_LEAVE, and random_generate_guid().
Referenced by _create_self_issued_jwt_payload().
E_MCL_ERROR_CODE security_handler_generate_rsa_key | ( | security_handler_t * | security_handler | ) |
To be 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 143 of file security_handler.c.
References DEBUG_ENTRY, 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 http_processor_initialize().
E_MCL_ERROR_CODE security_handler_hash_sha256 | ( | const mcl_uint8_t * | data, |
mcl_size_t | data_size, | ||
mcl_uint8_t ** | hash, | ||
mcl_size_t * | hash_size | ||
) |
To be 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 60 of file security_handler.c.
References DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_ERROR, MCL_OK, and security_hash_sha256().
E_MCL_ERROR_CODE 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 | ||
) |
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 78 of file security_handler.c.
References string_t::buffer, security_handler_t::client_secret, DEBUG_ENTRY, DEBUG_LEAVE, hmac_sha256(), string_t::length, MCL_DEBUG, MCL_ERROR, and MCL_OK.
Referenced by _calculate_signature().
E_MCL_ERROR_CODE security_handler_initialize | ( | security_handler_t ** | security_handler | ) |
Initializer of security handler.
[out] | security_handler | Handle to be created and initialized. |
Definition at line 23 of file security_handler.c.
References ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_NEW, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by http_processor_initialize().
E_MCL_ERROR_CODE security_handler_rsa_sign | ( | char * | rsa_key, |
char * | data, | ||
mcl_size_t | data_size, | ||
mcl_uint8_t ** | signature, | ||
mcl_size_t * | signature_size | ||
) |
To be 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 153 of file security_handler.c.
References DEBUG_ENTRY, DEBUG_LEAVE, and security_rsa_sign().
Referenced by _calculate_signature().