made signatures der, bug fix, registration now works

vtcsec_summit
Conor 2016-03-11 23:27:30 -05:00
rodzic 05de7ecefd
commit fc7ddd6ff1
5 zmienionych plików z 49 dodań i 38 usunięć

Wyświetl plik

@ -29,7 +29,6 @@ typedef enum
APP_HID_MSG,
APP_WINK,
_APP_WINK,
APP_ERROR,
}
APP_STATE;

Wyświetl plik

@ -19,13 +19,11 @@ void u2f_delay(uint16_t ms) {
void usb_write(uint8_t* buf, uint8_t len)
{
int16_t ec;
uint8_t errors;
u2f_prints("tx: ");
dump_hex(buf,len);
uint8_t errors = 0;
while (USB_STATUS_OK != (ec=USBD_Write(EP1IN, buf, len, false)))
{
u2f_delay(2);
if (errors++ > 26)
if (errors++ > 30)
{
u2f_printd("USB error",1, -ec);
break;

Wyświetl plik

@ -30,7 +30,6 @@ static void init(struct APP_DATA* ap)
void set_app_error(APP_ERROR_CODE ec)
{
appdata.state = APP_ERROR;
appdata.error = ec;
}
@ -160,10 +159,12 @@ int16_t main(void) {
appdata.state = APP_NOTHING;
}
break;
case APP_ERROR:
u2f_printb("error: ", 1, appdata.error);
appdata.state = APP_NOTHING;
break;
}
if (appdata.error)
{
u2f_printb("error: ", 1, appdata.error);
appdata.error = 0;
}

Wyświetl plik

@ -98,7 +98,6 @@ static struct atecc_response res_digest;
void u2f_sha256_start()
{
u2f_prints("sha input: \r\n");
shaoffset = 0;
atecc_send_recv(ATECC_CMD_SHA,
ATECC_SHA_START, 0,NULL,0,
@ -109,15 +108,11 @@ void u2f_sha256_start()
void u2f_sha256_update(uint8_t * buf, uint8_t len)
{
uint8_t i = 0;
u2f_prints("(prog) ");
dump_hex(buf,len);
u2f_prints("\r\n");
while(len--)
{
shabuf[shaoffset++] = *buf++;
if (shaoffset == 64)
{
dump_hex(shabuf,64);
atecc_send_recv(ATECC_CMD_SHA,
ATECC_SHA_UPDATE, 64,shabuf,64,
appdata.tmp, sizeof(appdata.tmp), NULL);
@ -129,13 +124,9 @@ void u2f_sha256_update(uint8_t * buf, uint8_t len)
void u2f_sha256_finish()
{
dump_hex(shabuf,shaoffset);
atecc_send_recv(ATECC_CMD_SHA,
ATECC_SHA_END, shaoffset,shabuf,shaoffset,
shabuf, sizeof(shabuf), &res_digest);
u2f_prints("sha digest:\r\n");
dump_hex(res_digest.buf, res_digest.len);
}
@ -212,24 +203,24 @@ int8_t u2f_new_keypair(uint8_t * handle, uint8_t * pubkey)
}
code char __attest[] =
"\x30\x82\x01\x5a\x30\x82\x01\x00\x02\x01\x01\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d"
"\x30\x82\x01\x5b\x30\x82\x01\x00\x02\x01\x01\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d"
"\x04\x03\x02\x30\x39\x31\x0b\x30\x09\x06\x03\x55\x04\x06\x13\x02\x56\x41\x31\x14"
"\x30\x12\x06\x03\x55\x04\x0a\x13\x0b\x43\x6f\x6e\x6f\x72\x43\x6f\x20\x4c\x4c\x43"
"\x31\x14\x30\x12\x06\x03\x55\x04\x03\x13\x0b\x75\x32\x66\x7a\x65\x72\x6f\x2e\x63"
"\x6f\x6d\x30\x1e\x17\x0d\x31\x36\x30\x33\x30\x36\x30\x32\x32\x38\x33\x38\x5a\x17"
"\x0d\x32\x32\x30\x33\x30\x35\x30\x32\x32\x38\x33\x38\x5a\x30\x39\x31\x0b\x30\x09"
"\x6f\x6d\x30\x1e\x17\x0d\x31\x36\x30\x33\x31\x31\x30\x34\x30\x33\x34\x30\x5a\x17"
"\x0d\x32\x32\x30\x33\x31\x30\x30\x34\x30\x33\x34\x30\x5a\x30\x39\x31\x0b\x30\x09"
"\x06\x03\x55\x04\x06\x13\x02\x56\x41\x31\x14\x30\x12\x06\x03\x55\x04\x0a\x13\x0b"
"\x43\x6f\x6e\x6f\x72\x43\x6f\x20\x4c\x4c\x43\x31\x14\x30\x12\x06\x03\x55\x04\x03"
"\x13\x0b\x75\x32\x66\x7a\x65\x72\x6f\x2e\x63\x6f\x6d\x30\x59\x30\x13\x06\x07\x2a"
"\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48\xce\x3d\x03\x01\x07\x03\x42\x00\x04"
"\xe0\xc4\x32\x2c\x33\xdc\x1e\xa3\x60\x10\x0a\x0f\x2a\xb7\xb7\x2c\xbe\x53\x3d\xac"
"\x4e\x9d\x4f\xee\x4a\xf5\x6c\xcd\xe9\xe2\x23\x7f\x9c\x65\x15\x5d\x9f\x25\x19\x72"
"\x87\xd5\x2f\x23\x9a\xb3\x41\xeb\x0c\xb5\xbb\x4b\xae\xc3\x9a\xf3\xe4\xfb\xa7\xd2"
"\x33\x9b\xa2\xa8\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d\x04\x03\x02\x03\x48\x00\x30"
"\x45\x02\x20\x12\xa2\x68\x62\xf4\x4d\x27\x61\xdf\x01\xc8\x74\x15\xba\xa6\x0d\x51"
"\x93\x70\x3c\xcc\x39\xe2\x2d\xfd\x71\x99\x7c\xd3\x26\x18\x2b\x02\x21\x00\xfa\x69"
"\x16\x10\xaa\xc0\xe7\x9b\x73\xea\x2a\xa3\x53\x6a\x13\x04\xcc\xf0\x04\x82\x4c\x3c"
"\xe4\xd4\xc9\x3b\x2e\xaa\x39\x9d\x60\x93"
"\xf0\x5e\x4a\x50\xdc\xf7\x6c\xc3\x80\xf4\x93\x37\xfa\x0c\xb5\x1f\x54\xcb\xfc\xc2"
"\xac\x6c\xb8\x3c\x4b\x45\x32\x37\xc2\xad\x38\x72\x7d\x28\x32\x6a\x99\xe3\x94\x8d"
"\x44\xed\xb3\x5a\x6f\x31\x5c\x05\x72\xb9\xe5\x76\x5f\xcd\x0f\x67\x7f\xf3\x1c\xe1"
"\x25\x51\x37\xab\x30\x0a\x06\x08\x2a\x86\x48\xce\x3d\x04\x03\x02\x03\x49\x00\x30"
"\x46\x02\x21\x00\x9d\xa8\xac\x34\xc6\x30\xae\x7d\x4b\x47\x63\xb1\x40\x11\x61\xaf"
"\xc9\xa5\xff\xa7\xb8\xa7\xed\xef\x01\x74\x25\x6e\x0e\x6b\x90\xbc\x02\x21\x00\x86"
"\x5e\x7d\x1d\x59\x8d\x04\xf3\x20\x62\xfc\xfc\x26\xe9\xdc\xbe\x05\x9d\x64\x62\x62"
"\x4d\xd4\x38\x26\xf6\x67\x3a\x57\xa8\x2b\x64"
;
uint8_t * u2f_get_attestation_cert()

Wyświetl plik

@ -52,6 +52,9 @@ static int16_t u2f_register(struct u2f_register_request * req)
uint8_t key_handle[U2F_KEY_HANDLE_SIZE];
uint8_t pubkey[64];
uint8_t pad_s = 0;
uint8_t pad_r = 0;
const uint16_t attest_size = u2f_attestation_cert_size();
if (u2f_get_user_feedback() != 0)
@ -63,10 +66,6 @@ static int16_t u2f_register(struct u2f_register_request * req)
{
return U2F_SW_CONDITIONS_NOT_SATISFIED;
}
u2f_prints("chal: ");
dump_hex(req->chal,32);
u2f_prints("app: ");
dump_hex(req->app,32);
u2f_sha256_start();
u2f_sha256_update(i,1);
u2f_sha256_update(req->app,32);
@ -85,7 +84,10 @@ static int16_t u2f_register(struct u2f_register_request * req)
return SW_WRONG_DATA;
}
u2f_hid_set_len(133 + U2F_KEY_HANDLE_SIZE + u2f_attestation_cert_size());
pad_r = (((uint8_t*)req)[0] & 0x80) == 0x80;
pad_s = (((uint8_t*)req)[32] & 0x80) == 0x80;
u2f_hid_set_len(139 + pad_s + pad_r + U2F_KEY_HANDLE_SIZE + u2f_attestation_cert_size());
i[0] = 0x5;
u2f_response_writeback(i,2);
u2f_response_writeback(pubkey,64);
@ -95,10 +97,30 @@ static int16_t u2f_register(struct u2f_register_request * req)
u2f_response_writeback(u2f_get_attestation_cert(),u2f_attestation_cert_size());
u2f_response_writeback((uint8_t*)req, 64);
// DER encoding
// write der sequence
// has to be minimum distance and padded with 0x00 if MSB is a 1.
i[0] = 0x30;
i[1] = 0x44 + pad_r + pad_s;
u2f_response_writeback(i,2);
i[1] = 0;
// length of R value plus 0x00 pad if necessary
u2f_response_writeback("\x02",1);
i[0] = 0x20 + pad_r;
u2f_response_writeback(i,1 + pad_r);
// R value
u2f_response_writeback((uint8_t*)req, 32);
// length of S value plus 0x00 pad if necessary
u2f_response_writeback("\x02",1);
i[0] = 0x20 + pad_s;
u2f_response_writeback(i,1 + pad_s);
// S value
u2f_response_writeback(((uint8_t*)req)+32, 32);
u2f_prints("sig: ");
dump_hex((uint8_t*)req, 64);
return U2F_SW_NO_ERROR;
}