Gpg4win: Replace GpgEX functionality through Windows registry
Open, NormalPublic

Assigned To
Authored By
• aheinecke
Jan 5 2023, 11:26 AM

Description

With GPA gone from Gpg4win there is no need anymore for a UIserver connection, we can just call Kleopatra like we do on Linux also on Windows.

This will also allow us to modify the context menu of Windows 11 as this is only modifyable by the registry. Currently GpgEX options on Win 11 are only shown if you open the legacy context menu.

Revisions and Commits

Event Timeline

• aheinecke created this task.
• aheinecke moved this task from Restricted Project Column to Restricted Project Column on the Restricted Project board.Jan 10 2023, 1:08 PM

Note to self after spending some time searching again for the documentation I saw previously about this: https://learn.microsoft.com/en-us/windows/win32/shell/context-menu-handlers#suppressing-verbs-and-controlling-visibility

So most of the code is basically:

# Explorer entry for unknown files
WriteRegStr SHCTX "Software\Classes\*\Kleopatra" "" "$(T_SIGN_ENCRYPT)"
# Filter out all our known
WriteRegStr SHCTX "Software\Classes\*\Kleopatra" "$\"AppliesTo$\" $\"System.FileName:~!$\".gpg$\" AND System.FileName:~!$\".asc$\" AND System.FileName:~!$\".cer$\" AND System.FileName:~!$\".p10$\" AND System.FileName:~!$\".p12$\" AND System.FileName:~!$\".p7c$\" AND System.FileName:~!$\".pfx$\" AND System.FileName:~!$\".crt$\" AND System.FileName:~!$\".der$\" AND System.FileName:~!$\".sig$\" AND System.FileName:~!$\".p7m$\" AND System.FileName:~!$\".p7s$\" AND System.FileName:~!$\".pem$\" AND System.FileName:~!$\".kgrp$\""
WriteRegStr SHCTX "Software\Classes\command" "" "$\"$INSTDIR\bin\Kleopatra.exe$\" -- $\"%1$\""

And then added keys for each extension with different Strings for the action.

But, it is of course more difficult then I thought, as Windows does not provide a way for multiple file selection to be passed to a command. Instead it sequentially calls the command with each parameter. This "should" work in theory in Kleopatra as we implement it as a Unique Service that should only run once. But for that my own code in kuniqueservice_win has to be improved. First thing I noticed that it should be above the "setAboutData" call in main as that is a very expensive call (checking the Version file and the signature of the Version file and calling gpgconf.exe for versions). I wonder if we could delay this some more as most of the about data is only needed once about is clicked. This really eats 1.5s on a slow machine of mine currently.

Still it is too slow to detect a race between two Kleopatras. Fixing this will actually also fix a bug we currently have that if you quadruple click kleopatra or an associated file you can start two instances.

• aheinecke mentioned this in Unknown Object (Maniphest Task).Sep 15 2023, 10:31 AM
• aheinecke moved this task from Restricted Project Column to Restricted Project Column on the Restricted Project board.Nov 3 2023, 8:47 AM
timegrid edited projects, added gpd5x; removed Restricted Project.Jan 23 2026, 11:08 AM
• ikloecker moved this task from Backlog to WIP on the gpd5x board.
• ikloecker mentioned this in Unknown Object (Maniphest Task).Mon, Nov 9, 9:47 AM

Defining the "Sign & Encrypt" commands for multiple selected files or a selected directory for the new Windows 11 context menu is not possible with only registry keys. Instead one needs to implement an IExplorerCommand.
https://blogs.windows.com/windowsdeveloper/2021/07/19/extending-the-context-menu-and-share-dialog-in-windows-11/

Additionally, we may have to define an "app identity" using a "sparse package":
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/integrate-packaged-app-with-file-explorer#use-a-sparse-package-for-an-unpackaged-app

• ikloecker mentioned this in Unknown Object (Maniphest Task).Mon, Nov 16, 9:04 AM
• ikloecker mentioned this in Unknown Object (Maniphest Task).Mon, Nov 23, 9:07 AM

This is how a modernization that keeps two main entries (called verbs by Microsoft) "Encrypt with Kleopatra" (as primary action) and "More Kleopatra" (as submenu with additional actions) would look like in Windows 11 26H2.

Note that there are only three entries in the "More Kleopatra" submenu because I didn't want to add all entries just to test how it looks like.

The "Kleopatra" submenu (please ignore the missing icon) is the result of the change in Windows 11 that "Apps with more than 1 verb are grouped into a flyout with app attribution" (https://blogs.windows.com/windowsdeveloper/2021/07/19/extending-the-context-menu-and-share-dialog-in-windows-11/). This means that the two main entries which were in the main context menu before Windows 11 are now (by default) hidden two levels deep below "App-Erweiterungen" (App extensions). Users can promote the "Kleopatra" submenu to the main context menu via "App-Erweiterungen verwalten" (Manage app extensions) but that requires a manual step. I'd be surprised if apps could hack themselves into the main context menu with some registry tricks or so because this would obviously run counter to Microsoft's clean-up of the context menu.

To avoid the extremely deep nesting I see two options:
a) Offer only one verb (e.g. "Encrypt with Kleopatra") for generic files and folders. This has the advantage that we avoid the grouping of multiple verbs into "a flyout with app attribution" so that the most important functionality for generic files and folders is at most one level away from the main context menu.
b) Offer many verbs (maybe a few less than offered in "More GpgEX options") which are grouped by Windows into "a flyout with app attribution". This way we keep the many options that were offered by the "More GpgEX options" and they will be at most two levels deep away from main window. This way we lose the prominent primary action "Sign and encrypt" that was offered outside of "More GpgEX options".

I think the middle ground of keeping the old behavior with a primary action next to a "More" submenu is not an option because of the deep nesting enforced by Windows 11 that's demonstrated by the screenshot.

• ebo added a subscriber: • ebo.
• ikloecker mentioned this in Unknown Object (Maniphest Task).Mon, Nov 30, 8:50 AM

Discussion results:

  • Reduce the verbs to only a single one: "Signieren und Verschlüsseln" / "Sign and Encrypt" (to keep the menu depth as minimal as possible)
  • In the installer, the "GpgEX" item should be renamed to a general term, e.g. "Kleopatra Explorererweiterung" (it's just a Kleopatra extension after all)
  • The "Sign and Encrypt" dialog should remember the last state (like in Kleopatra; probably the same state can be reused and no distinct state is needed?)

Note: the action in Kleopatra is called "Signieren/Verschlüsseln" / "Sign/Encrypt". Maybe we better keep it similiar?

The current GpgEx entry is "Sign and encrypt" - it's probably better without "/" in this context

The only thing you forgot to mention: it should be made clear in the tooltip that Kleopatra is used for the operation