You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

377 lines
14 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. ## What's wrong with ED25519 and Yubikey 5 ?
  2. #### TL;DR :
  3. In the last weeks, I tried to setup ed25519 gnupg keys for use with SSH on my new Yubikey 5C NFC. It works like a charm but when used with an SSH certificate, the authentication failed with an error like :
  4. sign_and_send_pubkey: signing failed for ED25519 "cardno:000615280015": agent refused operation
  5. Let's try it. For this demo, I'll let the Yubikey generate GnuPG's keys. This is easier to setup but not recommended in production as the master key can't be reused to generate other keys.
  6. (see here [https://support.yubico.com/hc/en-us/articles/360013790259-Using-Your-YubiKey-with-OpenPGP](https://support.yubico.com/hc/en-us/articles/360013790259-Using-Your-YubiKey-with-OpenPGP))
  7. Here's how to reproduce the error :
  8. <pre>
  9. $ <b>rm -R .gnupg</b>
  10. $ <b>rm -R .ssh</b>
  11. $ <b>ykman openpgp reset</b>
  12. WARNING! This will delete all stored OpenPGP keys and data and restore factory settings? [y/N]: <b>y</b>
  13. Resetting OpenPGP data, don't remove your YubiKey...
  14. Success! All data has been cleared and default PINs are set.
  15. PIN: 123456
  16. Reset code: NOT SET
  17. Admin PIN: 12345678
  18. </pre>
  19. Good, let's start with key generation :
  20. <pre>
  21. $ <b>gpg --card-edit</b>
  22. gpg: directory '/home/user/.gnupg' created
  23. gpg: keybox '/home/user/.gnupg/pubring.kbx' created
  24. Reader ...........: Yubico YubiKey OTP FIDO CCID 00 00
  25. Application ID ...: D2760001240103040006152800150000
  26. Application type .: OpenPGP
  27. Version ..........: 3.4
  28. Manufacturer .....: Yubico
  29. Serial number ....: 15280015
  30. Name of cardholder: [not set]
  31. Language prefs ...: [not set]
  32. Salutation .......:
  33. URL of public key : [not set]
  34. Login data .......: [not set]
  35. Signature PIN ....: not forced
  36. Key attributes ...: rsa2048 rsa2048 rsa2048
  37. Max. PIN lengths .: 127 127 127
  38. PIN retry counter : 3 0 3
  39. Signature counter : 0
  40. KDF setting ......: off
  41. Signature key ....: [none]
  42. Encryption key....: [none]
  43. Authentication key: [none]
  44. General key info..: [none]
  45. gpg/card> <b>admin</b>
  46. Admin commands are allowed
  47. gpg/card> <b>key-attr</b>
  48. Changing card key attribute for: Signature key
  49. Please select what kind of key you want:
  50. (1) RSA
  51. (2) ECC
  52. Your selection? <b>2</b>
  53. Please select which elliptic curve you want:
  54. (1) Curve 25519
  55. (4) NIST P-384
  56. Your selection? <b>1</b>
  57. The card will now be re-configured to generate a key of type: ed25519
  58. Note: There is no guarantee that the card supports the requested size.
  59. If the key generation does not succeed, please check the
  60. documentation of your card to see what sizes are allowed.
  61. Changing card key attribute for: Encryption key
  62. Please select what kind of key you want:
  63. (1) RSA
  64. (2) ECC
  65. Your selection? <b>2</b>
  66. Please select which elliptic curve you want:
  67. (1) Curve 25519
  68. (4) NIST P-384
  69. Your selection? <b>1</b>
  70. The card will now be re-configured to generate a key of type: cv25519
  71. Changing card key attribute for: Authentication key
  72. Please select what kind of key you want:
  73. (1) RSA
  74. (2) ECC
  75. Your selection? <b>2</b>
  76. Please select which elliptic curve you want:
  77. (1) Curve 25519
  78. (4) NIST P-384
  79. Your selection? <b>1</b>
  80. The card will now be re-configured to generate a key of type: ed25519
  81. gpg/card> <b>generate</b>
  82. Make off-card backup of encryption key? (Y/n) n
  83. Please note that the factory settings of the PINs are
  84. PIN = '123456' Admin PIN = '12345678'
  85. You should change them using the command --change-pin
  86. Please specify how long the key should be valid.
  87. 0 = key does not expire
  88. <n> = key expires in n days
  89. <n>w = key expires in n weeks
  90. <n>m = key expires in n months
  91. <n>y = key expires in n years
  92. Key is valid for? (0)
  93. Key does not expire at all
  94. Is this correct? (y/N) <b>y</b>
  95. GnuPG needs to construct a user ID to identify your key.
  96. Real name: <b>Dummy</b>
  97. Email address: <b>dummy@dummy.co</b>
  98. Comment:
  99. You selected this USER-ID:
  100. "Dummy <dummy@dummy.co>"
  101. Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? <b>O</b>
  102. gpg: /home/user/.gnupg/trustdb.gpg: trustdb created
  103. gpg: key B4A67FB911B1ED6B marked as ultimately trusted
  104. gpg: directory '/home/user/.gnupg/openpgp-revocs.d' created
  105. gpg: revocation certificate stored as '/home/user/.gnupg/openpgp-revocs.d/A157C7E15F3D6C7445B40626B4A67FB911B1ED6B.rev'
  106. public and secret key created and signed.
  107. gpg/card> <b>list</b>
  108. Reader ...........: Yubico YubiKey OTP FIDO CCID 00 00
  109. Application ID ...: D2760001240103040006152800150000
  110. Application type .: OpenPGP
  111. Version ..........: 3.4
  112. Manufacturer .....: Yubico
  113. Serial number ....: 15280015
  114. Name of cardholder: [not set]
  115. Language prefs ...: [not set]
  116. Salutation .......:
  117. URL of public key : [not set]
  118. Login data .......: [not set]
  119. Signature PIN ....: not forced
  120. Key attributes ...: ed25519 cv25519 ed25519
  121. Max. PIN lengths .: 127 127 127
  122. PIN retry counter : 3 0 3
  123. Signature counter : 4
  124. KDF setting ......: off
  125. Signature key ....: A157 C7E1 5F3D 6C74 45B4 0626 B4A6 7FB9 11B1 ED6B
  126. created ....: 2020-10-05 09:45:47
  127. Encryption key....: 2B46 118B DEB3 4AAC 4951 63DE 286C 74DF 1104 5D46
  128. created ....: 2020-10-05 09:45:47
  129. Authentication key: FFE2 8767 DD98 CD3F 587A 19F9 B1B9 E836 16EF 39E7
  130. created ....: 2020-10-05 09:45:47
  131. General key info..:
  132. pub ed25519/B4A67FB911B1ED6B 2020-10-05 Dummy <dummy@dummy.co>
  133. sec> ed25519/B4A67FB911B1ED6B created: 2020-10-05 expires: never
  134. card-no: 0006 15280015
  135. ssb> ed25519/B1B9E83616EF39E7 created: 2020-10-05 expires: never
  136. card-no: 0006 15280015
  137. ssb> cv25519/286C74DF11045D46 created: 2020-10-05 expires: never
  138. card-no: 0006 15280015
  139. gpg/card> <b>quit</b>
  140. pub ed25519 2020-10-05 [SC]
  141. A157C7E15F3D6C7445B40626B4A67FB911B1ED6B
  142. uid Dummy <dummy@dummy.co>
  143. sub ed25519 2020-10-05 [A]
  144. sub cv25519 2020-10-05 [E]
  145. $ <b>ssh-add -L</b>
  146. ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGzO7860chQPMw0NuLDhBqZd1IcfIqBnvy4GSbzZd4vu cardno:000615280015
  147. $ <b>mkdir sshca</b>
  148. $ <b>ssh-keygen -t ed25519 -N '' -C 'Test CA' -f sshca/ca</b>
  149. $ <b>cat sshca/ca.pub</b>
  150. ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICAL7l1sQuKe4daLfKGZuiRPZZXquokQyH+p6utlZxZ+ Test CA
  151. $ <b>ssh-add -L > sshca/id_ed25519.pub</b>
  152. $ <b>ssh-keygen -s sshca/ca -I test-dummy sshca/id_ed25519.pub</b>
  153. Signed user key sshca/id_ed25519-cert.pub: id "test-dummy" serial 0 valid forever
  154. $ <b>mkdir ~/.ssh</b>
  155. $ <b>cp sshca/id_ed25519-cert.pub ~/.ssh/</b>
  156. $ <b>ssh-keygen -Lf .ssh/id_ed25519-cert.pub</b>
  157. .ssh/id_ed25519-cert.pub:
  158. Type: ssh-ed25519-cert-v01@openssh.com user certificate
  159. Public key: ED25519-CERT SHA256:fuoQ5RdcNRAj0VAyw/vqA584nNW2HMYNGk4NQEFjTSM
  160. Signing CA: ED25519 SHA256:2PibPv047BiDZQgl51bKRnY2ZXpcbAP1g7GjAZ0DArI (using ssh-ed25519)
  161. Key ID: "test-dummy"
  162. Serial: 0
  163. Valid: forever
  164. Principals: (none)
  165. Critical Options: (none)
  166. Extensions:
  167. permit-X11-forwarding
  168. permit-agent-forwarding
  169. permit-port-forwarding
  170. permit-pty
  171. permit-user-rc
  172. </pre>
  173. At this point, you have to copy the CA's public key into your server's authorized_keys file . This can't be done with ssh-copy-id as the CA's key is not loaded into you ssh-agent nor available in the ~/.ssh directory.
  174. You should have something like :
  175. <pre>
  176. server:~# <b>cat .ssh/authorized_keys</b>
  177. cert-authority ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICAL7l1sQuKe4daLfKGZuiRPZZXquokQyH+p6utlZxZ+ Test CA
  178. </pre>
  179. Note the line beginning with cert-authority which is not common. For reference, read "AUTHORIZED_KEYS FILE FORMAT" chapter here : [http://man.he.net/man5/authorized_keys](http://man.he.net/man5/authorized_keys)
  180. Now, try to login :
  181. <pre>
  182. $ <b>ssh root@server</b>
  183. sign_and_send_pubkey: signing failed for ED25519 "cardno:000615280015": agent refused operation
  184. Password:
  185. </pre>
  186. So we're completely out of luck : authentication doesn't works.
  187. For comparison, let's try with an NIST P384 key :
  188. <pre>
  189. $ <b>ykman openpgp reset</b>
  190. WARNING! This will delete all stored OpenPGP keys and data and restore factory settings? [y/N]: y
  191. Resetting OpenPGP data, don't remove your YubiKey...
  192. Success! All data has been cleared and default PINs are set.
  193. PIN: 123456
  194. Reset code: NOT SET
  195. Admin PIN: 12345678
  196. $ <b>rm -R .gnupg</b>
  197. $ <b>rm -R .ssh</b>
  198. $ <b>gpg --card-edit</b>
  199. Reader ...........: Yubico YubiKey OTP FIDO CCID 00 00
  200. Application ID ...: D2760001240103040006152800150000
  201. Application type .: OpenPGP
  202. Version ..........: 3.4
  203. Manufacturer .....: Yubico
  204. Serial number ....: 15280015
  205. Name of cardholder: [not set]
  206. Language prefs ...: [not set]
  207. Salutation .......:
  208. URL of public key : [not set]
  209. Login data .......: [not set]
  210. Signature PIN ....: not forced
  211. Key attributes ...: rsa2048 rsa2048 rsa2048
  212. Max. PIN lengths .: 127 127 127
  213. PIN retry counter : 3 0 3
  214. Signature counter : 0
  215. KDF setting ......: off
  216. Signature key ....: [none]
  217. Encryption key....: [none]
  218. Authentication key: [none]
  219. General key info..: [none]
  220. gpg/card> <b>admin</b>
  221. Admin commands are allowed
  222. gpg/card> <b>key-attr</b>
  223. Changing card key attribute for: Signature key
  224. Please select what kind of key you want:
  225. (1) RSA
  226. (2) ECC
  227. Your selection? <b>2</b>
  228. Please select which elliptic curve you want:
  229. (1) Curve 25519
  230. (4) NIST P-384
  231. Your selection? <b>4</b>
  232. The card will now be re-configured to generate a key of type: nistp384
  233. Note: There is no guarantee that the card supports the requested size.
  234. If the key generation does not succeed, please check the
  235. documentation of your card to see what sizes are allowed.
  236. Changing card key attribute for: Encryption key
  237. Please select what kind of key you want:
  238. (1) RSA
  239. (2) ECC
  240. Your selection? <b>2</b>
  241. Please select which elliptic curve you want:
  242. (1) Curve 25519
  243. (4) NIST P-384
  244. Your selection? <b>4</b>
  245. The card will now be re-configured to generate a key of type: nistp384
  246. Changing card key attribute for: Authentication key
  247. Please select what kind of key you want:
  248. (1) RSA
  249. (2) ECC
  250. Your selection? <b>2</b>
  251. Please select which elliptic curve you want:
  252. (1) Curve 25519
  253. (4) NIST P-384
  254. Your selection? <b>4</b>
  255. The card will now be re-configured to generate a key of type: nistp384
  256. gpg/card> <b>generate</b>
  257. Make off-card backup of encryption key? (Y/n) <b>n</b>
  258. Please note that the factory settings of the PINs are
  259. PIN = '123456' Admin PIN = '12345678'
  260. You should change them using the command --change-pin
  261. Please specify how long the key should be valid.
  262. 0 = key does not expire
  263. <n> = key expires in n days
  264. <n>w = key expires in n weeks
  265. <n>m = key expires in n months
  266. <n>y = key expires in n years
  267. Key is valid for? (0)
  268. Key does not expire at all
  269. Is this correct? (y/N) <b>y</b>
  270. GnuPG needs to construct a user ID to identify your key.
  271. Real name: <b>Dummy</b>
  272. Email address: <b>dummy@dummy.co</b>
  273. Comment:
  274. You selected this USER-ID:
  275. "Dummy <dummy@dummy.co>"
  276. Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? <b>o</b>
  277. gpg: /home/user/.gnupg/trustdb.gpg: trustdb created
  278. gpg: key BA792909F5154B7A marked as ultimately trusted
  279. gpg: directory '/home/user/.gnupg/openpgp-revocs.d' created
  280. gpg: revocation certificate stored as '/home/user/.gnupg/openpgp-revocs.d/B591751A56B42EA25C8BEF60BA792909F5154B7A.rev'
  281. public and secret key created and signed.
  282. gpg/card> <b>list</b>
  283. Reader ...........: Yubico YubiKey OTP FIDO CCID 00 00
  284. Application ID ...: D2760001240103040006152800150000
  285. Application type .: OpenPGP
  286. Version ..........: 3.4
  287. Manufacturer .....: Yubico
  288. Serial number ....: 15280015
  289. Name of cardholder: [not set]
  290. Language prefs ...: [not set]
  291. Salutation .......:
  292. URL of public key : [not set]
  293. Login data .......: [not set]
  294. Signature PIN ....: not forced
  295. Key attributes ...: nistp384 nistp384 nistp384
  296. Max. PIN lengths .: 127 127 127
  297. PIN retry counter : 3 0 3
  298. Signature counter : 4
  299. KDF setting ......: off
  300. Signature key ....: B591 751A 56B4 2EA2 5C8B EF60 BA79 2909 F515 4B7A
  301. created ....: 2020-10-05 10:04:12
  302. Encryption key....: F087 DFD0 65E8 AFE3 8835 41EA 062D F688 F54D 721D
  303. created ....: 2020-10-05 10:04:12
  304. Authentication key: 8556 35FB BFD2 E642 8CFC D41B 47B0 098B 165E 8325
  305. created ....: 2020-10-05 10:04:12
  306. General key info..:
  307. pub nistp384/BA792909F5154B7A 2020-10-05 Dummy <dummy@dummy.co>
  308. sec> nistp384/BA792909F5154B7A created: 2020-10-05 expires: never
  309. card-no: 0006 15280015
  310. ssb> nistp384/47B0098B165E8325 created: 2020-10-05 expires: never
  311. card-no: 0006 15280015
  312. ssb> nistp384/062DF688F54D721D created: 2020-10-05 expires: never
  313. card-no: 0006 15280015
  314. gpg/card> <b>quit</b>
  315. pub nistp384 2020-10-05 [SC]
  316. B591751A56B42EA25C8BEF60BA792909F5154B7A
  317. uid Dummy <dummy@dummy.co>
  318. sub nistp384 2020-10-05 [A]
  319. sub nistp384 2020-10-05 [E]
  320. $ <b>ssh-add -L > sshca/id_ecdsa.pub</b>
  321. $ <b>ssh-keygen -s sshca/ca -I test-dummy sshca/id_ecdsa.pub</b>
  322. Signed user key sshca/id_ecdsa-cert.pub: id "test-dummy" serial 0 valid forever
  323. $ <b>cp sshca/id_ecdsa-cert.pub ~/.ssh/</b>
  324. $ <b>ssh-keygen -Lf .ssh/id_ecdsa-cert.pub</b>
  325. .ssh/id_ecdsa-cert.pub:
  326. Type: ecdsa-sha2-nistp384-cert-v01@openssh.com user certificate
  327. Public key: ECDSA-CERT SHA256:N3JmjLOQ5VClsChOlmeyh5a8kF0RCMdAOz1VWde8lwk
  328. Signing CA: ED25519 SHA256:2PibPv047BiDZQgl51bKRnY2ZXpcbAP1g7GjAZ0DArI (using ssh-ed25519)
  329. Key ID: "test-dummy"
  330. Serial: 0
  331. Valid: forever
  332. Principals: (none)
  333. Critical Options: (none)
  334. Extensions:
  335. permit-X11-forwarding
  336. permit-agent-forwarding
  337. permit-port-forwarding
  338. permit-pty
  339. permit-user-rc
  340. $ <b>ssh root@server</b>
  341. Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)
  342. root@server:~#
  343. </pre>
  344. **Authentication is working as expected here !**