1*19261079SEd MasteThis document describes OpenSSH's support for U2F/FIDO security keys. 2*19261079SEd Maste 3*19261079SEd MasteBackground 4*19261079SEd Maste---------- 5*19261079SEd Maste 6*19261079SEd MasteU2F is an open standard for two-factor authentication hardware, widely 7*19261079SEd Masteused for user authentication to websites. U2F tokens are ubiquitous, 8*19261079SEd Masteavailable from a number of manufacturers and are currently by far the 9*19261079SEd Mastecheapest way for users to achieve hardware-backed credential storage. 10*19261079SEd Maste 11*19261079SEd MasteThe U2F protocol however cannot be trivially used as an SSH protocol key 12*19261079SEd Mastetype as both the inputs to the signature operation and the resultant 13*19261079SEd Mastesignature differ from those specified for SSH. For similar reasons, 14*19261079SEd Masteintegration of U2F devices cannot be achieved via the PKCS#11 API. 15*19261079SEd Maste 16*19261079SEd MasteU2F also offers a number of features that are attractive in the context 17*19261079SEd Masteof SSH authentication. They can be configured to require indication 18*19261079SEd Masteof "user presence" for each signature operation (typically achieved 19*19261079SEd Masteby requiring the user touch the key). They also offer an attestation 20*19261079SEd Mastemechanism at key enrollment time that can be used to prove that a 21*19261079SEd Mastegiven key is backed by hardware. Finally the signature format includes 22*19261079SEd Mastea monotonic signature counter that can be used (at scale) to detect 23*19261079SEd Masteconcurrent use of a private key, should it be extracted from hardware. 24*19261079SEd Maste 25*19261079SEd MasteU2F private keys are generated through an enrollment operation, 26*19261079SEd Mastewhich takes an application ID - a URL-like string, typically "ssh:" 27*19261079SEd Mastein this case, but a HTTP origin for the case of web authentication, 28*19261079SEd Masteand a challenge string (typically randomly generated). The enrollment 29*19261079SEd Masteoperation returns a public key, a key handle that must be used to invoke 30*19261079SEd Mastethe hardware-backed private key, some flags and signed attestation 31*19261079SEd Masteinformation that may be used to verify that a private key is hosted on a 32*19261079SEd Masteparticular hardware instance. 33*19261079SEd Maste 34*19261079SEd MasteIt is common for U2F hardware to derive private keys from the key handle 35*19261079SEd Mastein conjunction with a small per-device secret that is unique to the 36*19261079SEd Mastehardware, thus requiring little on-device storage for an effectively 37*19261079SEd Masteunlimited number of supported keys. This drives the requirement that 38*19261079SEd Mastethe key handle be supplied for each signature operation. U2F tokens 39*19261079SEd Masteprimarily use ECDSA signatures in the NIST-P256 field, though the FIDO2 40*19261079SEd Mastestandard specifies additional key types, including one based on Ed25519. 41*19261079SEd Maste 42*19261079SEd MasteUse of U2F security keys does not automatically imply multi-factor 43*19261079SEd Masteauthentication. From sshd's perspective, a security key constitutes a 44*19261079SEd Mastesingle factor of authentication, even if protected by a PIN or biometric 45*19261079SEd Masteauthentication. To enable multi-factor authentication in ssh, please 46*19261079SEd Masterefer to the AuthenticationMethods option in sshd_config(5). 47*19261079SEd Maste 48*19261079SEd Maste 49*19261079SEd MasteSSH U2F Key formats 50*19261079SEd Maste------------------- 51*19261079SEd Maste 52*19261079SEd MasteOpenSSH integrates U2F as new key and corresponding certificate types: 53*19261079SEd Maste 54*19261079SEd Maste sk-ecdsa-sha2-nistp256@openssh.com 55*19261079SEd Maste sk-ecdsa-sha2-nistp256-cert-v01@openssh.com 56*19261079SEd Maste sk-ssh-ed25519@openssh.com 57*19261079SEd Maste sk-ssh-ed25519-cert-v01@openssh.com 58*19261079SEd Maste 59*19261079SEd MasteWhile each uses ecdsa-sha256-nistp256 as the underlying signature primitive, 60*19261079SEd Mastekeys require extra information in the public and private keys, and in 61*19261079SEd Mastethe signature object itself. As such they cannot be made compatible with 62*19261079SEd Mastethe existing ecdsa-sha2-nistp* key types. 63*19261079SEd Maste 64*19261079SEd MasteThe format of a sk-ecdsa-sha2-nistp256@openssh.com public key is: 65*19261079SEd Maste 66*19261079SEd Maste string "sk-ecdsa-sha2-nistp256@openssh.com" 67*19261079SEd Maste string curve name 68*19261079SEd Maste ec_point Q 69*19261079SEd Maste string application (user-specified, but typically "ssh:") 70*19261079SEd Maste 71*19261079SEd MasteThe corresponding private key contains: 72*19261079SEd Maste 73*19261079SEd Maste string "sk-ecdsa-sha2-nistp256@openssh.com" 74*19261079SEd Maste string curve name 75*19261079SEd Maste ec_point Q 76*19261079SEd Maste string application (user-specified, but typically "ssh:") 77*19261079SEd Maste uint8 flags 78*19261079SEd Maste string key_handle 79*19261079SEd Maste string reserved 80*19261079SEd Maste 81*19261079SEd MasteThe format of a sk-ssh-ed25519@openssh.com public key is: 82*19261079SEd Maste 83*19261079SEd Maste string "sk-ssh-ed25519@openssh.com" 84*19261079SEd Maste string public key 85*19261079SEd Maste string application (user-specified, but typically "ssh:") 86*19261079SEd Maste 87*19261079SEd MasteWith a private half consisting of: 88*19261079SEd Maste 89*19261079SEd Maste string "sk-ssh-ed25519@openssh.com" 90*19261079SEd Maste string public key 91*19261079SEd Maste string application (user-specified, but typically "ssh:") 92*19261079SEd Maste uint8 flags 93*19261079SEd Maste string key_handle 94*19261079SEd Maste string reserved 95*19261079SEd Maste 96*19261079SEd MasteThe certificate form for SSH U2F keys appends the usual certificate 97*19261079SEd Masteinformation to the public key: 98*19261079SEd Maste 99*19261079SEd Maste string "sk-ecdsa-sha2-nistp256-cert-v01@openssh.com" 100*19261079SEd Maste string nonce 101*19261079SEd Maste string curve name 102*19261079SEd Maste ec_point Q 103*19261079SEd Maste string application 104*19261079SEd Maste uint64 serial 105*19261079SEd Maste uint32 type 106*19261079SEd Maste string key id 107*19261079SEd Maste string valid principals 108*19261079SEd Maste uint64 valid after 109*19261079SEd Maste uint64 valid before 110*19261079SEd Maste string critical options 111*19261079SEd Maste string extensions 112*19261079SEd Maste string reserved 113*19261079SEd Maste string signature key 114*19261079SEd Maste string signature 115*19261079SEd Maste 116*19261079SEd Masteand for security key ed25519 certificates: 117*19261079SEd Maste 118*19261079SEd Maste string "sk-ssh-ed25519-cert-v01@openssh.com" 119*19261079SEd Maste string nonce 120*19261079SEd Maste string public key 121*19261079SEd Maste string application 122*19261079SEd Maste uint64 serial 123*19261079SEd Maste uint32 type 124*19261079SEd Maste string key id 125*19261079SEd Maste string valid principals 126*19261079SEd Maste uint64 valid after 127*19261079SEd Maste uint64 valid before 128*19261079SEd Maste string critical options 129*19261079SEd Maste string extensions 130*19261079SEd Maste string reserved 131*19261079SEd Maste string signature key 132*19261079SEd Maste string signature 133*19261079SEd Maste 134*19261079SEd MasteBoth security key certificates use the following encoding for private keys: 135*19261079SEd Maste 136*19261079SEd Maste string type (e.g. "sk-ssh-ed25519-cert-v01@openssh.com") 137*19261079SEd Maste string pubkey (the above key/cert structure) 138*19261079SEd Maste string application 139*19261079SEd Maste uint8 flags 140*19261079SEd Maste string key_handle 141*19261079SEd Maste string reserved 142*19261079SEd Maste 143*19261079SEd MasteDuring key generation, the hardware also returns attestation information 144*19261079SEd Mastethat may be used to cryptographically prove that a given key is 145*19261079SEd Mastehardware-backed. Unfortunately, the protocol required for this proof is 146*19261079SEd Mastenot privacy-preserving and may be used to identify U2F tokens with at 147*19261079SEd Masteleast manufacturer and batch number granularity. For this reason, we 148*19261079SEd Mastechoose not to include this information in the public key or save it by 149*19261079SEd Mastedefault. 150*19261079SEd Maste 151*19261079SEd MasteAttestation information is useful for out-of-band key and certificate 152*19261079SEd Masteregistration workflows, e.g. proving to a CA that a key is backed 153*19261079SEd Masteby trusted hardware before it will issue a certificate. To support this 154*19261079SEd Mastecase, OpenSSH optionally allows retaining the attestation information 155*19261079SEd Masteat the time of key generation. It will take the following format: 156*19261079SEd Maste 157*19261079SEd Maste string "ssh-sk-attest-v01" 158*19261079SEd Maste string attestation certificate 159*19261079SEd Maste string enrollment signature 160*19261079SEd Maste string authenticator data (CBOR encoded) 161*19261079SEd Maste uint32 reserved flags 162*19261079SEd Maste string reserved string 163*19261079SEd Maste 164*19261079SEd MasteA previous version of this format, emitted prior to OpenSSH 8.4 omitted 165*19261079SEd Mastethe authenticator data. 166*19261079SEd Maste 167*19261079SEd Maste string "ssh-sk-attest-v00" 168*19261079SEd Maste string attestation certificate 169*19261079SEd Maste string enrollment signature 170*19261079SEd Maste uint32 reserved flags 171*19261079SEd Maste string reserved string 172*19261079SEd Maste 173*19261079SEd MasteOpenSSH treats the attestation certificate and enrollment signatures as 174*19261079SEd Masteopaque objects and does no interpretation of them itself. 175*19261079SEd Maste 176*19261079SEd MasteSSH U2F signatures 177*19261079SEd Maste------------------ 178*19261079SEd Maste 179*19261079SEd MasteIn addition to the message to be signed, the U2F signature operation 180*19261079SEd Masterequires the key handle and a few additional parameters. The signature 181*19261079SEd Masteis signed over a blob that consists of: 182*19261079SEd Maste 183*19261079SEd Maste byte[32] SHA256(application) 184*19261079SEd Maste byte flags (including "user present", extensions present) 185*19261079SEd Maste uint32 counter 186*19261079SEd Maste byte[] extensions 187*19261079SEd Maste byte[32] SHA256(message) 188*19261079SEd Maste 189*19261079SEd MasteNo extensions are yet defined for SSH use. If any are defined in the future, 190*19261079SEd Masteit will be possible to infer their presence from the contents of the "flags" 191*19261079SEd Mastevalue. 192*19261079SEd Maste 193*19261079SEd MasteThe signature returned from U2F hardware takes the following format: 194*19261079SEd Maste 195*19261079SEd Maste byte flags (including "user present") 196*19261079SEd Maste uint32 counter 197*19261079SEd Maste byte[] ecdsa_signature (in X9.62 format). 198*19261079SEd Maste 199*19261079SEd MasteFor use in the SSH protocol, we wish to avoid server-side parsing of ASN.1 200*19261079SEd Masteformat data in the pre-authentication attack surface. Therefore, the 201*19261079SEd Mastesignature format used on the wire in SSH2_USERAUTH_REQUEST packets will 202*19261079SEd Mastebe reformatted to better match the existing signature encoding: 203*19261079SEd Maste 204*19261079SEd Maste string "sk-ecdsa-sha2-nistp256@openssh.com" 205*19261079SEd Maste string ecdsa_signature 206*19261079SEd Maste byte flags 207*19261079SEd Maste uint32 counter 208*19261079SEd Maste 209*19261079SEd MasteWhere the "ecdsa_signature" field follows the RFC5656 ECDSA signature 210*19261079SEd Masteencoding: 211*19261079SEd Maste 212*19261079SEd Maste mpint r 213*19261079SEd Maste mpint s 214*19261079SEd Maste 215*19261079SEd MasteFor Ed25519 keys the signature is encoded as: 216*19261079SEd Maste 217*19261079SEd Maste string "sk-ssh-ed25519@openssh.com" 218*19261079SEd Maste string signature 219*19261079SEd Maste byte flags 220*19261079SEd Maste uint32 counter 221*19261079SEd Maste 222*19261079SEd Mastewebauthn signatures 223*19261079SEd Maste------------------- 224*19261079SEd Maste 225*19261079SEd MasteThe W3C/FIDO webauthn[1] standard defines a mechanism for a web browser to 226*19261079SEd Masteinteract with FIDO authentication tokens. This standard builds upon the 227*19261079SEd MasteFIDO standards, but requires different signature contents to raw FIDO 228*19261079SEd Mastemessages. OpenSSH supports ECDSA/p256 webauthn signatures through the 229*19261079SEd Maste"webauthn-sk-ecdsa-sha2-nistp256@openssh.com" signature algorithm. 230*19261079SEd Maste 231*19261079SEd MasteThe wire encoding for a webauthn-sk-ecdsa-sha2-nistp256@openssh.com 232*19261079SEd Mastesignature is similar to the sk-ecdsa-sha2-nistp256@openssh.com format: 233*19261079SEd Maste 234*19261079SEd Maste string "webauthn-sk-ecdsa-sha2-nistp256@openssh.com" 235*19261079SEd Maste string ecdsa_signature 236*19261079SEd Maste byte flags 237*19261079SEd Maste uint32 counter 238*19261079SEd Maste string origin 239*19261079SEd Maste string clientData 240*19261079SEd Maste string extensions 241*19261079SEd Maste 242*19261079SEd MasteWhere "origin" is the HTTP origin making the signature, "clientData" is 243*19261079SEd Mastethe JSON-like structure signed by the browser and "extensions" are any 244*19261079SEd Masteextensions used in making the signature. 245*19261079SEd Maste 246*19261079SEd Maste[1] https://www.w3.org/TR/webauthn-2/ 247*19261079SEd Maste 248*19261079SEd Mastessh-agent protocol extensions 249*19261079SEd Maste----------------------------- 250*19261079SEd Maste 251*19261079SEd Mastessh-agent requires a protocol extension to support U2F keys. At 252*19261079SEd Mastepresent the closest analogue to Security Keys in ssh-agent are PKCS#11 253*19261079SEd Mastetokens, insofar as they require a middleware library to communicate with 254*19261079SEd Mastethe device that holds the keys. Unfortunately, the protocol message used 255*19261079SEd Masteto add PKCS#11 keys to ssh-agent does not include any way to send the 256*19261079SEd Mastekey handle to the agent as U2F keys require. 257*19261079SEd Maste 258*19261079SEd MasteTo avoid this, without having to add wholly new messages to the agent 259*19261079SEd Masteprotocol, we will use the existing SSH2_AGENTC_ADD_ID_CONSTRAINED message 260*19261079SEd Mastewith a new key constraint extension to encode a path to the middleware 261*19261079SEd Mastelibrary for the key. The format of this constraint extension would be: 262*19261079SEd Maste 263*19261079SEd Maste byte SSH_AGENT_CONSTRAIN_EXTENSION 264*19261079SEd Maste string sk-provider@openssh.com 265*19261079SEd Maste string middleware path 266*19261079SEd Maste 267*19261079SEd MasteThis constraint-based approach does not present any compatibility 268*19261079SEd Masteproblems. 269*19261079SEd Maste 270*19261079SEd MasteOpenSSH integration 271*19261079SEd Maste------------------- 272*19261079SEd Maste 273*19261079SEd MasteU2F tokens may be attached via a number of means, including USB and NFC. 274*19261079SEd MasteThe USB interface is standardised around a HID protocol, but we want to 275*19261079SEd Mastebe able to support other transports as well as dummy implementations for 276*19261079SEd Masteregress testing. For this reason, OpenSSH shall support a dynamically- 277*19261079SEd Masteloaded middleware libraries to communicate with security keys, but offer 278*19261079SEd Mastesupport for the common case of USB HID security keys internally. 279*19261079SEd Maste 280*19261079SEd MasteThe middleware library need only expose a handful of functions and 281*19261079SEd Mastenumbers listed in sk-api.h. Included in the defined numbers is a 282*19261079SEd MasteSSH_SK_VERSION_MAJOR that should be incremented for each incompatible 283*19261079SEd MasteAPI change. 284*19261079SEd Maste 285*19261079SEd Mastemiscellaneous options may be passed to the middleware as a NULL- 286*19261079SEd Masteterminated array of pointers to struct sk_option. The middleware may 287*19261079SEd Masteignore unsupported or unknown options unless the "required" flag is set, 288*19261079SEd Mastein which case it should return failure if an unsupported option is 289*19261079SEd Masterequested. 290*19261079SEd Maste 291*19261079SEd MasteAt present the following options names are supported: 292*19261079SEd Maste 293*19261079SEd Maste "device" 294*19261079SEd Maste 295*19261079SEd Maste Specifies a specific FIDO device on which to perform the 296*19261079SEd Maste operation. The value in this field is interpreted by the 297*19261079SEd Maste middleware but it would be typical to specify a path to 298*19261079SEd Maste a /dev node for the device in question. 299*19261079SEd Maste 300*19261079SEd Maste "user" 301*19261079SEd Maste 302*19261079SEd Maste Specifies the FIDO2 username used when enrolling a key, 303*19261079SEd Maste overriding OpenSSH's default of using an all-zero username. 304*19261079SEd Maste 305*19261079SEd MasteIn OpenSSH, the middleware will be invoked by using a similar mechanism to 306*19261079SEd Mastessh-pkcs11-helper to provide address-space containment of the 307*19261079SEd Mastemiddleware from ssh-agent. 308*19261079SEd Maste 309*19261079SEd Maste$OpenBSD: PROTOCOL.u2f,v 1.26 2020/09/09 03:08:01 djm Exp $ 310