README 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. Scute
  2. =====
  3. This is a PKCS #11 implementation for the GnuPG Agent using the GnuPG
  4. Smart Card Daemon. Currently, only the OpenPGP card is supported.
  5. TOC
  6. ===
  7. * Purpose
  8. * Prerequisites
  9. * Installation
  10. * Client Authentication
  11. * Troubleshooting
  12. * Features and Limitations
  13. * Development
  14. * Mozilla Bugs
  15. * Copyright and License
  16. Purpose
  17. =======
  18. Scute enables you to use your OpenPGP smart card for client
  19. authentication with SSL in Mozilla. See below for more details on how
  20. to get this working.
  21. In the future, Scute will enable you to use your OpenPGP smart card
  22. for email decryption and signing with Thunderbird, using the X.509
  23. protocol.
  24. Prerequisites
  25. =============
  26. For the compilation:
  27. * libgpg-error 1.4
  28. * libassuan 2.0.0
  29. At runtime:
  30. * Mozilla (or any other supported application using PKCS #11).
  31. * GnuPG 2.0, in particular: gpg-agent, scdaemon
  32. * Pinentry
  33. Installation
  34. ============
  35. To install the PKCS #11 Module, follow the generic installation
  36. instructions in the file INSTALL that accompanies this software. You
  37. also need to install the Mozilla Personal Security Manager (PSM),
  38. which may come with your GNU/Linux distribution in a package named
  39. mozilla-psm or similar.
  40. After installation, you can configure Mozilla to use Scute by
  41. visiting the preferences dialog in the "advanced" category, under
  42. "Security Devices". There you can "load" the module from its
  43. installed path, e.g. "/usr/lib/libscute.so".
  44. Note that for the module load to complete successfully, the GPG Agent
  45. must be running and available. On Unix systems this means that
  46. Mozilla needs to have the GPG_AGENT_INFO variable set correctly in its
  47. environment.
  48. Client Authentication
  49. =====================
  50. For client authentication to work, several steps need to be completed.
  51. Depending on your situation, some of these steps may be performed by
  52. third parties, like service providers. However, they can also all be
  53. performed locally, if use of client authentication with a local
  54. service is desired.
  55. For this introduction, we assume an Apache web server with SSL at the
  56. server side, and a connecting client running Firefox. As a
  57. certification authority (CA) we use OpenSSL. Scute provides a PKCS #11
  58. compatible security device to Firefox for client authentication. This
  59. security device gives Firefox access to the client's OpenPGP smart
  60. card.
  61. The Client Perspective
  62. ----------------------
  63. To get things started, we have to prepare an initialised OpenPGP smart
  64. card by uploading an off-card key or generating a key on the card.
  65. The card you got may already have been initialised. Otherwise, you
  66. can find more information on this step in the smartcard HowTo, which
  67. also documents other basic card operations:
  68. http://www.gnupg.org/(en)/howtos/card-howto/en/smartcard-howto.html
  69. Once the card is initialised, we have to generate a certificate
  70. signing request (CSR) to get the authentication key of the card
  71. (OPENPGP.3, the third key on the card) certified by the CA. This can
  72. be done using "gpgsm --gen-key". For the CSR, a distinguished name
  73. (DN) is required. Your CA will have more information about what this
  74. DN should contain. Below we use an example for a test-employee
  75. "Floppy Head" of the test-CA that ships with OpenSSL ("Snake Oil,
  76. Ltd.").
  77. Generating the CSR is then just a matter of answering a few questions:
  78. $ gpgsm --gen-key > client.csr
  79. Please select what kind of key you want:
  80. (1) RSA
  81. (2) Existing key
  82. (3) Existing key from card
  83. Your selection? 3
  84. Serial number of the card: 355F9746499F0D4B4ECEE4928B007D16
  85. Available keys:
  86. (1) D53137B94C38D9BF6A199706EA6D5253 OPENPGP.1
  87. (2) B0CD1A9DFC3539A1D6A8B851A11C8665 OPENPGP.2
  88. (3) 53DB41052CC590A40B403F3E6350E5DC OPENPGP.3
  89. Your selection? 3
  90. Possible actions for a RSA key:
  91. (1) sign, encrypt
  92. (2) sign
  93. (3) encrypt
  94. Your selection? 2
  95. Enter the X.509 subject name: CN=Floppy Head,OU="Webserver Team",O="Snake Oil, Ltd",L="Snake Town",ST="Snake Desert",C=XY
  96. Enter email addresses (end with an empty line):
  97. > floppy.head@example.org
  98. >
  99. Enter DNS names (optional; end with an empty line):
  100. >
  101. Enter URIs (optional; end with an empty line):
  102. >
  103. Create self-signed certificate? (y/N) n
  104. These parameters are used:
  105. Key-Type: card:OPENPGP.3
  106. Key-Length: 1024
  107. Key-Usage: sign
  108. Name-DN: CN=Floppy Head,OU="Webserver Team",O="Snake Oil, Ltd",L="Snake Town",ST="Snake Desert",C=XY
  109. Name-Email: floppy.head@example.org
  110. Proceed with creation? (y/N) y
  111. Now creating certificate request. This may take a while ...
  112. gpgsm: about to sign the CSR for key: &53DB41052CC590A40B403F3E6350E5DC
  113. gpgsm: certificate request created
  114. Ready. You should now send this request to your CA.
  115. It is required to enter the signing PIN of the card to complete this
  116. step. The certificate can then be found in the file "/tmp/floppy.csr".
  117. This file should then be sent to the CA for certification (see below).
  118. The CA will return to the client a certificate "/tmp/floppy.crt", who
  119. can then import the issuer certificate of the CA (in this example, we
  120. access directly the local server certificate) and its own certificate
  121. with gpgsm:
  122. $ gpgsm --import /etc/apache/ssl.crt/snakeoil-ca-rsa.crt
  123. gpgsm: total number processed: 1
  124. gpgsm: imported: 1
  125. marcus@ulysses:~/g10/projects/pkcs11-for-scdaemon/ca/usercert/card3$ gpgsm --import /tmp/floppy.crt
  126. gpgsm: total number processed: 1
  127. gpgsm: unchanged: 1
  128. $ gpgsm --list-keys Floppy
  129. Serial number: 08
  130. Issuer: /CN=Snake Oil CA/OU=Certificate Authority/O=Snake Oil, Ltd/L=Snake Town/ST=Snake Desert/C=XY/EMail=ca@snakeoil.dom
  131. Subject: /CN=Floppy Head/OU=Webserver Team/O=Snake Oil, Ltd/ST=Snake Desert/C=XY
  132. validity: 2006-10-11 13:17:08 through 2007-10-11 13:17:08
  133. key type: 1024 bit RSA
  134. fingerprint: C9:08:0E:86:92:6C:7B:4B:8C:23:1C:9D:D7:15:BF:D4:A4:00:54:11
  135. Now the client can configure his web browser. If desired, the client
  136. can install the web servers certificate (alternatively, Firefox will
  137. ask when establishing the initial connection).
  138. To actually perform the client authentication, the client needs to set
  139. up the web browser for use with Scute. The Scute PKCS #11 module,
  140. installed under /usr/lib/libscute.so by default, needs to be loaded as
  141. a security device in Firefox under
  142. Preferences->Advanced->Security->Certificates->Security Devices->Load
  143. When the security device is loaded, card insertion should cause the
  144. security device list be updated with the inserted token (the card), and the certificate that has been imported into gpgsm should be visible under
  145. Preferences->Advanced->Security->Certificates->View Certificates
  146. automatically.
  147. Firefox will by default select the certificate to be used for client
  148. authentication automatically from the list of available certificates.
  149. This setting can be changed if desired in
  150. Preferences->Advanced->Security->Certificates ("Select one
  151. automatically" vs. "Ask me every time")
  152. When the client then attempts to open the URL "https://localhost/" in
  153. this example, the web server will require SSL authentication, which
  154. causes Firefox to look (or ask) for a client certificate. If the
  155. certificate on the card is suitable (or selected), the user will have
  156. to enter the PIN number on the card to sign into the web site.
  157. The CA Perspective
  158. ------------------
  159. The CA will have to process the CSR submitted by the client. After
  160. verifying the identity of the submitter by some external means, the CA
  161. may use for example this OpenSSL command to create a certificate (we
  162. use the example CA shipping with the Apache SSL module on Ubuntu):
  163. # cd /etc/apache/ssl.crt/
  164. # openssl ca -in /tmp/floppy.csr -cert /etc/apache/ssl.crt/snakeoil-ca-rsa.crt -keyfile /etc/apache/ssl.key/snakeoil-ca-rsa.key -out /tmp/floppy.crt
  165. Using configuration from /usr/lib/ssl/openssl.cnf
  166. Check that the request matches the signature
  167. Signature ok
  168. Certificate Details:
  169. Serial Number: 8 (0x8)
  170. Validity
  171. Not Before: Oct 11 13:17:08 2006 GMT
  172. Not After : Oct 11 13:17:08 2007 GMT
  173. Subject:
  174. countryName = XY
  175. stateOrProvinceName = Snake Desert
  176. organizationName = Snake Oil, Ltd
  177. organizationalUnitName = Webserver Team
  178. commonName = Floppy Head
  179. X509v3 extensions:
  180. X509v3 Basic Constraints:
  181. CA:FALSE
  182. Netscape Comment:
  183. OpenSSL Generated Certificate
  184. X509v3 Subject Key Identifier:
  185. 72:AF:B8:13:3D:3D:9D:02:93:E4:D4:56:0C:06:90:4C:26:85:85:5D
  186. X509v3 Authority Key Identifier:
  187. DirName:/C=XY/ST=Snake Desert/L=Snake Town/O=Snake Oil, Ltd/OU=Certificate Authority/CN=Snake Oil CA/emailAddress=ca@snakeoil.dom
  188. serial:00
  189. Certificate is to be certified until Oct 11 13:17:08 2007 GMT (365 days)
  190. Sign the certificate? [y/n]:y
  191. 1 out of 1 certificate requests certified, commit? [y/n]y
  192. Write out database with 1 new entries
  193. Data Base Updated
  194. The resulting file, "/tmp/floppy.crt" is sent back from the CA to the
  195. client along with the issuer certificate.
  196. For more information how to set up and work with a CA using OpenSSL,
  197. please see the OpenSSL documentation.
  198. The Server Perspective
  199. ----------------------
  200. The service provider will set up an Apache web server with SSL
  201. support, and configure it to accept certificates from the CA. This
  202. step is quite involved. Garex has a concise HowTo online at
  203. http://www.garex.net/apache/ about how to do this. Beside the
  204. creation of a certificate that has its own fully qualified domain name
  205. (FQDN) as common name (CN part of the DN), this involves installing
  206. the Apache SSL module and configuration for it, for example in
  207. httpd.conf:
  208. SSLEngine on
  209. SSLCertificateFile /etc/apache/ssl.crt/server.crt
  210. SSLCertificateKeyFile /etc/apache/ssl.key/server.key
  211. SSLVerifyClient require
  212. SSLVerifyDepth 1
  213. SSLCACertificateFile /etc/apache/ssl.crt/snakeoil-ca-rsa.crt
  214. The file server.key is not protected by a passphrase (if it is, this
  215. passphrase needs to be provided when starting up Apache), and
  216. server.crt has "CN=localhost" as part of its DN for this example.
  217. Troubleshooting
  218. ===============
  219. Symptom: Loading the Scute security device in the security device
  220. manager of Firefox fails with "Unable to load module".
  221. Solution: Make sure that Scute is correctly installed, and that all
  222. libraries and executables are available. Make sure that gpg-agent is
  223. running and can be found via the environment variable GPG_AGENT_INFO.
  224. Symptom: Client authentication fails with "<example.com> has received
  225. an incorrect or unexpected message. Error code: -12227".
  226. Solution: Make sure that the correct OpenPGP card is inserted and the
  227. certificate available in GPGSM. Check that the OpenPGP card is
  228. detected correctly in the security device manager and the
  229. corresponding certificate is displayed in the certificate manager of
  230. Firefox.
  231. Symptom: The OpenPGP card is detected and displayed in the security
  232. device manager in Firefox, but no corresponding certificate is
  233. displayed in the certificate manager of Firefox.
  234. Solution: Make sure that the corresponding certificate is imported in
  235. GPGSM.
  236. Features and Limitations
  237. ========================
  238. Scute implements version 2.20 of the PKCS #11 specification.
  239. The OpenPGP smart card application is supported in read-only mode.
  240. The following functions are not supported:
  241. * C_Initialize: No support for native thread package. Locking
  242. callbacks must be provided if multi-threaded operation is desired.
  243. * C_WaitForSlotEvent: Not implemented. The interface as specified by
  244. PKCS #11 is broken anyway, as the function can not safely be
  245. canceled. Thus, we require polling.
  246. * C_GetOperationState, C_SetOperationState: Not supported.
  247. * C_InitToken, C_InitPIN, C_SetPIN: Not supported. No write
  248. operations are allowed. To configure the token, please use the
  249. tools accompanying the GnuPG software suite.
  250. * C_Login, C_Logout: Not supported. No login into the token by the
  251. software is required. Passphrase queries are implemented by the use
  252. of GPG Agent and Pinentry.
  253. * C_EncryptInit, C_Encrypt, C_EncryptUpdate, C_EncryptFinal,
  254. C_DigestInit, C_Digest, C_DigestUpdate, C_DigestKey, C_DigestFinal,
  255. C_VerifyInit, C_Verify, C_VerifyUpdate, C_VerifyFinal,
  256. C_VerifyRecoverInit, C_VerifyRec: Not supported. Only secret key
  257. operations are supported.
  258. * C_SignInit, C_Sign: Currently, only signing 36 bytes
  259. (MD5+SHA1) hashes is supported (used for client authentication).
  260. * C_DecryptInit, C_Decrypt: Not yet supported, but will be in the
  261. future.
  262. * C_SignUpdate, C_SignFinal, C_DecryptUpdate, C_DecryptFinal: No
  263. progressive crypto-operations are supported.
  264. * C_SignRecoverInit, C_SignRecover: Not supported.
  265. * C_DigestEncryptUpdate, C_DecryptDigestUpdate, C_SignEncryptUpdate,
  266. C_DecryptVerifyUpdate: Dual-purpose cryptographic functions are not
  267. supported.
  268. * C_GenerateKey, C_GenerateKeyPair, C_WrapKey, C_UnwrapKey,
  269. C_DeriveKey: Key management functions are not supported. Please use
  270. the tools accompanying the GnuPG software suite to generate and
  271. import keys for use with the token.
  272. * C_SeedRandom, C_GenerateRandom: Not supported at this point.
  273. C_GenerateRandom may be supported in the future, though.
  274. * C_CreateObject, C_CopyObject, C_DestroyObject, C_SetAttributeValue:
  275. Only read-only operations are supported on objects.
  276. * C_GetObjectSize: Not supported.
  277. * CKO_CERTIFICATE:
  278. The label specifies the key on the card used (e.g. OPENPGP.3). The
  279. ID is the fingerprint.
  280. * CKO_PRIVATE_KEY:
  281. The CKA_LOCAL attribute can not be supported by the OpenPGP card.
  282. It is always set to false (as the key on the card may be copied to
  283. the card from an external source).
  284. Development
  285. ===========
  286. Scute is single-threaded. There is a global lock that is taken in all
  287. entry points of Scute, except for C_Initialize, C_Finalize,
  288. C_GetFunctionList, and stubs.
  289. Here are a couple of hints on how to develop PKCS #11 modules for
  290. Mozilla:
  291. libopensc2 ships with a pkcs11-spy library that can be loaded as a
  292. wrapper around the PKCS #11 library you want to use to log all
  293. functions invoked by Mozilla. Here is how to use it:
  294. Set the PKCS11SPY_OUTPUT environment variable to a filename.
  295. pkcs11-spy appends its log messages at the end of this file. Set the
  296. PKCS11SPY environment variable to the filename of the PKCS #11 module
  297. you actually want to use. Start Mozilla within this environment.
  298. There is a different, probably more powerful way to debug Mozilla PKCS
  299. #11 libraries. However, to be able to use it, you need to configure
  300. and compile the Mozilla NSS sources with --enable-debug. Instructions
  301. can be found at:
  302. http://www.mozilla.org/projects/security/pki/nss/tech-notes/tn2.html
  303. Here are a couple of links to more information about implementing a
  304. PKCS #11 module for Mozilla:
  305. Implementing PKCS #11 for the Netscape Security Library
  306. (Caution: The content may be out of date)
  307. http://docs.sun.com/source/816-6150-10/index.htm
  308. http://docs.sun.com/source/816-6150-10/pkcs.htm
  309. Common PKCS #11 Implementation Problems
  310. http://www.mozilla.org/projects/security/pki/pkcs11/netscape/problems.html
  311. PKCS #11 Conformance Testing
  312. http://www.mozilla.org/projects/security/pki/pkcs11/
  313. And of course the Mozilla NSS web page:
  314. http://www.mozilla.org/projects/security/pki/nss/
  315. Mozilla Bugs
  316. ============
  317. Mozilla has a bug that causes the security devices list to become
  318. corrupt when a security device is unloaded: The wrong entry is removed
  319. from the list. This is corrected by waiting for a refresh or closing
  320. and reopening the security device manager.
  321. Copyright and License
  322. =====================
  323. Scute is copyrighted by g10 Code GmbH and licensed under the GNU
  324. General Pubic License version 2 or later with this exception:
  325. In addition, as a special exception, g10 Code GmbH gives permission
  326. to link this library: with the Mozilla Foundation's code for
  327. Mozilla (or with modified versions of it that use the same license
  328. as the "Mozilla" code), and distribute the linked executables. You
  329. must obey the GNU General Public License in all respects for all of
  330. the code used other than "Mozilla". If you modify the software, you
  331. may extend this exception to your version of the software, but you
  332. are not obligated to do so. If you do not wish to do so, delete this
  333. exception statement from your version and from all source files.
  334. g10 Code GmbH
  335. marcus@g10code.com
  336. Copyright 2006, 2009 g10 Code GmbH
  337. This file is free software; as a special exception the author gives
  338. unlimited permission to copy and/or distribute it, with or without
  339. modifications, as long as this notice is preserved.
  340. This file is distributed in the hope that it will be useful, but
  341. WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  342. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.