-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c18817
commit b9d7c7f
Showing
24 changed files
with
1,260 additions
and
953 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "os.h" | ||
#include "cx.h" | ||
#include "pki.h" | ||
#include "os_pki.h" | ||
|
||
int check_signature_with_pki(uint8_t *buffer, | ||
uint8_t buffer_length, | ||
uint8_t expected_key_usage, | ||
const cbuf_t *signature) { | ||
uint8_t key_usage = 0; | ||
size_t certificate_name_len = 0; | ||
uint8_t certificate_name[CERTIFICATE_TRUSTED_NAME_MAXLEN] = {0}; | ||
cx_ecfp_384_public_key_t public_key = {0}; | ||
|
||
bolos_err_t bolos_err; | ||
bolos_err = os_pki_get_info(&key_usage, certificate_name, &certificate_name_len, &public_key); | ||
if (bolos_err != 0x0000) { | ||
PRINTF("Error %x while getting PKI certificate info\n", bolos_err); | ||
return -1; | ||
} | ||
|
||
if (key_usage != expected_key_usage) { | ||
PRINTF("Wrong usage certificate %d, expected %d\n", key_usage, expected_key_usage); | ||
return -1; | ||
} | ||
|
||
PRINTF("Certificate '%s' loaded with success\n", certificate_name); | ||
|
||
// Checking the signature with PKI | ||
if (!os_pki_verify(buffer, buffer_length, (uint8_t *)signature->bytes, signature->size)) { | ||
PRINTF("Error, '%.*H' is not a signature of buffer '%.*H' by the PKI key '%.*H'\n", | ||
signature->size, | ||
signature->bytes, | ||
buffer_length, | ||
buffer, | ||
sizeof(public_key), | ||
&public_key); | ||
return -1; | ||
} | ||
|
||
PRINTF("Signature verified successfully\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <cx.h> | ||
#include <os.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#include "buf.h" | ||
|
||
int check_signature_with_pki(uint8_t *buffer, | ||
uint8_t buffer_length, | ||
uint8_t expected_key_usage, | ||
const cbuf_t *signature); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <cx.h> | ||
#include <os.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
#include "buf.h" | ||
|
||
// List of TLV tags recognized by the Exchange application | ||
#define TLV_TAGS \ | ||
X(STRUCT_TYPE, 0x01) \ | ||
X(STRUCT_VERSION, 0x02) \ | ||
X(TRUSTED_NAME_TYPE, 0x70) \ | ||
X(TRUSTED_NAME_SOURCE, 0x71) \ | ||
X(TRUSTED_NAME, 0x20) \ | ||
X(CHAIN_ID, 0x23) \ | ||
X(ADDRESS, 0x22) \ | ||
X(SOURCE_CONTRACT, 0x73) \ | ||
X(CHALLENGE, 0x12) \ | ||
X(SIGNER_KEY_ID, 0x13) \ | ||
X(SIGNER_ALGO, 0x14) \ | ||
X(SIGNATURE, 0x15) | ||
|
||
// Parsed TLV data | ||
typedef struct tlv_out_s { | ||
uint8_t struct_version; | ||
uint8_t struct_type; | ||
cbuf_t token_account; | ||
cbuf_t owner; | ||
cbuf_t spl_token; | ||
uint64_t chain_id; | ||
uint32_t challenge; | ||
uint8_t name_type; | ||
uint8_t name_source; | ||
|
||
uint8_t key_id; | ||
uint8_t sig_algorithm; | ||
cbuf_t input_sig; | ||
} tlv_out_t; |
Oops, something went wrong.