Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TouchID support refactoring #8311

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ if(UNIX AND NOT APPLE)
endif()
option(WITH_XC_DOCS "Enable building of documentation" ON)

if(APPLE)
# Perform the platform checks before applying the stricter compiler flags.
# Otherwise the kSecAccessControlTouchIDCurrentSet deprecation warning will result in an error.
try_compile(XC_APPLE_COMPILER_SUPPORT_BIOMETRY
${CMAKE_CURRENT_BINARY_DIR}/tiometry_test/
${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler-checks/macos/control_biometry_support.mm)
message(STATUS "Biometry compiler support: ${XC_APPLE_COMPILER_SUPPORT_BIOMETRY}")

try_compile(XC_APPLE_COMPILER_SUPPORT_TOUCH_ID
${CMAKE_CURRENT_BINARY_DIR}/touch_id_test/
${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler-checks/macos/control_touch_id_support.mm)
message(STATUS "Touch ID compiler support: ${XC_APPLE_COMPILER_SUPPORT_TOUCH_ID}")

try_compile(XC_APPLE_COMPILER_SUPPORT_WATCH
${CMAKE_CURRENT_BINARY_DIR}/tiometry_test/
${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler-checks/macos/control_watch_support.mm)
message(STATUS "Apple watch compiler support: ${XC_APPLE_COMPILER_SUPPORT_WATCH}")
endif()

if(WITH_CCACHE)
# Use the Compiler Cache (ccache) program
# (install with: sudo apt get ccache)
Expand Down
5 changes: 5 additions & 0 deletions cmake/compiler-checks/macos/control_biometry_support.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <Security/Security.h>

int main() {
return static_cast<int>(kSecAccessControlBiometryCurrentSet);
}
5 changes: 5 additions & 0 deletions cmake/compiler-checks/macos/control_touch_id_support.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <Security/Security.h>

int main() {
return static_cast<int>(kSecAccessControlTouchIDCurrentSet);
}
5 changes: 5 additions & 0 deletions cmake/compiler-checks/macos/control_watch_support.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <Security/Security.h>

int main() {
return static_cast<int>(kSecAccessControlWatch);
}
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ endif()
if(APPLE)
list(APPEND keepassx_SOURCES touchid/TouchID.mm)
# TODO: Remove -Wno-error once deprecation warnings have been resolved.
set_source_files_properties(touchid/TouchID.mm PROPERTY COMPILE_FLAGS "-Wno-old-style-cast -Wno-error")
set_source_files_properties(touchid/TouchID.mm PROPERTY COMPILE_FLAGS "-Wno-old-style-cast")
endif()

configure_file(config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepassx.h)
Expand Down
9 changes: 9 additions & 0 deletions src/config-keepassx.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@
#cmakedefine HAVE_RLIMIT_CORE 1
#cmakedefine HAVE_PT_DENY_ATTACH 1

#cmakedefine01 XC_APPLE_COMPILER_SUPPORT_BIOMETRY()
#cmakedefine01 XC_APPLE_COMPILER_SUPPORT_TOUCH_ID()
#cmakedefine01 XC_APPLE_COMPILER_SUPPORT_WATCH()

#define XC_COMPILER_SUPPORT(X) XC_COMPILER_SUPPORT_PRIVATE_DEFINITION_##X()
#define XC_COMPILER_SUPPORT_PRIVATE_DEFINITION_APPLE_BIOMETRY() XC_APPLE_COMPILER_SUPPORT_BIOMETRY()
#define XC_COMPILER_SUPPORT_PRIVATE_DEFINITION_TOUCH_ID() XC_APPLE_COMPILER_SUPPORT_TOUCH_ID()
#define XC_COMPILER_SUPPORT_PRIVATE_DEFINITION_WATCH_UNLOCK() XC_APPLE_COMPILER_SUPPORT_WATCH()

#endif // KEEPASSX_CONFIG_KEEPASSX_H
28 changes: 11 additions & 17 deletions src/touchid/TouchID.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef KEEPASSX_TOUCHID_H
#define KEEPASSX_TOUCHID_H

#define TOUCHID_UNDEFINED -1
#define TOUCHID_AVAILABLE 1
#define TOUCHID_NOT_AVAILABLE 0

#include <QHash>

class TouchID
Expand All @@ -15,30 +11,28 @@ class TouchID
private:
TouchID()
{
// Nothing to do here
}

// TouchID(TouchID const&); // Don't Implement
// void operator=(TouchID const&); // Don't implement

QHash<QString, QByteArray> m_encryptedMasterKeys;
int m_available = TOUCHID_UNDEFINED;

public:
TouchID(TouchID const&) = delete;

void operator=(TouchID const&) = delete;

bool storeKey(const QString& databasePath, const QByteArray& passwordKey);

bool getKey(const QString& databasePath, QByteArray& passwordKey) const;

bool containsKey(const QString& databasePath) const;
void reset(const QString& databasePath = "");

bool isAvailable();

bool authenticate(const QString& message = "") const;
static bool isAvailable();
static bool isWatchAvailable();
static bool isTouchIdAvailable();
droidmonkey marked this conversation as resolved.
Show resolved Hide resolved

private:
static void deleteKeyEntry(const QString& accountName);
static QString databaseKeyName(const QString& databasePath);

void reset(const QString& databasePath = "");
private:
QHash<QString, QByteArray> m_encryptedMasterKeys;
};

#endif // KEEPASSX_TOUCHID_H
Loading