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.

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