xref: /openbsd-src/usr.bin/ssh/PROTOCOL.certkeys (revision 581c1d79a7f24e9aa7f6eb57d67599269ce250e8)
1This document describes a simple public-key certificate authentication
2system for use by SSH.
3
4Background
5----------
6
7The SSH protocol currently supports a simple public key authentication
8mechanism. Unlike other public key implementations, SSH eschews the use
9of X.509 certificates and uses raw keys. This approach has some benefits
10relating to simplicity of configuration and minimisation of attack
11surface, but it does not support the important use-cases of centrally
12managed, passwordless authentication and centrally certified host keys.
13
14These protocol extensions build on the simple public key authentication
15system already in SSH to allow certificate-based authentication. The
16certificates used are not traditional X.509 certificates, with numerous
17options and complex encoding rules, but something rather more minimal: a
18key, some identity information and usage options that have been signed
19with some other trusted key.
20
21A sshd server may be configured to allow authentication via certified
22keys, by extending the existing ~/.ssh/authorized_keys mechanism to
23allow specification of certification authority keys in addition to
24raw user keys. The ssh client will support automatic verification of
25acceptance of certified host keys, by adding a similar ability to
26specify CA keys in ~/.ssh/known_hosts.
27
28All certificate types include certification information along with the
29public key that is used to sign challenges. In OpenSSH, ssh-keygen
30performs the CA signing operation.
31
32Certified keys are represented using new key types:
33
34    ssh-rsa-cert-v01@openssh.com
35    ssh-dss-cert-v01@openssh.com
36    ecdsa-sha2-nistp256-cert-v01@openssh.com
37    ecdsa-sha2-nistp384-cert-v01@openssh.com
38    ecdsa-sha2-nistp521-cert-v01@openssh.com
39    ssh-ed25519-cert-v01@openssh.com
40
41Two additional types exist for RSA certificates to force use of
42SHA-2 signatures (SHA-256 and SHA-512 respectively):
43
44    rsa-sha2-256-cert-v01@openssh.com
45    rsa-sha2-512-cert-v01@openssh.com
46
47These RSA/SHA-2 types should not appear in keys at rest or transmitted
48on the wire, but do appear in a SSH_MSG_KEXINIT's host-key algorithms
49field or in the "public key algorithm name" field of a "publickey"
50SSH_USERAUTH_REQUEST to indicate that the signature will use the
51specified algorithm.
52
53Protocol extensions
54-------------------
55
56The SSH wire protocol includes several extensibility mechanisms.
57These modifications shall take advantage of namespaced public key
58algorithm names to add support for certificate authentication without
59breaking the protocol - implementations that do not support the
60extensions will simply ignore them.
61
62Authentication using the new key formats described below proceeds
63using the existing SSH "publickey" authentication method described
64in RFC4252 section 7.
65
66New public key formats
67----------------------
68
69The certificate key types take a similar high-level format (note: data
70types and encoding are as per RFC4251 section 5). The serialised wire
71encoding of these certificates is also used for storing them on disk.
72
73#define SSH_CERT_TYPE_USER    1
74#define SSH_CERT_TYPE_HOST    2
75
76RSA certificate
77
78    string    "ssh-rsa-cert-v01@openssh.com"
79    string    nonce
80    mpint     e
81    mpint     n
82    uint64    serial
83    uint32    type
84    string    key id
85    string    valid principals
86    uint64    valid after
87    uint64    valid before
88    string    critical options
89    string    extensions
90    string    reserved
91    string    signature key
92    string    signature
93
94DSA certificate
95
96    string    "ssh-dss-cert-v01@openssh.com"
97    string    nonce
98    mpint     p
99    mpint     q
100    mpint     g
101    mpint     y
102    uint64    serial
103    uint32    type
104    string    key id
105    string    valid principals
106    uint64    valid after
107    uint64    valid before
108    string    critical options
109    string    extensions
110    string    reserved
111    string    signature key
112    string    signature
113
114ECDSA certificate
115
116    string    "ecdsa-sha2-nistp256-cert-v01@openssh.com" |
117              "ecdsa-sha2-nistp384-cert-v01@openssh.com" |
118              "ecdsa-sha2-nistp521-cert-v01@openssh.com"
119    string    nonce
120    string    curve
121    string    public_key
122    uint64    serial
123    uint32    type
124    string    key id
125    string    valid principals
126    uint64    valid after
127    uint64    valid before
128    string    critical options
129    string    extensions
130    string    reserved
131    string    signature key
132    string    signature
133
134ED25519 certificate
135
136    string    "ssh-ed25519-cert-v01@openssh.com"
137    string    nonce
138    string    pk
139    uint64    serial
140    uint32    type
141    string    key id
142    string    valid principals
143    uint64    valid after
144    uint64    valid before
145    string    critical options
146    string    extensions
147    string    reserved
148    string    signature key
149    string    signature
150
151The nonce field is a CA-provided random bitstring of arbitrary length
152(but typically 16 or 32 bytes) included to make attacks that depend on
153inducing collisions in the signature hash infeasible.
154
155e and n are the RSA exponent and public modulus respectively.
156
157p, q, g, y are the DSA parameters as described in FIPS-186-2.
158
159curve and public key are respectively the ECDSA "[identifier]" and "Q"
160defined in section 3.1 of RFC5656.
161
162pk is the encoded Ed25519 public key as defined by RFC8032.
163
164serial is an optional certificate serial number set by the CA to
165provide an abbreviated way to refer to certificates from that CA.
166If a CA does not wish to number its certificates, it must set this
167field to zero.
168
169type specifies whether this certificate is for identification of a user
170or a host using a SSH_CERT_TYPE_... value.
171
172key id is a free-form text field that is filled in by the CA at the time
173of signing; the intention is that the contents of this field are used to
174identify the identity principal in log messages.
175
176"valid principals" is a string containing zero or more principals as
177strings packed inside it. These principals list the names for which this
178certificate is valid; hostnames for SSH_CERT_TYPE_HOST certificates and
179usernames for SSH_CERT_TYPE_USER certificates. As a special case, a
180zero-length "valid principals" field means the certificate is valid for
181any principal of the specified type.
182
183"valid after" and "valid before" specify a validity period for the
184certificate. Each represents a time in seconds since 1970-01-01
18500:00:00. A certificate is considered valid if:
186
187    valid after <= current time < valid before
188
189critical options is a set of zero or more key options encoded as
190below. All such options are "critical" in the sense that an implementation
191must refuse to authorise a key that has an unrecognised option.
192
193extensions is a set of zero or more optional extensions. These extensions
194are not critical, and an implementation that encounters one that it does
195not recognise may safely ignore it.
196
197Generally, critical options are used to control features that restrict
198access where extensions are used to enable features that grant access.
199This ensures that certificates containing unknown restrictions do not
200inadvertently grant access while allowing new protocol features to be
201enabled via extensions without breaking certificates' backwards
202compatibility.
203
204The reserved field is currently unused and is ignored in this version of
205the protocol.
206
207The signature key field contains the CA key used to sign the
208certificate. The valid key types for CA keys are ssh-rsa,
209ssh-dss, ssh-ed25519 and the ECDSA types ecdsa-sha2-nistp256,
210ecdsa-sha2-nistp384, ecdsa-sha2-nistp521. "Chained" certificates, where
211the signature key type is a certificate type itself are NOT supported.
212Note that it is possible for a RSA certificate key to be signed by a
213Ed25519 or ECDSA CA key and vice-versa.
214
215signature is computed over all preceding fields from the initial string
216up to, and including the signature key. Signatures are computed and
217encoded according to the rules defined for the CA's public key algorithm
218(RFC4253 section 6.6 for ssh-rsa and ssh-dss, RFC5656 for the ECDSA
219types, and RFC8032 for Ed25519).
220
221Critical options
222----------------
223
224The critical options section of the certificate specifies zero or more
225options on the certificate's validity. The format of this field
226is a sequence of zero or more tuples:
227
228    string       name
229    string       data
230
231Options must be lexically ordered by "name" if they appear in the
232sequence. Each named option may only appear once in a certificate.
233
234The name field identifies the option. The data field contains
235option-specific information encoded as zero or more values inside
236the string. I.e. an empty data field would be encoded as a zero-
237length string (00 00 00 00), and data field that holds a single
238string value "a" would be encoded as (00 00 00 05 00 00 00 01 65).
239
240All options are "critical"; if an implementation does not recognise
241a option, then the validating party should refuse to accept the
242certificate.
243
244Custom options should append the originating author or organisation's
245domain name to the option name, e.g. "my-option@example.com".
246
247No critical options are defined for host certificates at present. The
248supported user certificate options and the contents and structure of
249their data fields are:
250
251Name                    Format        Description
252-----------------------------------------------------------------------------
253force-command           string        Specifies a command that is executed
254                                      (replacing any the user specified on the
255                                      ssh command-line) whenever this key is
256                                      used for authentication.
257
258source-address          string        Comma-separated list of source addresses
259                                      from which this certificate is accepted
260                                      for authentication. Addresses are
261                                      specified in CIDR format (nn.nn.nn.nn/nn
262                                      or hhhh::hhhh/nn).
263                                      If this option is not present, then
264                                      certificates may be presented from any
265                                      source address.
266
267verify-required         empty         Flag indicating that signatures made
268                                      with this certificate must assert FIDO
269                                      user verification (e.g. PIN or
270                                      biometric). This option only makes sense
271                                      for the U2F/FIDO security key types that
272                                      support this feature in their signature
273                                      formats.
274
275Extensions
276----------
277
278The extensions section of the certificate specifies zero or more
279non-critical certificate extensions. The encoding and ordering of
280extensions in this field is identical to that of the critical options,
281as is the requirement that each name appear only once.
282
283If an implementation does not recognise an extension, then it should
284ignore it.
285
286Custom options should append the originating author or organisation's
287domain name to the option name, e.g. "my-option@example.com".
288
289No extensions are defined for host certificates at present. The
290supported user certificate extensions and the contents and structure of
291their data fields are:
292
293Name                    Format        Description
294-----------------------------------------------------------------------------
295no-touch-required       empty         Flag indicating that signatures made
296                                      with this certificate need not assert
297                                      FIDO user presence. This option only
298                                      makes sense for the U2F/FIDO security
299                                      key types that support this feature in
300                                      their signature formats.
301
302permit-X11-forwarding   empty         Flag indicating that X11 forwarding
303                                      should be permitted. X11 forwarding will
304                                      be refused if this option is absent.
305
306permit-agent-forwarding empty         Flag indicating that agent forwarding
307                                      should be allowed. Agent forwarding
308                                      must not be permitted unless this
309                                      option is present.
310
311permit-port-forwarding  empty         Flag indicating that port-forwarding
312                                      should be allowed. If this option is
313                                      not present, then no port forwarding will
314                                      be allowed.
315
316permit-pty              empty         Flag indicating that PTY allocation
317                                      should be permitted. In the absence of
318                                      this option PTY allocation will be
319                                      disabled.
320
321permit-user-rc          empty         Flag indicating that execution of
322                                      ~/.ssh/rc should be permitted. Execution
323                                      of this script will not be permitted if
324                                      this option is not present.
325
326$OpenBSD: PROTOCOL.certkeys,v 1.20 2024/12/06 16:02:12 djm Exp $
327