Added resumable loading, along with signal handling.
This version can store state after receiving SIGINT. This is achieved by polling FIFO read state;
This commit is contained in:
@@ -1,24 +1,33 @@
|
||||
#include "U2F_Init_CMD.hpp"
|
||||
#include <stdexcept>
|
||||
#include "U2FMessage.hpp"
|
||||
#include "u2f.hpp"
|
||||
#include <iostream>
|
||||
#include "Field.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
U2F_Init_CMD U2F_Init_CMD::get()
|
||||
U2F_Init_CMD::U2F_Init_CMD(const shared_ptr<U2FMessage> uMsg)
|
||||
{
|
||||
const auto message = U2FMessage::read();
|
||||
|
||||
if (message.cmd != U2FHID_INIT)
|
||||
if (uMsg->cmd != U2FHID_INIT)
|
||||
throw runtime_error{ "Failed to get U2F Init message" };
|
||||
else if (message.data.size() != INIT_NONCE_SIZE)
|
||||
else if (uMsg->data.size() != INIT_NONCE_SIZE)
|
||||
throw runtime_error{ "Init nonce is incorrect size" };
|
||||
|
||||
U2F_Init_CMD cmd;
|
||||
cmd.nonce = *reinterpret_cast<const uint64_t*>(message.data.data());
|
||||
|
||||
clog << "Fully read nonce" << endl;
|
||||
|
||||
return cmd;
|
||||
this->nonce = *reinterpret_cast<const uint64_t*>(uMsg->data.data());
|
||||
}
|
||||
|
||||
void U2F_Init_CMD::respond(const uint32_t channelID) const
|
||||
{
|
||||
U2FMessage msg{};
|
||||
msg.cid = CID_BROADCAST;
|
||||
msg.cmd = U2FHID_INIT;
|
||||
|
||||
msg.data.insert(msg.data.end(), FIELD(this->nonce));
|
||||
msg.data.insert(msg.data.end(), FIELD(channelID));
|
||||
msg.data.push_back(2); //Protocol version
|
||||
msg.data.push_back(1); //Major device version
|
||||
msg.data.push_back(0); //Minor device version
|
||||
msg.data.push_back(1); //Build device version
|
||||
msg.data.push_back(CAPFLAG_WINK); //Wink capability
|
||||
|
||||
msg.write();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user