rsagen, rsafill, asn12rsa, rsa2asn1, rsa2pub, rsa2ssh, rsa2x509, rsa2csr – generate and format rsa keys
Plan 9 represents an RSA key as an attribute-value pair list
prefixed with the string
this is the generic key format used by
A full RSA private key has the following attributes:
the number of significant bits in
the encryption exponent
the product of
the decryption exponent
a large prime
another large prime
!kp, !kq, !c2
parameters derived from the other attributes, cached to speed decryption
All the numbers are in hexadecimal except
which is decimal.
An RSA public key omits the attributes beginning with
A key may have other attributes as well (for example, a
attribute identifying how this key is typically used),
but to these utilities such attributes are merely comments.
For example, a very small (and thus insecure) private key and corresponding
public key might be:
key proto=rsa size=8 ek=7 n=8F !dk=67 !p=B !q=D !kp=3 !kq=7 !c2=6
key proto=rsa size=8 ek=7 n=8F
Note that the order of the attributes does not matter.
prints a randomly generated RSA private key
is specified, it is printed between
is a sequence of attribute-value comments describing the key.
reads a private key,
attributes if they are missing,
and prints a full key.
reads an RSA private or public key stored as ASN.1
encoded in the binary Distinguished Encoding Rules (DER)
and prints a Plan 9 RSA key,
ASN.1/DER is a popular key format on Unix and Windows;
it is often encoded in text form using the Privacy Enhanced Mail (PEM) format
in a section labeled as an
auth/pemdecode 'RSA PRIVATE KEY' | auth/asn12rsa
extracts the key section from a textual ASN.1/DER/PEM key
into binary ASN.1/DER format and then
converts it to a Plan 9 RSA key.
reads a Plan 9 RSA public or private key,
removes the private attributes, and prints the resulting public key.
Comment attributes are preserved.
but outputs the public key in ASN.1/DER format.
reads a Plan 9 RSA public or private key and prints the public portion
in the format used by SSH2. The
option will set the comment.
reads a Plan 9 RSA private key and writes a self-signed X.509 certificate
encoded in ASN.1/DER format to standard output.
(Note that ASN.1/DER X.509 certificates are different from ASN.1/DER private keys).
The certificate uses the current time as its start time and expires
(default 3 years)
It contains the public half of the key
as the issuer/subject string (also known as a “Distinguished Name”).
This info is typically in the form:
C=US ST=NJ L=07974 O=Lucent OU='Bell Labs' CN=G.R.Emlin
One can append further Distinguished Names, DNS Names and
E-Mail addresses as a “Subject Alternative Name” separated
with a comma after the main subject.
The X.509 ASN.1/DER format is often encoded in text using a PEM section
labeled as a
auth/rsa2x509 'C=US OU=''Bell Labs''' file |
generates such a textual certificate.
Applications that serve TLS-encrypted sessions (for example,
expect certificates in ASN.1/DER/PEM format.
The Plan 9 RSA private key needs to be loaded into factotum
for TLS server applications. It is recommended to put the key into
avoiding it being stored unencrypted on the filesystem.
and a RSA private key and outputs a signing request in ASN.1 format.
Generate a fresh key and use it to start a TLS-enabled web server:
auth/rsagen -t 'service=tls owner=*' >key
auth/rsa2x509 'C=US CN=*.cs.bell-labs.com' key |
auth/pemencode CERTIFICATE >cert
cat key >/mnt/factotum/ctl
ip/httpd/httpd -c cert
Generate a fresh key and configure a remote Unix system to
allow use of that key for logins:
auth/rsagen -t 'service=ssh' >key
auth/rsa2ssh key | ssh unix 'cat >>.ssh/authorized_keys'
cat key >/mnt/factotum/ctl
Convert a private key in PEM format (as generated by OpenSSL)
and load it into factotum:
auth/pemdecode 'PRIVATE KEY' key.pem |
auth/asn12rsa -t 'service=tls' >/mnt/factotum/ctl
Generate a certificate signing request (CSR) in PEM format:
auth/rsa2csr 'CN=example.com' key |
auth/pemencode 'CERTIFICATE REQUEST'
Generate a tinc host key:
auth/rsagen -t 'service=tinc role=client host=myhost' > myhost.key
auth/rsa2pub < myhost.key |
auth/rsa2asn1 | auth/pemencode 'RSA PUBLIC KEY' > hosts/myhost
There are too many key formats.