Implemented authentication.
Near feature complete.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#include "U2F_Msg_CMD.hpp"
|
||||
#include "APDU.hpp"
|
||||
#include "U2F_Register_APDU.hpp"
|
||||
#include "U2F_Version_APDU.hpp"
|
||||
#include "U2F_Authenticate_APDU.hpp"
|
||||
#include "U2FMessage.hpp"
|
||||
#include "u2f.hpp"
|
||||
#include "APDU.hpp"
|
||||
#include <iostream>
|
||||
#include "Streams.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -58,10 +61,9 @@ shared_ptr<U2F_Msg_CMD> U2F_Msg_CMD::get()
|
||||
vector<uint8_t> data{ dat.begin() + 4, dat.end() };
|
||||
auto startPtr = data.begin(), endPtr = data.end();
|
||||
|
||||
if (usesData.at(cmd.ins))
|
||||
if (usesData.at(cmd.ins) || data.size() > 3)
|
||||
{
|
||||
clog << "Assuming command uses data" << endl;
|
||||
clog << "First bytes are: " << static_cast<uint16_t>(data[0]) << " " << static_cast<uint16_t>(data[1]) << " " << static_cast<uint16_t>(data[2]) << endl;
|
||||
//clog << "First bytes are: " << static_cast<uint16_t>(data[0]) << " " << static_cast<uint16_t>(data[1]) << " " << static_cast<uint16_t>(data[2]) << endl;
|
||||
|
||||
if (cBCount == 0)
|
||||
throw runtime_error{ "Invalid command - should have attached data" };
|
||||
@@ -77,15 +79,12 @@ shared_ptr<U2F_Msg_CMD> U2F_Msg_CMD::get()
|
||||
startPtr += 3;
|
||||
}
|
||||
|
||||
clog << "Got command uses " << cmd.lc << " bytes of data" << endl;
|
||||
|
||||
endPtr = startPtr + cmd.lc;
|
||||
|
||||
cmd.le = getLe(data.end() - endPtr, vector<uint8_t>(endPtr, data.end()));
|
||||
}
|
||||
else
|
||||
{
|
||||
clog << "Assuming command does not use data" << endl;
|
||||
cmd.lc = 0;
|
||||
endPtr = startPtr;
|
||||
cmd.le = getLe(cBCount, data);
|
||||
@@ -93,8 +92,50 @@ shared_ptr<U2F_Msg_CMD> U2F_Msg_CMD::get()
|
||||
|
||||
const auto dBytes = vector<uint8_t>(startPtr, endPtr);
|
||||
|
||||
if (cmd.ins == APDU::U2F_REG)
|
||||
return make_shared<U2F_Register_APDU>(cmd, dBytes);
|
||||
auto hAS = getHostAPDUStream().get();
|
||||
|
||||
fprintf(hAS, "<table>\n"
|
||||
"\t\t\t<thead>\n"
|
||||
"\t\t\t\t<tr>\n"
|
||||
"\t\t\t\t\t<th>CLA</th>\n"
|
||||
"\t\t\t\t\t<th>INS</th>\n"
|
||||
"\t\t\t\t\t<th>P1</th>\n"
|
||||
"\t\t\t\t\t<th>P2</th>\n"
|
||||
"\t\t\t\t\t<th>Lc</th>\n"
|
||||
"\t\t\t\t\t<th>Data</th>\n"
|
||||
"\t\t\t\t\t<th>Le</th>\n"
|
||||
"\t\t\t\t</tr>\n"
|
||||
"\t\t\t</thead>\n"
|
||||
"\t\t\t<tbody>\n"
|
||||
"\t\t\t\t<tr>\n"
|
||||
"\t\t\t\t\t<td>0x%02X</td>\n"
|
||||
"\t\t\t\t\t<td>0x%02X</td>\n"
|
||||
"\t\t\t\t\t<td>%u</td>\n"
|
||||
"\t\t\t\t\t<td>%u</td>\n"
|
||||
"\t\t\t\t\t<td>%3u</td>\n"
|
||||
"\t\t\t\t\t<td class=\"data\">", cmd.cla, cmd.ins, cmd.p1, cmd.p2, cmd.lc);
|
||||
|
||||
for (auto b : dBytes)
|
||||
fprintf(hAS, "%3u ", b);
|
||||
|
||||
fprintf(hAS, "</td>\n"
|
||||
"\t\t\t\t\t<td>%5u</td>\n"
|
||||
"\t\t\t\t</tr>\n"
|
||||
"\t\t\t</tbody>\n"
|
||||
"\t\t</table>\n"
|
||||
"\t\t<br />", cmd.le);
|
||||
|
||||
switch (cmd.ins)
|
||||
{
|
||||
case APDU::U2F_REG:
|
||||
return make_shared<U2F_Register_APDU>(cmd, dBytes);
|
||||
case APDU::U2F_AUTH:
|
||||
return make_shared<U2F_Authenticate_APDU>(cmd, dBytes);
|
||||
case APDU::U2F_VER:
|
||||
return make_shared<U2F_Version_APDU>(cmd);
|
||||
default:
|
||||
throw runtime_error{ "Unknown APDU command issued" };
|
||||
}
|
||||
}
|
||||
|
||||
void U2F_Msg_CMD::respond(){};
|
||||
|
||||
Reference in New Issue
Block a user