Merge pull request #51 from yparitcher/clean_build
clean up code: GCC warnings; add black to travis; fix linux build errors
This commit is contained in:
10
.travis.yml
10
.travis.yml
@@ -4,12 +4,16 @@ compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- deadsnakes
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- gcc-7
|
||||
- cppcheck
|
||||
- python3.6
|
||||
before_install:
|
||||
- sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
|
||||
- sudo apt-get update -q
|
||||
- sudo apt-get install -y gcc-arm-embedded
|
||||
- sudo apt-get install -y python3-venv
|
||||
script:
|
||||
- export CC=gcc-7
|
||||
- make test
|
||||
- pyenv shell 3.6.7
|
||||
- make travis
|
||||
|
40
Makefile
40
Makefile
@@ -13,7 +13,7 @@ EFM32_DEBUGGER= -s 440083537 --device EFM32JG1B200F128GM32
|
||||
#EFM32_DEBUGGER= -s 440121060 #dev board
|
||||
|
||||
src = $(wildcard pc/*.c) $(wildcard fido2/*.c) $(wildcard crypto/sha256/*.c) crypto/tiny-AES-c/aes.c
|
||||
obj = $(src:.c=.o) uECC.o
|
||||
obj = $(src:.c=.o) crypto/micro-ecc/uECC.o
|
||||
|
||||
LIBCBOR = tinycbor/lib/libtinycbor.a
|
||||
|
||||
@@ -33,7 +33,7 @@ CFLAGS += -DAES256=1 -DAPP_CONFIG=\"app.h\"
|
||||
|
||||
name = main
|
||||
|
||||
.PHONY: all
|
||||
.PHONY: all $(LIBCBOR) env2 env3 black wink2 wink3 fido2-test clean full-clean travis
|
||||
all: main
|
||||
|
||||
tinycbor/Makefile crypto/tiny-AES-c/aes.c:
|
||||
@@ -42,9 +42,17 @@ tinycbor/Makefile crypto/tiny-AES-c/aes.c:
|
||||
.PHONY: cbor
|
||||
cbor: $(LIBCBOR)
|
||||
|
||||
$(LIBCBOR): tinycbor/Makefile
|
||||
$(LIBCBOR):
|
||||
cd tinycbor/ && $(MAKE) clean && $(MAKE) -j8
|
||||
|
||||
test: env3
|
||||
$(MAKE) clean
|
||||
$(MAKE) -C . main
|
||||
$(MAKE) clean
|
||||
$(MAKE) -C ./targets/stm32l432 test PREFIX=$(PREFIX) "VENV=$(VENV)"
|
||||
$(MAKE) clean
|
||||
$(MAKE) cppcheck
|
||||
|
||||
.PHONY: efm8prog
|
||||
efm8prog:
|
||||
cd './targets/efm8\Keil 8051 v9.53 - Debug' && $(MAKE) all
|
||||
@@ -64,7 +72,7 @@ efm32bootprog: efm32com
|
||||
$(name): $(obj) $(LIBCBOR)
|
||||
$(CC) $(LDFLAGS) -o $@ $(obj) $(LDFLAGS)
|
||||
|
||||
uECC.o: ./crypto/micro-ecc/uECC.c
|
||||
crypto/micro-ecc/uECC.o: ./crypto/micro-ecc/uECC.c
|
||||
$(CC) -c -o $@ $^ -O2 -fdata-sections -ffunction-sections -DuECC_PLATFORM=$(ecc_platform) -I./crypto/micro-ecc/
|
||||
|
||||
env2:
|
||||
@@ -73,18 +81,14 @@ env2:
|
||||
env2/bin/pip install -r tools/requirements.txt
|
||||
|
||||
env3:
|
||||
# black requires >=py3.6
|
||||
virtualenv --python=python3.6 env3
|
||||
env3/bin/pip --version
|
||||
env3/bin/pip install -r tools/requirements.txt
|
||||
env3/bin/pip install black
|
||||
python3 -m venv env3
|
||||
env3/bin/pip -q install --upgrade -r tools/requirements.txt
|
||||
env3/bin/pip -q install --upgrade black
|
||||
|
||||
.PHONY: black blackcheck wink2 wink3 fido2-test cppcheck test clean
|
||||
# selectively reformat our own code
|
||||
|
||||
blackcheck: export BLACK_CHECK_FLAG := --check
|
||||
black blackcheck: env3
|
||||
env3/bin/black --skip-string-normalization $(BLACK_CHECK_FLAG) tools/
|
||||
black: env3
|
||||
env3/bin/black --skip-string-normalization --check tools/
|
||||
|
||||
wink2 wink3: wink% : env%
|
||||
$</bin/python tools/solotool.py solo --wink
|
||||
@@ -100,13 +104,17 @@ cppcheck:
|
||||
cppcheck $(CPPCHECK_FLAGS) fido2
|
||||
cppcheck $(CPPCHECK_FLAGS) pc
|
||||
|
||||
test: main cppcheck blackcheck
|
||||
|
||||
clean:
|
||||
rm -f *.o main.exe main $(obj)
|
||||
rm -rf env2 env3
|
||||
for f in crypto/tiny-AES-c/Makefile tinycbor/Makefile ; do \
|
||||
if [ -f "$$f" ]; then \
|
||||
(cd `dirname $$f` ; git checkout -- .) ;\
|
||||
fi ;\
|
||||
done
|
||||
|
||||
full-clean: clean
|
||||
rm -rf env2 env3
|
||||
|
||||
travis:
|
||||
$(MAKE) test VENV=". ../../env3/bin/activate;"
|
||||
$(MAKE) black
|
||||
|
@@ -24,12 +24,6 @@ Enter the `stm32l4xx` target directory.
|
||||
cd targets/stm32l432
|
||||
```
|
||||
|
||||
Build the cbor library.
|
||||
|
||||
```bash
|
||||
make cbor
|
||||
```
|
||||
|
||||
Now build Solo.
|
||||
|
||||
```
|
||||
|
22
fido2/ctap.c
22
fido2/ctap.c
@@ -309,7 +309,7 @@ static int is_matching_rk(CTAP_residentKey * rk, CTAP_residentKey * rk2)
|
||||
}
|
||||
|
||||
|
||||
static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, int len, CTAP_userEntity * user, uint8_t credtype, int32_t algtype, int32_t * sz, int store)
|
||||
static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, unsigned int len, CTAP_userEntity * user, uint8_t credtype, int32_t algtype, int32_t * sz, int store)
|
||||
{
|
||||
CborEncoder cose_key;
|
||||
int auth_data_sz, ret;
|
||||
@@ -380,8 +380,8 @@ static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * au
|
||||
memmove(&rk.id, &authData->attest.id, sizeof(CredentialId));
|
||||
memmove(&rk.user, user, sizeof(CTAP_userEntity));
|
||||
|
||||
int index = STATE.rk_stored;
|
||||
int i;
|
||||
unsigned int index = STATE.rk_stored;
|
||||
unsigned int i;
|
||||
for (i = 0; i < index; i++)
|
||||
{
|
||||
ctap_load_rk(i, &rk2);
|
||||
@@ -549,7 +549,8 @@ int ctap_authenticate_credential(struct rpId * rp, CTAP_credentialDescriptor * d
|
||||
uint8_t ctap_make_credential(CborEncoder * encoder, uint8_t * request, int length)
|
||||
{
|
||||
CTAP_makeCredential MC;
|
||||
int ret, i;
|
||||
int ret;
|
||||
unsigned int i;
|
||||
uint8_t auth_data_buf[300];
|
||||
CTAP_credentialDescriptor * excl_cred = (CTAP_credentialDescriptor *) auth_data_buf;
|
||||
uint8_t * sigbuf = auth_data_buf + 32;
|
||||
@@ -1358,8 +1359,9 @@ uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp)
|
||||
CborEncoder encoder;
|
||||
uint8_t status = 0;
|
||||
uint8_t cmd = *pkt_raw;
|
||||
uint64_t t1;
|
||||
uint64_t t2;
|
||||
#if DEBUG_LEVEL > 0
|
||||
uint64_t t1,t2;
|
||||
#endif
|
||||
pkt_raw++;
|
||||
length--;
|
||||
|
||||
@@ -1392,10 +1394,14 @@ uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp)
|
||||
case CTAP_MAKE_CREDENTIAL:
|
||||
device_set_status(CTAPHID_STATUS_PROCESSING);
|
||||
printf1(TAG_CTAP,"CTAP_MAKE_CREDENTIAL\n");
|
||||
#if DEBUG_LEVEL > 0
|
||||
t1 = millis();
|
||||
#endif
|
||||
status = ctap_make_credential(&encoder, pkt_raw, length);
|
||||
#if DEBUG_LEVEL > 0
|
||||
t2 = millis();
|
||||
printf1(TAG_TIME,"make_credential time: %d ms\n", t2-t1);
|
||||
#endif
|
||||
|
||||
resp->length = cbor_encoder_get_buffer_size(&encoder, buf);
|
||||
dump_hex1(TAG_DUMP, buf, resp->length);
|
||||
@@ -1404,10 +1410,14 @@ uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp)
|
||||
case CTAP_GET_ASSERTION:
|
||||
device_set_status(CTAPHID_STATUS_PROCESSING);
|
||||
printf1(TAG_CTAP,"CTAP_GET_ASSERTION\n");
|
||||
#if DEBUG_LEVEL > 0
|
||||
t1 = millis();
|
||||
#endif
|
||||
status = ctap_get_assertion(&encoder, pkt_raw, length);
|
||||
#if DEBUG_LEVEL > 0
|
||||
t2 = millis();
|
||||
printf1(TAG_TIME,"get_assertion time: %d ms\n", t2-t1);
|
||||
#endif
|
||||
|
||||
resp->length = cbor_encoder_get_buffer_size(&encoder, buf);
|
||||
|
||||
|
@@ -79,7 +79,7 @@ uint8_t parse_user(CTAP_makeCredential * MC, CborValue * val)
|
||||
size_t sz, map_length;
|
||||
uint8_t key[24];
|
||||
int ret;
|
||||
int i;
|
||||
unsigned int i;
|
||||
CborValue map;
|
||||
|
||||
|
||||
@@ -270,7 +270,7 @@ uint8_t parse_pub_key_cred_params(CTAP_makeCredential * MC, CborValue * val)
|
||||
uint8_t cred_type;
|
||||
int32_t alg_type;
|
||||
int ret;
|
||||
int i;
|
||||
unsigned int i;
|
||||
CborValue arr;
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ uint8_t parse_pub_key_cred_params(CTAP_makeCredential * MC, CborValue * val)
|
||||
return CTAP2_ERR_UNSUPPORTED_ALGORITHM;
|
||||
}
|
||||
|
||||
uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, int len)
|
||||
uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, unsigned int len)
|
||||
{
|
||||
size_t sz;
|
||||
int ret;
|
||||
@@ -344,7 +344,7 @@ uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, int len)
|
||||
|
||||
uint8_t parse_verify_exclude_list(CborValue * val)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
int ret;
|
||||
CborValue arr;
|
||||
size_t size;
|
||||
@@ -393,7 +393,7 @@ uint8_t parse_rp(struct rpId * rp, CborValue * val)
|
||||
size_t sz, map_length;
|
||||
char key[8];
|
||||
int ret;
|
||||
int i;
|
||||
unsigned int i;
|
||||
CborValue map;
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ uint8_t parse_options(CborValue * val, uint8_t * rk, uint8_t * uv, uint8_t * up)
|
||||
size_t sz, map_length;
|
||||
char key[8];
|
||||
int ret;
|
||||
int i;
|
||||
unsigned int i;
|
||||
_Bool b;
|
||||
CborValue map;
|
||||
|
||||
@@ -559,7 +559,7 @@ uint8_t parse_options(CborValue * val, uint8_t * rk, uint8_t * uv, uint8_t * up)
|
||||
uint8_t ctap_parse_make_credential(CTAP_makeCredential * MC, CborEncoder * encoder, uint8_t * request, int length)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
unsigned int i;
|
||||
int key;
|
||||
size_t map_length;
|
||||
CborParser parser;
|
||||
@@ -775,7 +775,8 @@ uint8_t parse_allow_list(CTAP_getAssertion * GA, CborValue * it)
|
||||
{
|
||||
CborValue arr;
|
||||
size_t len;
|
||||
int i,ret;
|
||||
int ret;
|
||||
unsigned int i;
|
||||
CTAP_credentialDescriptor * cred;
|
||||
|
||||
if (cbor_value_get_type(it) != CborArrayType)
|
||||
@@ -817,7 +818,7 @@ uint8_t parse_allow_list(CTAP_getAssertion * GA, CborValue * it)
|
||||
uint8_t ctap_parse_get_assertion(CTAP_getAssertion * GA, uint8_t * request, int length)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
unsigned int i;
|
||||
int key;
|
||||
size_t map_length;
|
||||
CborParser parser;
|
||||
@@ -943,7 +944,8 @@ uint8_t parse_cose_key(CborValue * it, uint8_t * x, uint8_t * y, int * kty, int
|
||||
{
|
||||
CborValue map;
|
||||
size_t map_length;
|
||||
int i,ret,key;
|
||||
int ret,key;
|
||||
unsigned int i;
|
||||
int xkey = 0,ykey = 0;
|
||||
*kty = 0;
|
||||
*crv = 0;
|
||||
@@ -1038,7 +1040,7 @@ uint8_t parse_cose_key(CborValue * it, uint8_t * x, uint8_t * y, int * kty, int
|
||||
uint8_t ctap_parse_client_pin(CTAP_clientPin * CP, uint8_t * request, int length)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
unsigned int i;
|
||||
int key;
|
||||
size_t map_length;
|
||||
size_t sz;
|
||||
|
@@ -24,7 +24,7 @@ const char * cbor_value_get_type_string(const CborValue *value);
|
||||
uint8_t parse_user(CTAP_makeCredential * MC, CborValue * val);
|
||||
uint8_t parse_pub_key_cred_param(CborValue * val, uint8_t * cred_type, int32_t * alg_type);
|
||||
uint8_t parse_pub_key_cred_params(CTAP_makeCredential * MC, CborValue * val);
|
||||
uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, int len);
|
||||
uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, unsigned int len);
|
||||
uint8_t parse_rp_id(struct rpId * rp, CborValue * val);
|
||||
uint8_t parse_rp(struct rpId * rp, CborValue * val);
|
||||
uint8_t parse_options(CborValue * val, uint8_t * rk, uint8_t * uv, uint8_t * up);
|
||||
|
@@ -98,7 +98,7 @@ static uint32_t get_new_cid()
|
||||
|
||||
static int8_t add_cid(uint32_t cid)
|
||||
{
|
||||
int i;
|
||||
uint32_t i;
|
||||
for(i = 0; i < CID_MAX-1; i++)
|
||||
{
|
||||
if (!CIDS[i].busy)
|
||||
@@ -114,7 +114,7 @@ static int8_t add_cid(uint32_t cid)
|
||||
|
||||
static int8_t cid_exists(uint32_t cid)
|
||||
{
|
||||
int i;
|
||||
uint32_t i;
|
||||
for(i = 0; i < CID_MAX-1; i++)
|
||||
{
|
||||
if (CIDS[i].cid == cid)
|
||||
@@ -127,7 +127,7 @@ static int8_t cid_exists(uint32_t cid)
|
||||
|
||||
static int8_t cid_refresh(uint32_t cid)
|
||||
{
|
||||
int i;
|
||||
uint32_t i;
|
||||
for(i = 0; i < CID_MAX-1; i++)
|
||||
{
|
||||
if (CIDS[i].cid == cid)
|
||||
@@ -142,7 +142,7 @@ static int8_t cid_refresh(uint32_t cid)
|
||||
|
||||
static int8_t cid_del(uint32_t cid)
|
||||
{
|
||||
int i;
|
||||
uint32_t i;
|
||||
for(i = 0; i < CID_MAX-1; i++)
|
||||
{
|
||||
if (CIDS[i].cid == cid)
|
||||
@@ -380,7 +380,7 @@ static int ctaphid_buffer_packet(uint8_t * pkt_raw, uint8_t * cmd, uint32_t * ci
|
||||
printf1(TAG_HID, "Recv packet\n");
|
||||
printf1(TAG_HID, " CID: %08x \n", pkt->cid);
|
||||
printf1(TAG_HID, " cmd: %02x\n", pkt->pkt.init.cmd);
|
||||
if (!is_cont_pkt(pkt)) printf1(TAG_HID, " length: %d\n", ctaphid_packet_len(pkt));
|
||||
if (!is_cont_pkt(pkt)) {printf1(TAG_HID, " length: %d\n", ctaphid_packet_len(pkt));}
|
||||
|
||||
int ret;
|
||||
uint32_t oldcid;
|
||||
@@ -533,13 +533,21 @@ uint8_t ctaphid_handle_packet(uint8_t * pkt_raw)
|
||||
uint8_t cmd;
|
||||
uint32_t cid;
|
||||
int len;
|
||||
#ifndef DISABLE_CTAPHID_CBOR
|
||||
int status;
|
||||
#endif
|
||||
|
||||
static uint8_t is_busy = 0;
|
||||
static CTAPHID_WRITE_BUFFER wb;
|
||||
CTAP_RESPONSE ctap_resp;
|
||||
|
||||
#ifndef DISABLE_CTAPHID_PING
|
||||
#ifndef DISABLE_CTAPHID_CBOR
|
||||
#if DEBUG_LEVEL > 0
|
||||
uint32_t t1,t2;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int bufstatus = ctaphid_buffer_packet(pkt_raw, &cmd, &cid, &len);
|
||||
|
||||
@@ -581,11 +589,15 @@ uint8_t ctaphid_handle_packet(uint8_t * pkt_raw)
|
||||
wb.cid = cid;
|
||||
wb.cmd = CTAPHID_PING;
|
||||
wb.bcnt = len;
|
||||
#if DEBUG_LEVEL > 0
|
||||
t1 = millis();
|
||||
#endif
|
||||
ctaphid_write(&wb, ctap_buffer, len);
|
||||
ctaphid_write(&wb, NULL,0);
|
||||
#if DEBUG_LEVEL > 0
|
||||
t2 = millis();
|
||||
printf1(TAG_TIME,"PING writeback: %d ms\n",(uint32_t)(t2-t1));
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
#ifndef DISABLE_CTAPHID_WINK
|
||||
@@ -629,12 +641,16 @@ uint8_t ctaphid_handle_packet(uint8_t * pkt_raw)
|
||||
wb.bcnt = (ctap_resp.length+1);
|
||||
|
||||
|
||||
#if DEBUG_LEVEL > 0
|
||||
t1 = millis();
|
||||
#endif
|
||||
ctaphid_write(&wb, &status, 1);
|
||||
ctaphid_write(&wb, ctap_resp.data, ctap_resp.length);
|
||||
ctaphid_write(&wb, NULL, 0);
|
||||
#if DEBUG_LEVEL > 0
|
||||
t2 = millis();
|
||||
printf1(TAG_TIME,"CBOR writeback: %d ms\n",(uint32_t)(t2-t1));
|
||||
#endif
|
||||
is_busy = 0;
|
||||
break;
|
||||
#endif
|
||||
|
@@ -46,7 +46,7 @@ void device_manage();
|
||||
|
||||
// sets status that's uses for sending status updates ~100ms.
|
||||
// A timer should be set up to call `ctaphid_update_status`
|
||||
void device_set_status(int status);
|
||||
void device_set_status(uint32_t status);
|
||||
|
||||
// Returns if button is currently pressed
|
||||
int device_is_button_pressed();
|
||||
|
@@ -57,7 +57,7 @@ __attribute__((weak)) void set_logging_tag(uint32_t tag)
|
||||
|
||||
void LOG(uint32_t tag, const char * filename, int num, const char * fmt, ...)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
if (((tag & 0x7fffffff) & LOGMASK) == 0)
|
||||
{
|
||||
|
@@ -58,9 +58,9 @@ void set_logging_mask(uint32_t mask);
|
||||
#else
|
||||
|
||||
#define set_logging_mask(mask)
|
||||
#define printf1(fmt, ...)
|
||||
#define printf2(fmt, ...)
|
||||
#define printf3(fmt, ...)
|
||||
#define printf1(tag,fmt, ...)
|
||||
#define printf2(tag,fmt, ...)
|
||||
#define printf3(tag,fmt, ...)
|
||||
#define dump_hex1(tag,data,len)
|
||||
|
||||
#endif
|
||||
|
@@ -19,7 +19,7 @@
|
||||
|
||||
#if !defined(TEST)
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
int main()
|
||||
{
|
||||
uint8_t hidmsg[64];
|
||||
uint32_t t1 = 0;
|
||||
|
19
fido2/u2f.c
19
fido2/u2f.c
@@ -11,11 +11,16 @@
|
||||
#include "log.h"
|
||||
#include "device.h"
|
||||
#include "wallet.h"
|
||||
#ifdef ENABLE_U2F_EXTENSIONS
|
||||
#include "extensions.h"
|
||||
#endif
|
||||
#include APP_CONFIG
|
||||
|
||||
// void u2f_response_writeback(uint8_t * buf, uint8_t len);
|
||||
#ifdef ENABLE_U2F
|
||||
static int16_t u2f_register(struct u2f_register_request * req);
|
||||
static int16_t u2f_authenticate(struct u2f_authenticate_request * req, uint8_t control);
|
||||
#endif
|
||||
int8_t u2f_response_writeback(const uint8_t * buf, uint16_t len);
|
||||
void u2f_reset_response();
|
||||
|
||||
@@ -25,7 +30,11 @@ static CTAP_RESPONSE * _u2f_resp = NULL;
|
||||
void u2f_request(struct u2f_request_apdu* req, CTAP_RESPONSE * resp)
|
||||
{
|
||||
uint16_t rcode = 0;
|
||||
#ifdef ENABLE_U2F
|
||||
#if DEBUG_LEVEL > 0
|
||||
uint64_t t1,t2;
|
||||
#endif
|
||||
#endif
|
||||
uint32_t len = ((req->LC3) | ((uint32_t)req->LC2 << 8) | ((uint32_t)req->LC1 << 16));
|
||||
uint8_t byte;
|
||||
|
||||
@@ -53,18 +62,26 @@ void u2f_request(struct u2f_request_apdu* req, CTAP_RESPONSE * resp)
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG_LEVEL > 0
|
||||
t1 = millis();
|
||||
#endif
|
||||
rcode = u2f_register((struct u2f_register_request*)req->payload);
|
||||
#if DEBUG_LEVEL > 0
|
||||
t2 = millis();
|
||||
printf1(TAG_TIME,"u2f_register time: %d ms\n", t2-t1);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case U2F_AUTHENTICATE:
|
||||
printf1(TAG_U2F, "U2F_AUTHENTICATE\n");
|
||||
#if DEBUG_LEVEL > 0
|
||||
t1 = millis();
|
||||
#endif
|
||||
rcode = u2f_authenticate((struct u2f_authenticate_request*)req->payload, req->p1);
|
||||
#if DEBUG_LEVEL > 0
|
||||
t2 = millis();
|
||||
printf1(TAG_TIME,"u2f_authenticate time: %d ms\n", t2-t1);
|
||||
#endif
|
||||
break;
|
||||
case U2F_VERSION:
|
||||
printf1(TAG_U2F, "U2F_VERSION\n");
|
||||
@@ -128,6 +145,7 @@ void u2f_set_writeback_buffer(CTAP_RESPONSE * resp)
|
||||
_u2f_resp = resp;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_U2F
|
||||
static void dump_signature_der(uint8_t * sig)
|
||||
{
|
||||
uint8_t sigder[72];
|
||||
@@ -300,6 +318,7 @@ static int16_t u2f_register(struct u2f_register_request * req)
|
||||
|
||||
return U2F_SW_NO_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t u2f_version()
|
||||
{
|
||||
|
@@ -26,7 +26,7 @@
|
||||
void authenticator_initialize();
|
||||
|
||||
uint32_t __device_status = 0;
|
||||
void device_set_status(int status)
|
||||
void device_set_status(uint32_t status)
|
||||
{
|
||||
if (status != CTAPHID_STATUS_IDLE && __device_status != status)
|
||||
{
|
||||
|
@@ -3,9 +3,11 @@ DEBUG=0
|
||||
endif
|
||||
|
||||
APPMAKE=build/application.mk
|
||||
BOOTMAKE=build/application.mk
|
||||
BOOTMAKE=build/bootloader.mk
|
||||
|
||||
merge_hex=python ../../tools/solotool.py mergehex
|
||||
merge_hex=../../tools/solotool.py mergehex
|
||||
|
||||
.PHONY: all all-hacker all-locked debugboot-app debugboot-boot boot-sig-checking boot-no-sig build-release-locked build-release build-release build-hacker build-debugboot clean clean2 flash flash_dfu flashboot detach cbor test
|
||||
|
||||
all:
|
||||
$(MAKE) -f $(APPMAKE) -j8 solo.hex PREFIX=$(PREFIX) DEBUG=$(DEBUG) EXTRA_DEFINES='-DFLASH_ROP=1'
|
||||
@@ -17,7 +19,7 @@ all-locked:
|
||||
$(MAKE) -f $(APPMAKE) -j8 solo.hex PREFIX=$(PREFIX) EXTRA_DEFINES='-DFLASH_ROP=2'
|
||||
|
||||
debugboot-app:
|
||||
$(MAKE) -f $(APPMAKE) -j8 solo.hex DEBUG=2 PREFIX=$(PREFIX)\
|
||||
$(MAKE) -f $(APPMAKE) -j8 solo.hex DEBUG=2 PREFIX=$(PREFIX) \
|
||||
LDSCRIPT=linker/stm32l4xx_extra.ld EXTRA_DEFINES='-DAPPLICATION_START_PAGE=16 -DSOLO_HACKER'
|
||||
|
||||
debugboot-boot:
|
||||
@@ -30,37 +32,39 @@ boot-sig-checking:
|
||||
boot-no-sig:
|
||||
$(MAKE) -f $(BOOTMAKE) -j8 bootloader.hex PREFIX=$(PREFIX) EXTRA_DEFINES='-DSOLO_HACKER' DEBUG=0
|
||||
|
||||
build-release-locked: clean2 boot-sig-checking clean all-locked
|
||||
$(merge_hex) solo.hex bootloader.hex all.hex
|
||||
build-release-locked: cbor clean2 boot-sig-checking clean all-locked
|
||||
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
|
||||
rm -f solo.hex bootloader.hex # don't program solo.hex ...
|
||||
|
||||
build-release: clean2 boot-sig-checking clean all
|
||||
$(merge_hex) solo.hex bootloader.hex all.hex
|
||||
build-release: cbor clean2 boot-sig-checking clean all
|
||||
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
|
||||
|
||||
build-hacker: clean2 boot-no-sig clean all-hacker
|
||||
$(merge_hex) solo.hex bootloader.hex all.hex
|
||||
build-hacker: cbor clean2 boot-no-sig clean all-hacker
|
||||
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
|
||||
|
||||
build-debugboot: clean2 debugboot-boot clean debugboot-app
|
||||
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(APPMAKE) clean
|
||||
$(MAKE) -f $(BOOTMAKE) clean
|
||||
clean2:
|
||||
rm -f solo.hex bootloader.hex all.hex
|
||||
rm -f solo.hex solo.map bootloader.hex bootloader.map all.hex
|
||||
$(MAKE) -f $(APPMAKE) clean
|
||||
$(MAKE) -f $(BOOTMAKE) clean
|
||||
|
||||
|
||||
flash: solo.hex bootloader.hex
|
||||
$(merge_hex) solo.hex bootloader.hex all.hex
|
||||
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
|
||||
STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect
|
||||
STM32_Programmer_CLI -c port=SWD -halt -d all.hex -rst
|
||||
|
||||
flash_dfu: solo.hex bootloader.hex
|
||||
$(merge_hex) solo.hex bootloader.hex all.hex
|
||||
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
|
||||
# STM32_Programmer_CLI -c port=usb1 -halt -e all --readunprotect
|
||||
STM32_Programmer_CLI -c port=usb1 -halt -rdu -d all.hex
|
||||
|
||||
flashboot: solo.hex bootloader.hex
|
||||
$(merge_hex) solo.hex bootloader.hex all.hex
|
||||
$(VENV) $(merge_hex) solo.hex bootloader.hex all.hex
|
||||
STM32_Programmer_CLI -c port=SWD -halt -e all --readunprotect
|
||||
STM32_Programmer_CLI -c port=SWD -halt -d bootloader.hex -rst
|
||||
|
||||
@@ -75,4 +79,11 @@ solo.hex:
|
||||
echo "You need to build the application first."
|
||||
|
||||
cbor:
|
||||
$(MAKE) -f application.mk -j8 cbor
|
||||
$(MAKE) -f $(APPMAKE) -j8 cbor
|
||||
|
||||
test:
|
||||
$(MAKE) build-release-locked
|
||||
$(MAKE) build-release
|
||||
$(MAKE) build-hacker
|
||||
$(MAKE) build-debugboot
|
||||
$(MAKE) clean2
|
||||
|
@@ -95,9 +95,10 @@ int is_bootloader_disabled()
|
||||
int bootloader_bridge(int klen, uint8_t * keyh)
|
||||
{
|
||||
static int has_erased = 0;
|
||||
int i;
|
||||
BootloaderReq * req = (BootloaderReq * )keyh;
|
||||
#ifndef SOLO_HACKER
|
||||
uint8_t hash[32];
|
||||
#endif
|
||||
uint8_t version = 1;
|
||||
uint16_t len = (req->lenh << 8) | (req->lenl);
|
||||
|
||||
@@ -107,8 +108,10 @@ int bootloader_bridge(int klen, uint8_t * keyh)
|
||||
return CTAP1_ERR_INVALID_LENGTH;
|
||||
}
|
||||
|
||||
#ifndef SOLO_HACKER
|
||||
uint8_t * pubkey = (uint8_t*)"\xd2\xa4\x2f\x8f\xb2\x31\x1c\xc1\xf7\x0c\x7e\x64\x32\xfb\xbb\xb4\xa3\xdd\x32\x20\x0f\x1b\x88\x9c\xda\x62\xc2\x83\x25\x93\xdd\xb8\x75\x9d\xf9\x86\xee\x03\x6c\xce\x34\x47\x71\x36\xb3\xb2\xad\x6d\x12\xb7\xbe\x49\x3e\x20\xa4\x61\xac\xc7\x71\xc7\x1f\xa8\x14\xf2";
|
||||
const struct uECC_Curve_t * curve = NULL;
|
||||
#endif
|
||||
|
||||
uint32_t addr = ((*((uint32_t*)req->addr)) & 0xffffff) | 0x8000000;
|
||||
|
||||
|
@@ -38,11 +38,13 @@ void BOOT_boot(void)
|
||||
((pFunction)bootAddress[1])();
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
int main()
|
||||
{
|
||||
uint8_t hidmsg[64];
|
||||
uint32_t t1 = 0;
|
||||
#ifdef SOLO_HACKER
|
||||
uint32_t stboot_time = 0;
|
||||
#endif
|
||||
uint32_t boot = 1;
|
||||
|
||||
set_logging_mask(
|
||||
@@ -102,7 +104,9 @@ int main(int argc, char * argv[])
|
||||
|
||||
printf1(TAG_RED,"Not authorized to boot (%08x == %08lx)\r\n", AUTH_WORD_ADDR, *(uint32_t*)AUTH_WORD_ADDR);
|
||||
}
|
||||
#ifdef SOLO_HACKER
|
||||
start_bootloader:
|
||||
#endif
|
||||
usbhid_init();
|
||||
printf1(TAG_GEN,"init usb\n");
|
||||
|
||||
|
@@ -43,7 +43,7 @@ endif
|
||||
DEFINES = -DDEBUG_LEVEL=$(DEBUG) -D$(CHIP) -DAES256=1 -DUSE_FULL_LL_DRIVER -DAPP_CONFIG=\"app.h\" $(EXTRA_DEFINES)
|
||||
# DEFINES += -DTEST_SOLO_STM32 -DTEST -DTEST_FIFO=1
|
||||
|
||||
CFLAGS=$(INC) -c $(DEFINES) -Wall -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS)
|
||||
CFLAGS=$(INC) -c $(DEFINES) -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS)
|
||||
LDFLAGS_LIB=$(HW) $(SEARCH) -specs=nano.specs -specs=nosys.specs -Wl,--gc-sections -u _printf_float -lnosys
|
||||
LDFLAGS=$(HW) $(LDFLAGS_LIB) -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref -Wl,-Bstatic -ltinycbor
|
||||
|
||||
@@ -69,7 +69,7 @@ all: $(TARGET).elf
|
||||
$(CP) -O ihex $^ $(TARGET).hex
|
||||
|
||||
clean:
|
||||
rm -f *.o src/*.o src/*.elf bootloader/*.o $(OBJ)
|
||||
rm -f *.o src/*.o *.elf bootloader/*.o $(OBJ)
|
||||
|
||||
|
||||
cbor:
|
||||
|
@@ -41,7 +41,7 @@ endif
|
||||
DEFINES = -DDEBUG_LEVEL=$(DEBUG) -D$(CHIP) -DAES256=1 -DUSE_FULL_LL_DRIVER -DAPP_CONFIG=\"bootloader.h\" $(EXTRA_DEFINES)
|
||||
# DEFINES += -DTEST_SOLO_STM32 -DTEST -DTEST_FIFO=1
|
||||
|
||||
CFLAGS=$(INC) -c $(DEFINES) -Wall -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS)
|
||||
CFLAGS=$(INC) -c $(DEFINES) -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS)
|
||||
LDFLAGS_LIB=$(HW) $(SEARCH) -specs=nano.specs -specs=nosys.specs -Wl,--gc-sections -lnosys
|
||||
LDFLAGS=$(HW) $(LDFLAGS_LIB) -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref -Wl,-Bstatic
|
||||
|
||||
@@ -68,4 +68,4 @@ all: $(TARGET).elf
|
||||
$(CP) -O ihex $^ $(TARGET).hex
|
||||
|
||||
clean:
|
||||
rm -f *.o src/*.o bootloader/*.o src/*.elf $(OBJ)
|
||||
rm -f *.o src/*.o bootloader/*.o *.elf $(OBJ)
|
||||
|
@@ -143,13 +143,13 @@ static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev,
|
||||
|
||||
static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length);
|
||||
//static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length);
|
||||
//static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
//static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
//static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length);
|
||||
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length);
|
||||
|
||||
@@ -789,12 +789,12 @@ static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
||||
/*static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_CfgFSDesc);
|
||||
return USBD_CDC_CfgFSDesc;
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* @brief USBD_CDC_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
@@ -802,12 +802,12 @@ static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
||||
/*static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_CfgHSDesc);
|
||||
return USBD_CDC_CfgHSDesc;
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* @brief USBD_CDC_GetCfgDesc
|
||||
* Return configuration descriptor
|
||||
@@ -815,12 +815,12 @@ static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length)
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
/*static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length)
|
||||
{
|
||||
*length = sizeof (USBD_CDC_OtherSpeedCfgDesc);
|
||||
return USBD_CDC_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
|
@@ -41,7 +41,7 @@ _Min_Stack_Size = 0x400; /* required amount of stack */
|
||||
/* Specify the memory areas */
|
||||
MEMORY
|
||||
{
|
||||
/* First 14 KB is bootloader */
|
||||
/* First 20 KB is bootloader */
|
||||
FLASH (rx) : ORIGIN = 0x08005000, LENGTH = 198K-8 /* Leave out 38 Kb at end for data */
|
||||
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
|
||||
SRAM2 (rw) : ORIGIN = 0x10000000, LENGTH = 16K
|
||||
|
@@ -99,7 +99,7 @@ void crypto_sha256_final(uint8_t * hash)
|
||||
void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac)
|
||||
{
|
||||
uint8_t buf[64];
|
||||
int i;
|
||||
unsigned int i;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (key == CRYPTO_MASTER_KEY)
|
||||
@@ -133,7 +133,7 @@ void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac)
|
||||
void crypto_sha256_hmac_final(uint8_t * key, uint32_t klen, uint8_t * hmac)
|
||||
{
|
||||
uint8_t buf[64];
|
||||
int i;
|
||||
unsigned int i;
|
||||
crypto_sha256_final(hmac);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (key == CRYPTO_MASTER_KEY)
|
||||
|
@@ -27,6 +27,9 @@
|
||||
#include "stm32l4xx_ll_iwdg.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
|
||||
void wait_for_usb_tether();
|
||||
|
||||
|
||||
uint32_t __90_ms = 0;
|
||||
uint32_t __device_status = 0;
|
||||
uint32_t __last_update = 0;
|
||||
@@ -60,7 +63,7 @@ uint32_t millis()
|
||||
return (((uint32_t)TIM6->CNT) + (__90_ms * 90));
|
||||
}
|
||||
|
||||
void device_set_status(int status)
|
||||
void device_set_status(uint32_t status)
|
||||
{
|
||||
__disable_irq();
|
||||
__last_update = millis();
|
||||
@@ -118,12 +121,12 @@ void usbhid_init()
|
||||
|
||||
void wait_for_usb_tether()
|
||||
{
|
||||
while (USBD_OK != CDC_Transmit_FS("tethered\r\n", 10) )
|
||||
while (USBD_OK != CDC_Transmit_FS((uint8_t*)"tethered\r\n", 10) )
|
||||
;
|
||||
while (USBD_OK != CDC_Transmit_FS("tethered\r\n", 10) )
|
||||
while (USBD_OK != CDC_Transmit_FS((uint8_t*)"tethered\r\n", 10) )
|
||||
;
|
||||
delay(10);
|
||||
while (USBD_OK != CDC_Transmit_FS("tethered\r\n", 10) )
|
||||
while (USBD_OK != CDC_Transmit_FS((uint8_t*)"tethered\r\n", 10) )
|
||||
;
|
||||
}
|
||||
|
||||
@@ -169,7 +172,9 @@ void main_loop_delay()
|
||||
|
||||
static int wink_time = 0;
|
||||
static uint32_t winkt1 = 0;
|
||||
#ifdef LED_WINK_VALUE
|
||||
static uint32_t winkt2 = 0;
|
||||
#endif
|
||||
void device_wink()
|
||||
{
|
||||
wink_time = 10;
|
||||
@@ -453,7 +458,9 @@ led_rgb(0x001040);
|
||||
delay(50);
|
||||
|
||||
|
||||
#if SKIP_BUTTON_CHECK_WITH_DELAY || SKIP_BUTTON_CHECK_FAST
|
||||
done:
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
|
@@ -133,7 +133,7 @@ void flash_write_dword(uint32_t addr, uint64_t data)
|
||||
|
||||
void flash_write(uint32_t addr, uint8_t * data, size_t sz)
|
||||
{
|
||||
int i;
|
||||
unsigned int i;
|
||||
uint8_t buf[8];
|
||||
while (FLASH->SR & (1<<16))
|
||||
;
|
||||
|
@@ -43,7 +43,9 @@ USBD_HandleTypeDef Solo_USBD_Device;
|
||||
static void LL_Init(void);
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
#if DEBUG_LEVEL > 0
|
||||
static void MX_USART1_UART_Init(void);
|
||||
#endif
|
||||
static void MX_TIM2_Init(void);
|
||||
static void MX_TIM6_Init(void);
|
||||
static void MX_RNG_Init(void);
|
||||
@@ -287,6 +289,7 @@ static void MX_TIM2_Init(void)
|
||||
|
||||
}
|
||||
|
||||
#if DEBUG_LEVEL > 0
|
||||
/* USART1 init function */
|
||||
static void MX_USART1_UART_Init(void)
|
||||
{
|
||||
@@ -324,6 +327,7 @@ static void MX_USART1_UART_Init(void)
|
||||
LL_USART_Enable(USART1);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Pinout Configuration
|
||||
*/
|
||||
|
@@ -53,7 +53,9 @@ void led_test_colors()
|
||||
{
|
||||
// Should produce pulsing of various colors
|
||||
int i = 0;
|
||||
#if DEBUG_LEVEL > 0
|
||||
int j = 0;
|
||||
#endif
|
||||
int inc = 1;
|
||||
uint32_t time = 0;
|
||||
#define update() do {\
|
||||
|
@@ -10,6 +10,10 @@
|
||||
|
||||
#endif
|
||||
|
||||
#define BOOT_VERSION_MAJ 1
|
||||
#define BOOT_VERSION_MIN 0
|
||||
#define BOOT_VERSION_PATCH 0
|
||||
|
||||
#define __STR_HELPER(x) #x
|
||||
#define __STR(x) __STR_HELPER(x)
|
||||
|
||||
|
Reference in New Issue
Block a user