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
  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 ED25519 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. Let's make things clear :
  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. server:~# <b>cat .ssh/authorized_keys</b>
  176. cert-authority ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICAL7l1sQuKe4daLfKGZuiRPZZXquokQyH+p6utlZxZ+ Test CA
  177. 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)
  178. Now, try to login :
  179. <pre>
  180. $ <b>ssh root@server</b>
  181. sign_and_send_pubkey: signing failed for ED25519 "cardno:000615280015": agent refused operation
  182. Password:
  183. </pre>
  184. So we're completely out of luck : authentication doesn't works.
  185. For comparison, let's try with an NIST P384 key :
  186. <pre>
  187. $ <b>ykman openpgp reset</b>
  188. WARNING! This will delete all stored OpenPGP keys and data and restore factory settings? [y/N]: y
  189. Resetting OpenPGP data, don't remove your YubiKey...
  190. Success! All data has been cleared and default PINs are set.
  191. PIN: 123456
  192. Reset code: NOT SET
  193. Admin PIN: 12345678
  194. $ <b>rm -R .gnupg</b>
  195. $ <b>rm -R .ssh</b>
  196. $ <b>gpg --card-edit</b>
  197. Reader ...........: Yubico YubiKey OTP FIDO CCID 00 00
  198. Application ID ...: D2760001240103040006152800150000
  199. Application type .: OpenPGP
  200. Version ..........: 3.4
  201. Manufacturer .....: Yubico
  202. Serial number ....: 15280015
  203. Name of cardholder: [not set]
  204. Language prefs ...: [not set]
  205. Salutation .......:
  206. URL of public key : [not set]
  207. Login data .......: [not set]
  208. Signature PIN ....: not forced
  209. Key attributes ...: rsa2048 rsa2048 rsa2048
  210. Max. PIN lengths .: 127 127 127
  211. PIN retry counter : 3 0 3
  212. Signature counter : 0
  213. KDF setting ......: off
  214. Signature key ....: [none]
  215. Encryption key....: [none]
  216. Authentication key: [none]
  217. General key info..: [none]
  218. gpg/card> <b>admin</b>
  219. Admin commands are allowed
  220. gpg/card> <b>key-attr</b>
  221. Changing card key attribute for: Signature key
  222. Please select what kind of key you want:
  223. (1) RSA
  224. (2) ECC
  225. Your selection? <b>2</b>
  226. Please select which elliptic curve you want:
  227. (1) Curve 25519
  228. (4) NIST P-384
  229. Your selection? <b>4</b>
  230. The card will now be re-configured to generate a key of type: nistp384
  231. Note: There is no guarantee that the card supports the requested size.
  232. If the key generation does not succeed, please check the
  233. documentation of your card to see what sizes are allowed.
  234. Changing card key attribute for: Encryption key
  235. Please select what kind of key you want:
  236. (1) RSA
  237. (2) ECC
  238. Your selection? <b>2</b>
  239. Please select which elliptic curve you want:
  240. (1) Curve 25519
  241. (4) NIST P-384
  242. Your selection? <b>4</b>
  243. The card will now be re-configured to generate a key of type: nistp384
  244. Changing card key attribute for: Authentication key
  245. Please select what kind of key you want:
  246. (1) RSA
  247. (2) ECC
  248. Your selection? <b>2</b>
  249. Please select which elliptic curve you want:
  250. (1) Curve 25519
  251. (4) NIST P-384
  252. Your selection? <b>4</b>
  253. The card will now be re-configured to generate a key of type: nistp384
  254. gpg/card> <b>generate</b>
  255. Make off-card backup of encryption key? (Y/n) <b>n</b>
  256. Please note that the factory settings of the PINs are
  257. PIN = '123456' Admin PIN = '12345678'
  258. You should change them using the command --change-pin
  259. Please specify how long the key should be valid.
  260. 0 = key does not expire
  261. <n> = key expires in n days
  262. <n>w = key expires in n weeks
  263. <n>m = key expires in n months
  264. <n>y = key expires in n years
  265. Key is valid for? (0)
  266. Key does not expire at all
  267. Is this correct? (y/N) <b>y</b>
  268. GnuPG needs to construct a user ID to identify your key.
  269. Real name: <b>Dummy</b>
  270. Email address: <b>dummy@dummy.co</b>
  271. Comment:
  272. You selected this USER-ID:
  273. "Dummy <dummy@dummy.co>"
  274. Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? <b>o</b>
  275. gpg: /home/user/.gnupg/trustdb.gpg: trustdb created
  276. gpg: key BA792909F5154B7A marked as ultimately trusted
  277. gpg: directory '/home/user/.gnupg/openpgp-revocs.d' created
  278. gpg: revocation certificate stored as '/home/user/.gnupg/openpgp-revocs.d/B591751A56B42EA25C8BEF60BA792909F5154B7A.rev'
  279. public and secret key created and signed.
  280. gpg/card> <b>list</b>
  281. Reader ...........: Yubico YubiKey OTP FIDO CCID 00 00
  282. Application ID ...: D2760001240103040006152800150000
  283. Application type .: OpenPGP
  284. Version ..........: 3.4
  285. Manufacturer .....: Yubico
  286. Serial number ....: 15280015
  287. Name of cardholder: [not set]
  288. Language prefs ...: [not set]
  289. Salutation .......:
  290. URL of public key : [not set]
  291. Login data .......: [not set]
  292. Signature PIN ....: not forced
  293. Key attributes ...: nistp384 nistp384 nistp384
  294. Max. PIN lengths .: 127 127 127
  295. PIN retry counter : 3 0 3
  296. Signature counter : 4
  297. KDF setting ......: off
  298. Signature key ....: B591 751A 56B4 2EA2 5C8B EF60 BA79 2909 F515 4B7A
  299. created ....: 2020-10-05 10:04:12
  300. Encryption key....: F087 DFD0 65E8 AFE3 8835 41EA 062D F688 F54D 721D
  301. created ....: 2020-10-05 10:04:12
  302. Authentication key: 8556 35FB BFD2 E642 8CFC D41B 47B0 098B 165E 8325
  303. created ....: 2020-10-05 10:04:12
  304. General key info..:
  305. pub nistp384/BA792909F5154B7A 2020-10-05 Dummy <dummy@dummy.co>
  306. sec> nistp384/BA792909F5154B7A created: 2020-10-05 expires: never
  307. card-no: 0006 15280015
  308. ssb> nistp384/47B0098B165E8325 created: 2020-10-05 expires: never
  309. card-no: 0006 15280015
  310. ssb> nistp384/062DF688F54D721D created: 2020-10-05 expires: never
  311. card-no: 0006 15280015
  312. gpg/card> <b>quit</b>
  313. pub nistp384 2020-10-05 [SC]
  314. B591751A56B42EA25C8BEF60BA792909F5154B7A
  315. uid Dummy <dummy@dummy.co>
  316. sub nistp384 2020-10-05 [A]
  317. sub nistp384 2020-10-05 [E]
  318. $ <b>ssh-add -L > sshca/id_ecdsa.pub</b>
  319. $ <b>ssh-keygen -s sshca/ca -I test-dummy sshca/id_ecdsa.pub</b>
  320. Signed user key sshca/id_ecdsa-cert.pub: id "test-dummy" serial 0 valid forever
  321. $ <b>cp sshca/id_ecdsa-cert.pub ~/.ssh/</b>
  322. $ <b>ssh-keygen -Lf .ssh/id_ecdsa-cert.pub</b>
  323. .ssh/id_ecdsa-cert.pub:
  324. Type: ecdsa-sha2-nistp384-cert-v01@openssh.com user certificate
  325. Public key: ECDSA-CERT SHA256:N3JmjLOQ5VClsChOlmeyh5a8kF0RCMdAOz1VWde8lwk
  326. Signing CA: ED25519 SHA256:2PibPv047BiDZQgl51bKRnY2ZXpcbAP1g7GjAZ0DArI (using ssh-ed25519)
  327. Key ID: "test-dummy"
  328. Serial: 0
  329. Valid: forever
  330. Principals: (none)
  331. Critical Options: (none)
  332. Extensions:
  333. permit-X11-forwarding
  334. permit-agent-forwarding
  335. permit-port-forwarding
  336. permit-pty
  337. permit-user-rc
  338. $ <b>ssh root@server</b>
  339. Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)
  340. root@server:~#
  341. </pre>
  342. **Authentication is working as expected here !**