blob: b01c979d9dc53a20e6155bd1a4397d4f4dd14e6d [file] [log] [blame]
rsc30f6ae12005-02-13 23:44:12 +00001.TH RSA 1
rsca784b112005-02-13 22:02:06 +00002.SH NAME
rsc45993342005-02-13 22:05:31 +00003dsagen, rsagen, rsafill, asn12dsa, asn12rsa, dsa2pub, rsa2csr, rsa2pub, dsa2ssh, rsa2ssh, rsa2x509 \- generate and format dsa and rsa keys
rsca784b112005-02-13 22:02:06 +00004.SH SYNOPSIS
5.PP
6.B dsagen
7[
8.B -t
9.I tag
10]
11.PP
12.B rsagen
13[
14.B -b
15.I nbits
16]
17[
18.B -t
19.I tag
20]
21.PP
22.B rsafill
23[
24.I file
25]
26.PP
27.B asn12dsa
28[
29.B -t
30.I tag
31]
32[
33.I file
34]
35.PP
36.B asn12rsa
37[
38.B -t
39.I tag
40]
41[
42.I file
43]
44.PP
45.B dsa2pub
46[
47.I file
48]
49.PP
50.B rsa2pub
51[
52.I file
53]
54.PP
55.B dsa2ssh
56[
57.I file
58]
59.PP
60.B rsa2ssh
61[
62.B -2
63]
64[
65.I file
66]
67.PP
68.B rsa2x509
69[
70.B -e
71.I expiretime
72]
73.I certinfo
74[
75.I file
76]
rsc45993342005-02-13 22:05:31 +000077.PP
78.B rsa2csr
79.I certinfo
80[
81.I file
82]
rsca784b112005-02-13 22:02:06 +000083.SH DESCRIPTION
84Plan 9 represents DSA and RSA keys as attribute-value pair lists
85prefixed with the string
86.BR key ;
87this is the generic key format used by
88.IR factotum (4).
89A full DSA private key has the following attributes:
90.TP
91.B proto
92must be
93.B dsa
94.TP
95.B p
96prime public modulus
97.TP
98.B q
99prime group order; divides
100.BR p -1
101.TP
102.B alpha
103group generator
104.TP
105.B key
106.BR alpha ^ !secret
107mod
108.B p
109.TP
110.B !secret
111the secret exponent
112.PD
113.PP
114A full RSA private key has the following attributes:
115.TP
116.B proto
117must be
118.B rsa
119.TP
120.B size
121the number of significant bits in
122.B n
123.TP
124.B ek
125the encryption exponent
126.TP
127.B n
128the product of
129.B !p
130and
131.B !q
132.TP
133.B !dk
134the decryption exponent
135.TP
136.B !p
137a large prime
138.TP
139.B !q
140another large prime
141.TP
142.B "!kp\fR, \fL!kq\fR, \fL!c2
143parameters derived from the other attributes, cached to speed decryption
144.PD
145.LP
146All the numbers in both keys are in hexadecimal except RSA's
147.I size ,
148which is decimal.
149A public key omits the attributes beginning with
150.L ! .
151A key may have other attributes as well (for example, a
152.B service
153attribute identifying how this key is typically used),
154but to these utilities such attributes are merely comments.
155.PP
156For example, a very small (and thus insecure) private key and corresponding
157public key might be:
158.IP
159.EX
160key proto=rsa size=8 ek=7 n=8F !dk=67 !p=B !q=D !kp=3 !kq=7 !c2=6
161key proto=rsa size=8 ek=7 n=8F
162.EE
163.LP
164Note that the order of the attributes does not matter.
165.PP
166.I Dsagen
167prints a randomly generated DSA private key using the
168NIST-recommended algorithm.
169If
170.I tag
171is specified, it is printed between
172.B key
173and
174.BR proto=dsa ;
175typically,
176.I tag
177is a sequence of attribute-value comments describing the key.
178.PP
179.I Rsagen
180prints a randomly generated RSA private key
181whose
182.B n
183has exactly
184.I nbits
185(default 1024)
186significant bits.
187.PP
188.I Rsafill
189reads a private key,
190recomputes the
191.BR !kp ,
192.BR !kq ,
193and
194.BR !c2
195attributes if they are missing,
196and prints a full key.
197.PP
198.I Asn12dsa
199reads an DSA private key stored as ASN.1
200encoded in the binary Distinguished Encoding Rules (DER)
201and prints a Plan 9 DSA key,
202inserting
203.I tag
204exactly as
205.I dsagen
206does.
207ASN.1/DER is a popular key format on Unix and Windows;
208it is often encoded in text form using the Privacy Enhanced Mail (PEM) format
209in a section labeled as an
210.RB `` DSA
211.B PRIVATE
212.BR KEY .''
213The command:
214.IP
215.EX
216pemdecode 'DSA PRIVATE KEY' | asn12dsa
217.EE
218.LP
219extracts the key section from a textual ASN.1/DER/PEM key
220into binary ASN.1/DER format and then
221converts it to a Plan 9 DSA key.
222.PP
223.I Asn12rsa
224is similar but operates on RSA keys.
225.PP
226.I Dsa2pub
227reads a Plan 9 DSA public or private key,
228removes the private attributes, and prints the resulting public key.
229Comment attribtes are preserved.
230.PP
231.I Rsa2pub
232is similar but operates on RSA keys.
233.PP
234.I Dsa2ssh
235reads a Plan 9 DSA public or private key and prints the
236public portion in the format used by SSH version 2 (version 1 did not support DSA).
237If the key has a
238.B comment
239attribute, that comment is appended to the key.
240.PP
241.I Rsa2ssh
242is similar but operates on RSA keys.
243It decides whether to print in version 1 or version 2
244format by inspecting the
245.B service
246attribute.
247.PP
248.I Dsa2ssh
249and
250.I rsa2ssh
251are useful for generating SSH's
252.B authorized_keys
253file.
254.PP
255.I Rsa2x509
256reads a Plan 9 RSA private key and writes a self-signed X.509 certificate
257encoded in ASN.1/DER format to standard output.
258(Note that ASN.1/DER X.509 certificates are different from ASN.1/DER private keys).
259The certificate uses the current time as its start time and expires
260.I expiretime
261seconds
262(default 3 years)
263later.
264It contains the public half of the key
265and includes
266.I certinfo
267as the issuer/subject string (also known as a ``Distinguished Name'').
268This info is typically in the form:
269.IP
270.EX
271C=US ST=NJ L=07974 O=Lucent OU='Bell Labs' CN=G.R.Emlin
272.EE
273.LP
274The X.509 ASN.1/DER format is often encoded in text using a PEM section
275labeled as a
276.RB `` CERTIFICATE .''
277The command:
278.IP
279.EX
280rsa2x509 'C=US OU=''Bell Labs''' file |
281pemencode CERTIFICATE
282.EE
283.LP
284generates such a textual certificate.
rsc45993342005-02-13 22:05:31 +0000285Applications that serve TLS-encrypted sessions
286typically expect certificates in ASN.1/DER/PEM format.
287.PP
288.I Rsa2csr
289is like
290.I rsa2x509
291but writes an X.509 certificate request.
rsca784b112005-02-13 22:02:06 +0000292.SH EXAMPLES
rsc45993342005-02-13 22:05:31 +0000293Generate a fresh key and use it to start the Plan 9 TLS-enabled web server:
rsca784b112005-02-13 22:02:06 +0000294.IP
295.EX
296rsagen -t 'service=tls owner=*' >key
297rsa2x509 'C=US CN=*.cs.bell-labs.com' key |
298 pemencode CERTIFICATE >cert
299cat key >/mnt/factotum/ctl
300ip/httpd/httpd -c cert
301.EE
302.PP
303Generate a fresh set of SSH keys (only one is necessary),
304load them into factotum,
305and configure a remote Unix system to allow those keys for logins:
306.IP
307.EX
rsc30f6ae12005-02-13 23:44:12 +0000308rsagen -t 'service=ssh role=decrypt' >rsa1
309rsagen -t 'service=ssh-rsa role=sign' >rsa2
310dsagen -t 'service=ssh-dss role=sign' >dsa2
rsca784b112005-02-13 22:02:06 +0000311.EE
312.PP
313Convert existing Unix SSH version 2 keys instead of generating new ones:
314.IP
315.EX
316cd $HOME/.ssh
317pemdecode 'DSA PRIVATE KEY' id_dsa | asn12dsa >dsa2
318pemdecode 'RSA PRIVATE KEY' id_rsa | asn12rsa >rsa2
319.EE
320.PP
321Load those keys into factotum:
322.IP
323.EX
324cat rsa1 rsa2 dsa2 | 9p write -l factotum/ctl
325.EE
326Allow use of those keys for logins on other systems:
327.IP
328.EX
329rsa2ssh rsa1 >auth.keys
330rsa2ssh rsa2 >>auth.keys
331dsa2ssh dsa2 >>auth.keys
332scp auth.keys unix:.ssh/authorized_keys
333.EE
334.SH SOURCE
335.B \*9/src/cmd/auth
336.SH "SEE ALSO
337.IR factotum (4),
338.IR pem (1),
339.IR ssh (1)
340.SH BUGS
341There are too many key formats.
342.PP
343There is no program to convert SSH version 1 RSA private keys.