RFC 4716

The Secure Shell (SSH) Public Key File Format

πŸ“… published November 2006, from ietf

RFC 4716: The Secure Shell (SSH) Public Key File Format ✨

Okay bestie, first things first, the title block πŸ’… This is RFC 4716, called The Secure Shell (SSH) Public Key File Format. It came out of the Network Working Group in November 2006, written by J. Galbraith (VanDyke Software), R. Thayer, and Canola & Jones. Its category is Informational πŸ¦‹, and the title block has no Obsoletes or Updates line, so it doesn't replace or change any other RFC. Part 1 covers the front matter, the file format, and the examples. Part 2 has the fingerprints, IANA, security, and references.

Status of This Memo

This one is just information for the Internet community 🌸 It is not an Internet standard of any kind, and distribution of it is totally unlimited.

Copyright (C) The IETF Trust (2006). πŸŽ€

Abstract

This doc makes an existing public key file format official πŸ”₯ It's the format SSH implementations already use to swap public keys with each other. It also defines a standard text representation for SSH public key fingerprints, so everyone's fingerprints look the same ✨

Table of Contents

1. Introduction ....................................................2
2. Conventions Used in This Document ...............................2
3. Key File Format .................................................2
   3.1. Line Termination Characters ................................2
   3.2. Begin and End Markers ......................................3
   3.3. Key File Header ............................................3
        3.3.1. Subject Header ......................................3
        3.3.2. Comment Header ......................................4
        3.3.3. Private Use Headers .................................4
   3.4. Public Key File Body .......................................4
   3.5. Differences with RFC 1421 PEM Formats ......................4
   3.6. Examples ...................................................5
4. Public Key Fingerprints .........................................6
5. IANA Considerations .............................................6
6. Security Considerations .........................................7
7. References ......................................................8
   7.1. Normative References .......................................8
   7.2. Informative References .....................................8

1. Introduction 🧚

Okay so SSH can use public/private key pairs for authentication, which is the whole "public key cryptography" thing πŸ”‘ But before you can use public key auth, the public keys have to get from the client to the server first. Obviously.

This doc describes a public key file format that works with any of the common file transfer mechanisms, so you can pass keys around however you like πŸ¦‹

SSH also uses key pairs to authenticate the server, and that's where it gets extra important. You need to check that the key the server hands you is actually its key πŸ‘€ This doc describes fingerprinting, which turns a public key into a short text string that uniquely represents it. Main character energy πŸ’–

2. Conventions Used in This Document

Here's the vibe check: the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. πŸ“–βœ¨

3. Key File Format πŸ“„

To do public key auth, SSH implementations have to share public key files between client and server so they can interoperate 🫢

A key file is a text file made of a sequence of lines. Each line in the file MUST NOT be longer than 72 8-bit bytes, not counting the line termination characters. Hard limit, babe πŸ™ˆ

3.1. Line Termination Characters πŸ“

Implementations SHOULD generate public key files using their system's local text file representation. Make it match your OS, it's giving consistency πŸ’…

If the public key files aren't transferred as text files, implementations SHOULD be prepared to read files with any of the common line termination sequences: <CR>, <LF>, or <CR><LF>. So basically, be flexible about line endings 🌈

3.2. Begin and End Markers πŸŽ€

The first line of a conforming key file MUST be a begin marker, which is the literal text:

---- BEGIN SSH2 PUBLIC KEY ----

The last line of a conforming key file MUST be an end marker, which is the literal text:

---- END SSH2 PUBLIC KEY ----

3.3. Key File Header 🌸

The key file header section is made up of multiple RFC822-style header fields. Each field is one line in this format:

Header-tag ':' ' ' Header-value

The Header-tag MUST NOT be more than 64 8-bit bytes, and it's case-insensitive. The Header-value MUST NOT be more than 1024 8-bit bytes. Each line in the header MUST NOT be more than 72 8-bit bytes. Lots of rules, but they're not that deep πŸ¦‹

A line is continued if its last character is a \. If the last character of a line is a \, the logical contents of that line are made by removing the \ and the line termination characters, then adding on the contents of the next line. It's basically a line-join, iykyk ✨

The Header-tag MUST be encoded in US-ASCII. The Header-value MUST be encoded in UTF-8 [RFC3629]. πŸ”₯

A line that isn't a continuation line and has no : in it is the first line of the base64-encoded body. (See Section 3.4.) So the header ends and the body starts there 🧚

The space of header-tags is managed as described in Section 5. We'll get to that in Part 2 🌈

Compliant implementations MUST ignore headers with unrecognized header-tags. Implementations SHOULD preserve those unrecognized headers when they manipulate the key file. Be nice to the headers you don't understand πŸ«ΆπŸ’œ

3.3.1. Subject Header πŸ“

This field stores the login-name that the key was generated under. For example:

Subject: user

3.3.2. Comment Header πŸ’–

The comment header holds a user-specified comment. The comment SHOULD be displayed when the key is used. ✨

It's suggested that this field default to user@hostname, for the user and machine that generated the key. For example:

Comment: user@example.com

Right now, common practice is to wrap the Header-value of the Comment in " characters, one at the start and one at the end. Some existing implementations fail if those quotation marks are left out, which is a whole mess 😭

Compliant implementations MUST function correctly if the quotation marks are omitted. Implementations MAY include the quotation marks. If the first and last characters of the Header-value are matching quotation marks, implementations SHOULD remove them before using the value. So the quotes are optional, but if they're there, strip them off πŸ’…

3.3.3. Private Use Headers πŸ¦‹

Headers with header-tags that begin with "x-" are reserved for private use. Your secret stash, no judgment 🀫🌈

3.4. Public Key File Body πŸ”‘

The body of a public key file is the base64 encoded ([RFC2045]) public key data, as specified by [RFC4253], Section 6.6:

string    certificate or public key format identifier
byte[n]   key/certificate data

Same as all the other lines, each line in the body MUST NOT be longer than 72 8-bit bytes, not counting the line termination characters. πŸŽ€

3.5. Differences with RFC 1421 PEM Formats πŸ‘‘

Implementers should take care to notice that, even though the format looks superficially similar to the ones specified by PEM [RFC1421] and OpenPGP [RFC2440], it is not identical. The big differences are:

  • The other specifications use different BEGIN/END delimiters: five dashes with no space, instead of four dashes and a space.
  • There is no blank line before the start of the base64-encoded contents.
  • There is no Cyclic Redundancy Check (CRC) at the end of the base64-encoded block.
  • Header continuation uses a backslash at the end of the continued line, rather than whitespace at the start of the next line.

Don't mix these up, bestie πŸ™ˆβ­

3.6. Examples 🧁

Here are some examples of public key files that are compliant. Heads up: the examples all wrap before 72 bytes to meet IETF document requirements, but they're still compliant πŸ’…

Example one, an RSA key with an x-command header:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "1024-bit RSA, converted from OpenSSH by me@example.com"
x-command: /home/me/bin/lock-in-guest.sh
AAAAB3NzaC1yc2EAAAABIwAAAIEA1on8gxCGJJWSRT4uOrR13mUaUk0hRf4RzxSZ1zRb
YYFw8pfGesIFoEuVth4HKyF8k1y4mRUnYHP1XNMNMJl1JcEArC2asV8sHf6zSPVffozZ
5TT4SfsUu/iKy9lUcCfXzwre4WWZSXXcPff+EHtWshahu3WzBdnGxm5Xoi89zcE=
---- END SSH2 PUBLIC KEY ----

Example two, a DSA key with a continued comment:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: This is my public key for use on \
servers which I don't like.
AAAAB3NzaC1kc3MAAACBAPY8ZOHY2yFSJA6XYC9HRwNHxaehvx5wOJ0rzZdzoSOXxbET
W6ToHv8D1UJ/z+zHo9Fiko5XybZnDIaBDHtblQ+Yp7StxyltHnXF1YLfKD1G4T6JYrdH
YI14Om1eg9e4NnCRleaqoZPF3UGfZia6bXrGTQf3gJq2e7Yisk/gF+1VAAAAFQDb8D5c
vwHWTZDPfX0D2s9Rd7NBvQAAAIEAlN92+Bb7D4KLYk3IwRbXblwXdkPggA4pfdtW9vGf
J0/RHd+NjB4eo1D+0dix6tXwYGN7PKS5R/FXPNwxHPapcj9uL1Jn2AWQ2dsknf+i/FAA
vioUPkmdMc0zuWoSOEsSNhVDtX3WdvVcGcBq9cetzrtOKWOocJmJ80qadxTRHtUAAACB
AN7CY+KKv1gHpRzFwdQm7HK9bb1LAo2KwaoXnadFgeptNBQeSXG1vO+JsvphVMBJc9HS
n24VYtYtsMu74qXviYjziVucWKjjKEb11juqnF0GDlB3VVmxHLmxnAz643WK42Z7dLM5
sY29ouezv4Xz2PuMch5VGPP+CDqzCM4loWgV
---- END SSH2 PUBLIC KEY ----

Example three, another DSA key, this time with a plain comment:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: DSA Public Key for use with MyIsp
AAAAB3NzaC1kc3MAAACBAPY8ZOHY2yFSJA6XYC9HRwNHxaehvx5wOJ0rzZdzoSOXxbET
W6ToHv8D1UJ/z+zHo9Fiko5XybZnDIaBDHtblQ+Yp7StxyltHnXF1YLfKD1G4T6JYrdH
YI14Om1eg9e4NnCRleaqoZPF3UGfZia6bXrGTQf3gJq2e7Yisk/gF+1VAAAAFQDb8D5c
vwHWTZDPfX0D2s9Rd7NBvQAAAIEAlN92+Bb7D4KLYk3IwRbXblwXdkPggA4pfdtW9vGf
J0/RHd+NjB4eo1D+0dix6tXwYGN7PKS5R/FXPNwxHPapcj9uL1Jn2AWQ2dsknf+i/FAA
vioUPkmdMc0zuWoSOEsSNhVDtX3WdvVcGcBq9cetzrtOKWOocJmJ80qadxTRHtUAAACB
AN7CY+KKv1gHpRzFwdQm7HK9bb1LAo2KwaoXnadFgeptNBQeSXG1vO+JsvphVMBJc9HS
n24VYtYtsMu74qXviYjziVucWKjjKEb11juqnF0GDlB3VVmxHLmxnAz643WK42Z7dLM5
sY29ouezv4Xz2PuMch5VGPP+CDqzCM4loWgV
---- END SSH2 PUBLIC KEY ----

Example four, an RSA key with a Subject and a wrapped comment:

---- BEGIN SSH2 PUBLIC KEY ----
Subject: me
Comment: 1024-bit rsa, created by me@example.com Mon Jan 15 \
08:31:24 2001
AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4
596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4
soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=
---- END SSH2 PUBLIC KEY ----

That's the end of part 1 πŸ¦‹βœ¨ Part 2 is coming up next with Public Key Fingerprints, IANA Considerations, Security Considerations, and the References πŸ’–

6. Security Considerations πŸ”

okay bestie, security is the serious part so let's go 🫢 the file format here has no way to check integrity or spot if someone messed with the data 😬 since anyone could tamper with it, you SHOULD protect these files with system-level stuff like Access Control Lists, UNIX permissions, or other Discretionary and/or Mandatory Access Controls πŸ›‘οΈ and if the contents get transferred, that SHOULD happen over a trusted channel πŸ”’

the header data in this format can hold basically unlimited info 😭 in lots of places it's harmless public stuff, but it can accidentally leak info about a user, a key, or how the key gets used. like imagine a comment that says Comment: Mary E. Jones, 123 Main St, Home Phone:... πŸ’€ the sites that deploy this format SHOULD review whether and how they use this header data πŸ‘€

the fingerprint method here uses MD5, a one-way hash that has known weaknesses around collision resistance πŸ™ˆ BUT the way it's used here only depends on 2nd-preimage resistance, not collision resistance, so the weakness doesn't actually hit this use case πŸ’…

MD5 is used here for historical reasons πŸ•°οΈ

7. References πŸ“š

7.1. Normative References

[RFC1321]  Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321,
           April 1992.

[RFC2045]  Freed, N. and N. Borenstein, "Multipurpose Internet Mail
           Extensions (MIME) Part One: Format of Internet Message
           Bodies", RFC 2045, November 1996.

[RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
           Requirement Levels", BCP 14, RFC 2119, March 1997.

[RFC3629]  Yergeau, F., "UTF-8, a transformation format of ISO
           10646", STD 63, RFC 3629, November 2003.

[RFC4253]  Ylonen, T. and C. Lonvick, "The Secure Shell (SSH)
           Transport Layer Protocol", RFC 4253, January 2006.

[RFC2434]  Narten, T. and H. Alvestrand, "Guidelines for Writing an
           IANA Considerations Section in RFCs", BCP 26, RFC 2434,
           October 1998.

7.2. Informative References

[RFC1421]  Linn, J., "Privacy Enhancement for Internet Electronic
           Mail: Part I: Message Encryption and Authentication
           Procedures", RFC 1421, February 1993.

[RFC2440]  Callas, J., Donnerhacke, L., Finney, H., and R. Thayer,
           "OpenPGP Message Format", RFC 2440, November 1998.

Authors' Addresses πŸ’Œ

Joseph Galbraith
VanDyke Software
4848 Tramway Ridge Blvd
Suite 101
Albuquerque, NM  87111
US

Phone: +1 505 332 5700
EMail: galb@vandyke.com


Rodney Thayer
Canola & Jones
650 Castro Street Suite 120-205
Mountain View CA 94041
US

Phone: +1 650 704 8389
EMail: rodney@canola-jones.com

Copyright (C) The IETF Trust (2006) 🫢

this document is subject to the rights, licenses and restrictions in BCP 78, and except as set out there, the authors keep all their rights πŸ“œ

it's provided "AS IS" and, as the legal text puts it:

THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST,
AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT
THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY
IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE.

Intellectual Property 🧾

the IETF doesn't take a position on whether any Intellectual Property Rights or other rights that might apply to the technology in this document are valid or in scope, or whether any license under those rights is available πŸ€·β€β™€οΈ it also doesn't claim it has done any independent search for such rights. info about how rights work for RFC documents lives in BCP 78 and BCP 79 πŸ“–

copies of IPR disclosures sent to the IETF Secretariat, any assurances of licenses that will be made available, and the results of attempts to get a general license or permission for implementers or users are all available from the IETF's online IPR repository at http://www.ietf.org/ipr πŸ”—

the IETF also invites anyone to flag copyrights, patents, patent applications, or other proprietary rights that might cover technology needed to implement this standard. send those to ietf-ipr@ietf.org πŸ“¨

Acknowledgement 🌸

Funding for the RFC Editor function is currently provided by the Internet Society πŸ’–

πŸ“¦ where this page comes from