JWT module implementation file. More...
#include "jwt.h"
#include "time_util.h"
#include "json_util.h"
#include "definitions.h"
#include "string_util.h"
#include "mcl_core/mcl_assert.h"
#include "mcl_core/mcl_memory.h"
Go to the source code of this file.
Macros | |
#define | JWT_HEADER_NAME_ALG "alg" |
#define | JWT_HEADER_NAME_TYPE "typ" |
#define | JWT_HEADER_NAME_KID "kid" |
#define | JWT_PAYLOAD_NAME_ISS "iss" |
#define | JWT_PAYLOAD_NAME_SUB "sub" |
#define | JWT_PAYLOAD_NAME_AUD "aud" |
#define | JWT_PAYLOAD_NAME_IAT "iat" |
#define | JWT_PAYLOAD_NAME_NBF "nbf" |
#define | JWT_PAYLOAD_NAME_EXP "exp" |
#define | JWT_PAYLOAD_NAME_SCHEMAS "schemas" |
#define | JWT_PAYLOAD_NAME_TEN "ten" |
#define | JWT_PAYLOAD_NAME_JTI "jti" |
#define | JWT_PAYLOAD_NAME_PUBLIC_KEY "public_key" |
#define | JWT_PAYLOAD_NAME_CONTENT_MD5 "content-md5" |
#define | JWT_HEADER_VALUE_ALG_SHARED_SECRET "HS256" |
#define | JWT_HEADER_VALUE_ALG_RSA_3072 "RS256" |
#define | JWT_HEADER_VALUE_TYP "JWT" |
#define | JWT_PAYLOAD_VALUE_SCHEMAS "urn:siemens:mindsphere:v1" |
#define | JWT_PAYLOAD_VALUE_AUD "southgate" |
Functions | |
static mcl_error_t | _create_self_issued_jwt_header (E_MCL_SECURITY_PROFILE security_profile, mcl_json_t **header) |
static mcl_error_t | _create_self_issued_jwt_payload (security_handler_t *security_handler, char *tenant, jwt_t *jwt) |
static mcl_error_t | _add_schema_to_jwt (mcl_json_t *payload) |
static mcl_error_t | _get_header_and_payload_encoded_base64_url (char *header, char *payload, char **header_encoded, char **payload_encoded) |
static mcl_error_t | _join_with_dot (char *string_a, char *string_b, char **joined) |
static mcl_error_t | _calculate_signature (jwt_t *jwt, char *header_and_payload, char **signature) |
static mcl_error_t | _generate_token (jwt_t *jwt, char *header, char *payload, char **token) |
mcl_error_t | jwt_initialize (security_handler_t *security_handler, E_MCL_SECURITY_PROFILE security_profile, char *tenant, jwt_t **jwt) |
char * | jwt_get_token (jwt_t *jwt) |
void | jwt_destroy (jwt_t **jwt) |
JWT module implementation file.
Definition in file jwt.c.
#define JWT_HEADER_NAME_ALG "alg" |
Definition at line 18 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_NAME_TYPE "typ" |
Definition at line 19 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_VALUE_ALG_RSA_3072 "RS256" |
Definition at line 35 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_VALUE_ALG_SHARED_SECRET "HS256" |
Definition at line 34 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_VALUE_TYP "JWT" |
Definition at line 36 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_PAYLOAD_NAME_AUD "aud" |
Definition at line 24 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_EXP "exp" |
Definition at line 27 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_IAT "iat" |
Definition at line 25 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_ISS "iss" |
Definition at line 22 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_JTI "jti" |
Definition at line 30 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_NBF "nbf" |
Definition at line 26 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_SCHEMAS "schemas" |
Definition at line 28 of file jwt.c.
Referenced by _add_schema_to_jwt().
#define JWT_PAYLOAD_NAME_SUB "sub" |
Definition at line 23 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_TEN "ten" |
Definition at line 29 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_VALUE_AUD "southgate" |
Definition at line 39 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_VALUE_SCHEMAS "urn:siemens:mindsphere:v1" |
Definition at line 38 of file jwt.c.
Referenced by _add_schema_to_jwt().
|
static |
Definition at line 391 of file jwt.c.
References json_util_add_string(), json_util_start_array(), JWT_PAYLOAD_NAME_SCHEMAS, JWT_PAYLOAD_VALUE_SCHEMAS, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and MCL_OK.
Referenced by _create_self_issued_jwt_payload().
|
static |
Definition at line 358 of file jwt.c.
References MCL_ASSERT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FREE, MCL_NULL, MCL_OK, MCL_SECURITY_SHARED_SECRET, rsa_t::private_key, security_handler_t::rsa, jwt_t::security_handler, security_handler_base64_url_encode(), security_handler_hmac_sha256(), security_handler_rsa_sign(), jwt_t::security_profile, and string_util_strlen().
Referenced by _generate_token().
|
static |
Definition at line 152 of file jwt.c.
References json_util_add_string(), json_util_destroy(), json_util_initialize(), JWT_HEADER_NAME_ALG, JWT_HEADER_NAME_TYPE, JWT_HEADER_VALUE_ALG_RSA_3072, JWT_HEADER_VALUE_ALG_SHARED_SECRET, JWT_HEADER_VALUE_TYP, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_JSON_OBJECT, MCL_OK, and MCL_SECURITY_SHARED_SECRET.
Referenced by jwt_initialize().
|
static |
Definition at line 195 of file jwt.c.
References _add_schema_to_jwt(), security_handler_t::client_id, jwt_t::issued_at, json_util_add_double(), json_util_add_string(), json_util_destroy(), json_util_initialize(), JWT_EXPIRATION_TIME, JWT_PAYLOAD_NAME_AUD, JWT_PAYLOAD_NAME_EXP, JWT_PAYLOAD_NAME_IAT, JWT_PAYLOAD_NAME_ISS, JWT_PAYLOAD_NAME_JTI, JWT_PAYLOAD_NAME_NBF, JWT_PAYLOAD_NAME_SUB, JWT_PAYLOAD_NAME_TEN, JWT_PAYLOAD_VALUE_AUD, MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_STATEMENT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_JSON_OBJECT, MCL_NULL, MCL_OK, jwt_t::payload, security_handler_generate_jti(), and time_util_get_time().
Referenced by jwt_initialize().
|
static |
Definition at line 274 of file jwt.c.
References _calculate_signature(), _get_header_and_payload_encoded_base64_url(), _join_with_dot(), MCL_ASSERT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR_RETURN, MCL_FAIL, MCL_FREE, MCL_NULL, and MCL_OK.
Referenced by jwt_get_token().
|
static |
Definition at line 304 of file jwt.c.
References MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_STATEMENT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FAIL, MCL_FREE, MCL_OK, security_handler_base64_url_encode(), and string_util_strlen().
Referenced by _generate_token().
|
static |
Definition at line 321 of file jwt.c.
References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR_SIZE, MCL_OK, MCL_OUT_OF_MEMORY, string_util_memcpy(), and string_util_strlen().
Referenced by _generate_token().
void jwt_destroy | ( | jwt_t ** | jwt | ) |
This function destroys jwt_t data structure.
[in] | jwt | JWT handle which is going to be destroyed. |
Definition at line 124 of file jwt.c.
References json_util_destroy(), MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, and MCL_NULL.
Referenced by _compose_access_token_request_payload(), and jwt_initialize().
char* jwt_get_token | ( | jwt_t * | jwt | ) |
This function is used to generate the JWT as json string.
[in] | jwt | JWT handle. |
Definition at line 90 of file jwt.c.
References _generate_token(), jwt_t::header, mcl_core_return_code_strings, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_FREE, mcl_json_util_to_string(), MCL_NULL, MCL_OK, and jwt_t::payload.
Referenced by _compose_access_token_request_payload().
mcl_error_t jwt_initialize | ( | security_handler_t * | security_handler, |
E_MCL_SECURITY_PROFILE | security_profile, | ||
char * | tenant, | ||
jwt_t ** | jwt | ||
) |
This function creates and initializes a data struct of jwt_t.
[in] | security_handler | Already initialized security handler. All JWT operations will be done using this object. |
[in] | security_profile | Onboarding security profile. |
[in] | tenant | Tenant which will be set in JWT payload. |
[out] | jwt | The newly initialized jwt handle. |
Definition at line 62 of file jwt.c.
References _create_self_issued_jwt_header(), _create_self_issued_jwt_payload(), jwt_destroy(), MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_STATEMENT_CODE_MESSAGE, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NEW, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by _compose_access_token_request_payload().