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