Bug 433313 - GPG encryption
Summary: GPG encryption
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: buildsystem (show other bugs)
Version: 5.1.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks: 488491
  Show dependency treegraph
 
Reported: 2021-02-20 10:30 UTC by bilatino
Modified: 2024-08-06 13:19 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.2
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bilatino 2021-02-20 10:30:50 UTC
In the new version the gpg encryption management does not appear. Unable to insert keys. It happens in ubuntu and Microsoft Windows



SUMMARY


STEPS TO REPRODUCE
1. 
2. 
3. 

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Mathieu Giorgino 2021-10-22 21:07:10 UTC
Same for me on Windows 10. GPG option does appear on version 5.0 but does NOT on version 5.1. I couldn't make it to work...
Comment 2 Thomas Baumgart 2021-10-23 07:48:24 UTC
This looks like a duplicate to bug 399230 to me. Please confirm by using a newer version than 5.1.2 or update here that it still does not work.
Comment 3 Thomas Baumgart 2021-10-23 07:48:42 UTC
Forgot to update state
Comment 4 Mathieu Giorgino 2021-10-24 20:06:07 UTC
I'm trying with Version 5.1.2-0af86e098, and I confirm it does not work on this version compared to Version 5.0.6.
Comment 5 Bug Janitor Service 2021-11-08 04:39:10 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Thomas Baumgart 2021-11-08 07:42:15 UTC
Updating state
Comment 7 Thomas Baumgart 2024-07-28 12:29:08 UTC
I just tried to duplicate this with current master. Intalled GPG4Win with all default settings (incl. installation of Kleopatra for key management), created a keypair and started KMyMoney. GPG was available and is working. I consider this fixed in 5.2.
Comment 8 Thomas Baumgart 2024-07-28 13:47:52 UTC
Well, that was a bit too quick. I need to re-open because saving the data somehow does not work because no file is created - also no error is shown. Back to debugging mode.
Comment 9 Thomas Baumgart 2024-07-28 18:55:06 UTC
With current master, I see the following line using dbgviewpp when writing encrypted:

  Invalid parameter passed to C runtime function.

This message does not get written (and the file gets created and written to disk) when saving unencrypted as .kmy file. I am running out of ideas how to debug this further. Any help appreciated.
Comment 10 Jack 2024-07-28 19:03:19 UTC
Can you identify where that message is written?  I don't generally use encryption myself, but hopefully later in the week I can make some time to run under a debugger.  Am I correct this is true in both 5.1.3 and git master?
Comment 11 Thomas Baumgart 2024-07-29 06:32:26 UTC
Git commit 433179af8ff4a812731c291a2d40c58a40dbe0c3 by Thomas Baumgart.
Committed on 29/07/2024 at 06:31.
Pushed by tbaumgart into branch 'master'.

Add trace messages to figure out encryption failure on Windows

This is to figure out what triggers the message "Invalid parameter
passed to C runtime function." which we see in the debug output when
writing using the encryption method.

M  +15   -0    kmymoney/plugins/xml/xmlstorage.cpp

https://invent.kde.org/office/kmymoney/-/commit/433179af8ff4a812731c291a2d40c58a40dbe0c3
Comment 12 Thomas Baumgart 2024-07-29 08:13:25 UTC
Output of the trace messages:

1	0.000000	8760	kmymoney.exe	saveToLocalFile(1)
2	3.125127	8760	kmymoney.exe	saveToLocalFile(2)
3	3.125275	8760	kmymoney.exe	saveToLocalFile(3)
4	3.125373	8760	kmymoney.exe	saveToLocalFile(4)
5	3.226704	8760	kmymoney.exe	saveToLocalFile(5)
6	3.226765	8760	kmymoney.exe	saveToLocalFile(6) addRecipient "0x40097792"
7	3.307992	8760	kmymoney.exe	saveToLocalFile(6) addRecipient "xxx@kde.org"
8	3.387963	8760	kmymoney.exe	saveToLocalFile(8)
9	3.388486	8760	kmymoney.exe	saveToLocalFile(9)
10	3.388518	8760	kmymoney.exe	saveToLocalFile(10)
11	3.389217	8760	kmymoney.exe	saveToLocalFile(11)
12	3.525290	8760	kmymoney.exe	"The currency pair BYR->BYN is invalid. Omitting from storage."
13	3.526784	8760	kmymoney.exe	saveToLocalFile(12)
14	3.701225	8760	kmymoney.exe	Invalid parameter passed to C runtime function.
15	3.728223	8760	kmymoney.exe	saveToLocalFile(13)
16	3.728271	8760	kmymoney.exe	saveToLocalFile(14)
17	3.728383	8760	kmymoney.exe	saveToLocalFile(15)
Comment 13 Ralf Habacker 2024-07-29 10:30:20 UTC
A kmymoney 5.2 snapshot using MinGW has been added recently to https://kmymoney.org/snapshots.php. With the embedded gpg2 package I checked saving and loading a gpg encrypted kmymoney file without any issue.
Comment 14 Thomas Baumgart 2024-07-29 11:55:47 UTC
Located the culprit:

2694	20.426516	8316	kmymoney.exe	KGPGFile::close(5)
2695	20.605514	8316	kmymoney.exe	Invalid parameter passed to C runtime function.
2696	20.638710	8316	kmymoney.exe	KGPGFile::close(6)

which is generated by

        qDebug() << "KGPGFile::close(5)";
        d->m_lastError = d->m_ctx->encrypt(d->m_recipients, d->m_data, dcipher, GpgME::Context::AlwaysTrust).error();
        qDebug() << "KGPGFile::close(6)";

but I still have no idea why it does not work on MSVC compiled code, but is said to be working on Linux and MinGW.
Comment 16 Ingo Klöcker 2024-07-29 15:30:20 UTC
Gpg4win (and the simple installer for GnuPG) includes the gpgme C library. Check if gpgme++ tries to use gpgme from the installed GnuPG instead of gpgme provided by KMyMoney. Or delete/rename the gpgme library included in Gpg4win/GnuPG and check if this fixes the problem.
Comment 17 Thomas Baumgart 2024-07-30 04:57:44 UTC
Using "C:\Windows\System32\perfmon.exe /res" the associated modules list on the CPU tab shows that it uses libgpgme-11.dll from the kmymoney/bin directory and none of the GPG4Win installation which provides/uses libgpgme-14.dll.
Comment 18 Ingo Klöcker 2024-07-30 11:51:37 UTC
If you start kmymoney.exe from a console after doing
```
set GPGME_DEBUG=9;c:\temp\gpgme.log
```
you'll get a verbose debug log of gpgme written to c:\temp\gpgme.log.
Comment 19 Thomas Baumgart 2024-08-05 11:15:34 UTC
Now fixed completely and verified to work on Windows to encrypt and decrypt files as expected.
Comment 20 Ralf Habacker 2024-08-06 12:40:42 UTC
(In reply to Thomas Baumgart from comment #19)
> Now fixed completely and verified to work on Windows to encrypt and decrypt
> files as expected.

Since it worked before with the MinGW builds, I'm wondering if MSVC builds behave differently at this point and if GPG support still works with this change.
Comment 21 Thomas Baumgart 2024-08-06 13:19:45 UTC
It should, because I tested the fix also with gcc. The problem is not so much Windows but the compiler and runtime environment as it seems.