Bug 328311

Summary: KMail doesn't let me manually select a non verified PGP key which doesn't contains the receivers address
Product: [Applications] kmail2 Reporter: kolAflash <kolAflash>
Component: composerAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED FIXED    
Severity: major    
Priority: NOR    
Version: 4.12   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In: 4.12.2
Sentry Crash Report:
Attachments: Fix for KDE bug 328311. Should work at least for KDE 4.11.4 and 4.12.1.

Description kolAflash 2013-12-02 04:06:44 UTC
I'm writing an email to a friend, who recently changed his email address. I got his unverified!!! PGP key, which he hasn't updated with to his new email address until now. When I try to send an encrypted email, KMail tells me:

> There are conflicting encryption preferences for these recipients.
> Encrypt this message?
> [Encrypt] [Do not encrypt] [Cancel]

That's all ok, because KMail can't autodetect the right key, because any key contains my friends new email address.

I select [Encrypt]. The KMail gives me a dialogue to manually select a key I want to use. I select my friends unverified key, which doesn't contains his new email address (the one I set as receiver). But I know he can decrypt that key. Then KMail gives me:

> It was not possible to create a message composer.

And I'm back in the composer window.
If I run KMail from shell, it gives me this message on the shell in exactly that moment:
kontact(11836) ValidTrustedOpenPGPEncryptionKey: bad validity 0

This error only appears if the PGP key hasn't been trusted in the PGP key-chain. If I repeat the scenario with a fully trusted key, everything is fine. Looks like KMail forgets to bring up this dialogue, which normally appears for non fully trusted keys.

> One or more of the OpenPGP encryption keys or S/MIME certificates for recipient "some-mail-address@example.com" is not fully trusted for encryption.
> The following keys or certificates have unknown trust level: 
> some-mail-address@example.com
> [Continue] [Cancel]

P.S.
My "Cryptographic Message Format" is set to "OpenPGP/MIME" in KMail. (relevant???)

Reproducible: Always

Steps to Reproduce:
1. Write an encrypted email to some address you don't have a PGP key for.
2. Click send and manually select some not fully trusted PGP key to encrypt with.
Actual Results:  
KMail jumps back to composer window, tells you
> It was not possible to create a message composer.
and puts this to stdout:
kontact(*****) ValidTrustedOpenPGPEncryptionKey: bad validity 0

Expected Results:  
Bring up this dialogue:

> One or more of the OpenPGP encryption keys or S/MIME certificates for recipient "some-mail-address@example.com" is not fully trusted for encryption.
> The following keys or certificates have unknown trust level: 
> some-mail-address@example.com
> [Continue] [Cancel]
Comment 1 kolAflash 2014-01-16 12:05:07 UTC
Same bug appears if I have to manually select a key, because I got multiple keys for the same email address in my key-chain.

Did anybody else experience this bug? Please tell!
Comment 2 kolAflash 2014-01-16 14:17:16 UTC
For my initial bug report I used KDE 4.11.2

Later I got regular updates to 4.11.3 and then 4.11.4 from my distribution (openSUSE 13.1).

Now I manually updated to 4.12.1 using this repository:
http://download.opensuse.org/repositories/KDE:/Release:/412/openSUSE_13.1/

Unfortunately none of this updates fixed the bug :-/
Comment 3 kolAflash 2014-01-16 20:30:58 UTC
Did some debugging with KDbg. May this be the reason?


kdepim-4.12.1/messagecomposer/composer/keyresolver.cpp:1625
Method:
std::vector<GpgME::Key> Kleo::KeyResolver::selectKeys(
  const QString &person, const QString &msg, const std::vector<GpgME::Key> &selectedKeys ) const
========
  keys.erase( std::remove_if( keys.begin(), keys.end(),
                              NotValidTrustedEncryptionKey ), // -= trusted?
                              keys.end() );
========

Maybe it should be like this instead?
========
  keys.erase( std::remove_if( keys.begin(), keys.end(),
                              NotValidTrustedEncryptionKey ), // -= trusted?
                              keys.end() );
========

Because the method is called from

kdepim-4.12.1/messagecomposer/composer/keyresolver.cpp:1696
========
return trustedOrConfirmed( selectKeys(...
========

The method "trustedOrConfirmed" already checks if the key is trusted and may ask the user what to do. But if "selectKeys" erases the key this won't happen.
Comment 4 kolAflash 2014-01-17 02:20:53 UTC
Created attachment 84676 [details]
Fix for KDE bug 328311. Should work at least for KDE 4.11.4 and 4.12.1.

My first KDE patch. Yeeeehaaa! :-)

Please test it and if OK, commit! I'll be here if you've got any questions.
Comment 5 Sandro Knauß 2014-01-22 18:15:49 UTC
Git commit 5cc79e9246caee7875bd640bd6264476bb7330ce by Sandro Knauß.
Committed on 22/01/2014 at 18:08.
Pushed by knauss into branch 'KDE/4.12'.

make it possible to manually select untrusted PGP keys

Fixes a bug in method "selectKeys", when manually selecting one or more
keys which are not marked as trusted. Method "selectKeys" is only called
from method "getEncryptionKeys" in lines: 1656, 1696

(patch written by kolAflash <kolAflash@kolahilft.de>, sponserd by me)
FIXED-IN: 4.12.2
REVIEW: 115182

M  +1    -1    messagecomposer/composer/keyresolver.cpp

http://commits.kde.org/kdepim/5cc79e9246caee7875bd640bd6264476bb7330ce