Skip to content

Commit

Permalink
TouchID support refactoring (#8311)
Browse files Browse the repository at this point in the history
Fixes #7695 - Properly set compile flags based on availability of watch unlock in the API.
  • Loading branch information
yowidin authored and droidmonkey committed Sep 11, 2022
1 parent 2693c6f commit aea7531
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 174 deletions.
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
25 changes: 10 additions & 15 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,29 @@ 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;
private:
static bool isWatchAvailable();
static bool isTouchIdAvailable();

void reset(const QString& databasePath = "");
static void deleteKeyEntry(const QString& accountName);
static QString databaseKeyName(const QString& databasePath);

private:
QHash<QString, QByteArray> m_encryptedMasterKeys;
};

#endif // KEEPASSX_TOUCHID_H
Loading

0 comments on commit aea7531

Please sign in to comment.