diff --git a/Channel.cpp b/Channel.cpp index 15e74a2..05ada7c 100644 --- a/Channel.cpp +++ b/Channel.cpp @@ -27,7 +27,6 @@ void Channel::handle(const shared_ptr uMsg) else if (this->lockedState != ChannelLockedState::Unlocked) throw runtime_error{ "Channel in incorrect (locked) state to handle request" }; - clog << "Handling uMsg with CMD: " << static_cast(uMsg->cmd) << endl; return U2F_CMD::get(uMsg)->respond(this->cid); } diff --git a/Controller.cpp b/Controller.cpp index a008d96..1b15ff2 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -18,8 +18,6 @@ void Controller::handleTransaction() auto opChannel = msg->cid; - clog << "Got msg with cmd of: " << static_cast(msg->cmd) << endl; - if (msg->cmd == U2FHID_INIT) { opChannel = nextChannel(); diff --git a/Packet.cpp b/Packet.cpp index 60e335a..a0e34e9 100644 --- a/Packet.cpp +++ b/Packet.cpp @@ -90,7 +90,6 @@ shared_ptr InitPacket::getPacket(const uint32_t rCID, const uint8_t "\t\t" "\t\t
"); - clog << "Fully read init packet" << endl; bytesRead = 0; return p; } @@ -143,7 +142,6 @@ shared_ptr ContPacket::getPacket(const uint32_t rCID, const uint8_t "\t\t\n" "\t\t
"); - //clog << "Fully read cont packet" << endl; readBytes = 0; return p; } @@ -183,7 +181,6 @@ shared_ptr Packet::getPacket() if (b & TYPE_MASK) { //Init packet - //clog << "Getting init packet" << endl; packet = InitPacket::getPacket(cid, b); if (packet) @@ -194,7 +191,6 @@ shared_ptr Packet::getPacket() else { //Cont packet - //clog << "Getting cont packet" << endl; packet = ContPacket::getPacket(cid, b); if (packet) diff --git a/Storage.cpp b/Storage.cpp index 4a66b29..8d39d45 100644 --- a/Storage.cpp +++ b/Storage.cpp @@ -50,13 +50,6 @@ void Storage::init(const string &dirPrefix) Storage::PubKey pubKey{}; b64decode(pubStr, pubKey); - clog << "Loaded key with pubkey: " << hex; - - for (auto b : pubKey) - clog << static_cast(b) << ' '; - - clog << dec << endl; - Storage::appParams[keyH] = appParam; Storage::privKeys[keyH] = privKey; Storage::pubKeys[keyH] = pubKey; diff --git a/U2FMessage.cpp b/U2FMessage.cpp index 1ab8e45..02c063e 100644 --- a/U2FMessage.cpp +++ b/U2FMessage.cpp @@ -85,8 +85,6 @@ shared_ptr U2FMessage::readNonBlock() message->data.assign(dataBytes.begin(), dataBytes.end()); currSeq = -1u; - std::clog << "Read all of message" << std::endl; - return message; } @@ -128,8 +126,6 @@ void U2FMessage::write() bytesWritten += newByteCount; } - //auto stream = *getHostStream(); - if (cmd == U2FHID_MSG) { auto dAS = getDevAPDUStream().get(); diff --git a/U2F_Authenticate_APDU.cpp b/U2F_Authenticate_APDU.cpp index 5a6b409..ba1f9d6 100644 --- a/U2F_Authenticate_APDU.cpp +++ b/U2F_Authenticate_APDU.cpp @@ -23,8 +23,6 @@ U2F_Authenticate_APDU::U2F_Authenticate_APDU(const U2F_Msg_CMD &msg, const vecto uint8_t keyHLen = data[64]; copy(data.begin() + 65, data.begin() + 65 + keyHLen, back_inserter(keyH)); - - clog << "Got U2F_Auth request" << endl; } void U2F_Authenticate_APDU::respond(const uint32_t channelID) const @@ -39,7 +37,7 @@ void U2F_Authenticate_APDU::respond(const uint32_t channelID) const if (keyH.size() != sizeof(Storage::KeyHandle)) { //Respond with error code - key handle is of wrong size - clog << "Invalid key handle length" << endl; + cerr << "Invalid key handle length" << endl; statusCode = APDU_STATUS::SW_WRONG_DATA; response.insert(response.end(), FIELD_BE(statusCode)); msg.write(); @@ -51,7 +49,7 @@ void U2F_Authenticate_APDU::respond(const uint32_t channelID) const if (Storage::appParams.find(keyHB) == Storage::appParams.end()) { //Respond with error code - key handle doesn't exist in storage - clog << "Invalid key handle" << endl; + cerr << "Invalid key handle" << endl; statusCode = APDU_STATUS::SW_WRONG_DATA; response.insert(response.end(), FIELD_BE(statusCode)); msg.write(); diff --git a/U2F_Msg_CMD.cpp b/U2F_Msg_CMD.cpp index 7aedb64..68bc375 100644 --- a/U2F_Msg_CMD.cpp +++ b/U2F_Msg_CMD.cpp @@ -17,9 +17,7 @@ uint32_t U2F_Msg_CMD::getLe(const uint32_t byteCount, vector bytes) if (byteCount != 0) { //Le must be length of data in bytes - clog << "Le must be length of data in bytes" << endl; - clog << "Le has a size of " << byteCount << " bytes" << endl; - + switch (byteCount) { case 1: @@ -59,14 +57,10 @@ shared_ptr U2F_Msg_CMD::generate(const shared_ptr uMsg) cmd.p1 = dat[2]; cmd.p2 = dat[3]; - clog << "Loaded U2F_Msg_CMD parameters" << endl; - vector data{ dat.begin() + 4, dat.end() }; const uint32_t cBCount = data.size(); auto startPtr = data.begin(), endPtr = data.end(); - clog << "Loaded iters" << endl; - if (usesData.at(cmd.ins) || data.size() > 3) { if (cBCount == 0) @@ -85,7 +79,6 @@ shared_ptr U2F_Msg_CMD::generate(const shared_ptr uMsg) endPtr = startPtr + cmd.lc; - clog << "Getting Le" << endl; cmd.le = getLe(data.end() - endPtr, vector(endPtr, data.end())); } else @@ -93,14 +86,11 @@ shared_ptr U2F_Msg_CMD::generate(const shared_ptr uMsg) cmd.lc = 0; endPtr = startPtr; - clog << "Getting Le" << endl; cmd.le = getLe(cBCount, data); } const auto dBytes = vector(startPtr, endPtr); - clog << "Determined message format" << endl; - auto hAS = getHostAPDUStream().get(); fprintf(hAS, "\n" @@ -134,8 +124,6 @@ shared_ptr U2F_Msg_CMD::generate(const shared_ptr uMsg) "\t\t
\n" "\t\t
", cmd.le); - clog << "Constructing message specialisation" << endl; - switch (cmd.ins) { case APDU::U2F_REG: @@ -149,6 +137,15 @@ shared_ptr U2F_Msg_CMD::generate(const shared_ptr uMsg) } } +void U2F_Msg_CMD::error(const uint32_t channelID, const uint16_t errCode) +{ + U2FMessage msg{}; + msg.cid = channelID; + msg.cmd = U2FHID_MSG; + msg.data.insert(msg.data.end(), FIELD_BE(errCode)); + msg.write(); +} + const map U2F_Msg_CMD::usesData = { { U2F_REG, true }, { U2F_AUTH, true }, @@ -157,10 +154,5 @@ const map U2F_Msg_CMD::usesData = { void U2F_Msg_CMD::respond(const uint32_t channelID) const { - U2FMessage msg{}; - msg.cid = channelID; - msg.cmd = U2FHID_MSG; - auto errorCode = APDU_STATUS::SW_INS_NOT_SUPPORTED; - msg.data.insert(msg.data.end(), FIELD_BE(errorCode)); - msg.write(); + U2F_Msg_CMD::error(channelID, static_cast(APDU_STATUS::SW_INS_NOT_SUPPORTED)); } diff --git a/U2F_Msg_CMD.hpp b/U2F_Msg_CMD.hpp index aa5ffdc..7403d1e 100644 --- a/U2F_Msg_CMD.hpp +++ b/U2F_Msg_CMD.hpp @@ -22,6 +22,7 @@ struct U2F_Msg_CMD : U2F_CMD public: static std::shared_ptr generate(const std::shared_ptr uMsg); + static void error(const uint32_t channelID, const uint16_t errCode); void respond(const uint32_t channelID) const; }; diff --git a/U2F_Register_APDU.cpp b/U2F_Register_APDU.cpp index a67ee81..63d7308 100644 --- a/U2F_Register_APDU.cpp +++ b/U2F_Register_APDU.cpp @@ -19,8 +19,8 @@ U2F_Register_APDU::U2F_Register_APDU(const U2F_Msg_CMD &msg, const vector(p1) << ", p2: " << static_cast(p2) << endl; - //throw runtime_error{ "Invalid APDU parameters" }; + cerr << "Ins: " << static_cast(ins) << ", p1: " << static_cast(p1) << ", p2: " << static_cast(p2) << endl; + cerr << "Invalid APDU parameters detected" << endl; } copy(data.data() + 0, data.data() + 32, challengeP.begin()); @@ -31,7 +31,6 @@ U2F_Register_APDU::U2F_Register_APDU(const U2F_Msg_CMD &msg, const vectorkeyH] = privKey; Storage::pubKeys[this->keyH] = pubKey; Storage::keyCounts[this->keyH] = 0; - - clog << "Produced pub key: " << hex; - - for (auto b : pubKey) - clog << static_cast(b) << ' '; - - clog << endl << dec << "Got U2F_Reg request" << endl; } void U2F_Register_APDU::respond(const uint32_t channelID) const @@ -59,7 +51,6 @@ void U2F_Register_APDU::respond(const uint32_t channelID) const auto& response = m.data; const auto appParam = Storage::appParams[this->keyH]; const auto pubKey = Storage::pubKeys[this->keyH]; - const auto privKey = Storage::privKeys[this->keyH]; response.push_back(0x05); copy(pubKey.begin(), pubKey.end(), back_inserter(response)); @@ -94,17 +85,13 @@ void U2F_Register_APDU::respond(const uint32_t channelID) const } Signature signature; - std::clog << "Will sign digest with priv key" << std::endl; uECC_sign(attestPrivKey, digest.data(), digest.size(), signature.data(), uECC_secp256r1()); //Append signature as DER - std::clog << "Will append sig as DER" << std::endl; appendSignatureAsDER(response, signature); response.push_back(static_cast(APDU_STATUS::SW_NO_ERROR) >> 8); response.push_back(static_cast(APDU_STATUS::SW_NO_ERROR) & 0xff); - std::clog << "Writing out " << response.size() << " bytes in response" << std::endl; - m.write(); } diff --git a/U2F_Version_APDU.cpp b/U2F_Version_APDU.cpp index 3d1df44..b5af8dc 100644 --- a/U2F_Version_APDU.cpp +++ b/U2F_Version_APDU.cpp @@ -9,8 +9,6 @@ using namespace std; U2F_Version_APDU::U2F_Version_APDU(const U2F_Msg_CMD &msg) { - clog << "Got U2F_Ver APDU request" << endl; - //Don't actually respond yet }