JWT module implementation file. More...
#include "jwt.h"
#include "log_util.h"
#include "definitions.h"
#include "memory.h"
#include "string_array.h"
#include "time_util.h"
#include "json_util.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" |
Variables | |
static string_t | dot = { ".", 1, MCL_STRING_NOT_COPY_NOT_DESTROY } |
JWT module implementation file.
Definition in file jwt.c.
#define JWT_HEADER_NAME_ALG "alg" |
Definition at line 23 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_NAME_TYPE "typ" |
Definition at line 24 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_VALUE_ALG_RSA_3072 "RS256" |
Definition at line 40 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_VALUE_ALG_SHARED_SECRET "HS256" |
Definition at line 39 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_HEADER_VALUE_TYP "JWT" |
Definition at line 41 of file jwt.c.
Referenced by _create_self_issued_jwt_header().
#define JWT_PAYLOAD_NAME_AUD "aud" |
Definition at line 29 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_EXP "exp" |
Definition at line 32 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_IAT "iat" |
Definition at line 30 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_ISS "iss" |
Definition at line 27 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_JTI "jti" |
Definition at line 35 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_NBF "nbf" |
Definition at line 31 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_SCHEMAS "schemas" |
Definition at line 33 of file jwt.c.
Referenced by _add_schema_to_jwt().
#define JWT_PAYLOAD_NAME_SUB "sub" |
Definition at line 28 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_NAME_TEN "ten" |
Definition at line 34 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_VALUE_AUD "southgate" |
Definition at line 44 of file jwt.c.
Referenced by _create_self_issued_jwt_payload().
#define JWT_PAYLOAD_VALUE_SCHEMAS "urn:siemens:mindsphere:v1" |
Definition at line 43 of file jwt.c.
Referenced by _add_schema_to_jwt().
|
static |
Definition at line 354 of file jwt.c.
References ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, json_util_add_string(), json_util_finish_array(), json_util_start_array(), JWT_PAYLOAD_NAME_SCHEMAS, JWT_PAYLOAD_VALUE_SCHEMAS, MCL_NULL, and MCL_OK.
Referenced by _create_self_issued_jwt_payload().
|
static |
Definition at line 322 of file jwt.c.
References ASSERT_CODE_MESSAGE, string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, string_t::length, 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(), and jwt_t::security_profile.
Referenced by _generate_token().
|
static |
Definition at line 158 of file jwt.c.
References DEBUG_ENTRY, DEBUG_LEAVE, JSON_OBJECT, 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_OK, and MCL_SECURITY_SHARED_SECRET.
Referenced by jwt_initialize().
|
static |
Definition at line 187 of file jwt.c.
References _add_schema_to_jwt(), ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, string_t::buffer, security_handler_t::client_id, DEBUG_ENTRY, DEBUG_LEAVE, jwt_t::issued_at, JSON_OBJECT, 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_NULL, MCL_OK, jwt_t::payload, security_handler_generate_jti(), string_destroy(), and time_util_get_time().
Referenced by jwt_initialize().
|
static |
Definition at line 233 of file jwt.c.
References _calculate_signature(), _get_header_and_payload_encoded_base64_url(), _join_with_dot(), ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_ERROR_RETURN, MCL_FAIL, MCL_NULL, MCL_OK, and string_destroy().
Referenced by jwt_get_token().
|
static |
Definition at line 262 of file jwt.c.
References ASSERT_CODE_MESSAGE, string_t::buffer, DEBUG_ENTRY, DEBUG_LEAVE, string_t::length, MCL_ERROR_RETURN, MCL_FAIL, MCL_OK, security_handler_base64_url_encode(), and string_destroy().
Referenced by _generate_token().
|
static |
Definition at line 286 of file jwt.c.
References ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, string_array_t::index, MCL_ERROR_RETURN, MCL_FAIL, MCL_FALSE, MCL_NULL, MCL_OK, string_array_add(), string_array_destroy(), string_array_initialize(), string_array_to_string(), and string_destroy().
Referenced by _generate_token().
void jwt_destroy | ( | jwt_t ** | jwt | ) |
To destroy the JWT Handler.
Will release the resources of JWT Handler. After destroy operation, handler shouldn't be used.
[in] | jwt | JWT Handler to destroy |
Definition at line 128 of file jwt.c.
References DEBUG_ENTRY, DEBUG_LEAVE, json_util_destroy(), MCL_DEBUG, MCL_FREE, and MCL_NULL.
Referenced by _compose_access_token_request_payload(), and jwt_initialize().
Used to generate the JWT Token as json string.
[in] | jwt | JWT Handler. |
Definition at line 97 of file jwt.c.
References _generate_token(), DEBUG_ENTRY, DEBUG_LEAVE, jwt_t::header, json_util_to_string(), MCL_NULL, MCL_OK, jwt_t::payload, string_destroy(), and string_initialize_dynamic().
Referenced by _compose_access_token_request_payload().
E_MCL_ERROR_CODE jwt_initialize | ( | security_handler_t * | security_handler, |
E_MCL_SECURITY_PROFILE | security_profile, | ||
string_t * | tenant, | ||
jwt_t ** | jwt | ||
) |
JWT Initializer.
[in] | security_handler | Already initialized security handler. All JWT operations will be done using this object. |
[in] | security_profile | Onboarding security profile. Important to get correct kind of authentication JWT. |
[in] | tenant | Tenant which will be set in JWT payload. |
[out] | jwt | The newly initialized jwt handler. |
Definition at line 70 of file jwt.c.
References _create_self_issued_jwt_header(), _create_self_issued_jwt_payload(), ASSERT_CODE_MESSAGE, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, jwt_destroy(), MCL_NEW, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.
Referenced by _compose_access_token_request_payload().
|
static |