This repository was archived by the owner on Jul 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathiotc_jwt.h
76 lines (65 loc) · 2.59 KB
/
iotc_jwt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Copyright 2018-2020 Google LLC
*
* This is part of the Google Cloud IoT Device SDK for Embedded C.
* It is licensed under the BSD 3-Clause license; you may not use this file
* except in compliance with the License.
*
* You may obtain a copy of the License at:
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __IOTC_JWT_H__
#define __IOTC_JWT_H__
#include <iotc_types.h>
#ifdef __cplusplus
extern "C" {
#endif
/*! \file
* @brief Creates JSON Web Tokens for authenticating to Cloud IoT Core.
*/
/** The size, in bytes, of the JWT header. */
#define IOTC_JWT_HEADER_BUF_SIZE 40
/** The size, in bytes, of the URL-encoded JWT header. */
#define IOTC_JWT_HEADER_BUF_SIZE_BASE64 \
(((IOTC_JWT_HEADER_BUF_SIZE + 2) / 3) * 4)
/** The size, in bytes, of the JWT payload. */
#define IOTC_JWT_PAYLOAD_BUF_SIZE 256
/** The size, in bytes, of the URL-encoded JWT payload. */
#define IOTC_JWT_PAYLOAD_BUF_SIZE_BASE64 \
(((IOTC_JWT_PAYLOAD_BUF_SIZE + 2) / 3) * 4)
/** The maximum size, in bytes, of the JWT signature. */
#define IOTC_JWT_MAX_SIGNATURE_SIZE 132
/** The maxiumum size, in bytes, of the URL-encoded JWT. */
#define IOTC_JWT_MAX_SIGNATURE_SIZE_BASE64 \
(((IOTC_JWT_MAX_SIGNATURE_SIZE + 2) / 3) * 4)
/** The size, in bytes, of the JWT. */
#define IOTC_JWT_SIZE \
(IOTC_JWT_HEADER_BUF_SIZE_BASE64 + 1 + IOTC_JWT_PAYLOAD_BUF_SIZE_BASE64 + \
1 + IOTC_JWT_MAX_SIGNATURE_SIZE_BASE64)
/**
* @brief Creates a JWT for authenticating to Cloud IoT Core.
*
* @param [in] expiration_period_sec The number of seconds before this JWT
* expires.
* @param [in] project_id The GCP project ID.
* @param [in] private_key_data ES256 private key data.
* @param [in,out] dst_jwt_buf A pointer to a buffer that stores a formatted and
* signed JWT.
* @param [in] dst_jwt_buf_len The length, in bytes, of the buffer to which
* dst_jwt_buf points.
* @param [out] bytes_written The number of bytes written to the buffer to which
* dst_jwt_buf points.
*/
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);
#ifdef __cplusplus
}
#endif
#endif /* __IOTC_JWT_H__ */