Made a service to enable auto-starting.

This commit is contained in:
2018-08-12 12:00:38 +00:00
parent 0de7ee2fd7
commit 5c908d8530
10 changed files with 33 additions and 10 deletions

View File

@@ -12,7 +12,7 @@ enum APDU_STATUS : uint16_t
SW_NO_ERROR = 0x9000, SW_NO_ERROR = 0x9000,
SW_WRONG_LENGTH = 0x6700, SW_WRONG_LENGTH = 0x6700,
SW_CONDITIONS_NOT_SATISFIED = 0x6985, SW_CONDITIONS_NOT_SATISFIED = 0x6985,
SW_COMMAND_NOT_ALLOWED = 0x6986,
SW_WRONG_DATA = 0x6A80, SW_WRONG_DATA = 0x6A80,
SW_INS_NOT_SUPPORTED = 0x6D00 SW_INS_NOT_SUPPORTED = 0x6D00,
SW_COMMAND_NOT_ALLOWED = 0x6E00,
}; };

View File

@@ -27,7 +27,10 @@ void Channel::handle(const shared_ptr<U2FMessage> uMsg)
else if (this->lockedState != ChannelLockedState::Unlocked) else if (this->lockedState != ChannelLockedState::Unlocked)
throw runtime_error{ "Channel in incorrect (locked) state to handle request" }; throw runtime_error{ "Channel in incorrect (locked) state to handle request" };
return U2F_CMD::get(uMsg)->respond(this->cid); auto cmd = U2F_CMD::get(uMsg);
if (cmd)
return cmd->respond(this->cid);
} }
void Channel::init(const ChannelInitState newInitState) void Channel::init(const ChannelInitState newInitState)

View File

@@ -15,6 +15,8 @@ U2FDevice: $(OBJECTS) libuECC.o libcppb64.o
install: U2FDevice install: U2FDevice
install -m775 -t /usr/bin U2FDevice install -m775 -t /usr/bin U2FDevice
install -m775 -t /etc/systemd/system U2FDevice.service
install -d /usr/share/U2FDevice/
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<

View File

@@ -18,7 +18,11 @@ sudo make install
To run To run
U2FDevice sudo systemctl start U2FDevice.service
To run automatically at boot
sudo systmectl enable U2FDevice.service
Debug files at Debug files at

View File

@@ -27,7 +27,10 @@ int main(int argc, char **argv)
} }
signal(SIGINT, signalCallback); signal(SIGINT, signalCallback);
Storage::init();
string privKeyDir = (argc == 2 ? argv[1] : "/usr/share/U2FDevice/");
Storage::init(privKeyDir);
Controller ch{ 0xF1D00000 }; Controller ch{ 0xF1D00000 };

8
U2FDevice.service Executable file
View File

@@ -0,0 +1,8 @@
[Unit]
Description=An implementation of the U2F device protocol for Raspberry Pi 0
[Service]
ExecStart=/usr/bin/U2FDevice
[Install]
WantedBy=multi-user.target

View File

@@ -17,7 +17,7 @@ U2F_Authenticate_APDU::U2F_Authenticate_APDU(const U2F_Msg_CMD &msg, const vecto
if (p2 != 0) if (p2 != 0)
{ {
//Invalid U2F (APDU) parameter detected //Invalid U2F (APDU) parameter detected
throw APDU_STATUS::SW_COMMAND_NOT_ALLOWED; throw APDU_STATUS::SW_CONDITIONS_NOT_SATISFIED;
} }
else if (data.size() < 66) else if (data.size() < 66)
{ {
@@ -81,7 +81,7 @@ void U2F_Authenticate_APDU::respond(const uint32_t channelID) const
default: default:
cerr << "Unknown APDU authentication command" << endl; cerr << "Unknown APDU authentication command" << endl;
this->error(channelID, APDU_STATUS::SW_COMMAND_NOT_ALLOWED); this->error(channelID, APDU_STATUS::SW_INS_NOT_SUPPORTED);
return; return;
} }

View File

@@ -172,11 +172,13 @@ shared_ptr<U2F_Msg_CMD> U2F_Msg_CMD::generate(const shared_ptr<U2FMessage> uMsg)
{ {
U2F_Msg_CMD::error(uMsg->cid, e); U2F_Msg_CMD::error(uMsg->cid, e);
throw runtime_error{ "APDU construction error" }; throw runtime_error{ "APDU construction error" };
return {};
} }
} }
void U2F_Msg_CMD::error(const uint32_t channelID, const uint16_t errCode) void U2F_Msg_CMD::error(const uint32_t channelID, const uint16_t errCode)
{ {
clog << "U2F_Msg_CMD::error " << errCode << endl;
U2FMessage msg{}; U2FMessage msg{};
msg.cid = channelID; msg.cid = channelID;
msg.cmd = U2FHID_MSG; msg.cmd = U2FHID_MSG;

View File

@@ -20,10 +20,11 @@ U2F_Register_APDU::U2F_Register_APDU(const U2F_Msg_CMD &msg, const vector<uint8_
//Incorrect registration size //Incorrect registration size
throw APDU_STATUS::SW_WRONG_LENGTH; throw APDU_STATUS::SW_WRONG_LENGTH;
} }
else if (p1 != 0x00 || p2 != 0x00) else if ((p1 != 0x00 && p1 != 0x03) || p2 != 0x00) //According to spec, 0x03 not allowed here
//However, browsers seem to do it, so...
{ {
//Invalid U2F Message (APDU) parameters detected //Invalid U2F Message (APDU) parameters detected
throw APDU_STATUS::SW_COMMAND_NOT_ALLOWED; throw APDU_STATUS::SW_INS_NOT_SUPPORTED;
} }
copy(data.data() + 0, data.data() + 32, challengeP.begin()); copy(data.data() + 0, data.data() + 32, challengeP.begin());

View File

@@ -11,7 +11,7 @@ U2F_Version_APDU::U2F_Version_APDU(const U2F_Msg_CMD &msg, const std::vector<uin
{ {
//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_INS_NOT_SUPPORTED;
else if (data.size() != 0) else if (data.size() != 0)
throw APDU_STATUS::SW_WRONG_LENGTH; throw APDU_STATUS::SW_WRONG_LENGTH;
} }