From 1a656d60e4d6660533a2584994bdd169b7a0dd69 Mon Sep 17 00:00:00 2001 From: merlokk Date: Sat, 26 Jan 2019 23:35:45 +0200 Subject: [PATCH] register works. but it needs to press a button.... --- targets/stm32l432/src/nfc.c | 22 +++++++++++++++++----- targets/stm32l432/src/nfc.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/targets/stm32l432/src/nfc.c b/targets/stm32l432/src/nfc.c index 4551c28..ea2c985 100644 --- a/targets/stm32l432/src/nfc.c +++ b/targets/stm32l432/src/nfc.c @@ -7,6 +7,7 @@ #include "log.h" #include "util.h" #include "device.h" +#include "u2f.h" #include "ctap_errors.h" @@ -326,12 +327,23 @@ void nfc_process_iblock(uint8_t * buf, int len) case APDU_FIDO_U2F_REGISTER: printf1(TAG_NFC, "U2F Register command.\r\n"); + + if (plen != 64) + { + printf1(TAG_NFC, "U2F Register request length error. len=%d.\r\n", plen); + nfc_write_response(buf[0], SW_WRONG_LENGTH); + return; + } + + uint8_t u2fbuffer[7 + 64 + 1] = {0}; + memcpy(u2fbuffer, &buf[1], 4); + memcpy(&u2fbuffer[6], &buf[5], plen + 1); + dump_hex1(TAG_NFC,u2fbuffer, 7 + 64 + 1); + ctap_response_init(&ctap_resp); - u2f_request(apdu, &ctap_resp); - status = ctap_resp.data[0]; - printf1(TAG_NFC, "U2F resp: %d len: %d\r\n", status, ctap_resp.length); - -// nfc_write_response(buf[0], SW_COND_USE_NOT_SATISFIED); + u2f_request((struct u2f_request_apdu *)u2fbuffer, &ctap_resp); + + printf1(TAG_NFC, "U2F resp len: %d\r\n", ctap_resp.length); nfc_write_response_chaining(buf[0], ctap_resp.data, ctap_resp.length); break; diff --git a/targets/stm32l432/src/nfc.h b/targets/stm32l432/src/nfc.h index c1c3042..195804f 100644 --- a/targets/stm32l432/src/nfc.h +++ b/targets/stm32l432/src/nfc.h @@ -69,6 +69,7 @@ typedef enum #define SW_SUCCESS 0x9000 #define SW_GET_RESPONSE 0x6100 // Command successfully executed; 'XX' bytes of data are available and can be requested using GET RESPONSE. +#define SW_WRONG_LENGTH 0x6700 #define SW_COND_USE_NOT_SATISFIED 0x6985 #define SW_FILE_NOT_FOUND 0x6a82 #define SW_INS_INVALID 0x6d00 // Instruction code not supported or invalid