Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ elseif(APPLE AND WITH_APP_BUNDLE)
set(PROXY_INSTALL_DIR "${BUNDLE_INSTALL_DIR}/MacOS")
set(BIN_INSTALL_DIR "${BUNDLE_INSTALL_DIR}/MacOS")
set(PLUGIN_INSTALL_DIR "${BUNDLE_INSTALL_DIR}/PlugIns")
set(XPC_INSTALL_DIR "${BUNDLE_INSTALL_DIR}/XPCServices")
set(DATA_INSTALL_DIR "${BUNDLE_INSTALL_DIR}/Resources")
else()
include(GNUInstallDirs)
Expand Down
2 changes: 2 additions & 0 deletions share/macosx/keepassxc.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<array>
<string>G2S7P7J672.org.keepassxc.keepassxc</string>
</array>
<key>com.apple.developer.authentication-services.autofill-credential-provider</key>
<true/>
</dict>
</plist>
138 changes: 136 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ if(APPLE)
gui/osutils/macutils/ScreenLockListenerMac.cpp
gui/osutils/macutils/AppKitImpl.mm
gui/osutils/macutils/AppKit.h
quickunlock/TouchID.mm)
quickunlock/TouchID.mm
autofill/AutoFill.h
autofill/AutoFill.mm
autofill/AutoFillProviderProtocol.h
autofill/AutoFillXPCProtocol.h)

# TODO: Remove -Wno-error once deprecation warnings have been resolved.
set_source_files_properties(quickunlock/TouchID.mm PROPERTY COMPILE_FLAGS "-Wno-old-style-cast")
set_source_files_properties(autofill/AutoFill.mm PROPERTY COMPILE_FLAGS "-fobjc-arc")
endif()

if(UNIX AND NOT APPLE)
Expand Down Expand Up @@ -398,7 +403,7 @@ target_link_libraries(keepassxc_gui
${sshagent_LIB})

if(APPLE)
target_link_libraries(keepassxc_gui "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication -framework ScreenCaptureKit")
target_link_libraries(keepassxc_gui "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication -framework ScreenCaptureKit -framework AuthenticationServices")
if(Qt5MacExtras_FOUND)
target_link_libraries(keepassxc_gui Qt5::MacExtras)
endif()
Expand Down Expand Up @@ -591,3 +596,132 @@ endif()
# The install commands in this subdirectory will be executed after all the install commands in the
# current scope are ran. It is required for correct functioning of macdeployqt.
add_subdirectory(post_install)

if(APPLE AND WITH_APP_BUNDLE)
set(AUTOFILL_TARGET "keepassxc-autofill")
set(AUTOFILL_XPC_TARGET "keepassxc-autofill-xpc")
set(MACOSX_EXTENSION_BUNDLE_ID "org.keepassxc.keepassxc.autofill")
set(MACOSX_XPC_BUNDLE_ID "org.keepassxc.KeePassXC.AutoFill-XPC-Service")

# Configure extension Info.plist
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/autofill/mac/Info.plist.in"
"${CMAKE_CURRENT_BINARY_DIR}/autofill/mac/Info.plist"
@ONLY
)

# Configure extension entitlements
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/autofill/mac/MacAutoFill.entitlements"
"${CMAKE_CURRENT_BINARY_DIR}/autofill/mac/MacAutoFill.entitlements"
@ONLY
)

# Configure XPC service Info.plist
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/autofill/AutoFillXPCService-Info.plist"
"${CMAKE_CURRENT_BINARY_DIR}/autofill/AutoFillXPCService-Info.plist"
@ONLY
)

# ===================
# AutoFill Extension
# ===================
add_library(${AUTOFILL_TARGET} MODULE
autofill/AutoFillProviderProtocol.h
autofill/AutoFillXPCProtocol.h
autofill/CredentialProviderViewController.mm
)

# Disable Qt AUTOMOC for pure Objective-C++ extension
set_target_properties(${AUTOFILL_TARGET} PROPERTIES
AUTOMOC OFF
AUTOUIC OFF
AUTORCC OFF
)

set_target_properties(${AUTOFILL_TARGET} PROPERTIES
BUNDLE TRUE
BUNDLE_EXTENSION "appex"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/autofill/mac/Info.plist"
MACOSX_BUNDLE_GUI_IDENTIFIER "${MACOSX_EXTENSION_BUNDLE_ID}"
MACOSX_BUNDLE_BUNDLE_NAME "KeePassXC AutoFill"
XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_CURRENT_BINARY_DIR}/autofill/mac/MacAutoFill.entitlements"
XCODE_ATTRIBUTE_SKIP_INSTALL "YES"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${MACOSX_EXTENSION_BUNDLE_ID}"
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES"
XCODE_ATTRIBUTE_WRAPPER_EXTENSION "appex"
)

target_compile_options(${AUTOFILL_TARGET} PRIVATE "-fobjc-arc")

target_link_libraries(${AUTOFILL_TARGET}
"-framework AuthenticationServices"
"-framework AppKit"
"-framework Foundation"
)

# ===================
# XPC Service
# ===================
add_executable(${AUTOFILL_XPC_TARGET}
autofill/AutoFillXPCService.m
autofill/AutoFillProviderProtocol.h
autofill/AutoFillXPCProtocol.h
)

# Disable Qt AUTOMOC for pure Objective-C XPC service
set_target_properties(${AUTOFILL_XPC_TARGET} PROPERTIES
AUTOMOC OFF
AUTOUIC OFF
AUTORCC OFF
)

set_target_properties(${AUTOFILL_XPC_TARGET} PROPERTIES
MACOSX_BUNDLE TRUE
BUNDLE_EXTENSION "xpc"
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_BINARY_DIR}/autofill/AutoFillXPCService-Info.plist"
MACOSX_BUNDLE_GUI_IDENTIFIER "${MACOSX_XPC_BUNDLE_ID}"
MACOSX_BUNDLE_BUNDLE_NAME "KeePassXC AutoFill XPC Service"
XCODE_ATTRIBUTE_SKIP_INSTALL "YES"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${MACOSX_XPC_BUNDLE_ID}"
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES"
)

target_compile_options(${AUTOFILL_XPC_TARGET} PRIVATE "-fobjc-arc")

target_link_libraries(${AUTOFILL_XPC_TARGET}
"-framework Foundation"
)

# ===================
# Embed into main app
# ===================
add_dependencies(${PROGNAME} ${AUTOFILL_TARGET} ${AUTOFILL_XPC_TARGET})

# Embed extension via Xcode's native embedding (CMake 3.21+)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21.0")
set_target_properties(${PROGNAME} PROPERTIES
XCODE_EMBED_APP_EXTENSIONS ${AUTOFILL_TARGET}
)
else()
# Fallback: copy extension into PlugIns directory manually
add_custom_command(TARGET ${PROGNAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/PlugIns"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_BUNDLE_DIR:${AUTOFILL_TARGET}>"
"$<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/PlugIns/${AUTOFILL_TARGET}.appex"
COMMENT "Embedding AutoFill extension into app bundle"
)
endif()

# Copy XPC service into XPCServices directory
add_custom_command(TARGET ${PROGNAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/XPCServices"
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_BUNDLE_DIR:${AUTOFILL_XPC_TARGET}>"
"$<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/XPCServices/${AUTOFILL_XPC_TARGET}.xpc"
COMMENT "Embedding AutoFill XPC service into app bundle"
)

endif()
45 changes: 45 additions & 0 deletions src/autofill/AutoFill.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
*
* 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 2 or (at your option)
* version 3 of the License.
*
* 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 <http://www.gnu.org/licenses/>.
*/

#ifndef KEEPASSX_AUTOFILL_H
#define KEEPASSX_AUTOFILL_H

#include <QObject>

class AutoFillPrivate;

class AutoFill : public QObject
{
Q_OBJECT

public:
explicit AutoFill(QObject* parent = nullptr);
~AutoFill();

bool isAvailable() const;

public Q_SLOTS:
void start();
void stop();

private:
Q_DISABLE_COPY(AutoFill)

AutoFillPrivate* d_ptr;
};

#endif // KEEPASSX_AUTOFILL_H
Loading