General robustification.
[u/mdw/catacomb] / key.1
CommitLineData
d03ab969 1.\" -*-nroff-*-
052b36d0 2.ie t \{\
3. ds ss \s8\u
4. ds se \d\s0
1476eebc 5. ds us \s8\d
6. ds ue \u\s0
052b36d0 7.\}
8.el \{\
9. ds ss ^
10. ds se
1476eebc 11. ds us _
12. ds se
052b36d0 13.\}
d07dfe80 14.TH key 1 "5 June 1999" "Straylight/Edgeware" "Catacomb cryptographic library"
d03ab969 15.SH NAME
16key \- simple key management system
17.SH SYNOPSIS
18.B key
19.RB [ \-k
20.IR keyring ]
21.I command
22.PP
23where
24.I command
25is one of:
26.PP
27.B add
d07dfe80 28.RB [ \-lqrLS ]
052b36d0 29.RB [ \-a
30.IR alg ]
31.RB [ \-b | \-B
d03ab969 32.IR bits ]
052b36d0 33.RB [ \-p
34.IR param ]
d07dfe80 35.RB [ \-R
052b36d0 36.IR tag ]
37.br
38\h'8n'
d03ab969 39.RB [ \-e
40.IR expire ]
052b36d0 41.RB [ \-t
42.IR tag ]
d03ab969 43.RB [ \-c
44.IR comment ]
eb31b00e 45.RB [ \-C
46.IR curve ]
47.br
48\h'8n'
d03ab969 49.I type
50.IR attr ...
51.br
52.B expire
052b36d0 53.IR tag ...
d03ab969 54.br
55.B delete
052b36d0 56.IR tag ...
57.br
58.B tag
59.I tag
60.RI [ new-tag ]
61.br
62.B comment
63.I tag
64.RI [ comment ]
d03ab969 65.br
66.B setattr
052b36d0 67.I tag
d03ab969 68.IR attr ...
69.br
052b36d0 70.B lock
71.I qtag
72.br
73.B unlock
74.I qtag
75.br
d03ab969 76.B list
052b36d0 77.RB [ \-uqv ]
78.RB [ \-f
79.IR filter ]
80.RI [ tag ...]
81.br
82.B fingerprint
83.RB [ \-f
84.IR filter ]
85.RI [ tag ...]
d03ab969 86.br
87.B tidy
88.br
89.B extract
052b36d0 90.RB [ \-f
91.IR filter ]
d03ab969 92.I file
052b36d0 93.RI [ tag ...]
d03ab969 94.br
95.B merge
96.I file
97.SH DESCRIPTION
98The
99.B key
100command performs useful operations on Catacomb keyring files. It
101provides a number of subcommands, by which the various operations may be
102carried out.
103.SS "Global options"
104Before the command name,
105.I "global options"
106may be given. The following global options are supported:
107.TP
d07dfe80 108.BR "\-h, \-\-help " [ \fIcommand ]
d03ab969 109Writes a brief summary of
110.BR key 's
111various options to standard output, and
d07dfe80 112returns a successful exit status. With a command name, gives help on
113that command.
d03ab969 114.TP
115.B "\-v, \-\-version"
116Writes the program's version number to standard output, and returns a
117successful exit status.
118.TP
119.B "\-u, \-\-usage"
120Writes a very terse command line summary to standard output, and returns
121a successful exit status.
122.TP
c9e31e42 123.BI "\-k, \-\-keyring " file
d03ab969 124Names the keyring file which
125.B key
126is to process. The default keyring, used if this option doesn't specify
127one, is the file named
128.B keyring
129in the current directory. The keyring must be stored in a regular file:
130pipes, sockets, devices etc. are not allowed.
131The
132.B key
133program attempts to lock the keyring before accessing it, using
134.BR fcntl (2)
135locking. It will however time out after a short while (10 seconds) and
136report a failure.
137.SS Concepts
138In addition to the actual key data itself, a Catacomb key has a number
139of other pieces of information attached to it:
140.TP
052b36d0 141.B "keyid"
142Every key has a 32-bit identifying number, written in hexadecimal.
143Keyids are not actually related to the key contents: they're generated
144randomly. Applications use keyids to refer to specific keys; users are
145probably better off with tags and types. A
d03ab969 146.I deleted
147key cannot be looked up by keyid.
148.TP
052b36d0 149.B "tag"
150A key's tag is a unique string which can be used by users and
151applications to identify the key. Tag strings may not contain spaces,
152colons or dots. A
153.I deleted
154key cannot be looked up by tag. Whenever a tag name is wanted, a hex
155keyid or key type string can be given instead.
156.TP
157.B "type"
d03ab969 158A key's type string describes what the key may be used for. The type
159string is arbitrary, except that it may not contain whitespace
052b36d0 160characters, dots or colons. Applications use key types to obtain an
161arbitrary but suitable key for some purpose. An
d03ab969 162.I expired
052b36d0 163key cannot be looked up by type, but may be looked up by keyid or tag.
164.TP
165.B "key encoding"
166There are a number of different ways in which keys can be represented,
167according to the uses to which the key will be put. Most symmetric
168algorithms use
169.I binary
170keys. Keys used with number-theoretic systems (like most common
171public-key systems) use
172.I "multiprecision integer"
173keys. Algorithms which require several key constituents (again, like
174most public-key systems) use
175.I structured
176keys, which consist of a collection of named parts. Finally, keys
177(including structured keys) can be encrypted.
178.TP
179.B "filter"
180Keys and key components may be selected by a filter expression, a
181sequence of flag names separated by commas. Flags are:
182.BR binary ,
183.BR integer ,
184.B struct
185or
186.B encrypt
187(describing the key encoding);
188.BR symmetric ,
189.BR private ,
190.B public
191or
192.B shared
193(describing the category of key);
194.B burn
195and its negation
196.B \-burn
197(whether the key should be erased from memory after use); and
198.B secret
199and its negation
200.B \-secret
201(whether the key is safe to divulge).
202.TP
203.B "qualified tag"
204A key component may be identified by the key's tag (or keyid, or type).
205Subcomponents of structured keys are identified by following the tag by
206a dot and the name of the subcomponent.
d03ab969 207.TP
208.B "expiry time"
209Most keys expire after a certain amount of time. Once a key has
210expired, it will no longer be chosen as a result of a lookup by key
211type. However, it is not deleted until its deletion time is also
212reached.
213.TP
214.B "deletion time"
215A key's deletion time is the latest expiry time of any of the objects
216which require that key. For example, a key used for authenticating
217cryptographic cookies should have its deletion time set to the longest
052b36d0 218expiry time of any of the cookies it can authenticate. Once a key's
219deletion time is passed, it can no longer be referred to by
d03ab969 220applications, and will be removed from the keyring next time it's
221written to disk.
222.TP
052b36d0 223.B "comment"
d03ab969 224A key may be given a comment when it's created. The comment is for the
225benefit of users, and isn't interpreted by applications at all.
226(Hopefully.)
227.TP
052b36d0 228.B "attributes"
d03ab969 229A key as zero or more name/value pairs. The names and values are
230arbitrary strings, except they may not contain null bytes. Some
231attributes may have meaning for particular applications or key types;
232others may be assigned global meanings in future.
233.SH "COMMAND REFERENCE"
234.SS add
235The
236.B add
237command creates a new key and adds it to the keyring. The command
238accepts the following options:
239.TP
052b36d0 240.BI "\-a, \-\-algorithm " alg
241Selects a key generation algorithm. The default algorithm is
242.BR binary ;
243the different algorithms are described below.
244.TP
c9e31e42 245.BI "\-b, \-\-bits " bits
d03ab969 246The length of the key to generate, in bits. The default, if this option
052b36d0 247is not supplied, depends on the key-generation algorithm.
248.TP
249.BI "\-B, \-\-qbits " bits
250The length of the subsidiary key or parameter, in bits. Not all
251key-generation algorithms have a subsidiary key size.
252.TP
253.BI "\-p, \-\-parameters " tag
254Selects a key containing parameter values to copy. Not all
255key-generation algorithms allow the use of shared parameters.
d03ab969 256.TP
c9e31e42 257.BI "\-e, \-\-expire " expire
d03ab969 258The expiry date for the generated key. This may be the string
259.RB ` forever '
260if the key should never expire automatically, or any date acceptable to
261the
262.BR getdate (3)
263library function. Briefly,
264.B getdate
265understands absolute dates such as
266.RB ` 1999-08-02 '
267or
268.RB ` "August 2nd, 1999" ',
269and (perhaps more usefully) relative dates such as
270.RB ` "+2 weeks" '.
271The default is to allow a 2 week expiry, which isn't useful.
272.TP
c9e31e42 273.BI "\-c, \-\-comment " comment
d03ab969 274Sets a comment for the key. The default is not to attach a comment.
052b36d0 275.TP
eb31b00e 276.BI "\-C, \-\-curve " curve-spec
277Use the elliptic curve described by
278.I curve-spec
279when generating elliptic curve parameters.
280.TP
052b36d0 281.BI "\-t, \-\-tag " tag
282Selects a tag string for the key. The default is not to set a tag. It
283is an error to select a tag which already exists.
284.TP
d07dfe80 285.BI "\-r, \-\-retag"
286If a
287.B \-t
288option is given, remove this tag from any key which already has it.
289.TP
290.BI "\-R, \-\-rand-id " tag
052b36d0 291Selects the key to use for the random number generator. Catacomb's
292random number generator can be
293.IR keyed ,
294so that, even if the inputs to the generator are compromised, knowledge
295of the key is also necessary to be able to predict the output. By
296default, the latest-expiring key with type
297.B catacomb-rand
298is used, if present; if not, no key is used.
299.TP
300.BI "\-l, \-\-lock"
301Requests that the secret parts of the newly-generated key be encrypted
302using a passphrase.
303.TP
304.BI "\-q, \-\-quiet"
305Suppresses the progress indication which is usually generated while
306time-consuming key generation tasks are being performed.
1476eebc 307.TP
308.BI "\-L, --lim-lee"
309When generating Diffie-Hellman parameters, generate a Lim-Lee prime
310rather than a random (or safe) prime. See the details on Diffie-Hellman
311key generation below.
312.TP
313.BI "\-S, --subgroup"
314When generating Diffie-Hellman parameters with a Lim-Lee prime, choose a
315generator of a prime-order subgroup rather than a subgroup of order
316.RI ( p "- 1)/2."
d03ab969 317.PP
318The key's type is given by the required
319.I type
320argument. Following the type are zero or more attributes, which are
321attached to the key in the same way as for the
322.B setattr
323command.
324.PP
052b36d0 325The key-generation algorithms supported are as follows:
326.TP
327.B "binary"
328Generates a plain binary key of the requested length. If the requested
329key length is not a multiple of eight, the high-order bits of the first
330octet of the key are zeroed. The default key length is 128 bits.
331.TP
332.B "des"
333Generates a DES key, with parity bits. The key length must be 56, 112
334or 168; the default is 56. The low-order bit of each octet is ignored by
335the DES algorithm; it is used to give each octet odd parity.
336.TP
337.B "rsa"
338Generates a public/private key pair for use with the RSA algorithm.
339.IP
340The key components are
341.I p
342and
343.IR q ,
344a pair of prime numbers;
345.IR n ,
346the product of
347.I p
348and
349.IR q ;
350.IR e ,
351the public exponent;
352.IR d ,
353the private exponent, chosen such that
354.IR ed \ \(==\ 1
355(mod
356.RI ( p \ \-\ 1)( q \ \-\ 1));
357and some other values useful for optimizing private-key operations:
358.IR q \*(ss\-1\*(se\ mod\ p ,
359.IR d \ mod\ p \ \-\ 1,
360and
361.IR d \ mod\ q \ \-\ 1.
362The values
363.I n
364and
365.I e
366constitute the public key; the rest must be kept secret. The key size
367requested by the
368.B \-b
369option determines the size of the modulus
370.IR n ;
371the default is 1024 bits.
372.IP
373The key generation algorithm chooses
374.I p
375and
376.I q
377to be
378.I strong
379primes: both
380.IR p \ \-\ 1
381and
382.IR p \ +\ 1
383have large prime factors \- call them
384.I r
385and
386.I s
387respectively \- and
388.IR r \ \-\ 1
389also has a large prime factor;
390.I q
391has similar properties.
392.IP
393The modulus
394.I n
395cannot be sensibly used as a shared parameter, since knowledge of
396corrssponding public and private exponents is sufficient to be able to
397factor the modulus and recover other users' private keys.
398.TP
eb31b00e 399.B "dh-param"
052b36d0 400Generates parameters for use with the Diffie-Hellman key exchange
401protocol, and many related systems, such as ElGamal encryption and
1476eebc 402signatures, and even DSA. (The separate DSA algorithm uses the
403generator described in FIPS186-1.)
404.IP
405The Diffie-Hellman parameters are a prime modulus
406.I p
052b36d0 407and a generator
408.I g
1476eebc 409of a subgroup of
410.BR Z / \c
411.IB p Z
412of order
413.IR q .
414The
052b36d0 415.B \-b
1476eebc 416option controls the size of the modulus
052b36d0 417.IR p ;
1476eebc 418the default size is 1024 bits.
419.IP
420If no
052b36d0 421.I q
1476eebc 422size is selected using the
052b36d0 423.B \-B
1476eebc 424option and the Lim-Lee prime option is disabled, then
425.I p
426is chosen to be a `safe' prime (i.e.,
052b36d0 427.IR p \ =\ 2 q \ +\ 1,
1476eebc 428with
429.I q
430prime). In this case, the value of
431.I g
432is fixed as 4.
433.IP
434If a size is chosen for
435.I q
436and Lim-Lee primes are not selected then the prime
437.I q
438is generated and
439.I p
440is chosen so that
441.IR p \ \-\ 1
442is a multiple of
443.IR q .
444.IP
445If the
446.B \-L
447option was given Lim-Lee primes are selected: the parameters are chosen
448such that
449.IR p \ =\ 2\ q \*(us0\*(ue\ q \*(us1\*(ue\ q \*(us2\*(ue\ ...\ +\ 1,
450where the
451.IR q \*(us i\*(ue
452are primes at least as large as the setting given by the
453.B \-B
454option (or 256 bits, if no setting was given).
052b36d0 455.IP
1476eebc 456If the
457.B \-S
458option was given, the generator
459.I g
460is chosen to generate the subgroup of order
461.IR q \*(us0\*(ue;
462otherwise,
463.I g
464will generate the group of order
465.RI ( p \ \-\ 1)/2\ =\ q \*(us0\*(ue\ q \*(us1\*(ue\ q \*(us2\*(ue\ ...
052b36d0 466.TP
467.B "dh"
468Generates a public/private key pair for use with offline Diffie-Hellman,
469ElGamal, DSA or similar discrete-logarithm-based systems. It selects a
470private key
471.IR x \ <\ q ,
472and computes the public key
473.IR y \ =\ g\*(ssx\*(se \ mod\ p .
474.TP
475.B "dsa-param"
476Generates parameters for the DSA algorithm. DSA parameters are also
477suitable for use with Diffie-Hellman and ElGamal system.
478.IP
479The main difference between DSA and Diffie-Hellman parameter generation
480is thatthe DSA parameter generation
481algorithm creates a
482.I seed
483from which the parameters are derived, and, assuming that the SHA-1 hash
484function is strong, it's not feasible to construct a seed from which
485deliberately weak parameters are derived. The algorithm used is the one
486described in the DSA standard, FIPS\ 186, extended only to allow
487sequential search for a prime
488.I q
489and to allow arbitrary parameter sizes. The seed is stored,
490Base64-encoded, as the value of the attribute
491.BR seed .
492.IP
493The default lengths for
494.I p
495and
496.I q
497are 768 and 160 bits respectively, since the DSA standard specifies that
498.I q
499be 160 bits, and the choice of 768 bits for
500.I p
501gives commensurate security.
502.TP
503.B "dsa"
504Generates a public/private key pair for DSA. As for Diffie-Hellman
505keys, it selects a
506private key
507.IR x \ <\ q ,
508and computes the public key
509.IR y \ =\ g\*(ssx\*(se \ mod\ p .
510.TP
511.B "bbs"
512Generates a public/private key pair for the Blum-Blum-Shub random-number
513generator, and the Blum-Goldwasser semantically-secure public-key
514encryption system.
515.IP
516The key components are prime numbers
517.I p
518and
519.IR q ,
520both congruent to 3 (mod\ 4), and their product
521.IR n .
522The public key is simply the modulus
523.IR n ;
524the factors
525.I p
526and
527.I q
528are the private key.
529.IP
530The key-generation algorithm ensures that the two primes
531.I p
532and
533.I q
534are
535.I strong
536(see the discussion of strong primes above, in the section on RSA keys),
537and that
538.RI ( p \ \-\ 1)/2
539and
540.RI ( q \ \-\ 1)/2
541are relatively prime, giving a maximum possible period length.
542.IP
543The key size requested by the
544.B \-b
545option determines the length of the modulus
546.IR n ;
547the default length is 1024 bits.
eb31b00e 548.TP
549.B "ec-param"
550Store an elliptic curve specification. If no explicit
551.I curve-spec
552is given (the
553.RB ` \-C '
554option) then a curve is chosen whose order is about the size given by the
555.RB ` \-b '
556option (default is 256 bits).
557.IP
558A
559.I curve-spec
560can be given explicitly (in which case
561.RB ` \-b '
562is ignored). It can either be the name of a built-in curve (say
563.B "key add \-C list"
564for a list of curve names) or a full specification. The curve is
565checked for correctness and security according to the SEC1
566specification: failed checks cause a warning to be issued to standard
567error (though the program continues anyway). The check can be
568suppressed using the
569.RB ` \-q '
570option.
571.IP
572A curve specification consists of the following elements optionally
573separated by whitespace: a
574.IR "field type" ,
575which is one of
576.BR "prime" ,
577.BR "niceprime" ,
578or
579.BR "binpoly" ;
580an optional
581.RB ` : ';
582the field modulus
583.IR p ;
584an optional
585.RB ` / ';
586a
587.IR "curve type" ,
588which is one of
589.BR "prime" ,
590.BR "primeproj" ,
591.BR "bin" ,
592and
593.BR "binproj"
594(the `proj' types currently have much better performance);
595an optional
596.RB ` : ';
597the two field-element parameters
598.I a
599and
600.IR b
601which define the elliptic curve
602.IR E ,
603separated by an optional
604.RB ` , ';
605an optional
606.RB ` / ';
607the
608.IR x -
609and
610.IR y -coordinates
611of the generator point
612.IR G ,
613separated by an optional
614.RB ` , ';
615an optional
616.RB ` : ';
617the order
618.I r
619of the group generated by
620.IR G ;
621an optional
622.RB ` * ';
623and the
624.I cofactor
625.I h
626=
627.RI # E / r .
628.TP
629.B "ec"
630Generate a private scalar and a corresponding public point on an
631elliptic curve. See
632.B ec-param
633above for how to specify elliptic curve parameter sets. The scalar
634.I x
635is chosen unformly between 0 and the curve order
636.IR r ;
637the public point is then
638.I x
639\(mu
640.IR G .
052b36d0 641.SS "expire"
d03ab969 642Forces keys to immediately expire. An expired key is not chosen when a
643program requests a key by its type. The keys to expire are listed by
644their
052b36d0 645.IR tag s.
646.SS "delete"
d03ab969 647Deletes keys immediately. The keys to delete are listed by their
052b36d0 648.IR tag s.
d03ab969 649Be careful when deleting keys. It might be a better idea
650to expire keys rather than deleting them.
052b36d0 651.SS "tag"
652Sets, deletes or changes the tag attached to a key. The first tag or
653keyid names the key to be modified; the second, if present specifies the
654new tag to be set. If no second argument is given, the existing tag, if
d07dfe80 655any, is removed and no new tag is set. It is an error to set a tag
656which already exists on another key, unless you give the
657.B \-r
658option, which removes the tag first.
052b36d0 659.SS "setattr"
d03ab969 660Attaches attributes to a key. The key to which the attributes should be
661attached is given by its
052b36d0 662.IR tag .
d03ab969 663Each attribute has the form
664.IB name = value\fR.
665An attribute can be deleted by assigning it an empty value. Although
666the keyring file format is capable of representing an attribute with an
667empty value as distinct from a nonexistant attribute, this interface
668does not allow empty attributes to be set.
052b36d0 669.SS "comment"
670Sets, deletes or changes the comment attached to a key. The first
671argument is a key tag or keyid which names the key to be modified; the
672second, if present, is the new comment. If no second argument is given,
673the existing comment, if any, is removed, and no new comment is set.
674.SS "lock"
675Locks a key or key component using a passphrase. If the key is already
676locked, the existing passphrase is requested, and a new passphrase is
677set.
678.SS "unlock"
679Unlocks a passphrase-locked key or key component. If the key is not
680locked, an error is reported.
681.SS "list"
d03ab969 682Lists the keys in the keyring. A couple of options are supported:
683.TP
684.B "\-v, \-\-verbose"
685Increases the amount of information displayed for each key. Repeat for
686a greater effect.
687.TP
688.B "\-q, \-\-quiet"
689Decreases the amount of information displayed for each key. Each use
690cancels a
691.RB ` \-v '
692option.
c9e31e42 693.TP
694.B "\-u, \-\-utc"
695Display key expiry times as UTC rather than using the local time zone.
052b36d0 696.TP
697.BI "\-f, \-\-filter " filter
698Specifies a filter. Only keys and key components which match the filter
699are listed.
d03ab969 700.PP
701By default, a single line of output is generated for each, showing
702keyids, types, expiry and deletion dates, and comments. Additional
703.RB ` \-v '
704options show more information, such as the exact time of day for expiry
052b36d0 705and deletion, key attributes, and a dump of the actual key data. If the
706verbosity level is sufficiently high, passphrases are requested to
707decrypt locked keys. Make sure nobody is looking over your shoulder
708when you do this!
709.SS "fingerprint"
710Reports a fingerprint (secure hash) on components of requested keys.
711The following option is supported:
712.TP
713.BI "\-f, \-\-filter " filter
714Specifies a filter. Only keys and key components which match the filter
715are fingerprinted. The default is to only fingerprint nonsecret
716components.
717.PP
718The keys to be fingerprinted are named by their tags or keyids given as
719command line arguments. If no key tags are given, all keys which match
720the filter are fingerprinted.
721.SS "tidy"
d03ab969 722Simply reads the keyring from file and writes it back again. This has
723the effect of removing any deleted keys from the file.
052b36d0 724.SS "extract"
725Writes a selection of keys to a file. An option is supported:
726.TP
727.BI "\-f, \-\-filter " filter
728Specifies a filter. Only keys and key components which match the filter
729are written.
730.PP
731Keys extracted are written to the file named by the first argument,
d03ab969 732which may be
733.RB ` \- '
734to designate standard output. The keys to extract are listed by their
052b36d0 735tags; if no tags are given, all keys which match the filter are
736extracted. The output is a valid keyring file.
737.SS "merge"
d03ab969 738Merges the keys from the named
739.IR file ,
740which may be
741.RB ` \- '
742to designate standard input, with the keyring. Keys already in the
743keyring are not overwritten: you must explicitly remove them first if
744you want them to be replaced during the merge.
d03ab969 745.SH "SEE ALSO"
746.BR keyring (5).
747.SH AUTHOR
748Mark Wooding, <mdw@nsict.org>
749