Added ping command functionality.
This commit is contained in:
3
APDU.hpp
3
APDU.hpp
@@ -10,8 +10,9 @@ enum APDU : uint8_t
|
|||||||
enum APDU_STATUS : uint16_t
|
enum APDU_STATUS : uint16_t
|
||||||
{
|
{
|
||||||
SW_NO_ERROR = 0x9000,
|
SW_NO_ERROR = 0x9000,
|
||||||
SW_WRONG_DATA = 0x6A80,
|
SW_WRONG_LENGTH = 0x6700,
|
||||||
SW_CONDITIONS_NOT_SATISFIED = 0x6985,
|
SW_CONDITIONS_NOT_SATISFIED = 0x6985,
|
||||||
SW_COMMAND_NOT_ALLOWED = 0x6986,
|
SW_COMMAND_NOT_ALLOWED = 0x6986,
|
||||||
|
SW_WRONG_DATA = 0x6A80,
|
||||||
SW_INS_NOT_SUPPORTED = 0x6D00
|
SW_INS_NOT_SUPPORTED = 0x6D00
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ void Controller::handleTransaction()
|
|||||||
channels.at(opChannel).handle(msg);
|
channels.at(opChannel).handle(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t Controller::nextChannel()
|
uint32_t Controller::nextChannel()
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
currChannel++;
|
currChannel++;
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ class Controller
|
|||||||
Controller(const uint32_t startChannel = 1);
|
Controller(const uint32_t startChannel = 1);
|
||||||
|
|
||||||
void handleTransaction();
|
void handleTransaction();
|
||||||
const uint32_t nextChannel();
|
uint32_t nextChannel();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,5 @@ struct U2FMessage
|
|||||||
U2FMessage(const uint32_t nCID, const uint8_t nCMD);
|
U2FMessage(const uint32_t nCID, const uint8_t nCMD);
|
||||||
static std::shared_ptr<U2FMessage> readNonBlock();
|
static std::shared_ptr<U2FMessage> readNonBlock();
|
||||||
void write();
|
void write();
|
||||||
|
static void error(const uint32_t tCID, const uint8_t tErr);
|
||||||
protected:
|
|
||||||
static void error(const uint32_t tCID, const uint16_t tErr);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "u2f.hpp"
|
#include "u2f.hpp"
|
||||||
#include "U2F_Msg_CMD.hpp"
|
#include "U2F_Msg_CMD.hpp"
|
||||||
#include "U2F_Init_CMD.hpp"
|
#include "U2F_Init_CMD.hpp"
|
||||||
|
#include "U2F_Ping_CMD.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -11,6 +12,8 @@ shared_ptr<U2F_CMD> U2F_CMD::get(const shared_ptr<U2FMessage> uMsg)
|
|||||||
{
|
{
|
||||||
switch (uMsg->cmd)
|
switch (uMsg->cmd)
|
||||||
{
|
{
|
||||||
|
case U2FHID_PING:
|
||||||
|
return make_shared<U2F_Ping_CMD>(uMsg);
|
||||||
case U2FHID_MSG:
|
case U2FHID_MSG:
|
||||||
return U2F_Msg_CMD::generate(uMsg);
|
return U2F_Msg_CMD::generate(uMsg);
|
||||||
case U2FHID_INIT:
|
case U2FHID_INIT:
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ shared_ptr<U2F_Msg_CMD> U2F_Msg_CMD::generate(const shared_ptr<U2FMessage> uMsg)
|
|||||||
case APDU::U2F_AUTH:
|
case APDU::U2F_AUTH:
|
||||||
return make_shared<U2F_Authenticate_APDU>(cmd, dBytes);
|
return make_shared<U2F_Authenticate_APDU>(cmd, dBytes);
|
||||||
case APDU::U2F_VER:
|
case APDU::U2F_VER:
|
||||||
return make_shared<U2F_Version_APDU>(cmd);
|
return make_shared<U2F_Version_APDU>(cmd, dBytes);
|
||||||
default:
|
default:
|
||||||
cerr << "Invalid command used" << endl;
|
cerr << "Invalid command used" << endl;
|
||||||
throw APDU_STATUS::SW_INS_NOT_SUPPORTED;
|
throw APDU_STATUS::SW_INS_NOT_SUPPORTED;
|
||||||
|
|||||||
20
U2F_Ping_CMD.cpp
Normal file
20
U2F_Ping_CMD.cpp
Normal 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
14
U2F_Ping_CMD.hpp
Normal 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;
|
||||||
|
};
|
||||||
@@ -7,12 +7,12 @@
|
|||||||
|
|
||||||
using namespace std;
|
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
|
//Don't actually respond yet unless invalid
|
||||||
if (msg.p1 != 0 || msg.p2 != 0)
|
if (msg.p1 != 0 || msg.p2 != 0)
|
||||||
throw APDU_STATUS::SW_COMMAND_NOT_ALLOWED;
|
throw APDU_STATUS::SW_COMMAND_NOT_ALLOWED;
|
||||||
else if (msg.data.size() != 0)
|
else if (data.size() != 0)
|
||||||
throw APDU_STATUS::SW_WRONG_LENGTH;
|
throw APDU_STATUS::SW_WRONG_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
struct U2F_Version_APDU : U2F_Msg_CMD
|
struct U2F_Version_APDU : U2F_Msg_CMD
|
||||||
{
|
{
|
||||||
public:
|
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;
|
void respond(const uint32_t channelID) const override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ int main()
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void signalCallback(int signum)
|
void signalCallback([[maybe_unused]] int signum)
|
||||||
{
|
{
|
||||||
contProc = false;
|
contProc = false;
|
||||||
clog << "Caught SIGINT signal" << endl;
|
clog << "Caught SIGINT signal" << endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user