pkcs11.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <PAGE>
  2. <INCLUDE file="inc/header.tmpl" />
  3. <VAR match="VAR_SEL_FEATURES" replace="selected" />
  4. <VAR match="VAR_SEL_FEATURE_PKCS11" replace="selected" />
  5. <PARSE file="menu1.xml" />
  6. <PARSE file="menu2-features.xml" />
  7. <INCLUDE file="inc/content.tmpl" />
  8. <h1>Smart Card / PKCS#11 support</h1>
  9. <p>OpenConnect supports the use of X.509 certificates and keys from
  10. smart cards <i>(as well as software storage such as GNOME Keyring and
  11. SoftHSM)</i> by means of the PKCS#11 standard. Objects from PKCS#11 tokens
  12. are specified by a PKCS#11 URI according to
  13. <a href="https://tools.ietf.org/html/rfc7512">RFC 7512</a>.</p>
  14. <p>In order to use a certificate or key with OpenConnect, you must
  15. provide a PKCS#11 URI which identifies it sufficiently. That can be as simple
  16. as the following example:
  17. <ul><li> <tt>openconnect -c <i>pkcs11:id=%01</i> vpn.example.com</tt></li></ul>
  18. However, if you're now looking blankly at a USB crypto device and
  19. wondering what PKCS#11 URI to use, the following documentation should
  20. hopefully assist you in working it out.</p>
  21. <h2>Identifying the token</h2>
  22. <p>In order to use a PKCS#11 token with OpenConnect, first it must be installed
  23. appropriately in the system's
  24. <a href="https://p11-glue.github.io/p11-glue/p11-kit/manual/config.html">p11-kit configuration</a>.
  25. You shouldn't need to worry about this; it should automatically be the case for
  26. properly packaged software on any modern operating system.</p>
  27. <p>Typically, the smart card support is likely to be
  28. provided by <a href="https://github.com/OpenSC/OpenSC/wiki">OpenSC</a> and a
  29. distribution's packaging of OpenSC should automatically have registered
  30. the OpenSC module with p11-kit by creating a file such as
  31. <tt>/usr/share/p11-kit/modules/opensc.module</tt>.</p>
  32. <p>In order to query the available PKCS#11 modules, and the certificates
  33. stored therein, the best tool to use is the
  34. <a href="https://www.gnutls.org/manual/html_node/p11tool-Invocation.html">p11tool</a>
  35. distributed with GnuTLS. In Fedora it's in the <tt>gnutls-utils</tt> package.</p>
  36. <p>First identify the PKCS#11 modules which are available by using the <tt>--list-tokens</tt> option:</p>
  37. <ul><li><tt>p11tool --list-tokens</tt></li></ul>
  38. This should produce output including something like the following:
  39. <table border="1"><tr><td><pre>
  40. Token 7:
  41. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29
  42. Label: PIV_II (PIV Card Holder pin)
  43. Type: Hardware token
  44. Manufacturer: piv_II
  45. Model: PKCS#15 emulated
  46. Serial: 108421384210c3f5
  47. </pre></td></tr></table>
  48. <p>This example shows the relatively common <a href="https://www.opensc-project.org/opensc/wiki/UnitedStatesPIV">PIV</a>
  49. SmartCard, in this case in a <a href="https://developers.yubico.com/yubico-piv-tool/YubiKey-NEO-PIV-Introduction.html">Yubikey NEO</a> device.</p>
  50. <h2>Locating the certificate</h2>
  51. <p>Having established that the token is present and registered correctly with p11-kit, the next
  52. step is to identify the URI of the certificate you wish to use. You will note that
  53. the above output of <tt>p11tool --list-tokens</tt> gave a PKCS#11 URI for each token.
  54. With that, we can now query the objects available <em>within</em> a specific token, using the <tt>--list-all-certs</tt>
  55. option. We can cut and paste the PKCS#11 URI for the token, but be careful to put it within
  56. quotes because it contains semicolons:</p>
  57. <ul><li><tt>p11tool --list-all-certs 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29'</tt></li></ul>
  58. <p>Note that the PKCS#11 URI specifies a list of attributes which must
  59. match. Some of these match criteria may be redundant — in this case
  60. we've asked it to list the certificates in a token
  61. which has a model of <i>"PKCS#15 emulated"</i> <b>and</b> a
  62. manufacturer of <i>"piv_II"</i> <b>and</b> serial number
  63. <i>108421384210c3f5</i> <b>and</b> token label <i>"PIV_II (PIV Card
  64. Holder pin)"</i>. Since any <em>one</em> of those criteria would probably
  65. be sufficient to uniquely identify this token from the other configured tokens
  66. in our system, a simpler command line would also work. For example:</p>
  67. <ul><li><tt>p11tool --list-all-certs pkcs11:manufacturer=piv_II</tt></li></ul>
  68. The output of either such command should look something like this:
  69. <table border="1"><tr><td><pre>Object 0:
  70. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%01;object=Certificate%20for%20PIV%20Authentication;object-type=cert
  71. Type: X.509 Certificate
  72. Label: Certificate for PIV Authentication
  73. ID: 01
  74. Object 1:
  75. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%02;object=Certificate%20for%20Digital%20Signature;object-type=cert
  76. Type: X.509 Certificate
  77. Label: Certificate for Digital Signature
  78. ID: 02
  79. Object 2:
  80. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%03;object=Certificate%20for%20Key%20Management;object-type=cert
  81. Type: X.509 Certificate
  82. Label: Certificate for Key Management
  83. ID: 03
  84. Object 3:
  85. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%04;object=Certificate%20for%20Card%20Authentication;object-type=cert
  86. Type: X.509 Certificate
  87. Label: Certificate for Card Authentication
  88. ID: 04
  89. </pre></td></tr></table>
  90. <p>This device has four certificates installed; the URL for each one
  91. is given in the output. <i>(Choosing <em>between</em> the certificates on
  92. a given device, if there is more than one, is left as an exercise for
  93. the user. You may need to try each one.)</i></p>
  94. <p>Some devices may not even permit you to list the certificates
  95. without logging in. In that case add <tt>--login</tt> to the
  96. <tt>p11tool</tt> command line above, and provide the PIN when
  97. requested</p>
  98. <p>For OpenConnect 7.01 we should be able to use the URI seen here in
  99. its entirety, and the software will be cunning enough to
  100. find the corresponding key:
  101. <ul><li><tt>openconnect -c 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%01;object=Certificate%20for%20PIV%20Authentication;object-type=cert' vpn.example.com</tt></li></ul>
  102. Older versions, however, may require a little help...</p>
  103. <h2>Helping OpenConnect find the key</h2>
  104. <p>If no explicit <tt>-k</tt> argument is given to specify the key,
  105. OpenConnect will use the contents of the <tt>-c</tt> argument as the
  106. basis for finding <em>both</em> certificate and key.</p>
  107. <p>It will sensibly add <tt>object-type=cert</tt> or <tt>object-type=private</tt>
  108. for itself, according to which object it is trying to locate each time. But in
  109. version 7.00 and earlier, it would <em>not</em> do that if the URI you provide
  110. already contained any <tt>object-type=</tt> element. So the first thing you need to do with
  111. older versions of OpenConnect is trim that part of the URI. So the above example might now be:
  112. <ul><li><tt>openconnect -c 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%01;object=Certificate%20for%20PIV%20Authentication' vpn.example.com</tt></li></ul>
  113. </p>
  114. <p>Additionally, it can sometimes be the case that although the ID
  115. (<tt>id=</tt>) for a certificate should match the ID of its matching
  116. key, the label (<tt>object=</tt>) might <em>not</em> match. Newer versions
  117. of OpenConnect (7.01+), on failing to find a key, will <em>strip</em> the label
  118. from the search URI and add the ID of the certificate that was found (even if
  119. no ID was part of the original search terms provided with the <tt>-c</tt> option). But older versions don't.</p>
  120. <p>So it can be useful also to remove the <tt>object=</tt> part of the URI and leave only the <tt>id=</tt> attribute to specify the individual object, so that you're giving search criteria which are true for both the certificate <em>and</em> the key:
  121. <ul><li><tt>openconnect -c 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%01' vpn.example.com</tt></li></ul>
  122. </p>
  123. <p>And while we're at it, that's <em>still</em> a massively redundant way of specifying which token
  124. to look in, so we can cut that down as we did before just to make it less unwieldy:
  125. <ul><li><tt>openconnect -c 'pkcs11:manufacturer=piv_II;id=%01' vpn.example.com</tt></li></ul>
  126. <h2>Searching for the key manually</h2>
  127. <p>If the heuristics for finding the key don't work, you can always
  128. provide an explicit PKCS#11 URI for the key with the <tt>-k</tt>
  129. option. You can look for them by using the <tt>--list-privkeys</tt> option to <tt>p11tool</tt>. You will almost certainly want to use the <tt>--login</tt> option too:</p>
  130. <ul><li><tt>p11tool --list-privkeys --login pkcs11:manufacturer=piv_II</tt></li></ul>
  131. <table border="1"><tr><td><pre>Token 'PIV_II (PIV Card Holder pin)' with URL 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29' requires user PIN
  132. Enter PIN:
  133. Object 0:
  134. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%01;object=PIV%20AUTH%20key;object-type=private
  135. Type: Private key
  136. Label: PIV AUTH key
  137. Flags: CKA_WRAP/UNWRAP; CKA_PRIVATE; CKA_SENSITIVE;
  138. ID: 01
  139. Object 1:
  140. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%02;object=SIGN%20key;object-type=private
  141. Type: Private key
  142. Label: SIGN key
  143. Flags: CKA_PRIVATE; CKA_SENSITIVE;
  144. ID: 02
  145. Object 2:
  146. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%03;object=KEY%20MAN%20key;object-type=private
  147. Type: Private key
  148. Label: KEY MAN key
  149. Flags: CKA_WRAP/UNWRAP; CKA_PRIVATE; CKA_SENSITIVE;
  150. ID: 03
  151. Object 3:
  152. URL: pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%04;object=CARD%20AUTH%20key;object-type=private
  153. Type: Private key
  154. Label: CARD AUTH key
  155. Flags: CKA_SENSITIVE;
  156. ID: 04
  157. </pre></td></tr></table>
  158. <p>
  159. Here's the full longhand specification of both certificate <em>and</em> key:
  160. <ul><li><tt>openconnect -c 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%01;object=Certificate%20for%20PIV%20Authentication;object-type=cert' -k 'pkcs11:model=PKCS%2315%20emulated;manufacturer=piv_II;serial=108421384210c3f5;token=PIV_II%20%28PIV%20Card%20Holder%20pin%29;id=%01;object=PIV%20AUTH%20key;object-type=private' vpn.example.com</tt></li></ul>
  161. OpenConnect doesn't care; you can use certificate and key from entirely
  162. <em>different</em> hardware tokens if you want to. Or one from a file. Or a key
  163. from a TPM and a certificate from a PKCS#11 hardware token. Or all kinds of bizarre combinations. But if it's a <em>sensible</em> combination on a sanely configured PKCS#11 token, and OpenConnect can't infer the key location from the certificate, then please <a href="mail.html">send us an email</a> and we'll try to fix it.</p>
  164. </p>
  165. <INCLUDE file="inc/footer.tmpl" />
  166. </PAGE>