Skip to content

Commit b3d3492

Browse files
committed
Add fido vault
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
1 parent b914293 commit b3d3492

9 files changed

Lines changed: 145 additions & 548 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,12 @@ list(APPEND SOURCES
131131
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_cred_mgmt.c
132132
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_config.c
133133
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_vendor.c
134-
${CMAKE_CURRENT_LIST_DIR}/src/fido/vault.c
134+
${CMAKE_CURRENT_LIST_DIR}/src/fido/fido_vault.c
135135
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_large_blobs.c
136136
${CMAKE_CURRENT_LIST_DIR}/src/fido/management.c
137137
${CMAKE_CURRENT_LIST_DIR}/src/fido/defs.c
138138
)
139139

140-
if (NOT ESP_PLATFORM)
141-
list(APPEND SOURCES
142-
${CMAKE_CURRENT_LIST_DIR}/pico-keys-sdk/third-party/mbedtls/library/x509.c
143-
${CMAKE_CURRENT_LIST_DIR}/pico-keys-sdk/third-party/mbedtls/library/x509_crt.c
144-
${CMAKE_CURRENT_LIST_DIR}/pico-keys-sdk/third-party/mbedtls/library/pkparse.c
145-
${CMAKE_CURRENT_LIST_DIR}/pico-keys-sdk/third-party/mbedtls/library/pk_ecc.c
146-
)
147-
endif()
148-
149140
if(ENABLE_OATH_APP)
150141
list(APPEND SOURCES
151142
${CMAKE_CURRENT_LIST_DIR}/src/fido/oath_container.c

src/fido/cbor_vendor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "mbedtls/x509_csr.h"
4444
#include "mbedtls/x509_crt.h"
4545

46-
#include "vault.h"
46+
#include "fido_vault.h"
4747

4848
extern uint8_t keydev_dec[32];
4949
extern bool has_keydev_dec;

src/fido/fido.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ int scan_files_fido(void) {
459459
else {
460460
printf("FATAL ERROR: CERT DEV not found in memory!\r\n");
461461
}
462-
ef_vault_label = file_search_by_fid(EF_VAULT_LABEL, NULL, SPECIFY_EF);
463462
ef_counter = file_search_by_fid(EF_COUNTER, NULL, SPECIFY_EF);
464463
if (ef_counter) {
465464
if (!file_has_data(ef_counter)) {
Lines changed: 86 additions & 467 deletions
Large diffs are not rendered by default.

src/fido/fido_vault.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of the Pico FIDO distribution (https://github.com/polhenarejos/pico-fido).
3+
* Copyright (c) 2022 Pol Henarejos.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published by
7+
* the Free Software Foundation, version 3.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef _VAULT_H_
19+
#define _VAULT_H_
20+
21+
#include <stdbool.h>
22+
#include <stddef.h>
23+
#include <stdint.h>
24+
#include "ctap2_cbor.h"
25+
#include "credential.h"
26+
#include "serial.h"
27+
#include "fs/vault_container.h"
28+
29+
#define VAULT_X448_BYTES PICOKEYS_VAULT_X448_BYTES
30+
#define VAULT_APP_ID 0u
31+
#define VAULT_CREDENTIAL_METADATA_MAX 512
32+
#define VAULT_KEY_BYTES PICOKEYS_VAULT_KEY_SIZE
33+
#define VAULT_ID_BYTES PICOKEYS_VAULT_KEY_SIZE
34+
#define VAULT_ENROLL_CHALLENGE_BYTES PICOKEYS_VAULT_ENROLL_CHALLENGE_BYTES
35+
#define VAULT_ENROLL_CERT_MAX PICOKEYS_VAULT_ENROLL_CERT_MAX
36+
#define VAULT_ENROLL_MIN_PACKET_LEN PICOKEYS_VAULT_ENROLL_MIN_PACKET_LEN
37+
#define VAULT_LABEL_MAX 64
38+
#define VAULT_ENROLL_PLAIN_MAX PICOKEYS_VAULT_ENROLL_PLAIN_MAX
39+
#define VAULT_STORE_LEN PICOKEYS_VAULT_RECORD_SIZE
40+
#define VAULT_BLOB_SERIAL_MAX 16
41+
#define VAULT_BLOB_SERIAL_LEN_OFFSET (4 + VAULT_ID_BYTES + VAULT_ID_BYTES)
42+
#define VAULT_BLOB_SERIAL_OFFSET (VAULT_BLOB_SERIAL_LEN_OFFSET + 1)
43+
#define VAULT_BLOB_ALGORITHM_OFFSET (VAULT_BLOB_SERIAL_OFFSET + VAULT_BLOB_SERIAL_MAX)
44+
#define VAULT_BLOB_HEADER_LEN (VAULT_BLOB_ALGORITHM_OFFSET + 1)
45+
#define VAULT_BLOB_NONCE_BYTES PICOKEYS_VAULT_BLOB_NONCE_SIZE
46+
#define VAULT_PLAIN_MAX (MAX_CRED_ID_LENGTH + VAULT_CREDENTIAL_METADATA_MAX + 256)
47+
#define VAULT_BLOB_MAX (VAULT_BLOB_HEADER_LEN + 24 + VAULT_PLAIN_MAX + 32)
48+
extern int vault_load_key(uint8_t key[VAULT_KEY_BYTES]);
49+
extern int vault_enrollment_finish(const uint8_t *packet, size_t packet_len);
50+
extern int vault_export_blob(const uint8_t *requested_id, size_t requested_id_len, uint8_t algorithm, uint8_t *blob, size_t blob_capacity, size_t *blob_len, uint8_t *metadata, size_t metadata_capacity, size_t *metadata_len);
51+
extern int vault_import_blob(const uint8_t *blob, size_t blob_len);
52+
extern int vault_encode_credential_metadata(const Credential *credential, const uint8_t rp_id_hash[RP_ID_HASH_LEN], uint8_t *buffer, size_t buffer_len, size_t *metadata_len);
53+
extern CborError vault_vendor_command(uint64_t vendorCmd, CborByteString vendorParam, CborByteString pinUvAuthParam, uint64_t pinUvAuthProtocol, const uint8_t *raw_vendor_params, size_t raw_vendor_params_len, uint64_t vault_algorithm, bool vault_algorithm_present, CborEncoder encoder, size_t *resp_size, bool *response_handled, int *ctap_error);
54+
55+
#endif

src/fido/files.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ file_entry_t file_entries[] = {
2424
{ .fid = EF_EE_DEV, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // End Entity Certificate Device
2525
{ .fid = EF_EE_DEV_EA, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // End Entity Enterprise Attestation Certificate
2626
{ .fid = EF_VAULT_KEY, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // Vault key protected by the device key
27-
{ .fid = EF_VAULT_LABEL, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // Vault label
27+
{ .fid = EF_VAULT_LABEL, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // Legacy vault label migration input
2828
{ .fid = EF_COUNTER, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // Global counter
2929
{ .fid = EF_PIN, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // PIN
3030
{ .fid = EF_AUTHTOKEN, .parent = 0, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = ACL_NONE }, // AUTH TOKEN
@@ -50,4 +50,3 @@ file_t *ef_authtoken = NULL;
5050
file_t *ef_keydev_enc = NULL;
5151
file_t *ef_largeblob = NULL;
5252
file_t *ef_vault_key = NULL;
53-
file_t *ef_vault_label = NULL;

src/fido/files.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,5 @@ extern file_t *ef_authtoken;
5656
extern file_t *ef_keydev_enc;
5757
extern file_t *ef_largeblob;
5858
extern file_t *ef_vault_key;
59-
extern file_t *ef_vault_label;
6059

6160
#endif //_FILES_H_

src/fido/vault.h

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)