mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 23:48:12 +00:00
Added support for known appid.
This commit is contained in:
parent
b3bfc64d2f
commit
5c13e78deb
@ -32,10 +32,12 @@
|
||||
#include "nist256p1.h"
|
||||
#include "rng.h"
|
||||
#include "hmac.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "u2f/u2f.h"
|
||||
#include "u2f/u2f_hid.h"
|
||||
#include "u2f/u2f_keys.h"
|
||||
#include "u2f_knownapps.h"
|
||||
#include "u2f.h"
|
||||
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
@ -96,31 +98,12 @@ uint8_t buttonState(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void int2hex(uint8_t *dst, const uint32_t i)
|
||||
{
|
||||
dst[0] = '0' + ((i >> 28) & 0x0F);
|
||||
dst[1] = '0' + ((i >> 24) & 0x0F);
|
||||
dst[2] = '0' + ((i >> 20) & 0x0F);
|
||||
dst[3] = '0' + ((i >> 16) & 0x0F);
|
||||
dst[4] = '0' + ((i >> 12) & 0x0F);
|
||||
dst[5] = '0' + ((i >> 8) & 0x0F);
|
||||
dst[6] = '0' + ((i >> 4) & 0x0F);
|
||||
dst[7] = '0' + (i & 0x0F);
|
||||
dst[8] = '\0';
|
||||
|
||||
int t = 0;
|
||||
for (; t < 8; t++) {
|
||||
if (dst[t] > '9')
|
||||
dst[t] += 7; // 'A'-'9'+1
|
||||
}
|
||||
}
|
||||
|
||||
char *debugInt(const uint32_t i)
|
||||
{
|
||||
static uint8_t n = 0;
|
||||
static uint8_t id[8][9];
|
||||
int2hex(id[n], i);
|
||||
debugLog(0, "", (const char *)id[n]);
|
||||
static char id[8][9];
|
||||
uint32hex(i, id[n]);
|
||||
debugLog(0, "", id[n]);
|
||||
char *ret = (char *)id[n];
|
||||
n = (n + 1) % 8;
|
||||
return ret;
|
||||
@ -426,6 +409,21 @@ void u2f_version(const APDU *a)
|
||||
send_u2f_msg(version_response, sizeof(version_response));
|
||||
}
|
||||
|
||||
static const char *getReadableAppId(const uint8_t appid[32]) {
|
||||
unsigned int i;
|
||||
static char buf[6+2+6+1];
|
||||
|
||||
for (i = 0; i < sizeof(u2f_well_known)/sizeof(U2FWellKnown); i++) {
|
||||
if (memcmp(appid, u2f_well_known[i].appid, 32) == 0)
|
||||
return u2f_well_known[i].appname;
|
||||
}
|
||||
|
||||
data2hex(appid, 3, &buf[0]);
|
||||
buf[6] = buf[7] = '.';
|
||||
data2hex(appid+(sizeof(appid)-3), 3, &buf[8]);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const HDNode *getDerivedNode(uint32_t *address_n, size_t address_n_count)
|
||||
{
|
||||
static HDNode node;
|
||||
@ -529,7 +527,8 @@ void u2f_register(const APDU *a)
|
||||
send_u2f_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
|
||||
buttonUpdate(); // Clear button state
|
||||
layoutDialog(DIALOG_ICON_QUESTION, "Cancel", "Register",
|
||||
NULL, "Register U2F", "security key", "", "", "", NULL);
|
||||
NULL, "Register U2F", "security key",
|
||||
"", getReadableAppId(req->appId), "", NULL);
|
||||
dialog_timeout = U2F_TIMEOUT;
|
||||
last_req_state = REG;
|
||||
return;
|
||||
@ -661,7 +660,8 @@ void u2f_authenticate(const APDU *a)
|
||||
send_u2f_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
|
||||
buttonUpdate(); // Clear button state
|
||||
layoutDialog(DIALOG_ICON_QUESTION, "Cancel", "Authenticate", NULL,
|
||||
"Authenticate U2F", "security key", "", "", "", NULL);
|
||||
"Authenticate U2F", "security key",
|
||||
"", getReadableAppId(req->appId), "", NULL);
|
||||
dialog_timeout = U2F_TIMEOUT;
|
||||
last_req_state = AUTH;
|
||||
return;
|
||||
|
57
firmware/u2f_knownapps.h
Normal file
57
firmware/u2f_knownapps.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is part of the TREZOR project.
|
||||
*
|
||||
* Copyright (C) 2016 Jochen Hoenicke <hoenicke@gmail.com>
|
||||
*
|
||||
* This library is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __U2F_KNOWNAPPS_H_INCLUDED__
|
||||
#define __U2F_KNOWNAPPS_H_INCLUDED__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t appid[32];
|
||||
const char *appname;
|
||||
} U2FWellKnown;
|
||||
|
||||
static const U2FWellKnown u2f_well_known[3] = {
|
||||
{
|
||||
// didn't feel like tracing that one yet
|
||||
{ 0xa5,0x46,0x72,0xb2,0x22,0xc4,0xcf,0x95,
|
||||
0xe1,0x51,0xed,0x8d,0x4d,0x3c,0x76,0x7a,
|
||||
0x6c,0xc3,0x49,0x43,0x59,0x43,0x79,0x4e,
|
||||
0x88,0x4f,0x3d,0x02,0x3a,0x82,0x29,0xfd },
|
||||
"Google"
|
||||
},
|
||||
{
|
||||
// https://github.com/u2f/trusted_facets
|
||||
{ 0x70,0x61,0x7d,0xfe,0xd0,0x65,0x86,0x3a,
|
||||
0xf4,0x7c,0x15,0x55,0x6c,0x91,0x79,0x88,
|
||||
0x80,0x82,0x8c,0xc4,0x07,0xfd,0xf7,0x0a,
|
||||
0xe8,0x50,0x11,0x56,0x94,0x65,0xa0,0x75 },
|
||||
"Github"
|
||||
},
|
||||
{
|
||||
// https://www.dropbox.com/u2f-app-id.json
|
||||
{ 0xc5,0x0f,0x8a,0x7b,0x70,0x8e,0x92,0xf8,
|
||||
0x2e,0x7a,0x50,0xe2,0xbd,0xc5,0x5d,0x8f,
|
||||
0xd9,0x1a,0x22,0xfe,0x6b,0x29,0xc0,0xcd,
|
||||
0xf7,0x80,0x55,0x30,0x84,0x2a,0xf5,0x81 },
|
||||
"Dropbox"
|
||||
}
|
||||
};
|
||||
|
||||
#endif // U2F_KNOWNAPPS_INCLUDED
|
Loading…
Reference in New Issue
Block a user