![]() |
QuarkLink-Client
v1.5.1
Crypto Quantique's QuarkLink-Client library
|
Where the QuarkLink magic happens. More...
#include <stdint.h>#include <stdbool.h>#include <string.h>Data Structures | |
| struct | quarklink_context_t |
| Quarklink context. More... | |
Macros | |
| #define | QUARKLINK_MAX_SHORT_DATA_LENGTH (30) |
| #define | QUARKLINK_MAX_URI_LENGTH (50) |
| #define | QUARKLINK_MAX_DEVICE_ID_LENGTH (65) |
| Device IDs are always 64-char strings. | |
| #define | QUARKLINK_MAX_ENDPOINT_LENGTH (128) |
| #define | QUARKLINK_MAX_KEY_LENGTH (256) |
| #define | QUARKLINK_MAX_CSR_LENGTH (2048) |
| #define | QUARKLINK_MAX_TOKEN_LENGTH (650) |
| #define | QUARKLINK_MAX_SHORT_CERT_LENGTH (1500) |
| #define | QUARKLINK_MAX_LONG_CERT_LENGTH (2048) |
Typedefs | |
| typedef struct quarklink_context_t | quarklink_context_t |
| Quarklink context. More... | |
Enumerations | |
| enum | quarklink_return_t { QUARKLINK_ERROR = -1 , QUARKLINK_INVALID_PARAMETER = -2 , QUARKLINK_CACERTS_ERROR = -3 , QUARKLINK_COMMUNICATION_ERROR = -4 , QUARKLINK_VALUE_NOT_AVAILABLE = -5 , QUARKLINK_NVM_ERROR = -6 , QUARKLINK_NOT_INITIALISED = -7 , QUARKLINK_AZURE_PROVISIONING_ERROR = -8 , QUARKLINK_SUCCESS = 0 , QUARKLINK_STATUS_ENROLLED = 10 , QUARKLINK_STATUS_FWUPDATE_REQUIRED = 11 , QUARKLINK_STATUS_NOT_ENROLLED = 12 , QUARKLINK_STATUS_CERTIFICATE_EXPIRED = 13 , QUARKLINK_STATUS_REVOKED = 14 , QUARKLINK_FWUPDATE_WRONG_SIGNATURE = 20 , QUARKLINK_FWUPDATE_MISSING_SIGNATURE = 21 , QUARKLINK_FWUPDATE_ERROR = 22 , QUARKLINK_FWUPDATE_NO_UPDATE = 23 , QUARKLINK_FWUPDATE_UPDATED = 24 , QUARKLINK_FW_UPDATE_WIFI_LOST = 25 , QUARKLINK_DEVICE_DOES_NOT_EXIST = 30 , QUARKLINK_DEVICE_REVOKED = 31 , QUARKLINK_CONTEXT_NO_CREDENTIALS_STORED = 40 , QUARKLINK_CONTEXT_NO_ENROLMENT_INFO_STORED = 41 , QUARKLINK_CONTEXT_NOTHING_STORED = 42 } |
| Quarklink return codes. More... | |
Functions | |
| quarklink_return_t | quarklink_init (quarklink_context_t *quarklink, const char *endpoint, const char *rootCert) |
| Initialise the Quarklink environment. More... | |
| quarklink_return_t | quarklink_enrol (quarklink_context_t *quarklink) |
| Enrol with Quarklink to provision and get credentials. More... | |
| quarklink_return_t | quarklink_status (quarklink_context_t *quarklink) |
| Request the current status of the device to Quarklink. More... | |
| quarklink_return_t | quarklink_firmwareUpdate (quarklink_context_t *quarklink, const char *signingKey) |
| Request a firmware update to QuarkLink, then runs the firmware over the air update. More... | |
| quarklink_return_t | quarklink_getDeviceID (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the unique device ID. More... | |
| quarklink_return_t | quarklink_getDeviceCert (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the device certificate. More... | |
| quarklink_return_t | quarklink_getRootCert (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the configured QuarkLink root certificate. More... | |
| quarklink_return_t | quarklink_getEndpoint (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the configured QuarkLink endpoint. More... | |
| quarklink_return_t | quarklink_getPort (const quarklink_context_t *quarklink, uint16_t *port) |
| Get the configured QuarkLink port. More... | |
| quarklink_return_t | quarklink_getIoTHubCert (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the configured IoT Hub root certificate. More... | |
| quarklink_return_t | quarklink_getIoTHubEndpoint (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the configured Iot Hub endpoint. More... | |
| quarklink_return_t | quarklink_getIoTHubPort (const quarklink_context_t *quarklink, uint16_t *port) |
| Get the configured IoT Hub port. More... | |
| quarklink_return_t | quarklink_getURL (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the complete QuarkLink URL, in the form of 'https://endpoint:port'. More... | |
| quarklink_return_t | quarklink_getEnrolmentKey (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the enrolment private key in PEM format. More... | |
| quarklink_return_t | quarklink_getDeviceKey (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the device private key in PEM format. More... | |
| quarklink_return_t | quarklink_getTempCert (const quarklink_context_t *quarklink, char *buffer, int length) |
| Get the temporary QuarkLink certificate (PEM format). More... | |
| quarklink_return_t | quarklink_setRootCert (quarklink_context_t *quarklink, const char *rootCert) |
| Set the root certificate. More... | |
| quarklink_return_t | quarklink_setEndpoint (quarklink_context_t *quarklink, const char *endpoint, uint16_t port) |
| Set the endpoint. More... | |
| quarklink_return_t | quarklink_persistContext (const quarklink_context_t *quarklink) |
| Persist the current context to non-volatile storage. More... | |
| quarklink_return_t | quarklink_persistEnrolmentContext (const quarklink_context_t *quarklink) |
| Persist the current context to non-volatile storage. More... | |
| quarklink_return_t | quarklink_loadStoredContext (quarklink_context_t *quarklink) |
| Load the QuarkLink context saved in non-volatile storage. More... | |
| quarklink_return_t | quarklink_deleteEnrolmentContext (const quarklink_context_t *quarklink) |
Only delete the enrollment details from the context saved with quarklink_persistContext(). More... | |
| quarklink_return_t | quarklink_deleteContext (const quarklink_context_t *quarklink) |
Delete the QuarkLink context saved with quarklink_persistContext(). More... | |
| int | quarklink_isDeviceEnrolled () |
| Check if the device is currently enrolled. More... | |
| int | quarklink_isDeviceNotEnrolled () |
| Check if the device is currently not enrolled. More... | |
| int | quarklink_isDeviceRevoked () |
| Check if the device is currently revoked. More... | |
| int | quarklink_isDevicePendingRevoke () |
| Check if the device is currently pending on a revoke. More... | |
| int | quarklink_isDeviceCertificateExpired () |
| Check if the device certificate is expired. More... | |
| int | quarklink_isDeviceFwUpdateAvailable () |
| Check if there is a firmware update available for the device. More... | |
Variables | |
| const char | QUARKLINK_VERSION [] |
| Constants. More... | |
Where the QuarkLink magic happens.
| typedef struct quarklink_context_t quarklink_context_t |
Quarklink context.
This struct is ~6.4KB and contains all the resources needed by a user that wants to use Quarklink. All certificates are in PEM format.
| enum quarklink_return_t |
Quarklink return codes.
Values below 0 are effectively errors, 0 is the general value for "success", values greater than 0 are not necessarily errors.
| quarklink_return_t quarklink_init | ( | quarklink_context_t * | quarklink, |
| const char * | endpoint, | ||
| const char * | rootCert | ||
| ) |
Initialise the Quarklink environment.
| [in,out] | quarklink | the QuarkLink context to initialise. |
| [in] | endpoint | the name of the QuarkLink instance (e.g. cryptoquantique.quarklink.io) |
| [in] | rootCert | the root certificate for the QuarkLink instance |
| QUARKLINK_SUCCESS | for success |
| Others | for error |
| quarklink_return_t quarklink_enrol | ( | quarklink_context_t * | quarklink | ) |
Enrol with Quarklink to provision and get credentials.
| [in,out] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| QUARKLINK_SUCCESS | for success |
| QUARKLINK_DEVICE_DOES_NOT_EXIST | |
| QUARKLINK_DEVICE_REVOKED | |
| QUARKLINK_CACERTS_ERROR | |
| Other | errors |
| quarklink_return_t quarklink_status | ( | quarklink_context_t * | quarklink | ) |
Request the current status of the device to Quarklink.
| [in,out] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| QUARKLINK_STATUS_ENROLLED | |
| QUARKLINK_STATUS_FWUPDATE_REQUIRED | |
| QUARKLINK_STATUS_NOT_ENROLLED | |
| QUARKLINK_STATUS_CERTIFICATE_EXPIRED | |
| QUARKLINK_STATUS_REVOKED | |
| Other | errors |
| quarklink_return_t quarklink_firmwareUpdate | ( | quarklink_context_t * | quarklink, |
| const char * | signingKey | ||
| ) |
Request a firmware update to QuarkLink, then runs the firmware over the air update.
| [in,out] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| signingKey | the public key used to validate the firmware, in PEM format. NULL for no key or if the key was provisioned using QuarkLink provisioning task. |
| QUARKLINK_FWUPDATE_UPDATED | |
| QUARKLINK_FWUPDATE_NO_UPDATE | |
| QUARKLINK_FWUPDATE_WRONG_SIGNATURE | |
| QUARKLINK_FWUPDATE_MISSING_SIGNATURE | |
| QUARKLINK_FWUPDATE_ERROR | |
| Other | errors |
| quarklink_return_t quarklink_getDeviceID | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the unique device ID.
QUARKLINK_MAX_DEVICE_ID_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the device ID will be copied |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getDeviceCert | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the device certificate.
QUARKLINK_MAX_CERTIFICATE_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the device certificate will be copied |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getRootCert | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the configured QuarkLink root certificate.
QUARKLINK_MAX_CERTIFICATE_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the root certificate will be copied |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getEndpoint | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the configured QuarkLink endpoint.
QUARKLINK_MAX_ENDPOINT_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first The endpoint is configured in the form of instance.quarklink.io. |
| [out] | buffer | the buffer where the endpoint will be copied |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getPort | ( | const quarklink_context_t * | quarklink, |
| uint16_t * | port | ||
| ) |
Get the configured QuarkLink port.
| [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | port | the variable where the port value will be copied |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getIoTHubCert | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the configured IoT Hub root certificate.
QUARKLINK_MAX_CERTIFICATE_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the root certificate will be copied |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getIoTHubEndpoint | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the configured Iot Hub endpoint.
QUARKLINK_MAX_ENDPOINT_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the endpoint will be copied |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getIoTHubPort | ( | const quarklink_context_t * | quarklink, |
| uint16_t * | port | ||
| ) |
Get the configured IoT Hub port.
| [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | port | the variable where the port value will be copied |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getURL | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the complete QuarkLink URL, in the form of 'https://endpoint:port'.
QUARKLINK_MAX_ENDPOINT_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the URL will be saved |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getEnrolmentKey | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the enrolment private key in PEM format.
QUARKLINK_MAX_KEY_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the key will be saved |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getDeviceKey | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the device private key in PEM format.
QUARKLINK_MAX_KEY_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the key will be saved |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_getTempCert | ( | const quarklink_context_t * | quarklink, |
| char * | buffer, | ||
| int | length | ||
| ) |
Get the temporary QuarkLink certificate (PEM format).
QUARKLINK_MAX_CERTIFICATE_LENGTH bytes. | [in] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [out] | buffer | the buffer where the certificate will be copied |
| [in] | length | the size of the buffer provided |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER | |
| QUARKLINK_VALUE_NOT_AVAILABLE |
| quarklink_return_t quarklink_setRootCert | ( | quarklink_context_t * | quarklink, |
| const char * | rootCert | ||
| ) |
Set the root certificate.
Use to update if it changed after quarklink_init was called.
| [in,out] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [in] | rootCert | the new root certificate |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER |
| quarklink_return_t quarklink_setEndpoint | ( | quarklink_context_t * | quarklink, |
| const char * | endpoint, | ||
| uint16_t | port | ||
| ) |
Set the endpoint.
Use to update if it changed after quarklink_init was called.
| [in,out] | quarklink | the QuarkLink context, make sure to initialise it with quarklink_init() first |
| [in] | endpoint | the new root certificate |
| [in] | port | the new port (default is 443) |
| QUARKLINK_SUCCESS | |
| QUARKLINK_INVALID_PARAMETER |
| quarklink_return_t quarklink_persistContext | ( | const quarklink_context_t * | quarklink | ) |
Persist the current context to non-volatile storage.
Call this function to store the QuarkLink details. Use quarklink_loadStoredContext() to load the persisted context. QuarkLink details include rootCert, endpoint and port.
| [in] | quarklink | the context to be stored. Needs to be initialised first. |
| QUARKLINK_SUCCESS | |
| QUARKLINK_NOT_INITIALISED | |
| QUARKLINK_NVM_ERROR |
| quarklink_return_t quarklink_persistEnrolmentContext | ( | const quarklink_context_t * | quarklink | ) |
Persist the current context to non-volatile storage.
Call this function after a successful enrol to avoid re-enrolling the device every time it restarts. Use quarklink_loadStoredContext() to load the persisted context. Enrolment context includes: deviceCert, IoT Hub endpoint, port and certificate, scopeID, firmware update topic.
| [in] | quarklink | the context to be stored. Needs to be initialised first. |
| QUARKLINK_SUCCESS | |
| QUARKLINK_NOT_INITIALISED | |
| QUARKLINK_NVM_ERROR |
| quarklink_return_t quarklink_loadStoredContext | ( | quarklink_context_t * | quarklink | ) |
Load the QuarkLink context saved in non-volatile storage.
Call this function to load the last configuration, to avoid re-enrolling the device after each restart. Use quarklink_persistContext() to persist the context.
| [out] | quarklink | the context to be updated with the stored configuration. Needs to be initialised first. |
| QUARKLINK_SUCCESS | |
| QUARKLINK_NOT_INITIALISED | |
| QUARKLINK_CONTEXT_NO_CREDENTIALS_STORED | |
| QUARKLINK_CONTEXT_NO_ENROLMENT_INFO_STORED | |
| QUARKLINK_CONTEXT_NOTHING_STORED | |
| QUARKLINK_NVM_ERROR |
| quarklink_return_t quarklink_deleteEnrolmentContext | ( | const quarklink_context_t * | quarklink | ) |
Only delete the enrollment details from the context saved with quarklink_persistContext().
Enrollment details include: deviceCert, IoT Hub endpoint, port and certificate, scopeID, firmware update topic.
| [in] | quarklink | the context to be deleted. Needs to be initialised first. |
| QUARKLINK_SUCCESS | |
| QUARKLINK_ERROR |
| quarklink_return_t quarklink_deleteContext | ( | const quarklink_context_t * | quarklink | ) |
Delete the QuarkLink context saved with quarklink_persistContext().
Quarklink context includes: rootCert, endpoint and port.
| [in] | quarklink | the context to be deleted. Needs to be initialised first. |
| QUARKLINK_SUCCESS | |
| QUARKLINK_ERROR |
| int quarklink_isDeviceEnrolled | ( | ) |
Check if the device is currently enrolled.
This function needs to be called after quarklink_status(), in order to have an up-to-date device status.
quarklink_isDeviceEnrolled(), quarklink_isDeviceNotEnrolled(), quarklink_isDeviceRevoked() and quarklink_isDevicePendingRevoke() are mutually exclusive, meaning only one of these can be true at the same time.| int quarklink_isDeviceNotEnrolled | ( | ) |
Check if the device is currently not enrolled.
This function needs to be called after quarklink_status(), in order to have an up-to-date device status.
quarklink_isDeviceEnrolled(), quarklink_isDeviceNotEnrolled(), quarklink_isDeviceRevoked() and quarklink_isDevicePendingRevoke() are mutually exclusive, meaning only one of these can be true at the same time.| int quarklink_isDeviceRevoked | ( | ) |
Check if the device is currently revoked.
This function needs to be called after quarklink_status(), in order to have an up-to-date device status.
quarklink_isDeviceEnrolled(), quarklink_isDeviceNotEnrolled(), quarklink_isDeviceRevoked() and quarklink_isDevicePendingRevoke() are mutually exclusive, meaning only one of these can be true at the same time.| int quarklink_isDevicePendingRevoke | ( | ) |
Check if the device is currently pending on a revoke.
This function needs to be called after quarklink_status(), in order to have an up-to-date device status.
quarklink_isDeviceEnrolled(), quarklink_isDeviceNotEnrolled(), quarklink_isDeviceRevoked() and quarklink_isDevicePendingRevoke() are mutually exclusive, meaning only one of these can be true at the same time.| int quarklink_isDeviceCertificateExpired | ( | ) |
Check if the device certificate is expired.
This function needs to be called after quarklink_status(), in order to have an up-to-date device status.
quarklink_isDeviceEnrolled(), quarklink_isDeviceNotEnrolled(), quarklink_isDeviceRevoked() and quarklink_isDevicePendingRevoke() are mutually exclusive, meaning only one of these can be true at the same time.| int quarklink_isDeviceFwUpdateAvailable | ( | ) |
Check if there is a firmware update available for the device.
This function needs to be called after quarklink_status(), in order to have an up-to-date device status.
quarklink_isDeviceEnrolled(), quarklink_isDeviceNotEnrolled(), quarklink_isDeviceRevoked() and quarklink_isDevicePendingRevoke() are mutually exclusive, meaning only one of these can be true at the same time.
|
extern |
Constants.
Current QuarkLink version