From eb2d377ffbf25c471b2af5fe17a4ae51af897c1d Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Tue, 12 Feb 2019 14:00:05 -0500 Subject: [PATCH] add extension to solo to get version and RNG --- fido2/extensions/extensions.c | 13 +++--- fido2/extensions/solo.c | 76 ++++++++++++++++++++++++++++++++ fido2/extensions/solo.h | 27 ++++++++++++ targets/stm32l432/application.mk | 1 + 4 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 fido2/extensions/solo.c create mode 100644 fido2/extensions/solo.h diff --git a/fido2/extensions/extensions.c b/fido2/extensions/extensions.c index ad8e660..7d413c2 100644 --- a/fido2/extensions/extensions.c +++ b/fido2/extensions/extensions.c @@ -1,21 +1,21 @@ /* * Copyright (C) 2018 SoloKeys, Inc. - * + * * This file is part of Solo. - * + * * Solo is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * Solo 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Solo. If not, see - * + * * This code is available under licenses for commercial use. * Please contact SoloKeys for more information. */ @@ -23,6 +23,7 @@ #include "extensions.h" #include "u2f.h" #include "wallet.h" +#include "solo.h" #include "device.h" #include "log.h" @@ -69,6 +70,8 @@ int16_t bridge_u2f_to_extensions(uint8_t * _chal, uint8_t * _appid, uint8_t klen ret = bootloader_bridge(klen, keyh); #elif defined(WALLET_EXTENSION) ret = bridge_u2f_to_wallet(_chal, _appid, klen, keyh); +#else + ret = bridge_u2f_to_solo(_chal, _appid, klen, keyh); #endif if (ret != 0) diff --git a/fido2/extensions/solo.c b/fido2/extensions/solo.c new file mode 100644 index 0000000..9072588 --- /dev/null +++ b/fido2/extensions/solo.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2018 SoloKeys, Inc. + * + * This file is part of Solo. + * + * Solo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Solo 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Solo. If not, see + * + * This code is available under licenses for commercial use. + * Please contact SoloKeys for more information. + */ + +#include +#include "extensions.h" +#include "u2f.h" +#include "wallet.h" +#include "device.h" +#include "ctap.h" +#include "ctap_errors.h" + +#include "log.h" +#include APP_CONFIG + +int16_t bridge_u2f_to_solo(uint8_t * _chal, uint8_t * _appid, uint8_t klen, uint8_t * keyh) +{ + static uint8_t msg_buf[72]; + int reqlen = klen; + int i; + int8_t ret = 0; + + wallet_request * req = (wallet_request *) msg_buf; + + printf1(TAG_WALLET, "u2f-solo [%d]: ", reqlen); dump_hex1(TAG_WALLET, msg_buf, reqlen); + + switch(req->operation) + { + case WalletVersion: + msg_buf[0] = SOLO_VERSION_MAJ; + msg_buf[0] = SOLO_VERSION_MIN; + u2f_response_writeback((uint8_t*)WALLET_VERSION, sizeof(WALLET_VERSION)-1); + break; + case WalletRng: + printf1(TAG_WALLET,"SoloRng\n"); + + ret = ctap_generate_rng(msg_buf, 72); + if (ret != 1) + { + printf1(TAG_WALLET,"Rng failed\n"); + ret = CTAP2_ERR_PROCESSING; + goto cleanup; + } + ret = 0; + + u2f_response_writeback((uint8_t *)msg_buf,72); + break; + + default: + printf2(TAG_ERR,"Invalid wallet command: %x\n",req->operation); + ret = CTAP1_ERR_INVALID_COMMAND; + break; + } + +cleanup: + + return ret; +} diff --git a/fido2/extensions/solo.h b/fido2/extensions/solo.h new file mode 100644 index 0000000..04e9d8d --- /dev/null +++ b/fido2/extensions/solo.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2018 SoloKeys, Inc. + * + * This file is part of Solo. + * + * Solo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Solo 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Solo. If not, see + * + * This code is available under licenses for commercial use. + * Please contact SoloKeys for more information. + */ +#ifndef SOLO_H_ +#define SOLO_H_ + +int16_t bridge_u2f_to_solo(uint8_t * _chal, uint8_t * _appid, uint8_t klen, uint8_t * keyh); + +#endif diff --git a/targets/stm32l432/application.mk b/targets/stm32l432/application.mk index 89ece0d..acc3e48 100644 --- a/targets/stm32l432/application.mk +++ b/targets/stm32l432/application.mk @@ -13,6 +13,7 @@ SRC += $(wildcard lib/*.c) $(wildcard lib/usbd/*.c) SRC += ../../fido2/util.c ../../fido2/u2f.c ../../fido2/test_power.c SRC += ../../fido2/stubs.c ../../fido2/log.c ../../fido2/ctaphid.c ../../fido2/ctap.c SRC += ../../fido2/ctap_parse.c ../../fido2/main.c +SRC += ../../fido2/extensions/extensions.c ../../fido2/extensions/solo.c # Crypto libs SRC += ../../crypto/sha256/sha256.c ../../crypto/micro-ecc/uECC.c ../../crypto/tiny-AES-c/aes.c