Improved Makefile. Added initial Android support.
This commit is contained in:
30
Architecture.hpp
Normal file
30
Architecture.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
U2FDevice - A program to allow Raspberry Pi Zeros to act as U2F tokens
|
||||
Copyright (C) 2018 Michael Kuc
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define ARCHITECTURE ANDROID
|
||||
|
||||
#if ARCHITECTURE == RASPBERRY_PI
|
||||
#define STORAGE_PREFIX "/usr/share/"
|
||||
#define HID_DEV "/dev/hidg0"
|
||||
#define DEBUG_STREAMS
|
||||
#elif ARCHITECTURE == ANDROID
|
||||
#define STORAGE_PREFIX "/sdcard/U2F"
|
||||
#define HID_DEV "/dev/hidg2"
|
||||
#endif
|
||||
5
LED.cpp
5
LED.cpp
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LED.hpp"
|
||||
#include "Architecture.hpp"
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -36,6 +37,7 @@ bool getLEDState()
|
||||
|
||||
void disableACTTrigger(bool nowDisabled)
|
||||
{
|
||||
#if ARCHITECTURE == RASPBERRY_PI
|
||||
ofstream trigFile{ "/sys/class/leds/led0/trigger", ofstream::out | ofstream::trunc };
|
||||
|
||||
if (!trigFile)
|
||||
@@ -43,10 +45,12 @@ void disableACTTrigger(bool nowDisabled)
|
||||
|
||||
if (!static_cast<bool>(trigFile << (nowDisabled ? "none" : "mmc0")))
|
||||
throw runtime_error{ "Failed to write led0 trigger to file" };
|
||||
#endif
|
||||
}
|
||||
|
||||
void enableACTLED(bool nowOn)
|
||||
{
|
||||
#if ARCHITECTURE == RASPBERRY_PI
|
||||
if (nowOn == getLEDState())
|
||||
return;
|
||||
|
||||
@@ -59,6 +63,7 @@ void enableACTLED(bool nowOn)
|
||||
throw runtime_error{ "Failed to write led0 brightness to file" };
|
||||
|
||||
ledState() = nowOn;
|
||||
#endif
|
||||
}
|
||||
|
||||
void toggleACTLED()
|
||||
|
||||
7
Makefile
7
Makefile
@@ -18,16 +18,19 @@ install: U2FDevice
|
||||
install -m775 -t /etc/systemd/system Services/U2FDevice.service
|
||||
install -d /usr/share/U2FDevice/
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)
|
||||
g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
$(OBJ_DIR):
|
||||
mkdir $(OBJ_DIR)
|
||||
|
||||
-include $(OBJECTS:.o=.d)
|
||||
|
||||
clean:
|
||||
rm $(OBJ_DIR)/*
|
||||
rm U2FDevice
|
||||
|
||||
.PHONY: libuECC.o libcppb64.so clean install
|
||||
.PHONY: libuECC.o libcppb64.o clean install
|
||||
libuECC.o:
|
||||
$(MAKE) -C micro-ecc
|
||||
cp micro-ecc/libuECC.o libuECC.o
|
||||
|
||||
@@ -26,14 +26,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef DEBUG_STREAMS
|
||||
FILE* initHTML(FILE *fPtr, const string &title);
|
||||
void closeHTML(FILE *fPtr);
|
||||
#endif
|
||||
|
||||
shared_ptr<int> getHostDescriptor()
|
||||
{
|
||||
static shared_ptr<int> descriptor{};
|
||||
|
||||
descriptor.reset(new int{ open("/dev/hidg0", O_RDWR | O_NONBLOCK | O_APPEND) }, [](int* fd){
|
||||
descriptor.reset(new int{ open(HID_DEV, O_RDWR | O_NONBLOCK | O_APPEND) }, [](int* fd){
|
||||
close(*fd);
|
||||
delete fd;
|
||||
});
|
||||
@@ -122,6 +124,7 @@ shared_ptr<FILE> getDevAPDUStream()
|
||||
return stream;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_STREAMS
|
||||
FILE* initHTML(FILE *fPtr, const string &title)
|
||||
{
|
||||
fprintf(fPtr, "<html>\n"
|
||||
@@ -172,3 +175,4 @@ void closeHTML(FILE *fPtr)
|
||||
"</html>");
|
||||
fclose(fPtr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -19,11 +19,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#pragma once
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include "Architecture.hpp"
|
||||
|
||||
std::shared_ptr<int> getHostDescriptor();
|
||||
|
||||
#ifdef DEBUG_STREAMS
|
||||
std::shared_ptr<FILE> getComHostStream();
|
||||
std::shared_ptr<FILE> getHostPacketStream();
|
||||
std::shared_ptr<FILE> getHostAPDUStream();
|
||||
std::shared_ptr<FILE> getComDevStream();
|
||||
std::shared_ptr<FILE> getDevPacketStream();
|
||||
std::shared_ptr<FILE> getDevAPDUStream();
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Architecture.hpp"
|
||||
#include <iostream>
|
||||
#include "Storage.hpp"
|
||||
#include "Controller.hpp"
|
||||
@@ -46,7 +47,7 @@ int main(int argc, char **argv)
|
||||
|
||||
signal(SIGINT, signalCallback);
|
||||
|
||||
string privKeyDir = (argc == 2 ? argv[1] : "/usr/share/U2FDevice/");
|
||||
string privKeyDir = (argc == 2 ? argv[1] : STORAGE_PREFIX);
|
||||
|
||||
Storage::init(privKeyDir);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user