Improved U2F HID error handling.
Fixed U2FMessage's error reporting. Implemented better error reporting.
This commit is contained in:
@@ -160,11 +160,10 @@ U2FMessage::U2FMessage(const uint32_t nCID, const uint8_t nCMD)
|
|||||||
: cid{ nCID }, cmd{ nCMD }
|
: cid{ nCID }, cmd{ nCMD }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void U2FMessage::error(const uint32_t tCID, const uint16_t tErr)
|
void U2FMessage::error(const uint32_t tCID, const uint8_t tErr)
|
||||||
{
|
{
|
||||||
U2FMessage msg{};
|
U2FMessage msg{};
|
||||||
msg.cid = tCID;
|
msg.cid = tCID;
|
||||||
msg.cmd = U2FHID_ERROR;
|
msg.cmd = U2FHID_ERROR;
|
||||||
msg.data.push_back((tErr >> 8) & 0xFF);
|
msg.data.push_back(tErr);
|
||||||
msg.data.push_back(tErr & 0xFF);
|
|
||||||
}
|
}
|
||||||
|
|||||||
26
U2F_CMD.cpp
26
U2F_CMD.cpp
@@ -7,20 +7,20 @@ using namespace std;
|
|||||||
|
|
||||||
shared_ptr<U2F_CMD> U2F_CMD::get(const shared_ptr<U2FMessage> uMsg)
|
shared_ptr<U2F_CMD> U2F_CMD::get(const shared_ptr<U2FMessage> uMsg)
|
||||||
{
|
{
|
||||||
switch (uMsg->cmd)
|
try
|
||||||
{
|
{
|
||||||
case U2FHID_MSG:
|
switch (uMsg->cmd)
|
||||||
try
|
{
|
||||||
{
|
case U2FHID_MSG:
|
||||||
return U2F_Msg_CMD::generate(uMsg);
|
return U2F_Msg_CMD::generate(uMsg);
|
||||||
}
|
case U2FHID_INIT:
|
||||||
catch (runtime_error)
|
return make_shared<U2F_Init_CMD>(uMsg);
|
||||||
{
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
case U2FHID_INIT:
|
}
|
||||||
return make_shared<U2F_Init_CMD>(uMsg);
|
catch (runtime_error)
|
||||||
default:
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,16 @@ U2F_Init_CMD::U2F_Init_CMD(const shared_ptr<U2FMessage> uMsg)
|
|||||||
{
|
{
|
||||||
if (uMsg->cmd != U2FHID_INIT)
|
if (uMsg->cmd != U2FHID_INIT)
|
||||||
throw runtime_error{ "Failed to get U2F Init message" };
|
throw runtime_error{ "Failed to get U2F Init message" };
|
||||||
|
else if (uMsg->cid != CID_BROADCAST)
|
||||||
|
{
|
||||||
|
U2FMessage::error(uMsg->cid, ERR_OTHER);
|
||||||
|
throw runtime_error{ "Invalid CID for init command" };
|
||||||
|
}
|
||||||
else if (uMsg->data.size() != INIT_NONCE_SIZE)
|
else if (uMsg->data.size() != INIT_NONCE_SIZE)
|
||||||
|
{
|
||||||
|
U2FMessage::error(uMsg->cid, ERR_INVALID_LEN);
|
||||||
throw runtime_error{ "Init nonce is incorrect size" };
|
throw runtime_error{ "Init nonce is incorrect size" };
|
||||||
|
}
|
||||||
|
|
||||||
this->nonce = *reinterpret_cast<const uint64_t*>(uMsg->data.data());
|
this->nonce = *reinterpret_cast<const uint64_t*>(uMsg->data.data());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user