Added ping command functionality.

This commit is contained in:
2018-08-10 18:31:22 +00:00
parent a20c190fea
commit 2b01dbc605
11 changed files with 47 additions and 11 deletions

View File

@@ -10,8 +10,9 @@ enum APDU : uint8_t
enum APDU_STATUS : uint16_t
{
SW_NO_ERROR = 0x9000,
SW_WRONG_DATA = 0x6A80,
SW_WRONG_LENGTH = 0x6700,
SW_CONDITIONS_NOT_SATISFIED = 0x6985,
SW_COMMAND_NOT_ALLOWED = 0x6986,
SW_WRONG_DATA = 0x6A80,
SW_INS_NOT_SUPPORTED = 0x6D00
};

View File

@@ -36,7 +36,7 @@ void Controller::handleTransaction()
channels.at(opChannel).handle(msg);
}
const uint32_t Controller::nextChannel()
uint32_t Controller::nextChannel()
{
do
currChannel++;

View File

@@ -12,5 +12,5 @@ class Controller
Controller(const uint32_t startChannel = 1);
void handleTransaction();
const uint32_t nextChannel();
uint32_t nextChannel();
};

View File

@@ -15,7 +15,5 @@ struct U2FMessage
U2FMessage(const uint32_t nCID, const uint8_t nCMD);
static std::shared_ptr<U2FMessage> readNonBlock();
void write();
protected:
static void error(const uint32_t tCID, const uint16_t tErr);
static void error(const uint32_t tCID, const uint8_t tErr);
};

View File

@@ -2,6 +2,7 @@
#include "u2f.hpp"
#include "U2F_Msg_CMD.hpp"
#include "U2F_Init_CMD.hpp"
#include "U2F_Ping_CMD.hpp"
using namespace std;
@@ -11,6 +12,8 @@ shared_ptr<U2F_CMD> U2F_CMD::get(const shared_ptr<U2FMessage> uMsg)
{
switch (uMsg->cmd)
{
case U2FHID_PING:
return make_shared<U2F_Ping_CMD>(uMsg);
case U2FHID_MSG:
return U2F_Msg_CMD::generate(uMsg);
case U2FHID_INIT:

View File

@@ -162,7 +162,7 @@ shared_ptr<U2F_Msg_CMD> U2F_Msg_CMD::generate(const shared_ptr<U2FMessage> uMsg)
case APDU::U2F_AUTH:
return make_shared<U2F_Authenticate_APDU>(cmd, dBytes);
case APDU::U2F_VER:
return make_shared<U2F_Version_APDU>(cmd);
return make_shared<U2F_Version_APDU>(cmd, dBytes);
default:
cerr << "Invalid command used" << endl;
throw APDU_STATUS::SW_INS_NOT_SUPPORTED;

20
U2F_Ping_CMD.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include "U2F_Ping_CMD.hpp"
#include "u2f.hpp"
using namespace std;
U2F_Ping_CMD::U2F_Ping_CMD(const shared_ptr<U2FMessage> uMsg)
: nonce{ uMsg->data }
{
if (uMsg->cmd != U2FHID_PING)
throw runtime_error{ "Failed to get U2F ping message" };
}
void U2F_Ping_CMD::respond(const uint32_t channelID) const
{
U2FMessage msg{};
msg.cid = channelID;
msg.cmd = U2FHID_PING;
msg.data = nonce;
msg.write();
}

14
U2F_Ping_CMD.hpp Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
#include <memory>
#include "U2F_CMD.hpp"
#include "U2FMessage.hpp"
struct U2F_Ping_CMD : U2F_CMD
{
std::vector<uint8_t> nonce;
public:
U2F_Ping_CMD(const std::shared_ptr<U2FMessage> uMsg);
virtual void respond(const uint32_t channelID) const override;
};

View File

@@ -7,12 +7,12 @@
using namespace std;
U2F_Version_APDU::U2F_Version_APDU(const U2F_Msg_CMD &msg)
U2F_Version_APDU::U2F_Version_APDU(const U2F_Msg_CMD &msg, const std::vector<uint8_t> &data)
{
//Don't actually respond yet unless invalid
if (msg.p1 != 0 || msg.p2 != 0)
throw APDU_STATUS::SW_COMMAND_NOT_ALLOWED;
else if (msg.data.size() != 0)
else if (data.size() != 0)
throw APDU_STATUS::SW_WRONG_LENGTH;
}

View File

@@ -4,6 +4,6 @@
struct U2F_Version_APDU : U2F_Msg_CMD
{
public:
U2F_Version_APDU(const U2F_Msg_CMD &msg);
U2F_Version_APDU(const U2F_Msg_CMD &msg, const std::vector<uint8_t> &data);
void respond(const uint32_t channelID) const override;
};

View File

@@ -28,7 +28,7 @@ int main()
return EXIT_SUCCESS;
}
void signalCallback(int signum)
void signalCallback([[maybe_unused]] int signum)
{
contProc = false;
clog << "Caught SIGINT signal" << endl;