diff --git a/Controller.cpp b/Controller.cpp index 6e0f481..a28a450 100644 --- a/Controller.cpp +++ b/Controller.cpp @@ -12,10 +12,15 @@ Controller::Controller(const uint32_t startChannel) void Controller::handleTransaction() { - if (channels.size() != 0 && chrono::duration_cast(chrono::system_clock::now() - lastMessage) < 5s) - toggleACTLED(); - else - enableACTLED(false); + try + { + if (channels.size() != 0 && chrono::duration_cast(chrono::system_clock::now() - lastMessage) < 5s) + toggleACTLED(); + else + enableACTLED(false); + } + catch (runtime_error) + {} auto msg = U2FMessage::readNonBlock(); diff --git a/Makefile b/Makefile index 18537a8..4c41286 100755 --- a/Makefile +++ b/Makefile @@ -13,6 +13,9 @@ OBJECTS := $(MODULES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o) U2FDevice: $(OBJECTS) libuECC.o libcppb64.o g++ $(LDFLAGS) -o $@ $^ +install: U2FDevice + install -m775 -t /usr/bin U2FDevice + $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< @@ -22,7 +25,7 @@ clean: rm $(OBJ_DIR)/* rm U2FDevice -.PHONY: libuECC.o libcppb64.so clean +.PHONY: libuECC.o libcppb64.so clean install libuECC.o: $(MAKE) -C micro-ecc cp micro-ecc/libuECC.o libuECC.o diff --git a/U2FDevice.cpp b/U2FDevice.cpp index e2bd1cf..f2a4d79 100644 --- a/U2FDevice.cpp +++ b/U2FDevice.cpp @@ -11,7 +11,7 @@ void signalCallback(int signum); volatile bool contProc = true; -int main() +int main(int argc, char **argv) { try { @@ -21,6 +21,9 @@ int main() catch (runtime_error &e) { cerr << e.what() << endl; + + if (getuid() != 0) + cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl; } signal(SIGINT, signalCallback); @@ -30,7 +33,19 @@ int main() while (contProc) { - ch.handleTransaction(); + try + { + ch.handleTransaction(); + } + catch (const runtime_error &e) + { + cerr << e.what() << endl; + + if (getuid() != 0) + cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl; + raise(SIGINT); + return EXIT_FAILURE; + } usleep(10000); } @@ -52,5 +67,5 @@ int main() void signalCallback([[maybe_unused]] int signum) { contProc = false; - clog << "\nCaught SIGINT signal" << endl; + clog << "\nClosing" << endl; }