Google Cloud IoT Device SDK for Embedded C API
Macros | Functions
iotc_jwt.h File Reference
#include <iotc_types.h>

Go to the source code of this file.

Macros

#define IOTC_JWT_HEADER_BUF_SIZE   40
 
#define IOTC_JWT_HEADER_BUF_SIZE_BASE64   (((IOTC_JWT_HEADER_BUF_SIZE + 2) / 3) * 4)
 
#define IOTC_JWT_PAYLOAD_BUF_SIZE   256
 
#define IOTC_JWT_PAYLOAD_BUF_SIZE_BASE64   (((IOTC_JWT_PAYLOAD_BUF_SIZE + 2) / 3) * 4)
 
#define IOTC_JWT_MAX_SIGNATURE_SIZE   132
 
#define IOTC_JWT_MAX_SIGNATURE_SIZE_BASE64   (((IOTC_JWT_MAX_SIGNATURE_SIZE + 2) / 3) * 4)
 
#define IOTC_JWT_SIZE
 

Functions

iotc_state_t iotc_create_iotcore_jwt (const char *project_id, uint32_t expiration_period_sec, const iotc_crypto_key_data_t *private_key_data, char *dst_jwt_buf, size_t dst_jwt_buf_len, size_t *bytes_written)
 

Macro Definition Documentation

◆ IOTC_JWT_HEADER_BUF_SIZE

#define IOTC_JWT_HEADER_BUF_SIZE   40

Definition at line 26 of file iotc_jwt.h.

◆ IOTC_JWT_HEADER_BUF_SIZE_BASE64

#define IOTC_JWT_HEADER_BUF_SIZE_BASE64   (((IOTC_JWT_HEADER_BUF_SIZE + 2) / 3) * 4)

Definition at line 27 of file iotc_jwt.h.

◆ IOTC_JWT_MAX_SIGNATURE_SIZE

#define IOTC_JWT_MAX_SIGNATURE_SIZE   132

Definition at line 34 of file iotc_jwt.h.

◆ IOTC_JWT_MAX_SIGNATURE_SIZE_BASE64

#define IOTC_JWT_MAX_SIGNATURE_SIZE_BASE64   (((IOTC_JWT_MAX_SIGNATURE_SIZE + 2) / 3) * 4)

Definition at line 35 of file iotc_jwt.h.

◆ IOTC_JWT_PAYLOAD_BUF_SIZE

#define IOTC_JWT_PAYLOAD_BUF_SIZE   256

Definition at line 30 of file iotc_jwt.h.

◆ IOTC_JWT_PAYLOAD_BUF_SIZE_BASE64

#define IOTC_JWT_PAYLOAD_BUF_SIZE_BASE64   (((IOTC_JWT_PAYLOAD_BUF_SIZE + 2) / 3) * 4)

Definition at line 31 of file iotc_jwt.h.

◆ IOTC_JWT_SIZE

#define IOTC_JWT_SIZE
Value:
#define IOTC_JWT_PAYLOAD_BUF_SIZE_BASE64
Definition: iotc_jwt.h:31
#define IOTC_JWT_HEADER_BUF_SIZE_BASE64
Definition: iotc_jwt.h:27
#define IOTC_JWT_MAX_SIGNATURE_SIZE_BASE64
Definition: iotc_jwt.h:35

Definition at line 38 of file iotc_jwt.h.

Function Documentation

◆ iotc_create_iotcore_jwt()

iotc_state_t iotc_create_iotcore_jwt ( const char *  project_id,
uint32_t  expiration_period_sec,
const iotc_crypto_key_data_t private_key_data,
char *  dst_jwt_buf,
size_t  dst_jwt_buf_len,
size_t *  bytes_written 
)

Creates a JWT which will be used to connect to the IoT Core service. The JWT should be used in the MQTT Connect password field when connecting to IoT Core.

The function currently supports ES256 key types only, as its intended for small devices where ECC algorithims should be used to their smaller key footprint requirements.

Note: This function invokes the Crypto BSP functions iotc_bsp_sha256(), iotc_bsp_ecc(), and iotc_bsp_base64_encode_urlsafe() to fullfill string encoding and signature functionality.

Parameters
[in]expiration_period_secthe length of time (in seconds) before this JWT will expire.
[in]project_idthe project id the device belongs to in the GCP IoT organization.
[in]private_key_datadata identifying a private key to be used to sign the JWT. For more information on how to generate a private-public key pair for your device, please see: https://cloud.google.com/iot/docs/how-tos/credentials/keys.
[in/out]a pointer to a buffer to hold the formatted and signed JWT.
[in]dst_jwt_buf_lenthe length of the dst_jwt_buf buffer, in bytes.
[out]bytes_writtenwill contain the number of bytes that were written to the provided dst_jwt_buf.
Returns
IOTC_STATE_OK if jwt generation was successful.
IOTC_INVALID_PARAMETER if the project_id, private_key_data or dst_jwt_buf parameters are NULL, or if either of the crypto bsp functions returns IOTC_BSP_CRYPTO_INVALID_INPUT_PARAMETER_ERROR.
IOTC_ALG_NOT_SUPPORTED_ERROR if the private_key_data->crypto_key_signature_algorithm is not of type IOTC_CRYPTO_KEY_SIGNATURE_ALGORITHM_ES256.
IOTC_NULL_KEY_DATA_ERROR if the private_key_data is of type IOTC_CRYPTO_KEY_UNION_TYPE_PEM and the private_key_data->crypto_key_union.key_pem.key pointer is NULL.
IOTC_NOT_IMPLEMENTED if the private_key_data->crypto_key_union is of an uknown type.
IOTC_BUFFER_TOO_SMALL_ERROR if the crypto BSP returns