diff --git a/applets/ctap/ctap.c b/applets/ctap/ctap.c index ab8215aa..11d9ea6b 100644 --- a/applets/ctap/ctap.c +++ b/applets/ctap/ctap.c @@ -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); @@ -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); } diff --git a/virt-card/fabrication.c b/virt-card/fabrication.c index 9c690167..6f9c1e09 100644 --- a/virt-card/fabrication.c +++ b/virt-card/fabrication.c @@ -5,6 +5,7 @@ #include "oath.h" #include "openpgp.h" #include "piv.h" +#include <../applets/ctap/ctap-internal.h> #include #include #include @@ -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; @@ -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(); }