Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
ledger_pki.c
Go to the documentation of this file.
1#include "os_types.h"
2#include "os_pki.h"
3#include "ledger_pki.h"
4
6 const uint8_t *expected_key_usage,
7 const cx_curve_t *expected_curve,
8 const buffer_t signature)
9{
10 uint8_t key_usage = 0;
11 size_t certificate_name_len = 0;
12 uint8_t certificate_name[CERTIFICATE_TRUSTED_NAME_MAXLEN] = {0};
13 cx_ecfp_384_public_key_t public_key = {0};
14 bolos_err_t bolos_err;
15
16 // Retrieve currently loaded PKI certificate information
17 bolos_err = os_pki_get_info(&key_usage, certificate_name, &certificate_name_len, &public_key);
18 if (bolos_err != 0x0000) {
19 PRINTF("Error %x while getting PKI certificate info\n", bolos_err);
21 }
22
23 // Ensure the loaded certificate key usage and curve match the expected values
24 if (expected_key_usage != NULL && key_usage != *expected_key_usage) {
25 PRINTF("Wrong usage certificate %d, expected %d\n", key_usage, *expected_key_usage);
27 }
28 if (expected_curve != NULL && public_key.curve != *expected_curve) {
29 PRINTF("Wrong curve %d, expected %d\n", public_key.curve, *expected_curve);
31 }
32
33 PRINTF("Certificate '%s' loaded with success\n", certificate_name);
34
35 // Verify the signature using PKI
36 if (!os_pki_verify(
37 (uint8_t *) hash.ptr, hash.size, (uint8_t *) signature.ptr, signature.size)) {
38 PRINTF("Error, '%.*H' is not a signature of hash '%.*H' by the PKI key '%.*H'\n",
39 signature.size,
40 signature.ptr,
41 hash.size,
42 hash.ptr,
43 sizeof(public_key),
44 &public_key);
46 }
47
48 PRINTF("Signature verified successfully\n");
50}
check_signature_with_pki_status_t check_signature_with_pki(const buffer_t hash, const uint8_t *expected_key_usage, const cx_curve_t *expected_curve, const buffer_t signature)
Checks a signature using the PKI certificate.
Definition ledger_pki.c:5
@ CHECK_SIGNATURE_WITH_PKI_WRONG_CERTIFICATE_CURVE
Definition ledger_pki.h:10
@ CHECK_SIGNATURE_WITH_PKI_WRONG_CERTIFICATE_USAGE
Definition ledger_pki.h:9
@ CHECK_SIGNATURE_WITH_PKI_WRONG_SIGNATURE
Definition ledger_pki.h:11
@ CHECK_SIGNATURE_WITH_PKI_MISSING_CERTIFICATE
Definition ledger_pki.h:8
@ CHECK_SIGNATURE_WITH_PKI_SUCCESS
Definition ledger_pki.h:7
enum check_signature_with_pki_status_e check_signature_with_pki_status_t
uint8_t * ptr
Definition buffer.h:22
size_t size
Pointer to byte buffer.
Definition buffer.h:23