Skip to content

feat: Add support for Cygwin#13

Open
VonJagdstrumel wants to merge 2 commits into
hargoniX:mainfrom
VonJagdstrumel:main
Open

feat: Add support for Cygwin#13
VonJagdstrumel wants to merge 2 commits into
hargoniX:mainfrom
VonJagdstrumel:main

Conversation

@VonJagdstrumel

Copy link
Copy Markdown

Description

This PR introduces support for Cygwin environments.

Cygwin emulates a native Unix-like system. As a result, the existing logic incorrectly attempts to communicate with KeePassXC via a standard Unix socket. However, the Windows implementation of KeePassXC provides a Win32 named pipe.

To bridge this gap, this change implements a CygwinPipe class. By using os.open with \\.\pipe\ paths, we can interface with the Windows named pipe directly.

Why this approach?

  • Compatibility: pywin32 is not easily installable (or often not available at all) under Cygwin's Python distribution.
  • Simplicity: This avoids the need for complex ctypes wrappers to call the Windows API, relying instead on the fact that Cygwin can handle Windows device paths when opened in binary mode.

Key Changes

  • New CygwinPipe Class:

    • Provides a socket-like interface (connect, close, sendall, recv).
    • Uses os.open with os.O_RDWR | os.O_BINARY to interact with the Windows pipe filesystem directly from the Cygwin layer.
  • Platform Detection Logic:

    • Updated the Connection class to check for system.startswith("CYGWIN_NT").
    • Ensures that when running under Cygwin, the client bypasses the AF_UNIX socket logic in favor of the new CygwinPipe.
  • Path Resolution:

    • Updated get_socket_path() to treat Cygwin similarly to Windows, utilizing the named pipe naming convention: org.keepassxc.KeePassXC.BrowserServer_<user>.
  • Global Imports:

    • Moved import getpass to the top level to ensure availability across all platform branches, as it is now required for both native Windows and Cygwin paths.

How to Test

  1. Environment: Open a Cygwin terminal.
  2. Configuration: Ensure KeePassXC is running on the host Windows machine with "Browser Integration" enabled.
  3. Execution: Perform keepassxc_proxy_client actions.
    • Expected Result: The client should successfully connect to the named pipe, perform the public key exchange, and be able to retrieve database entries.
$ powershell -Command '(gci \\.\pipe\ | ? Name -Like "org.keepassxc.KeePassXC.BrowserServer_*").FullName'
\\.\pipe\org.keepassxc.KeePassXC.BrowserServer_Steve

$ ps -W | awk 'NR == 1 || $0 ~ /KeePassXC\.exe$/'
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
  4201848       0       0       7544  ?              0   May 12 C:\Program Files\KeePassXC\KeePassXC.exe

$ uname
CYGWIN_NT-10.0-19045

$ keepassxc_proxy_client create > ~/.kpc.json

$ perl -pe 's/[^"]+(?="})/REDACTED/' ~/.kpc.json
{"name": "CLI", "public_key": "REDACTED"}

$ keepassxc_proxy_client get ~/.kpc.json https://example.org/
Hello, world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant