diff --git a/src/fido/cbor_client_pin.c b/src/fido/cbor_client_pin.c
index ef2cd4d..0464129 100644
--- a/src/fido/cbor_client_pin.c
+++ b/src/fido/cbor_client_pin.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#ifndef ESP_PLATFORM
#include "common.h"
#else
@@ -35,7 +36,6 @@
#include "files.h"
#include "random.h"
#include "crypto_utils.h"
-#include "pico_keys.h"
#include "apdu.h"
#include "kek.h"
diff --git a/src/fido/cbor_config.c b/src/fido/cbor_config.c
index 02bcd06..3da353d 100644
--- a/src/fido/cbor_config.c
+++ b/src/fido/cbor_config.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "ctap2_cbor.h"
#include "fido.h"
#include "ctap.h"
@@ -22,7 +23,6 @@
#include "files.h"
#include "apdu.h"
#include "credential.h"
-#include "pico_keys.h"
#include "random.h"
#include "mbedtls/ecdh.h"
#include "mbedtls/chachapoly.h"
diff --git a/src/fido/cbor_cred_mgmt.c b/src/fido/cbor_cred_mgmt.c
index 901ec00..3f90a37 100644
--- a/src/fido/cbor_cred_mgmt.c
+++ b/src/fido/cbor_cred_mgmt.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "fido.h"
#include "ctap.h"
#include "hid/ctap_hid.h"
@@ -22,7 +23,6 @@
#include "files.h"
#include "apdu.h"
#include "credential.h"
-#include "pico_keys.h"
uint8_t rp_counter = 1;
uint8_t rp_total = 0;
diff --git a/src/fido/cbor_get_assertion.c b/src/fido/cbor_get_assertion.c
index e2cbaab..7829378 100644
--- a/src/fido/cbor_get_assertion.c
+++ b/src/fido/cbor_get_assertion.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "cbor.h"
#include "ctap.h"
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
@@ -24,7 +25,6 @@
#include "fido.h"
#include "files.h"
#include "crypto_utils.h"
-#include "pico_keys.h"
#include "apdu.h"
#include "cbor_make_credential.h"
#include "credential.h"
diff --git a/src/fido/cbor_get_info.c b/src/fido/cbor_get_info.c
index 216e7ee..63a98a6 100644
--- a/src/fido/cbor_get_info.c
+++ b/src/fido/cbor_get_info.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "ctap2_cbor.h"
#include "hid/ctap_hid.h"
#include "fido.h"
diff --git a/src/fido/cbor_large_blobs.c b/src/fido/cbor_large_blobs.c
index e1b0aa5..d1078c4 100644
--- a/src/fido/cbor_large_blobs.c
+++ b/src/fido/cbor_large_blobs.c
@@ -15,13 +15,13 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "ctap2_cbor.h"
#include "fido.h"
#include "ctap.h"
#include "hid/ctap_hid.h"
#include "files.h"
#include "apdu.h"
-#include "pico_keys.h"
#include "mbedtls/sha256.h"
static uint64_t expectedLength = 0, expectedNextOffset = 0;
diff --git a/src/fido/cbor_make_credential.c b/src/fido/cbor_make_credential.c
index 72e615b..359bf91 100644
--- a/src/fido/cbor_make_credential.c
+++ b/src/fido/cbor_make_credential.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "cbor_make_credential.h"
#include "ctap2_cbor.h"
#include "hid/ctap_hid.h"
@@ -25,7 +26,6 @@
#include "credential.h"
#include "mbedtls/sha256.h"
#include "random.h"
-#include "pico_keys.h"
#include "crypto_utils.h"
int cbor_make_credential(const uint8_t *data, size_t len) {
diff --git a/src/fido/cbor_reset.c b/src/fido/cbor_reset.c
index afc8298..cc18e9c 100644
--- a/src/fido/cbor_reset.c
+++ b/src/fido/cbor_reset.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "file.h"
#include "fido.h"
#include "ctap.h"
diff --git a/src/fido/cbor_selection.c b/src/fido/cbor_selection.c
index 8a0e1c2..8e2c395 100644
--- a/src/fido/cbor_selection.c
+++ b/src/fido/cbor_selection.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "fido.h"
#include "ctap.h"
diff --git a/src/fido/cbor_vendor.c b/src/fido/cbor_vendor.c
index 042140c..39e00bf 100644
--- a/src/fido/cbor_vendor.c
+++ b/src/fido/cbor_vendor.c
@@ -15,13 +15,13 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "ctap2_cbor.h"
#include "fido.h"
#include "ctap.h"
#include "hid/ctap_hid.h"
#include "files.h"
#include "apdu.h"
-#include "pico_keys.h"
#include "random.h"
#include "mbedtls/ecdh.h"
#include "mbedtls/chachapoly.h"
diff --git a/src/fido/cmd_authenticate.c b/src/fido/cmd_authenticate.c
index 41aa729..db6d5da 100644
--- a/src/fido/cmd_authenticate.c
+++ b/src/fido/cmd_authenticate.c
@@ -15,8 +15,8 @@
* along with this program. If not, see .
*/
-#include "fido.h"
#include "pico_keys.h"
+#include "fido.h"
#include "apdu.h"
#include "ctap.h"
#include "random.h"
diff --git a/src/fido/cmd_register.c b/src/fido/cmd_register.c
index b7f1ff3..643af3b 100644
--- a/src/fido/cmd_register.c
+++ b/src/fido/cmd_register.c
@@ -15,8 +15,8 @@
* along with this program. If not, see .
*/
-#include "fido.h"
#include "pico_keys.h"
+#include "fido.h"
#include "apdu.h"
#include "ctap.h"
#include "random.h"
@@ -69,11 +69,7 @@ int cmd_register() {
}
if (memcmp(req->appId, bogus_firefox,
CTAP_APPID_SIZE) == 0 || memcmp(req->appId, bogus_chrome, CTAP_APPID_SIZE) == 0)
-#ifndef ENABLE_EMULATION
{ return ctap_error(CTAP1_ERR_CHANNEL_BUSY); }
-#else
- { return SW_DATA_INVALID(); }
-#endif
mbedtls_ecdsa_context key;
mbedtls_ecdsa_init(&key);
int ret = derive_key(req->appId, true, resp->keyHandleCertSig, MBEDTLS_ECP_DP_SECP256R1, &key);
diff --git a/src/fido/credential.c b/src/fido/credential.c
index 5fca7d0..75b88a5 100644
--- a/src/fido/credential.c
+++ b/src/fido/credential.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "mbedtls/chachapoly.h"
#include "mbedtls/sha256.h"
#include "credential.h"
@@ -26,7 +27,6 @@
#include "ctap.h"
#include "random.h"
#include "files.h"
-#include "pico_keys.h"
#include "otp.h"
int credential_derive_chacha_key(uint8_t *outk, const uint8_t *);
diff --git a/src/fido/defs.c b/src/fido/defs.c
index 4089fce..c5db7ae 100644
--- a/src/fido/defs.c
+++ b/src/fido/defs.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
- #include "fido.h"
+#include "pico_keys.h"
+#include "fido.h"
uint8_t PICO_PRODUCT = 2; // Pico FIDO
diff --git a/src/fido/fido.c b/src/fido/fido.c
index 5e66815..742dd62 100644
--- a/src/fido/fido.c
+++ b/src/fido/fido.c
@@ -15,9 +15,9 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "fido.h"
#include "kek.h"
-#include "pico_keys.h"
#include "apdu.h"
#include "ctap.h"
#include "files.h"
@@ -25,7 +25,7 @@
#include "random.h"
#include "mbedtls/x509_crt.h"
#include "mbedtls/hkdf.h"
-#if defined(USB_ITF_CCID) || defined(ENABLE_EMULATION)
+#if defined(USB_ITF_CCID)
#include "ccid/ccid.h"
#endif
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
diff --git a/src/fido/fido.h b/src/fido/fido.h
index 2a0ed2f..8af6977 100644
--- a/src/fido/fido.h
+++ b/src/fido/fido.h
@@ -31,11 +31,7 @@
#ifdef MBEDTLS_EDDSA_C
#include "mbedtls/eddsa.h"
#endif
-#ifndef ENABLE_EMULATION
#include "hid/ctap_hid.h"
-#else
-#include
-#endif
#define CTAP_PUBKEY_LEN (65)
#define KEY_PATH_LEN (32)
diff --git a/src/fido/kek.c b/src/fido/kek.c
index 8608151..030e05c 100644
--- a/src/fido/kek.c
+++ b/src/fido/kek.c
@@ -15,8 +15,8 @@
* along with this program. If not, see .
*/
-#include "fido.h"
#include "pico_keys.h"
+#include "fido.h"
#include "stdlib.h"
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
#include "pico/stdlib.h"
diff --git a/src/fido/known_apps.c b/src/fido/known_apps.c
index e5f1e7c..ffa1cc8 100644
--- a/src/fido/known_apps.c
+++ b/src/fido/known_apps.c
@@ -15,6 +15,7 @@
* along with this program. If not, see .
*/
+#include "pico_keys.h"
#include "fido.h"
#include "ctap2_cbor.h"
diff --git a/src/fido/management.c b/src/fido/management.c
index 1827509..6f6360d 100644
--- a/src/fido/management.c
+++ b/src/fido/management.c
@@ -15,8 +15,8 @@
* along with this program. If not, see .
*/
-#include "fido.h"
#include "pico_keys.h"
+#include "fido.h"
#include "apdu.h"
#include "version.h"
#include "files.h"
diff --git a/src/fido/oath.c b/src/fido/oath.c
index 9155727..ea6602d 100644
--- a/src/fido/oath.c
+++ b/src/fido/oath.c
@@ -15,8 +15,8 @@
* along with this program. If not, see .
*/
-#include "fido.h"
#include "pico_keys.h"
+#include "fido.h"
#include "apdu.h"
#include "files.h"
#include "random.h"
diff --git a/src/fido/otp.c b/src/fido/otp.c
index e434d27..a9adf33 100644
--- a/src/fido/otp.c
+++ b/src/fido/otp.c
@@ -15,8 +15,8 @@
* along with this program. If not, see .
*/
-#include "fido.h"
#include "pico_keys.h"
+#include "fido.h"
#include "apdu.h"
#include "files.h"
#include "random.h"
@@ -24,14 +24,17 @@
#include "asn1.h"
#include "hid/ctap_hid.h"
#include "usb.h"
-#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
+#if defined(PICO_PLATFORM)
#include "bsp/board.h"
#endif
+#ifdef ENABLE_EMULATION
+void add_keyboard_buffer(const uint8_t *buf, size_t len, bool press_enter) {}
+void append_keyboard_buffer(const uint8_t *buf, size_t len) {}
+#else
+#include "tusb.h"
+#endif
#include "mbedtls/aes.h"
#include "management.h"
-#ifndef ENABLE_EMULATION
-#include "tusb.h"
-#endif
#define FIXED_SIZE 16
#define KEY_SIZE 16
@@ -116,12 +119,10 @@ uint16_t otp_status(bool is_otp);
int otp_process_apdu();
int otp_unload();
-#ifndef ENABLE_EMULATION
extern int (*hid_set_report_cb)(uint8_t, uint8_t, hid_report_type_t, uint8_t const *, uint16_t);
extern uint16_t (*hid_get_report_cb)(uint8_t, uint8_t, hid_report_type_t, uint8_t *, uint16_t);
int otp_hid_set_report_cb(uint8_t, uint8_t, hid_report_type_t, uint8_t const *, uint16_t);
uint16_t otp_hid_get_report_cb(uint8_t, uint8_t, hid_report_type_t, uint8_t *, uint16_t);
-#endif
const uint8_t otp_aid[] = {
7,
@@ -200,15 +201,12 @@ uint16_t calculate_crc(const uint8_t *data, size_t data_len) {
return crc & 0xFFFF;
}
-#ifndef ENABLE_EMULATION
static uint8_t session_counter[2] = { 0 };
-#endif
int otp_button_pressed(uint8_t slot) {
init_otp();
if (!cap_supported(CAP_OTP)) {
return 3;
}
-#ifndef ENABLE_EMULATION
file_t *ef = search_dynamic_file(slot == 1 ? EF_OTP_SLOT1 : EF_OTP_SLOT2);
const uint8_t *data = file_get_data(ef);
otp_config_t *otp_config = (otp_config_t *) data;
@@ -317,19 +315,15 @@ int otp_button_pressed(uint8_t slot) {
low_flash_available();
}
}
-#else
- (void) slot;
-#endif
+
return 0;
}
INITIALIZER( otp_ctor ) {
register_app(otp_select, otp_aid);
button_pressed_cb = otp_button_pressed;
-#ifndef ENABLE_EMULATION
hid_set_report_cb = otp_hid_set_report_cb;
hid_get_report_cb = otp_hid_get_report_cb;
-#endif
}
int otp_unload() {
@@ -490,20 +484,20 @@ int cmd_otp() {
return SW_WRONG_DATA();
}
int ret = 0;
-#ifndef ENABLE_EMULATION
uint8_t *rdata_bk = apdu.rdata;
if (otp_config->cfg_flags & CHAL_BTN_TRIG) {
status_byte = 0x20;
otp_status(_is_otp);
+#ifndef ENABLE_EMULATION
if (wait_button() == true) {
status_byte = 0x00;
otp_status(_is_otp);
return SW_CONDITIONS_NOT_SATISFIED();
}
+#endif
status_byte = 0x10;
apdu.rdata = rdata_bk;
}
-#endif
if (p1 == 0x30 || p1 == 0x38) {
if (!(otp_config->cfg_flags & CHAL_HMAC)) {
return SW_WRONG_DATA();
@@ -568,8 +562,6 @@ int otp_process_apdu() {
return SW_INS_NOT_SUPPORTED();
}
-#ifndef ENABLE_EMULATION
-
uint8_t otp_frame_rx[70] = {0};
uint8_t otp_frame_tx[70] = {0};
uint8_t otp_exp_seq = 0, otp_curr_seq = 0;
@@ -671,5 +663,3 @@ uint16_t otp_hid_get_report_cb(uint8_t itf,
return reqlen;
}
-
-#endif