Bug 126292 - kmail picks wrong public keys for email addresses that end with the same strings
Summary: kmail picks wrong public keys for email addresses that end with the same strings
Status: RESOLVED FIXED
Alias: None
Product: kmail
Classification: Unmaintained
Component: encryption (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Till Adam
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-26 16:04 UTC by Kai Blin
Modified: 2009-08-01 14:42 UTC (History)
2 users (show)

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


Attachments
Dialog showing the wrong email address for the encryption key! (21.86 KB, image/jpeg)
2006-12-05 17:49 UTC, Reinhold Kainhofer
Details
proposed fix (559 bytes, patch)
2006-12-05 23:36 UTC, Ingo Klöcker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Blin 2006-04-26 16:04:55 UTC
Version:           KMail 1.8.2 (using KDE KDE 3.4.2)
Installed from:    SuSE RPMs
OS:                Linux

Assume I have a public key for a user with an email of foo.bar@example.com and I'm trying to send a signed email to email
an email address bar@example.com kmail claims there is a public key available and offers to encrypt the message, too.

When following up on that by clicking sign&encrypt it will open a window offering to select the keys used, claiming that it picked a key for bar@example.com, but actually picked the key for foo.bar@example.com

I can't think of any way this can be a security issue, but it's really annoying for sure.
Comment 1 Reinhold Kainhofer 2006-12-05 13:58:59 UTC
Actually, I see a security issue very well:
Imagine you have an account me@example.com, and since you don't trust the admin of your mailserver, you want all mail to you to be encrypted (you have the secret key on your secure machine). Now, you have all reason to be suspicious, because the admin generates a key for not.me@example.com and somehow manages to distribute the public key to some contacts of you. Now someone wants to send you a confidential mail, encrypts it (unfortunately with the not.me@example.com key....) and sends it to you. The admin of the mailserver can decrypt the mail using his private key, read it and re-send it to you encrypted with your correct key.
You'll never find out (unless the admin fails to properly fix up the mail headers...) that someone is intercepting your mails...

Cheers,
Reinhold
Comment 2 Reinhold Kainhofer 2006-12-05 14:44:08 UTC
I can confirm the bug! I tried sending a mail to kainhofer@tuwien.ac.at (which does not even exist, while I have the public key for reinhold.kainhofer@tuwien.ac.at in my keyring). I still got asked by kmail to use the key with the ID of reinhold.kainhofer@tuwien.ac.at for encrypting to kainhofer@tuwien.ac.at!

Nasty security bug. Encrypting with a key that should not be used is always a security issue...

Cheers,
Reinhold
Comment 3 Reinhold Kainhofer 2006-12-05 17:49:59 UTC
Created attachment 18804 [details]
Dialog showing the wrong email address for the encryption key!

Some further investigation indicates that 
  Kleo::QGpgMEKeyListJob
which is called from Kleo::KeyResolver::lookup (which in turn is called from
Kleo::KeyResolver::getEncryptionKeys) does a substring match, not a string
match. So all addressees that contain the receiver's email adress will be
returned. If only one matches (even if it is not the correct receiver), that
one will automatically be suggested (with the email adress of the receiver
instead of the address of the key being shown in the selection dialog!!!).

E.g. if you try to send a mail to k@kd, it will still use the encryption key
for dirk@kde.org, as that's the only address that matches. However, the dialog
shows that the key is for k@kde.org (screenshot attached)!

Cheers,
Reinhold
Comment 4 Ingo Klöcker 2006-12-05 23:34:41 UTC
Actually the dialog shows that the key 0x2BB2D54A will be used for recipient k@kd. The dialog does not claim that the key belongs to k@kd. Of course, I agree that the difference is subtle. Moreover, I agree that a substring search is not a good idea in this particular case. I propose the attached patch.
Comment 5 Ingo Klöcker 2006-12-05 23:36:49 UTC
Created attachment 18808 [details]
proposed fix
Comment 6 Ingo Klöcker 2006-12-05 23:41:02 UTC
Note, that with this patch KMail will fail to find keys where the uid is just a raw email address (I have a few of those keys in my keyring), but I think that's an acceptable drawback since the user can still manually search for a matching key.
Comment 7 Marc Mutz 2007-08-21 11:47:18 UTC
I've asked upstream about what they think about establishing the addition of <> around patterns in search strings as a protocol to request matching only email addresses, and find matches even in the cases where the angle brackets would not normally be part of the original string (e.g. in the case Ingo described, and probably also in the case where an X.509 certificate has the email address in the DN instead of in the corresponding field. Let's see what they say.
Comment 8 Marc Mutz 2007-08-21 12:59:43 UTC
Werner Koch mentions this is the correct fix.
Ingo: Dis you test that this fails when name and comment are empty for a key, or did you just guess?
Bottomline: This is the correct fix. It is established protocol in gpg. If it fails for some bugs, that's a bug in gpg, and should be filed against it.
Comment 9 Bruno Bigras 2009-07-31 13:35:57 UTC
I wasn't able to reproduce this bug with KDE 4.3 RC3.

Anyone still having this problem?
Comment 10 Kai Blin 2009-07-31 13:56:51 UTC
I'm not currently in a position to test, as I'm still on a distro using KDE 3.5.10 with Kmail 1.9.10. at least in that setup it's still an issue. Once I have time to upgrade to KDE4 I'll give that a try.
Comment 11 Allen Winter 2009-08-01 14:42:17 UTC
we'll close this then.
if anyone using KDE 4.3 or higher can still reproduce this bug then feel free to reopen.