[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    Re: [Kde-pim] KMail and "encrypt to self" issue
From:       Alexis Papadopoulos <iacp () free ! fr>
Date:       2007-08-23 8:31:59
Message-ID: 200708231131.59264.iacp () free ! fr
[Download RAW message or body]

Hello,

I'm attaching a patch which modifies cryptplug in order to set a passphrase 
callback (see gpgme_set_passphrase_cb) for when no gpg-agent is running. The 
callback code is directly taken and adapted from libkpgp which is rather nice 
since you get the same dialog when you wish to encrypt a mail (although when 
decryption DOES work, there's yet another dialog which is used, don't know 
exactly where it comes from, probably likpgp, which isn't very consistent, 
but then again, it works...).

This fixes the following issue :
_ Any encrypted mail whose PGP content is located within an 
application/pgp-encrypted Content-Type will not get decrypted if no gpg-agent 
is running. In other words, mails in your SENT folder which were encrypted 
with your private key ("never encrypt to self" must be unchecked), or 
encrypted mails you receive from other KMail clients (at least in the tests 
I've made)

I leave this to your consideration and will open a bug entry if deemed 
necessary.

Btw, Markus, could you please try and launch gpg-agent to see if this fixes 
your issues ? We most probably have the same problem (although I cannot 
explain why you're asked for a passphrase with deleted keys :S). Basically, 
do this within a terminal : 
eval `gpg-agent --daemon`
kmail

Tell us if this allows you to decrypt the mails you didn't get a dialog for 
before.

Thanks,
acp

On Thursday 23 August 2007, Markus Feilner wrote:
> Am Dienstag 21 August 2007 15:31:23 schrieb Alexis Papadopoulos:
> > On Tuesday 21 August 2007, Tom Albers wrote:
> > > One of you is getting the question for the passphrase, the other one is
> > > not. Different problems.
> >
> > My bad, I had somewhat misread his post. Although, no, we DO have a
> > omewhat similar problem. I ONLY get asked for a passphrase for mails sent
> > by others (none of my contacts are using KMail though).
> >
> > However when I choose the "encrypt to self mails" (or encrypt a mail
> > using my own key and sending it to myself, "encrypt to self" unchecked)
> > well, no passphrase is asked and I get the exact same error as Markus
> > gets...
> >
> > So the result is the same, altough the cause might actually differ
> > indeed. If Marcus could install pinentry and inform if it solved his
> > issue, that'd be great...
>
> Pinentry-qt is installed.
> BTW, I party do get a password dialog:
> The strange (or funny) behaviour is:
>
> I have tried with several keys (generated by Kgpg), including completely
> new ones. Then I sent several messages to myself. And whats happening now
> is: An old e-mail encrypted with a key deleted in Kgpg can still be
> decrypted by kmail. A password dialog pops up, and it works fine with the
> old password.
>
> However, any new key works only for encryption, where I am asked for the
> PW, but I am not asked after receiving the mail when I want to read it.
> Kpgp's editor decrypts the mail, if I copy the sourcecode, thus enc. seems
> to work.
>
> :-)
>
> I guess I will try to remove ~/gnupg and try again.
>
> > Btw, previous posts : http://lists.kde.org/?t=118673691300005&r=1&w=2
> >
> > acp

["patch_gpgme_passphrase_cb" (text/x-diff)]

Index: certmanager/lib/cryptplug.cpp
===================================================================
--- certmanager/lib/cryptplug.cpp	(revision 703479)
+++ certmanager/lib/cryptplug.cpp	(working copy)
@@ -34,6 +34,11 @@
 #include <gpgmepp/data.h>
 #include <gpgmepp/importresult.h>
 
+#include "ui/passphrasedialog.h"
+#include <klocale.h>
+#include <kstandarddirs.h>
+
+
 /*! \file gpgmeplug.c
     \brief GPGME implementation of CRYPTPLUG following the
     specification located in common API header cryptplug.h.
@@ -263,7 +268,45 @@
   return p;
 }
 
+gpgme_error_t passphrase_cb(void *HOOK, const char *UID_HINT,
+                            const char *PASSPHRASE_INFO,
+                            int PREV_WAS_BAD, int FD) {
 
+  QString msg = PREV_WAS_BAD ?
+                i18n( "You need a passphrase to unlock the secret key for user:<br/> \
%1 (retry)" ) : +                i18n( "You need a passphrase to unlock the secret \
key for user:<br/> %1" ); +  msg = msg.arg( QString::fromUtf8( UID_HINT ) ) + \
"<br/><br/>"; +  msg.prepend( "<qt>" );
+  msg += i18n( "This dialog will reappear every time the passphrase is needed. For a \
more secure solution that also allows caching the passphrase, use gpg-agent." ) + \
"<br/>"; +  const QString gpgAgent = KStandardDirs::findExe( "gpg-agent" );
+  if ( !gpgAgent.isEmpty() ) {
+    msg += i18n( "gpg-agent was found in %1, but does not appear to be running." )
+           .arg( gpgAgent );
+  } else {
+    msg += i18n( "gpg-agent is part of gnupg-%1, which you can download from %2" )
+           .arg( "1.9" )
+           .arg( "http://www.gnupg.org/download" );  // add #gnupg2 if you can make \
this a real link +  }
+  msg += "<br/>";
+  msg += i18n( "For information on how to set up gpg-agent, see %1" )
+         .arg( "http://kmail.kde.org/kmail-pgpmime-howto.html" );
+  msg += "<br/><br/>";
+  msg += i18n( "Enter passphrase:" );
+  Kleo::PassphraseDialog dlg( msg, i18n("Passphrase Dialog") );
+  if ( dlg.exec() != QDialog::Accepted ) {
+    return GPG_ERR_CANCELED;
+  }
+
+  if (dlg.passphrase()) {
+    write(FD, dlg.passphrase(), strlen(dlg.passphrase()));
+    write(FD, "\n", 1);
+    return GPG_ERR_NO_ERROR;
+  }
+  else {
+    return GPG_ERR_BAD_PASSPHRASE;
+  }
+}
+
 CryptPlug::CryptPlug() {
 }
 
@@ -351,6 +394,11 @@
 
   gpgme_data_new( &gPlaintext );
 
+  if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP)
+    gpgme_set_passphrase_cb(ctx, passphrase_cb, NULL);
+  else
+    gpgme_set_passphrase_cb(ctx, NULL, NULL);
+
   err = gpgme_op_decrypt( ctx, gCiphertext, gPlaintext );
   if( err ) {
     fprintf( stderr, "\ngpgme_op_decrypt() returned this error code:  %i\n\n", err \
); @@ -1072,6 +1120,11 @@
 
   gpgme_data_new( &gPlaintext );
 
+  if (gpgme_get_protocol(ctx) == GPGME_PROTOCOL_OpenPGP)
+    gpgme_set_passphrase_cb(ctx, passphrase_cb, NULL);
+  else
+    gpgme_set_passphrase_cb(ctx, NULL, NULL);
+
   err = gpgme_op_decrypt_verify( ctx, gCiphertext, gPlaintext );
   gpgme_data_release( gCiphertext );
 



_______________________________________________
KDE PIM mailing list kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic