Difference between revisions of "S/MIME howto"

From Claws Mail FAQ
Jump to: navigation, search
(Added section on the gpg-agent and KDE startup of it)
m (Reverted edit of Innateemissary9, changed back to last version by Claws)
(10 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
==Claws Mail & S/MIME plugin howto==
 
==Claws Mail & S/MIME plugin howto==
 +
This howto describes configuring S/MIME for Claws Mail which uses GnuPG. It is
 +
based on Gentoo Linux but should be working fine on every other distribution if
 +
adjusting it accordingly.
 +
<br />
  
Recently there were many requests on the mailing list on how to configure the S/MIME plugin to work properly. It is not a trivial task as the GUI doesn't provide any configuration options and everything needs to be done in the console.
+
As of 16th November 2009 Thawte discontinued their free S/MIME certificates. As
 
+
some things of this howto were also somewhat out of date and many things were
I've had a "half-working" setup but always failed on some point when importing S/MIME certificates. I now managed to have a working config and hopefully this howto will give an insight on how to achieve it.
+
based on Thawte, it's time for an update. A big difference to the previous howto
 
+
is enabling the use of certificate revocation lists (CRL) which didn't work
This howto is based on Gentoo but should be working fine on every other distribution if adjusting it accordingly :)
+
properly with Thawte before. I won't use OCSP support because of privacy issues,
 +
see man dirmngr.
  
 
===Requirements===
 
===Requirements===
# recent Claws Mail version, recommended: v2.7.1 (multiple RFC fixes), or CVS
+
# recent Claws Mail version, recommended: latest available version (v3.7.3 at the time of writing this), because many fixes for S/MIME have been incorporated lately
# recent S/MIME plugin, recommended: v0.6.0 (multiple RFC fixes), or CVS
+
# most recent S/MIME plugin/package, or "smime" USE flag on Gentoo
# S/MIME certificate (this howto is based on Thawte Freemail certs)
+
# S/MIME certificate (e.g. you can get free (personal use) certificates from Comodo at http://www.instantssl.com)
# pinentry, gnupg, gpgme, ca-certificates (and openssl) in recent versions
+
# pinentry, gnupg, gpgme, dirmngr (for CRL support), ca-certificates (and openssl) in recent versions
# gpg-agent to cache the passphrase
+
# gpg-agent
 +
<br />
 +
It is important to note that gpgme >=1.1.8 ''does not work for me'' and always
 +
results in an error message hence I have it masked here and use v1.1.6.
 +
See bug 2059: http://www.thewildbeast.co.uk/claws-mail/bugzilla/show_bug.cgi?id=2059
 +
<br />
 +
I've tested this howto with the following package versions:
 +
<br />
 +
# emerge -p pinentry gnupg gpgme ca-certificates dirmngr claws-mail
 +
    [ebuild  R  ] app-crypt/pinentry-0.7.6  USE="gtk ncurses qt3 qt4 -caps -static" 464 kB
 +
    [ebuild  R  ] app-misc/ca-certificates-20090709  151 kB
 +
    [ebuild  R  ] app-crypt/dirmngr-1.0.3  USE="nls" 544 kB
 +
    [ebuild  R  ] app-crypt/gnupg-2.0.13  USE="bzip2 ldap nls smartcard -adns -caps -doc -openct -pcsc-lite (-selinux) -static" 3,855 kB
 +
    [ebuild  R  ] app-crypt/gpgme-1.1.6  USE="-pth" 1,061 kB
 +
    [ebuild  R  ] mail-client/claws-mail-3.7.3  USE="bogofilter crypt dbus dillo gnome gnutls imap ipv6 kde ldap nntp session smime spamassassin ssl xface -doc -pda -spell -startup-notification" 0 kB
  
Those are the versions I'm using:
+
===Configuring & running the GPG agent===
 +
Claws Mail depends on a running gpg-agent for using any S/MIME feature. Furthermore
 +
it is used to cache the passphrase. A gpg-agent will need a pinentry
 +
application to ask for the pin.
  
# emerge -p pinentry gnupg gpgme ca-certificates
 
[ebuild  R  ] app-crypt/pinentry-0.7.2-r3  USE="gtk ncurses qt3 -caps" 390 kB
 
[ebuild  R  ] app-crypt/gnupg-2.0.1-r1  USE="X bzip2 ldap nls -caps -doc -openct -pcsc-lite (-selinux) -smartcard" 0 kB
 
[ebuild  R  ] app-crypt/gpgme-1.1.2-r1  0 kB
 
[ebuild  R  ] app-misc/ca-certificates-20050804  92 kB
 
 
===Optional===
 
I'm using keychain to start gpg-agent. Choose what you like, here are somes howtos:
 
 
<br />
 
<br />
http://www.claws-mail.org/faq/index.php/Plugins#How_do_I_configure_gpg-agent_and_the_PGP_plugin.3F http://gentoo-wiki.com/HOWTO_KMail_gpg-agent_kde#Setting_up_gpg-agent_with_keychain
+
Configuration file: "$HOME/.gnupg/gpg-agent.conf" (adjust the paths accordingly)
 
+
<br />
===Runing the GPG agent===
+
pinentry-program /usr/bin/pinentry-qt
 +
default-cache-ttl 86400  # be aware that the passphrases will be cached for 86400 seconds! set accordingly to your needs
 +
max-cache-ttl 86400
 +
  disable-scdaemon
 +
write-env-file ~/.gnupg/.gpg-agent-info
 +
allow-mark-trusted
 +
keep-display
 +
display :0.0
 +
debug-level basic
 +
<br />
  
If you're using gpg2, then because of gpgme, claws-mail will depend on a running gpg-agent. This means, you will have to run a gpg-agent in order to be able to use anything via gpgme. A gpg-agent will need a pinentry application to ask for the pin. Running gpg-agent is quite trivial:
+
Running gpg-agent is quite trivial:
  
 
  eval `gpg-agent --daemon`
 
  eval `gpg-agent --daemon`
  
As you see, it eval's, that means, gpg-agent returns an environment variable and exports it, something like `FOO=bar; export FOO`. This means, that you will have to run claws-mail from the same session, because it will need this environment variable in order to access the agent. check gpg-agent(1) for more details on the usual startup customs.
+
As you see, it eval's the command, that means, gpg-agent returns an environment
 +
variable and exports it, something like `GPG_AGENT_INFO=xxx; export
 +
GPG_AGENT_INFO`. This means, that you will have to run claws-mail from the same
 +
session, because it will need this environment variable in order to access the
 +
agent. Check gpg-agent(1) for more details on the usual startup customs.
  
 
====KDE Users====
 
====KDE Users====
 
+
KDE has a way to run scripts and thus export environment variables at startup
KDE has a way to run scripts and thus export environment variables at startup time. Every application running in this session will get these variables, so it's very handsome here. All you have to do is create a file under ~/.kde/env/ (if it doesn't exist, then create it). I named it gpgagent.sh. The contents of this shell script is quite trivial:
+
time. Every application running in this session will get access to these variables. All
 +
you have to do is create a file under the directory ~/.kde/env/ (if it doesn't
 +
exist, then create it). I named it gpgagent.sh, the content of this shell script
 +
is quite trivial (don't forget to chmod +x):
  
 
  #!/bin/sh
 
  #!/bin/sh
 
 
  eval `gpg-agent --daemon`
 
  eval `gpg-agent --daemon`
  
Well done!
+
Also create the directory ~/.kde/shutdown/ and place another shell script in it
 +
(e.g. again gpgagent.sh) with the following contents:
 +
#!/bin/sh
 +
# the second field of the GPG_AGENT_INFO variable is the
 +
# process ID of the gpg-agent active in the current session
 +
# so we'll just kill that, rather than all of them :)
 +
[ -n "${GPG_AGENT_INFO}" ] && kill `echo "${GPG_AGENT_INFO}" | cut -d ':' -f 2`
  
===Importing S/MIME certificates into gpgsm===
 
(from http://www.gnupg.org/aegypten/development.en.html#howto_import_external_certs)
 
<br /><br />
 
First one has to obtain the Thawte Freemail certificate and install it into Firefox/Thunderbird. Export/Backup the certificate from Firefox/Thunderbird e.g. to "certbundle.p12" file and remember the passphrase.
 
  
Convert the file into PEM format:<br />
+
====Optional====
$ openssl pkcs12 -in certbundle.p12 -out certbundle.pem -nodes
+
You can also use keychain, ~/.xsession startup, or any other method to start
(use the export passphrase)
+
gpg-agent. Choose what you like, here are somes howtos:
 +
<br />
 +
http://www.funtoo.org/en/security/keychain/intro/<br />
 +
http://www.gentoo-wiki.info/HOWTO_KMail_gpg-agent_kde#Setting_up_gpg-agent_with_keychain<br />
 +
http://www.claws-mail.org/faq/index.php/Plugins#How_do_I_configure_gpg-agent_and_the_PGP_plugin.3F <br />
 +
man gpg-agent, section DESCRIPTION
  
Extract the key: <br />
 
$ openssl pkcs12 -in certbundle.pem -export -out certkey.p12 -nocerts -nodes
 
  
Import the key into gpgsm:<br />
+
===Importing S/MIME certificates into gpgsm===
  $ gpgsm --call-protect-tool --p12-import --store certkey.p12
+
Regardless whether you have obtained your S/MIME certificate in Mozilla Firefox
 +
or another browser, you have to export/backup it to a PKCS12 (.p12) file
 +
somewhere on your disk. I'm using the filename "certbundle.p12" for this howto,
 +
you can call it as you wish (e.g. $emailaddress_$certdate.p12)
 +
 
 +
Current versions of GnuPG support importing PKCS12 files directly, there's no
 +
need to use openssl anymore, as described in the previous howto. (If it doesn't
 +
work for you, you can still view the old howto through the history and use
 +
openssl to extract and convert the keys). Gpg-agent has to be properly setup and
 +
running by now.
 +
<br />
 +
  $ gpgsm --import certbundle.p12
 +
<br />
 +
You will be asked to enter your passphrase for the backup file in the pinentry
 +
popup and you then have choose another passphrase for importing it to gpgsm.
 +
This passphrase will be the one you have to enter everytime you want to decrypt
 +
or sign emails (of course there's the possibility to cache the passphrase).
  
Now one has to add the issuers certificate (Thawte) into gpgsm, you can use the certs included in the Freemail cert, but I did the following:
+
Now one has to add the issuer certificates (CA + intermediate CA) into gpgsm if
 +
they are not already there. The following command will add more than 100 CA certificates
 +
from the ca-certificates package, but you could also only add the specific CA's
 +
for your certificate if you want.
 
<br />
 
<br />
  $ gpgsm --import /usr/share/ca-certificates/mozilla/Thawte*
+
  $ gpgsm --import /usr/share/ca-certificates/mozilla/*
(Thawte_Personal_Basic_CA.crt, Thawte_Personal_Premium_CA.crt, Thawte_Server_CA.crt, Thawte_Personal_Freemail_CA.crt, Thawte_Premium_Server_CA.crt, Thawte_Time_Stamping_CA.crt)
+
  
 
Check if your key has been added:<br />
 
Check if your key has been added:<br />
 
  $ gpgsm --list-secret-keys
 
  $ gpgsm --list-secret-keys
  
If this doesn't show a secret key, you may have to import the three certificates from certbundle.pem: separate them to three files (starting with "--- BEGIN CERTIFICATE ---" and ending with "--- END CERTIFICATE ---"), then run <br />
 
$ gpgsm --import cert1.pem cert2.pem cert3.pem
 
  
===Configuring S/MIME===
+
===Configuring GnuPG S/MIME===
You need to create the file (if it doesn't exist) "$HOME/.gnupg/trustlist.txt" to add Thawte to the trusted key list. This makes it possible to verify/sign/.../ with your Thawte certificate. I also added my own certificate to the trustlist. Add the following lines which contain the fingerprint (not serial number!) of the key and the letter S at the end:<br />
+
You'll now have to properly configure GnuPG for S/MIME. As opposed to the
 
+
previous howto, we'll also be using certificate revocation list (CRL) support with dirmngr to
#  1.2.840.113549.1.9.1=#706572736F6E616C2D667265656D61696C407468617774652E636F6D,CN=Thawte
+
be able to detect revoked certificates within the mail client. (It didn't work
# Personal Freemail CA,OU=Certification Services Division,O=Thawte
+
before because Thawte has some messed up CRL which GnuPG couldn't handle
# Consulting,L=Cape Town,ST=Western Cape,C=ZA
+
properly - but because Thawte doesn't provide S/MIME anymore, we're fine now :)
209900B63D955728140CD13622D8C687A4EB0085 S
+
We only have to import the large Thawte CRL once as all of their certificates
 +
have been revoked.
 
<br />
 
<br />
 
You'll enter your own key similarly
 
  
 
This is my "$HOME/.gnupg/gpgsm.conf":<br />
 
This is my "$HOME/.gnupg/gpgsm.conf":<br />
disable-crl-checks
 
 
  disable-policy-checks
 
  disable-policy-checks
 
  auto-issuer-key-retrieve
 
  auto-issuer-key-retrieve
 +
include-certs -1  # this will include all certificates in the chain up to the root
 
  debug-level basic
 
  debug-level basic
 +
<br />
 +
You will also probably want to enter the following entry to gpgsm.conf ( use
 +
the fingerprint output from the command "gpgsm --list-secret-keys")
 +
default-key  fingerprint_of_your_key
  
You will also probably want to enter your:
+
<br />
 +
My "$HOME/.gnupg/dirmngr.conf" file only contains the following line, everything
 +
is set to default. Dirmngr will be used for CRL support internally by GnuPG. It
 +
is also possible to setup a system-wide dirmngr daemon which is not part of this
 +
howto (see man page).
 +
debug-level basic
 +
<br />
 +
If you encounter any problems with CRL support you can use the old
 +
configuration files from the history in this wiki which disables it. Be aware
 +
that by having imported all CA's dirmngr might encounter a CRL where it can't
 +
fetch it properly and hangs (sometimes happens to me when starting kleopatra).
  
default-key fingerprint_of_your_key
+
====Importing Thawte CRL and testing CRL support====
 +
As of 16th November 2009 all Thawte S/MIME certificates have been revoked. As
 +
dirmngr doesn't automatically work with the Thawte CRL, one has to import them
 +
manually once. A working gpg-agent setup is again needed, then perform the
 +
following steps:
 +
  # download the Thawte CRL
 +
wget http://crl.thawte.com/ThawtePersonalFreemailCA.crl
 +
wget http://crl.thawte.com/ThawtePersonalFreemailIssuingCA.crl
 +
 +
# import to dirmngr
 +
gpgsm --call-dirmngr loadcrl ThawtePersonalFreemailCA.crl
 +
gpgsm --call-dirmngr loadcrl ThawtePersonalFreemailIssuingCA.crl
 +
<br />
 +
If you have old Thawte certificates that are still valid according to their
 +
expiry date or other revoked certificates you can verify that dirmngr works with
 +
the following command:
 +
gpgsm --list-keys --with-validation <keyid|name|fingerprint>
 +
<br />
 +
The output will be like this:
 +
  [...]
 +
  validity: 2009-03-24 08:26:26 through 2010-03-24 08:26:26
 +
  key type: 2048 bit RSA
 +
  fingerprint: xxxx
 +
  [certificate has been revoked]
 +
  [validation model used: shell]
 +
  [certificate is bad: Certificate revoked]
  
 +
See "[certificate is bad: Certificate revoked]" message instead of
 +
"[certificate is good]".
 +
 +
====Setting up the trust====
 +
We used the option "allow-mark-trusted" in gpg-agent.conf which allows the
 +
client to mark keys as trusted, i.e. put them in the file
 +
$HOME/.gnupg/trustlist.txt (see man gpg-agent). Hence you should be asked
 +
automatically to trust another key or CA, e.g. it mainly happens for me when I
 +
click on an email in Claws Mail where the CA is missing from trustlist.txt or
 +
when I start the tool "kleopatra" where I'm asked to trust the CAs.
 
<br />
 
<br />
gpg-agent is only necessary for caching the passphrase: "$HOME/.gnupg/gpg-agent.conf"<br />
 
  
pinentry-program /usr/bin/pinentry-qt
+
If it doesn't work for you automatically you have to create the file (if it
default-cache-ttl 86400    # be aware that the passphrases will be  cached for 86400 seconds! set accordingly to your need
+
doesn't exist) "$HOME/.gnupg/trustlist.txt" to add your CA (e.g. Comodo, Thawte)
  max-cache-ttl 86400
+
to the trusted key list. This makes it possible to verify/sign/.../ with your
  disable-scdaemon
+
personal certificate. I also added my own certificate to the trustlist.
allow-mark-trusted
+
<br />
 +
 
 +
Usually one adds the SHA1 fingerprints to the file (not the serial number, and
 +
it doesn't matter whether with or without the colon). With
 +
the following command (borrowed and adjusted from this German howto
 +
http://www.kire.ch/blog/2009/05/07/claws-mail-und-smime-verschlusselung-mit-cacert-zertifikat/)
 +
you can add all your CA's and keys at once (of course you have to trust all the CA's of
 +
the ca-certificate package - if you don't then you have to manually dump the
 +
certificate chain and add the fingerprints accordingly):
 +
<br />
 +
  gpgsm --list-keys 2>/dev/null | grep fingerprint | awk '{print $2 " S"}' >> ~/.gnupg/trustlist.txt
 +
  (the command will append, not overwrite the old file)
 +
<br />
 +
Note that when manually changing trustlist.txt or gpg-agent.conf, you need to give
 +
gpg-agent a SIGHUP.
 +
<br />
 +
 
 +
===Setting up Claws Mail itself===
 +
There's not much you have to configure in Claws Mail. Go to the menu "Configuration - Edit Accounts | choose your account | - Edit - Account - Privacy - Default privacy system" => S-MIME
 +
<br />
 +
Set the options to your need, e.g. I've set all but the last (Save sent encrypted as clear text).
 +
<br />
 +
As we have configured gpgsm to use a "default key" you can set "Use default GnuPG key" in the Account preferences Plugins/GPG menu.
 +
 
 +
===Working with Claws Mail S/MIME and problems/bugs===
 +
* If you receive the error message "The signature can't be checked - Unknown IPC Command" and you're using "seahorse-agent" try to switch to the gpg-agent of the GnuPG package.
  
===Working with S/MIME plugin and problems/bugs===
+
* If you encounter the error message "Couldn't decrypt: No CMS object" then it is likely that your gpgme version is incompatible with Claws Mail. In my tests only v1.1.6 worked, everything newer (1.1.8 and 1.2.0) doesn't work for me! This doesn't necessarily mean that it doesn't work for you. See http://www.thewildbeast.co.uk/claws-mail/bugzilla/show_bug.cgi?id=2059
* As of current CVS (CM =>2.7.0cvs11 and S/MIME >=0.5.8cvs2) the S/MIME plugin is more RFC compliant and signing, encrypting, decrypting and verifying messages is working very well now. I tested compatibility with Outlook 11 and Thunderbird, some Kmail emails in my inbox decrypt fine too!
+
  
* I'm only aware of one problem, where you'll get "Bad signature" warnings, when you forward (via CM) a signed+encrypted email with an attachment and sign+encrypt the email itself again too.
+
* Error message "Cannot sign: General error" usually means that there's something wrong with the gpg-agent (e.g. not running or wrong environment)
  
* Error: Couldn't decrypt: "unsupported algorithm" - this happens when you receive an email which got encrypted with RC2 algorithm (e.g. some Outlook 11 and some Thunderbird MUAs). I'm currently not aware of a solution, as the underlying libgcrypt doesn't handle it for patent reasons. (see https://intevation.de/roundup/aegypten/issue11 and http://forums.mozillazine.org/viewtopic.php?p=2858116 )
+
* If you're an old Thawte user trying to use their offer for a free VeriSign S/MIME certificate with Claws Mail, you're out of luck because GnuPG doesn't support the ancient MD2 algorithm being used by VeriSign for their CA. I've tried getting it to work but never succeeded (except by using Thunderbird), here's a statement from the developer of GnuPG/libgcrypt: http://lists.gnupg.org/pipermail/gpa-dev/2003-October/001482.html
  
* It seems the "Trust key" dialog doesn't show the name of the key, e.g. "The key of ' ' is not fully trusted". <br />CM first asks for the key of the recipient and then asks for the sender's key because CM can't extract it properly: "No exact match for 'email@address'; please select the key." (guess that is because I have two certs..).<br /> If I send an email to a friend and include myself (To:), CM will ask me three times for the correct keys.
+
* I'm only aware of one problem in Claws Mail, where you'll get "Bad signature" warnings, when you forward (via CM) a signed+encrypted email with an attachment and sign+encrypt the email itself again too.
  
* As of now the "Select Keys" dialog when encrypting emails is a bit awkward to use if you have more than one key (e.g. one additional key that is expired and you still want to keep it to be able to decrypt older emails). It only shows the Key ID and no info about the expiry date which makes it more difficult to choose the correct one.
+
* Error message: Couldn't decrypt: "unsupported algorithm" - this happens when you receive an email which got encrypted with the RC2 algorithm (e.g. some Outlook and some Thunderbird MUAs). I'm currently not aware of a solution on your side, as the underlying libgcrypt doesn't handle it for patent reasons. (see https://intevation.de/roundup/aegypten/issue11 and http://forums.mozillazine.org/viewtopic.php?p=2858116 ) You can ask your email partner to reconfigure their clients though (I know that it works for recent Outlook versions on >=Windows Vista to force certain algorithms).

Revision as of 06:53, 23 October 2012

Contents

Claws Mail & S/MIME plugin howto

This howto describes configuring S/MIME for Claws Mail which uses GnuPG. It is based on Gentoo Linux but should be working fine on every other distribution if adjusting it accordingly.

As of 16th November 2009 Thawte discontinued their free S/MIME certificates. As some things of this howto were also somewhat out of date and many things were based on Thawte, it's time for an update. A big difference to the previous howto is enabling the use of certificate revocation lists (CRL) which didn't work properly with Thawte before. I won't use OCSP support because of privacy issues, see man dirmngr.

Requirements

  1. recent Claws Mail version, recommended: latest available version (v3.7.3 at the time of writing this), because many fixes for S/MIME have been incorporated lately
  2. most recent S/MIME plugin/package, or "smime" USE flag on Gentoo
  3. S/MIME certificate (e.g. you can get free (personal use) certificates from Comodo at http://www.instantssl.com)
  4. pinentry, gnupg, gpgme, dirmngr (for CRL support), ca-certificates (and openssl) in recent versions
  5. gpg-agent


It is important to note that gpgme >=1.1.8 does not work for me and always results in an error message hence I have it masked here and use v1.1.6. See bug 2059: http://www.thewildbeast.co.uk/claws-mail/bugzilla/show_bug.cgi?id=2059
I've tested this howto with the following package versions:

# emerge -p pinentry gnupg gpgme ca-certificates dirmngr claws-mail
   [ebuild   R   ] app-crypt/pinentry-0.7.6  USE="gtk ncurses qt3 qt4 -caps -static" 464 kB
   [ebuild   R   ] app-misc/ca-certificates-20090709  151 kB
   [ebuild   R   ] app-crypt/dirmngr-1.0.3  USE="nls" 544 kB
   [ebuild   R   ] app-crypt/gnupg-2.0.13  USE="bzip2 ldap nls smartcard -adns -caps -doc -openct -pcsc-lite (-selinux) -static" 3,855 kB
   [ebuild   R   ] app-crypt/gpgme-1.1.6  USE="-pth" 1,061 kB
   [ebuild   R   ] mail-client/claws-mail-3.7.3  USE="bogofilter crypt dbus dillo gnome gnutls imap ipv6 kde ldap nntp session smime spamassassin ssl xface -doc -pda -spell -startup-notification" 0 kB

Configuring & running the GPG agent

Claws Mail depends on a running gpg-agent for using any S/MIME feature. Furthermore it is used to cache the passphrase. A gpg-agent will need a pinentry application to ask for the pin.


Configuration file: "$HOME/.gnupg/gpg-agent.conf" (adjust the paths accordingly)

pinentry-program /usr/bin/pinentry-qt
default-cache-ttl 86400   # be aware that the passphrases will be cached for 86400 seconds! set accordingly to your needs
max-cache-ttl 86400
disable-scdaemon
write-env-file ~/.gnupg/.gpg-agent-info
allow-mark-trusted
keep-display
display :0.0
debug-level basic


Running gpg-agent is quite trivial:

eval `gpg-agent --daemon`

As you see, it eval's the command, that means, gpg-agent returns an environment variable and exports it, something like `GPG_AGENT_INFO=xxx; export GPG_AGENT_INFO`. This means, that you will have to run claws-mail from the same session, because it will need this environment variable in order to access the agent. Check gpg-agent(1) for more details on the usual startup customs.

KDE Users

KDE has a way to run scripts and thus export environment variables at startup time. Every application running in this session will get access to these variables. All you have to do is create a file under the directory ~/.kde/env/ (if it doesn't exist, then create it). I named it gpgagent.sh, the content of this shell script is quite trivial (don't forget to chmod +x):

#!/bin/sh
eval `gpg-agent --daemon`

Also create the directory ~/.kde/shutdown/ and place another shell script in it (e.g. again gpgagent.sh) with the following contents:

#!/bin/sh
# the second field of the GPG_AGENT_INFO variable is the
# process ID of the gpg-agent active in the current session
# so we'll just kill that, rather than all of them :)
[ -n "${GPG_AGENT_INFO}" ] && kill `echo "${GPG_AGENT_INFO}" | cut -d ':' -f 2`


Optional

You can also use keychain, ~/.xsession startup, or any other method to start gpg-agent. Choose what you like, here are somes howtos:
http://www.funtoo.org/en/security/keychain/intro/
http://www.gentoo-wiki.info/HOWTO_KMail_gpg-agent_kde#Setting_up_gpg-agent_with_keychain
http://www.claws-mail.org/faq/index.php/Plugins#How_do_I_configure_gpg-agent_and_the_PGP_plugin.3F
man gpg-agent, section DESCRIPTION


Importing S/MIME certificates into gpgsm

Regardless whether you have obtained your S/MIME certificate in Mozilla Firefox or another browser, you have to export/backup it to a PKCS12 (.p12) file somewhere on your disk. I'm using the filename "certbundle.p12" for this howto, you can call it as you wish (e.g. $emailaddress_$certdate.p12)

Current versions of GnuPG support importing PKCS12 files directly, there's no need to use openssl anymore, as described in the previous howto. (If it doesn't work for you, you can still view the old howto through the history and use openssl to extract and convert the keys). Gpg-agent has to be properly setup and running by now.

$ gpgsm --import certbundle.p12


You will be asked to enter your passphrase for the backup file in the pinentry popup and you then have choose another passphrase for importing it to gpgsm. This passphrase will be the one you have to enter everytime you want to decrypt or sign emails (of course there's the possibility to cache the passphrase).

Now one has to add the issuer certificates (CA + intermediate CA) into gpgsm if they are not already there. The following command will add more than 100 CA certificates from the ca-certificates package, but you could also only add the specific CA's for your certificate if you want.

$ gpgsm --import /usr/share/ca-certificates/mozilla/*

Check if your key has been added:

$ gpgsm --list-secret-keys


Configuring GnuPG S/MIME

You'll now have to properly configure GnuPG for S/MIME. As opposed to the previous howto, we'll also be using certificate revocation list (CRL) support with dirmngr to be able to detect revoked certificates within the mail client. (It didn't work before because Thawte has some messed up CRL which GnuPG couldn't handle properly - but because Thawte doesn't provide S/MIME anymore, we're fine now :) We only have to import the large Thawte CRL once as all of their certificates have been revoked.

This is my "$HOME/.gnupg/gpgsm.conf":

disable-policy-checks
auto-issuer-key-retrieve
include-certs -1  # this will include all certificates in the chain up to the root
debug-level basic


You will also probably want to enter the following entry to gpgsm.conf ( use the fingerprint output from the command "gpgsm --list-secret-keys")

default-key  fingerprint_of_your_key


My "$HOME/.gnupg/dirmngr.conf" file only contains the following line, everything is set to default. Dirmngr will be used for CRL support internally by GnuPG. It is also possible to setup a system-wide dirmngr daemon which is not part of this howto (see man page).

debug-level basic


If you encounter any problems with CRL support you can use the old configuration files from the history in this wiki which disables it. Be aware that by having imported all CA's dirmngr might encounter a CRL where it can't fetch it properly and hangs (sometimes happens to me when starting kleopatra).

Importing Thawte CRL and testing CRL support

As of 16th November 2009 all Thawte S/MIME certificates have been revoked. As dirmngr doesn't automatically work with the Thawte CRL, one has to import them manually once. A working gpg-agent setup is again needed, then perform the following steps:

# download the Thawte CRL
wget http://crl.thawte.com/ThawtePersonalFreemailCA.crl
wget http://crl.thawte.com/ThawtePersonalFreemailIssuingCA.crl

# import to dirmngr
gpgsm --call-dirmngr loadcrl ThawtePersonalFreemailCA.crl
gpgsm --call-dirmngr loadcrl ThawtePersonalFreemailIssuingCA.crl


If you have old Thawte certificates that are still valid according to their expiry date or other revoked certificates you can verify that dirmngr works with the following command:

gpgsm --list-keys --with-validation <keyid|name|fingerprint>


The output will be like this:

 [...]
 validity: 2009-03-24 08:26:26 through 2010-03-24 08:26:26
 key type: 2048 bit RSA
 fingerprint: xxxx
 [certificate has been revoked]
 [validation model used: shell]
 [certificate is bad: Certificate revoked]

See "[certificate is bad: Certificate revoked]" message instead of "[certificate is good]".

Setting up the trust

We used the option "allow-mark-trusted" in gpg-agent.conf which allows the client to mark keys as trusted, i.e. put them in the file $HOME/.gnupg/trustlist.txt (see man gpg-agent). Hence you should be asked automatically to trust another key or CA, e.g. it mainly happens for me when I click on an email in Claws Mail where the CA is missing from trustlist.txt or when I start the tool "kleopatra" where I'm asked to trust the CAs.

If it doesn't work for you automatically you have to create the file (if it doesn't exist) "$HOME/.gnupg/trustlist.txt" to add your CA (e.g. Comodo, Thawte) to the trusted key list. This makes it possible to verify/sign/.../ with your personal certificate. I also added my own certificate to the trustlist.

Usually one adds the SHA1 fingerprints to the file (not the serial number, and it doesn't matter whether with or without the colon). With the following command (borrowed and adjusted from this German howto http://www.kire.ch/blog/2009/05/07/claws-mail-und-smime-verschlusselung-mit-cacert-zertifikat/) you can add all your CA's and keys at once (of course you have to trust all the CA's of the ca-certificate package - if you don't then you have to manually dump the certificate chain and add the fingerprints accordingly):

gpgsm --list-keys 2>/dev/null | grep fingerprint | awk '{print $2 " S"}' >> ~/.gnupg/trustlist.txt
(the command will append, not overwrite the old file)


Note that when manually changing trustlist.txt or gpg-agent.conf, you need to give gpg-agent a SIGHUP.

Setting up Claws Mail itself

There's not much you have to configure in Claws Mail. Go to the menu "Configuration - Edit Accounts | choose your account | - Edit - Account - Privacy - Default privacy system" => S-MIME
Set the options to your need, e.g. I've set all but the last (Save sent encrypted as clear text).
As we have configured gpgsm to use a "default key" you can set "Use default GnuPG key" in the Account preferences Plugins/GPG menu.

Working with Claws Mail S/MIME and problems/bugs

  • If you receive the error message "The signature can't be checked - Unknown IPC Command" and you're using "seahorse-agent" try to switch to the gpg-agent of the GnuPG package.
  • If you encounter the error message "Couldn't decrypt: No CMS object" then it is likely that your gpgme version is incompatible with Claws Mail. In my tests only v1.1.6 worked, everything newer (1.1.8 and 1.2.0) doesn't work for me! This doesn't necessarily mean that it doesn't work for you. See http://www.thewildbeast.co.uk/claws-mail/bugzilla/show_bug.cgi?id=2059
  • Error message "Cannot sign: General error" usually means that there's something wrong with the gpg-agent (e.g. not running or wrong environment)
  • If you're an old Thawte user trying to use their offer for a free VeriSign S/MIME certificate with Claws Mail, you're out of luck because GnuPG doesn't support the ancient MD2 algorithm being used by VeriSign for their CA. I've tried getting it to work but never succeeded (except by using Thunderbird), here's a statement from the developer of GnuPG/libgcrypt: http://lists.gnupg.org/pipermail/gpa-dev/2003-October/001482.html
  • I'm only aware of one problem in Claws Mail, where you'll get "Bad signature" warnings, when you forward (via CM) a signed+encrypted email with an attachment and sign+encrypt the email itself again too.
  • Error message: Couldn't decrypt: "unsupported algorithm" - this happens when you receive an email which got encrypted with the RC2 algorithm (e.g. some Outlook and some Thunderbird MUAs). I'm currently not aware of a solution on your side, as the underlying libgcrypt doesn't handle it for patent reasons. (see https://intevation.de/roundup/aegypten/issue11 and http://forums.mozillazine.org/viewtopic.php?p=2858116 ) You can ask your email partner to reconfigure their clients though (I know that it works for recent Outlook versions on >=Windows Vista to force certain algorithms).