Difference between revisions of "S/MIME howto"

From Claws Mail FAQ
Jump to: navigation, search
m (Reverted edit of Innateemissary9, changed back to last version by Claws)
(20 intermediate revisions by 10 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
 +
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.
  
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.
+
===Requirements===
 +
# 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
 +
# most recent S/MIME plugin/package, or "smime" USE flag on Gentoo
 +
# S/MIME certificate (e.g. you can get free (personal use) certificates from Comodo at http://www.instantssl.com)
 +
# pinentry, gnupg, gpgme, dirmngr (for CRL support), ca-certificates (and openssl) in recent versions
 +
# 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
  
This howto is based on Gentoo but should be working fine on every other distribution if adjusting it accordingly :)
+
===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.
  
===Requirements===
+
<br />
# recent Claws Mail version
+
Configuration file: "$HOME/.gnupg/gpg-agent.conf" (adjust the paths accordingly)
# recent S/MIME plugin (I'm using 0.5.7cvs2 which fixes some decryption bugs)
+
<br />
# S/MIME certificate (this howto is based on Thawte Freemail certs)
+
pinentry-program /usr/bin/pinentry-qt
# pinentry, gnupg, gpgme, ca-certificates (and openssl) in recent versions
+
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 />
  
Those are the versions I'm using:
+
Running gpg-agent is quite trivial:
  
  # emerge -p pinentry gnupg gpgme ca-certificates
+
  eval `gpg-agent --daemon`
[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===
+
As you see, it eval's the command, that means, gpg-agent returns an environment
# running gpg-agent for caching the passphrase
+
variable and exports it, something like `GPG_AGENT_INFO=xxx; export
I'm using keychain to start gpg-agent. Choose what you like, here are somes howtos:
+
GPG_AGENT_INFO`. This means, that you will have to run claws-mail from the same
<br />
+
session, because it will need this environment variable in order to access the
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
+
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):
  
===Importing S/MIME certificates into gpgsm===
+
#!/bin/sh
(from http://www.gnupg.org/aegypten/development.en.html#howto_import_external_certs)
+
eval `gpg-agent --daemon`
<br /><br />
+
First one has to obtain the Thawte Freemail certificate and install it into Firefox/Thunderbird. Export the certificate from Firefox/Thunderbird e.g. to "certbundle.p12" file and remember the passphrase.
+
  
Convert the file into PEM format:<br />
+
Also create the directory ~/.kde/shutdown/ and place another shell script in it
  $ openssl pkcs12 -in certbundle.p12 -out certbundle.pem -nodes
+
(e.g. again gpgagent.sh) with the following contents:
(use the export passphrase)
+
#!/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`
  
Extract the key: <br />
 
$ openssl pkcs12 -in certbundle.pem -export -out certkey.p12 -nocerts -nodes
 
  
Import the key into gpgsm:<br />
+
====Optional====
$ gpgsm --call-protect-tool --p12-import --store certkey.p12
+
You can also use keychain, ~/.xsession startup, or any other method to start
 +
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
 +
 
 +
 
 +
===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.
 +
<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 />
Line 52: Line 121:
  
  
===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. 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 />
  
 
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
  
 
<br />
 
<br />
gpg-agent is only necessary for caching the passphrase: "$HOME/.gnupg/gpg-agent.conf"<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).
  
pinentry-program /usr/bin/pinentry-qt
+
====Importing Thawte CRL and testing CRL support====
  default-cache-ttl 86400    # be aware that the passphrases will be cached for 86400 seconds! set accordingly to your need
+
As of 16th November 2009 all Thawte S/MIME certificates have been revoked. As
  max-cache-ttl 86400
+
dirmngr doesn't automatically work with the Thawte CRL, one has to import them
  disable-scdaemon
+
manually once. A working gpg-agent setup is again needed, then perform the
  allow-mark-trusted
+
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 />
 +
 +
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.
 +
<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 S/MIME plugin and problems/bugs===
+
===Working with Claws Mail S/MIME and problems/bugs===
I think because few people managed to get it to work properly there weren't many bug reports yet :) There are some things I encountered which don't work fine, e.g. keep in mind:
+
* 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.  
  
from the README:
+
* 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
WARNING: This plugin doesn't handle sign+encrypt and encryption of multipart messages very well (yet).
+
  
* That means if you encrypt and sign a message you get some header stuff in the body of the message and it will be a lot more garbage if you have attached files. Encrypting alone (without attachments) or signing alone (with or without attachments) works fine.
+
* Error message "Cannot sign: General error" usually means that there's something wrong with the gpg-agent (e.g. not running or wrong environment)
  
* I always have to choose my key twice in the "Select Keys" dialog when encrypting? 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.
+
* 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
  
* Although I added my own fingerprint to trustlist.txt CM always says that the recipient is not fully trusted when I send encrypted/signed emails.  
+
* 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 expired one you still want to keep to be able to decrypt older emails). It only shows the Key ID and no info about the 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 07: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).