Reformatting.
This commit is contained in:
@@ -17,33 +17,29 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "U2F_Authenticate_APDU.hpp"
|
||||
#include "Field.hpp"
|
||||
#include "U2FMessage.hpp"
|
||||
#include "u2f.hpp"
|
||||
#include "Field.tpp"
|
||||
#include "APDU.hpp"
|
||||
#include <iostream>
|
||||
#include "Field.hpp"
|
||||
#include "Field.tpp"
|
||||
#include "Signature.hpp"
|
||||
#include "U2FMessage.hpp"
|
||||
#include "micro-ecc/uECC.h"
|
||||
#include "u2f.hpp"
|
||||
#include <iostream>
|
||||
#include <mbedtls/sha256.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
U2F_Authenticate_APDU::U2F_Authenticate_APDU(const U2F_Msg_CMD &msg, const vector<uint8_t> &data)
|
||||
: U2F_Msg_CMD{ msg }
|
||||
{
|
||||
if (p2 != 0)
|
||||
{
|
||||
//Invalid U2F (APDU) parameter detected
|
||||
U2F_Authenticate_APDU::U2F_Authenticate_APDU(const U2F_Msg_CMD& msg, const vector<uint8_t>& data)
|
||||
: U2F_Msg_CMD{ msg } {
|
||||
if (p2 != 0) {
|
||||
// Invalid U2F (APDU) parameter detected
|
||||
throw APDU_STATUS::SW_CONDITIONS_NOT_SATISFIED;
|
||||
}
|
||||
else if (data.size() < 66)
|
||||
{
|
||||
//Invalid authentication request
|
||||
} else if (data.size() < 66) {
|
||||
// Invalid authentication request
|
||||
throw APDU_STATUS::SW_WRONG_LENGTH;
|
||||
}
|
||||
|
||||
copy(data.begin() + 0, data.begin() + 32, challengeP.begin());
|
||||
copy(data.begin() + 0, data.begin() + 32, challengeP.begin());
|
||||
copy(data.begin() + 32, data.begin() + 64, appParam.begin());
|
||||
|
||||
uint8_t keyHLen = data[64];
|
||||
@@ -51,21 +47,18 @@ U2F_Authenticate_APDU::U2F_Authenticate_APDU(const U2F_Msg_CMD &msg, const vecto
|
||||
copy(data.begin() + 65, data.begin() + 65 + keyHLen, back_inserter(keyH));
|
||||
}
|
||||
|
||||
void U2F_Authenticate_APDU::respond(const uint32_t channelID) const
|
||||
{
|
||||
if (keyH.size() != sizeof(Storage::KeyHandle))
|
||||
{
|
||||
//Respond with error code - key handle is of wrong size
|
||||
void U2F_Authenticate_APDU::respond(const uint32_t channelID) const {
|
||||
if (keyH.size() != sizeof(Storage::KeyHandle)) {
|
||||
// Respond with error code - key handle is of wrong size
|
||||
cerr << "Invalid key handle length" << endl;
|
||||
this->error(channelID, APDU_STATUS::SW_WRONG_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
auto keyHB = *reinterpret_cast<const Storage::KeyHandle*>(keyH.data());
|
||||
|
||||
if (Storage::appParams.find(keyHB) == Storage::appParams.end())
|
||||
{
|
||||
//Respond with error code - key handle doesn't exist in storage
|
||||
|
||||
if (Storage::appParams.find(keyHB) == Storage::appParams.end()) {
|
||||
// Respond with error code - key handle doesn't exist in storage
|
||||
cerr << "Invalid key handle" << endl;
|
||||
this->error(channelID, SW_WRONG_DATA);
|
||||
return;
|
||||
@@ -77,11 +70,10 @@ void U2F_Authenticate_APDU::respond(const uint32_t channelID) const
|
||||
msg.cid = channelID;
|
||||
msg.cmd = U2FHID_MSG;
|
||||
|
||||
auto &response = msg.data;
|
||||
auto& response = msg.data;
|
||||
APDU_STATUS statusCode = APDU_STATUS::SW_NO_ERROR;
|
||||
|
||||
switch (p1)
|
||||
{
|
||||
switch (p1) {
|
||||
case ControlCode::CheckOnly:
|
||||
if (appMatches)
|
||||
statusCode = APDU_STATUS::SW_CONDITIONS_NOT_SATISFIED;
|
||||
@@ -92,9 +84,9 @@ void U2F_Authenticate_APDU::respond(const uint32_t channelID) const
|
||||
msg.write();
|
||||
return;
|
||||
case ControlCode::EnforcePresenceSign:
|
||||
//Continue processing
|
||||
// Continue processing
|
||||
case ControlCode::DontEnforcePresenceSign:
|
||||
//Continue processing
|
||||
// Continue processing
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -104,7 +96,7 @@ void U2F_Authenticate_APDU::respond(const uint32_t channelID) const
|
||||
}
|
||||
|
||||
const auto& privKey = Storage::privKeys[keyHB];
|
||||
auto& keyCount = Storage::keyCounts[keyHB];
|
||||
auto& keyCount = Storage::keyCounts[keyHB];
|
||||
keyCount++;
|
||||
|
||||
response.push_back(0x01);
|
||||
@@ -117,7 +109,8 @@ void U2F_Authenticate_APDU::respond(const uint32_t channelID) const
|
||||
mbedtls_sha256_init(&shaContext);
|
||||
mbedtls_sha256_starts(&shaContext, 0);
|
||||
|
||||
mbedtls_sha256_update(&shaContext, reinterpret_cast<const uint8_t *>(appParam.data()), sizeof(appParam));
|
||||
mbedtls_sha256_update(&shaContext, reinterpret_cast<const uint8_t*>(appParam.data()),
|
||||
sizeof(appParam));
|
||||
uint8_t userPresence{ 1u };
|
||||
mbedtls_sha256_update(&shaContext, &userPresence, 1);
|
||||
const auto beCounter = beEncode(keyCount);
|
||||
|
||||
Reference in New Issue
Block a user