Astarte Device SDK ESP32
ESP32 device SDK for the Astarte platform
astarte_credentials.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018, Ispirata Srl, info@ispirata.com.
3  *
4  * SPDX-License-Identifier: LGPL-2.1+ OR Apache-2.0
5  */
6 
12 #ifndef _ASTARTE_CREDENTIALS_H_
13 #define _ASTARTE_CREDENTIALS_H_
14 
15 #include "astarte.h"
16 
17 #include <stdbool.h>
18 #include <string.h>
19 
20 #define ASTARTE_CREDENTIALS_DEFAULT_NVS_PARTITION NULL
21 
22 enum credential_type_t
23 {
24  ASTARTE_CREDENTIALS_CSR = 1,
25  ASTARTE_CREDENTIALS_KEY,
26  ASTARTE_CREDENTIALS_CERTIFICATE
27 };
28 
29 typedef astarte_err_t (*astarte_credentials_store_t)(
30  void *opaque, enum credential_type_t cred_type, const void *credential, size_t length);
31 typedef astarte_err_t (*astarte_credentials_fetch_t)(
32  void *opaque, enum credential_type_t cred_type, char *out, size_t length);
33 typedef bool (*astarte_credentials_exists_t)(void *opaque, enum credential_type_t cred_type);
34 typedef astarte_err_t (*astarte_credentials_remove_t)(
35  void *opaque, enum credential_type_t cred_type);
36 
37 typedef struct
38 {
39  astarte_credentials_store_t astarte_credentials_store;
40  astarte_credentials_fetch_t astarte_credentials_fetch;
41  astarte_credentials_exists_t astarte_credentials_exists;
42  astarte_credentials_remove_t astarte_credentials_remove;
44 
45 typedef struct
46 {
48  void *opaque;
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
63 
75 
84 
91 
102 
113 
124 
134 
144 astarte_err_t astarte_credentials_get_csr(char *out, size_t length);
145 
156 
168  const char *cert_pem, char *out, size_t length);
169 
179 astarte_err_t astarte_credentials_get_key(char *out, size_t length);
180 
192 
203 
214 
222 
230 
238 
239 /*
240  * @brief store a credential using filesystem storage
241  *
242  * @details this API might change in future versions.
243  */
244 astarte_err_t astarte_credentials_store(
245  void *opaque, enum credential_type_t cred_type, const void *credential, size_t length);
246 
247 /*
248  * @brief fetch a credential using filesystem storage
249  *
250  * @details this API might change in future versions.
251  */
252 astarte_err_t astarte_credentials_fetch(
253  void *opaque, enum credential_type_t cred_type, char *out, size_t length);
254 
255 /*
256  * @brief return true whether a credential exists on fileystem storage
257  *
258  * @details this API might change in future versions.
259  */
260 bool astarte_credentials_exists(void *opaque, enum credential_type_t cred_type);
261 
262 /*
263  * @brief remove a credential from filesystem storage
264  *
265  * @details this API might change in future versions.
266  */
267 astarte_err_t astarte_credentials_remove(void *opaque, enum credential_type_t cred_type);
268 
269 /*
270  * @brief store a credential using NVS
271  *
272  * @details this API might change in future versions.
273  */
274 astarte_err_t astarte_credentials_nvs_store(
275  void *opaque, enum credential_type_t cred_type, const void *credential, size_t length);
276 
277 /*
278  * @brief fetch a credential using NVS
279  *
280  * @details this API might change in future versions.
281  */
282 astarte_err_t astarte_credentials_nvs_fetch(
283  void *opaque, enum credential_type_t cred_type, char *out, size_t length);
284 
285 /*
286  * @brief return true whether a credential exists on NVS
287  *
288  * @details this API might change in future versions.
289  */
290 bool astarte_credentials_nvs_exists(void *opaque, enum credential_type_t cred_type);
291 
292 /*
293  * @brief remove a credential from NVS
294  *
295  * @details this API might change in future versions.
296  */
297 astarte_err_t astarte_credentials_nvs_remove(void *opaque, enum credential_type_t cred_type);
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif
Astarte types and defines.
astarte_err_t
Astarte return codes.
Definition: astarte.h:28
astarte_err_t astarte_credentials_get_csr(char *out, size_t length)
get the saved CSR
bool astarte_credentials_has_certificate()
check if the certificate exists
astarte_err_t astarte_credentials_create_key()
create Astarte private key.
astarte_err_t astarte_credentials_get_key(char *out, size_t length)
get the private key to connect with the Astarte MQTT v1 protocol
astarte_err_t astarte_credentials_create_csr()
create Astarte CSR to be sent to Pairing API.
bool astarte_credentials_has_key()
check if the private key exists
astarte_err_t astarte_credentials_set_storage_context(astarte_credentials_context_t *creds_context)
replace credentials context.
astarte_err_t astarte_credentials_get_stored_credentials_secret(char *out, size_t length)
get the stored credentials_secret
bool astarte_credentials_has_csr()
check if the CSR exists
astarte_err_t astarte_credentials_set_stored_credentials_secret(const char *credentials_secret)
save the credentials_secret in the NVS
astarte_err_t astarte_credentials_delete_certificate()
delets the saved certificate used to connect with the Astarte MQTT v1 protocol
astarte_err_t astarte_credentials_save_certificate(const char *cert_pem)
save the certificate to connect with the Astarte MQTT v1 protocol
astarte_err_t astarte_credentials_init()
initialize Astarte credentials.
astarte_err_t astarte_credentials_get_certificate(char *out, size_t length)
get the certificate to connect with the Astarte MQTT v1 protocol
astarte_err_t astarte_credentials_erase_stored_credentials_secret()
delete the credentials_secret from the NVS
astarte_err_t astarte_credentials_use_nvs_storage(const char *partition_label)
use a NVS partition as credentials context.
astarte_err_t astarte_credentials_get_certificate_common_name(const char *cert_pem, char *out, size_t length)
get the certificate Common Name
bool astarte_credentials_is_initialized()
check if Astarte credentials are initialized.
Definition: astarte_credentials.h:46
Definition: astarte_credentials.h:38