Skip to content

Commit

Permalink
keep SM2 config during FIDO2 reset
Browse files Browse the repository at this point in the history
  • Loading branch information
z4yx committed Jan 2, 2024
1 parent 661030f commit 0d11de4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 5 additions & 4 deletions applets/ctap/ctap.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ uint8_t ctap_install(uint8_t reset) {
if (write_attr(CTAP_CERT_FILE, KH_KEY_ATTR, kh_key, sizeof(kh_key)) < 0) return CTAP2_ERR_UNHANDLED_REQUEST;
random_buffer(kh_key, sizeof(kh_key));
if (write_attr(CTAP_CERT_FILE, HE_KEY_ATTR, kh_key, sizeof(kh_key)) < 0) return CTAP2_ERR_UNHANDLED_REQUEST;
ctap_sm2_attr.enabled = 0;
ctap_sm2_attr.curve_id = 9; // An unused one. See https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves
ctap_sm2_attr.algo_id = -48; // An unused one. See https://www.iana.org/assignments/cose/cose.xhtml#algorithms
if (write_attr(CTAP_CERT_FILE, SM2_ATTR, &ctap_sm2_attr, sizeof(ctap_sm2_attr)) < 0) return CTAP2_ERR_UNHANDLED_REQUEST;
memcpy(kh_key,
(uint8_t[]) {0x80, 0x76, 0xbe, 0x8b, 0x52, 0x8d, 0x00, 0x75, 0xf7, 0xaa, 0xe9, 0x8d, 0x6f, 0xa5, 0x7a, 0x6d,
0x3c}, 17);
Expand All @@ -96,6 +92,11 @@ uint8_t ctap_install(uint8_t reset) {

int ctap_install_private_key(const CAPDU *capdu, RAPDU *rapdu) {
if (LC != PRI_KEY_SIZE) EXCEPT(SW_WRONG_LENGTH);
// initialize SM2 config
ctap_sm2_attr.enabled = 0;
ctap_sm2_attr.curve_id = 9; // An unused one. See https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves
ctap_sm2_attr.algo_id = -48; // An unused one. See https://www.iana.org/assignments/cose/cose.xhtml#algorithms
if (write_attr(CTAP_CERT_FILE, SM2_ATTR, &ctap_sm2_attr, sizeof(ctap_sm2_attr)) < 0) return CTAP2_ERR_UNHANDLED_REQUEST;
return write_attr(CTAP_CERT_FILE, KEY_ATTR, DATA, LC);
}

Expand Down
16 changes: 16 additions & 0 deletions virt-card/fabrication.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "oath.h"
#include "openpgp.h"
#include "piv.h"
#include <../applets/ctap/ctap-internal.h>
#include <admin.h>
#include <aes.h>
#include <apdu.h>
Expand Down Expand Up @@ -62,6 +63,7 @@ static void fake_fido_personalization() {
uint8_t c_buf[1024], r_buf[1024];
CAPDU capdu;
RAPDU rapdu;
CTAP_sm2_attr sm2_attr;
capdu.data = c_buf;
rapdu.data = r_buf;

Expand All @@ -82,6 +84,20 @@ static void fake_fido_personalization() {
capdu.lc = sizeof(cert);
admin_process_apdu(&capdu, &rapdu);
assert(rapdu.sw == 0x9000);

capdu.ins = ADMIN_INS_READ_CTAP_SM2_CONFIG;
capdu.lc = 0;
admin_process_apdu(&capdu, &rapdu);
assert(rapdu.sw == 0x9000);

memcpy(&sm2_attr, r_buf, sizeof(sm2_attr));
sm2_attr.enabled = 1;

capdu.ins = ADMIN_INS_WRITE_CTAP_SM2_CONFIG;
capdu.data = &sm2_attr;
capdu.lc = sizeof(sm2_attr);
admin_process_apdu(&capdu, &rapdu);
assert(rapdu.sw == 0x9000);
}

static void fido2_init() { fake_fido_personalization(); }
Expand Down

0 comments on commit 0d11de4

Please sign in to comment.