RSA(1)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’… RSA(1) πŸ’…

okay so bestie, welcome to the General Commands Manual page for the whole key-making squad. This is RSA(1), and it is literally giving β€œgenerate and format DSA and RSA keys” with main character energy. No cap: every command, flag, example and warning is still here, just with more sparkle ✨.

🌸 NAME 🌸

dsagen, rsagen, rsafill, asn12dsa, asn12rsa, dsa2pub, rsa2csr, rsa2pub, dsa2ssh, rsa2ssh, rsa2x509 β€” generate and format dsa and rsa keys.

✨ SYNOPSIS ✨

dsagen [ -t tag ]

rsagen [ -b nbits ] [ -t tag ]

rsafill [ file ]

asn12dsa [ -t tag ] [ file ]

asn12rsa [ -t tag ] [ file ]

dsa2pub [ file ]

rsa2pub [ file ]

dsa2ssh [ file ]

rsa2ssh [ -2 ] [ file ]

rsa2x509 [ -e expiretime ] certinfo [ file ]

rsa2csr certinfo [ file ]

πŸ’– DESCRIPTION πŸ’–

Plan 9 represents DSA and RSA keys as attribute-value pair lists prefixed with the string key; this is the generic key format used by factotum(4). A full DSA private key has the following attributes:

  • proto β€” must be dsa
  • p β€” prime public modulus
  • q β€” prime group order; divides p-1
  • alpha β€” group generator
  • key β€” alpha^!secret mod p
  • !secret β€” the secret exponent

A full RSA private key has the following attributes:

  • proto β€” must be rsa
  • size β€” the number of significant bits in n
  • ek β€” the encryption exponent
  • n β€” the product of !p and !q
  • !dk β€” the decryption exponent
  • !p β€” a large prime
  • !q β€” another large prime
  • !kp, !kq, !c2 β€” parameters derived from the other attributes, cached to speed decryption

All the numbers in both keys are in hexadecimal except RSA's size, which is decimal. A public key omits the attributes beginning with !. A key may have other attributes as well (for example, a service 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.

⚠️ vibe check: that example key is very small and thus insecure β€” it is a demo, not a flex, bestie πŸ’€.

dsagen prints a randomly generated DSA private key using the NIST-recommended algorithm. If tag is specified, it is printed between key and proto=dsa; typically, tag is a sequence of attribute-value comments describing the key.

rsagen prints a randomly generated RSA private key whose n has exactly nbits (default 1024) significant bits.

rsafill reads a private key, recomputes the !kp, !kq, and !c2 attributes if they are missing, and prints a full key.

asn12dsa reads a DSA private key stored as ASN.1 encoded in the binary Distinguished Encoding Rules (DER) and prints a Plan 9 DSA key, inserting tag exactly as dsagen does. 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 a DSA PRIVATE KEY. The command:

pemdecode 'DSA PRIVATE KEY' | asn12dsa

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 DSA key.

asn12rsa is similar but operates on RSA keys.

dsa2pub reads a Plan 9 DSA public or private key, removes the private attributes, and prints the resulting public key. Comment attributes are preserved.

rsa2pub is similar but operates on RSA keys.

dsa2ssh reads a Plan 9 DSA public or private key and prints the public portion in the format used by SSH version 2 (version 1 did not support DSA). If the key has a comment attribute, that comment is appended to the key.

rsa2ssh is similar but operates on RSA keys. It decides whether to print in version 1 or version 2 format by inspecting the service attribute.

dsa2ssh and rsa2ssh are useful for generating SSH's authorized_keys file.

rsa2x509 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 expiretime seconds (default 3 years) later. It contains the public half of the key and includes certinfo 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

The X.509 ASN.1/DER format is often encoded in text using a PEM section labeled as a CERTIFICATE. The command:

rsa2x509 'C=US OU=''Bell Labs''' file |
pemencode CERTIFICATE

generates such a textual certificate. Applications that serve TLS-encrypted sessions typically expect certificates in ASN.1/DER/PEM format.

rsa2csr is like rsa2x509 but writes an X.509 certificate request.

πŸŽ€ EXAMPLES πŸŽ€

Generate a fresh key and use it to start the Plan 9 TLS-enabled web server:

rsagen -t 'service=tls owner=*' >key
rsa2x509 'C=US CN=*.cs.bell-labs.com' key |
pemencode CERTIFICATE >cert
cat key >/mnt/factotum/ctl
ip/httpd/httpd -c cert

Generate a fresh set of SSH keys (only one is necessary), load them into factotum, and configure a remote Unix system to allow those keys for logins:

rsagen -t 'service=ssh role=decrypt' >rsa1
rsagen -t 'service=ssh-rsa role=sign' >rsa2
dsagen -t 'service=ssh-dss role=sign' >dsa2

Convert existing Unix SSH version 2 keys instead of generating new ones:

cd $HOME/.ssh
pemdecode 'DSA PRIVATE KEY' id_dsa | asn12dsa >dsa2
pemdecode 'RSA PRIVATE KEY' id_rsa | asn12rsa >rsa2

Load those keys into factotum:

cat rsa1 rsa2 dsa2 | 9p write -l factotum/ctl

Allow use of those keys for logins on other systems:

rsa2ssh rsa1 >auth.keys
rsa2ssh rsa2 >>auth.keys
dsa2ssh dsa2 >>auth.keys
scp auth.keys unix:.ssh/authorized_keys

πŸ¦‹ SOURCE πŸ¦‹

/src/cmd/auth β€” that is the source, bestie 🫢.

🌈 SEE ALSO 🌈

factotum(4), pem(1), ssh(1) β€” the supporting cast, go read them too ✨.

πŸ’€ BUGS πŸ’€

  • There are too many key formats.
  • There is no program to convert SSH version 1 RSA private keys.

and that's the footer, bestie: xoxo, RSA(1) from the General Commands Manual πŸ’–βœ¨πŸ«Ά