README 15 KB

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