security_handler.c File Reference

Security handler module implementation file. More...

#include "security_handler.h"
#include "security.h"
#include "base64.h"
#include "hmac.h"
#include "definitions.h"
#include "memory.h"
#include "random.h"
#include "log_util.h"
Include dependency graph for security_handler.c:

Go to the source code of this file.

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_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_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_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...
 

Detailed Description

Security handler module implementation file.


Date
Jun 27, 2016

Definition in file security_handler.c.

Function Documentation

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.

Parameters
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.
Returns
  • MCL_OK in case of success.
  • MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • MCL_BAD_CONTENT_ENCODING if provided 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.

Here is the call graph for this function:

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.

Parameters
[in]dataData to be encoded.
[in]data_sizeData size.
[out]encoded_dataEncoded result.
Returns

Definition at line 97 of file security_handler.c.

References base64_encode(), DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_ERROR, and MCL_OK.

Here is the call graph for this function:

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.

Parameters
[in]dataData to be encoded.
[in]data_sizeData size.
[out]encoded_dataEncoded result.
Returns

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]security_handlerHandler 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[out]jtiGenerated jti string : 128 bit random number, base64 encoded.
Returns

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]security_handlerHandler to be used.
Returns

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in]dataData to be hashed.
[in]data_sizeSize of data.
[out]hashGenerated hash result.
[out]hash_sizeLength of the generated hash.
Returns

Definition at line 60 of file security_handler.c.

References DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, MCL_ERROR, MCL_OK, and security_hash_sha256().

Here is the call graph for this function:

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.

Parameters
[in]security_handlerSecurity handler to use its authorization key.
[in]dataData to calculate HMAC SHA256 for.
[in]data_sizeSize of data.
[out]hashA newly allocated memory which contains the result of HMAC SHA256.
[out]hash_sizeSize of hash, which should be 32 bytes after SHA256 calculation.
Returns

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().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE security_handler_initialize ( security_handler_t **  security_handler)

Initializer of security handler.

Parameters
[out]security_handlerHandle to be created and initialized.
Returns

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().

Here is the caller graph for this function:

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.

Parameters
[in]rsa_keyThe key to be used in signing.
[in]dataThe data to be signed.
[in]data_sizeSize of the data.
[out]signatureGenerated signature.
[out]signature_sizeSize of signature.
Returns

Definition at line 153 of file security_handler.c.

References DEBUG_ENTRY, DEBUG_LEAVE, and security_rsa_sign().

Referenced by _calculate_signature().

Here is the call graph for this function:

Here is the caller graph for this function: