chiark / gitweb /
debian/: Use `dh_python2' for packaging.
[catacomb-python] / pwsafe.1
CommitLineData
a8f59fc0
MW
1.\" -*-nroff-*-
2.\"
3.\" Describe the password safe
4.\"
5.\" (c) 2016 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the Python interface to Catacomb.
11.\"
12.\" Catacomb/Python is free software; you can redistribute it and/or modify
13.\" it under the terms of the GNU General Public License as published by
14.\" the Free Software Foundation; either version 2 of the License, or
15.\" (at your option) any later version.
16.\"
17.\" Catacomb/Python is distributed in the hope that it will be useful,
18.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20.\" GNU General Public License for more details.
21.\"
22.\" You should have received a copy of the GNU General Public License
23.\" along with Catacomb/Python; if not, write to the Free Software Foundation,
24.\" Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25.
26.ie t \{\
27. if \n(.g \{\
28. fam P
29. \}
30. ds o \(bu
31.\}
32.el \{\
33. ds o o
34.\}
35.
36.de hP
37.IP
38\h'-\w'\fB\\$1\ \fP'u'\fB\\$1\ \fP\c
39..
40.
41.TH pwsafe 1 "13 May 2016" "Straylight/Edgeware" "Catacomb cryptographic library"
42.SH NAME
43pwsafe \- store passwords somewhat securely
44.
45.\"--------------------------------------------------------------------------
46.SH SYNOPSIS
47.
48.B pwsafe
49.RB [ \-f
50.IR file ]
51.I command
52.RI [ arguments
53\&...]
54.PP
55Subcommands:
56'RS
57.B changepp
58.br
59.B copy
60.I dest-file
61.RI [ glob-pattern ]
62.br
63.B create
64.RB [ \-c
65.IR cipher ]
66.RB [ \-d
67.IR db-type ]
68.RB [ \-h
69.IR hash ]
70.RB [ \-m
71.IR mac ]
72.RI [ pp-tag ]
73.br
74.B delete
75.I tag
76.br
77.RB [ find ]
78.I label
79.br
80.B list
81.RI [ glob-pattern ]
82.br
83.B store
84.I label
85.RI [ value ]
86.br
87.B to-pixie
88.RI [ label
89.RI [ pixie-tag ]]
90.br
91.B xfer
92.RB [ \-d
93.IR db-type ]
94.I dest-file
95.RE
96.
97.\"--------------------------------------------------------------------------
98.SH DESCRIPTION
99.
100The
101.B pwsafe
102command maintains a database of passwords
103or other short-ish textual secrets.
104Each password is identified by a
105.IR label .
106The database is ultimately protected by a master password.
107It should quite difficult for an adversary
108who has the database file(s)
109but not your master password
110to find out what any of the stored passwords are,
111or even what the labels are.
112.PP
113The
114.B pwsafe
115program will prompt you for the password as necessary.
116If you are running the Catacomb
117.BR pixie (1)
118then it will first ask the pixie for any necessary passwords,
119and use the pixie to remember the master password for a short while.
120.PP
121A number of database backends are available.
122.TP
123.B gdbm
124Uses the GDBM database library to store a database as a single file.
125Provided for compatibility;
126not recommended for new databases.
127.TP
128.B sqlite
129Uses the SQLite3 library to store a database as a single file.
130SQLite3 has good performance and integrity properties.
131.TP
132.B flat
133Stores the password database as a flat text file.
134Not recommended for large databases because performance will be bad,
135but the simple format admits easy hacking.
136.TP
137.B dir
138Stores the password database as a directory structure.
139This uses much more disk space than the alternatives,
140and enumerating passwords is slow,
141but the directory structure can easily be managed by
142a version control system such as Git.
143.PP
144The following command-line options are available.
145.TP
146.B "\-h, \-\-help"
147Print a help summary to standard output,
148and exit with status zero.
149.TP
150.B "\-v, \-\-version"
151Print the program's version number to standard output,
152and exit with status zero.
153.TP
154.B "\-u, \-\-usage"
155Print a very terse usage summary to standard output,
156and exit with status zero.
157.TP
158.BI "\-f, \-\-file=" file
159Use
160.I file
161as the password database file or directory.
162If this is not specified,
163then the value of the
164.B PWSAFE
165environment variable is used;
166if that too is unset, then the default
167.IB home /.pwsafe \fR,
168is used, where
169.I home
170is the value of the
171.B HOME
172environment variable.
173It is a fatal error if
174.B HOME
175is unset.
176.PP
177The provided commands are described in their own sections below.
178.
179.SS "create"
180Create a new, empty password database.
181As a safety check,
182the file/directory named by the top-level
183.B \-f
184option (or default value)
185must not exist.
186.PP
187You will be prompted (twice) for a master password for the database.
188.PP
189The optional positional argument is the tag
190by which the database's master password
191will be known to the passphrase pixie.
192The default tag is
193.BR pwsafe .
194.PP
195The following options are accepted.
196.TP
197.BI "\-c, \-\-cipher=" cipher
198Use the Catacomb
199.I cipher
200to encrypt blobs.
201Run
202.B catcrypt show cipher
203for a list.
204The default is
205.BR rijndael-cbc .
206.TP
207.BI "\-d, \-\-database=" db-type
208Use the
209.I db-type
210database backend.
211See above for a list of the supported backends.
212Note that
213.B gdbm
214and
215.B sqlite
216depend on external modules, and may not be available.
217The default is
218.BR flat .
219.TP
220.BI "\-h, \-\-hash=" hash
221Use the Catacomb
222.I hash
223for key derivation and password-label mangling.
224Run
225.B catcrypt show hash
226for a list.
227The default is
228.BR sha256 .
229.TP
230.BI "\-m, \-\-mac=" mac
231Use the Catacomb
232.I mac
233to protect the integrity of blobs.
234Run
235.B catcrypt show mac
236for a list.
237The default is
238.IR hash -hmac
239where
240.I hash
241is the hash function chosen by the
242.B \-h
243option.
244.
245.SS "changepp"
246Change the master password for a database.
247This will
248.I not
249re-encrypt all of the records,
250so its utility is somewhat limited.
251See also the
252.B copy
253command.
254The program will prompt you for
255the existing master password (if it's not known by the pixie)
256and the new one (twice, always).
257.
258.SS "copy"
259Copy password records from the
260.I file
261to the
262.I dest-file
263which must be an existing password database.
264If a
265.B glob-pattern
266is given,
267then only records whose
268.I label
269matches the pattern are copied;
270otherwise all password records are copied.
271Any existing passwords in the destination database with the same labels
272will be overwritten.
273.PP
274The destination need not use the same database backend
275or cryptographic parameters as the source.
276.PP
277You will be prompted for the necessary master passwords.
278.
279.SS "delete"
280Delete the password with the given
281.I label
282from the database.
283An error is reported if there is no such password.
284.PP
285You will be prompted for master password if necessary.
286.
287.SS "find"
288Write the password with the given label to standard output,
289followed by a newline.
290.PP
291You will be prompted for master password if necessary.
292.PP
293This is the default operation:
294as a convenience,
295you can write
296.IP
297.B pwsafe
298.I label
299.PP
300rather than
301.IP
302.B pwsafe
303.B find
304.I label
305.PP
306if the
307.I label
308isn't the same as any of
309.BR pwsafe 's
310command names.
311.
312.SS "list"
313Write the labels of the passwords in the database,
314one per line,
315to standard output.
316(If labels contain newline characters,
317you will end up with a mess.)
318If a
319.I glob-pattern
320is supplied,
321then only labels which match the pattern are written.
322.PP
323You will be prompted for master password if necessary.
324.
325.SS "store"
326Store a password, associating it with the given
327.IR label .
328.PP
329If a
330.I value
331is supplied on the command line,
332then it is used as the password value.
333(Note that command-line arguments can be seen
334by other users of the system,
335and may be recorded by the shell.
336This is usually a bad idea.)
337.PP
338As a special case, if the
339.I value
340is
341.BR \- ,
342then the password is read from the first line of standard input;
343the trailing newline is removed.
344The author commonly writes
345.IP
346.BI "gorp -fbase64 | pwsafe store " label " \-"
347.PP
348to set random passwords.
349.PP
350Finally, if no
351.I value
352is given,
353then
354.B pwsafe
355will prompt twice for the password.
356.PP
357You will be prompted for the master password if necessary
358.I before
359the new password value is fetched.
360.PP
361If there is an existing password with the same
362.I label
363then it is overwritten.
364.
365.SS "topixie"
366With no arguments,
367store
368.I all
369of the passwords in the database in the pixie,
370with correspondingly named tags.
371This is probably a bad idea.
372.PP
373With a
374.IR label ,
375store only the labelled password in the pixie.
376With a
377.IR pixie-tag ,
378use that as the tag;
379otherwise use the
380.IR label .
381.PP
382You will be prompted for the master password if necessary.
383.
384.SS "xfer"
385Create a new database containing all of the records of an existing one.
386.PP
387This works at the storage-backend level.
388The new database contains exactly the same metadata and passwords
389as the original.
390It is
391.I not
392necessary to enter a password:
393the blobs are simply copied over without being decrypted.
394.PP
395The following options are accepted.
396.TP
397.BI "\-d, \-\-database=" db-type
398Use the
399.I db-type
400database backend.
401See above for a list of the supported backends.
402Note that
403.B gdbm
404and
405.B sqlite
406depend on external modules, and may not be available.
407The default is
408.BR flat .
409.
410.\"--------------------------------------------------------------------------
411.SH TECHNICAL DETAILS
412.
413The password database contains two kinds of records:
414.I metadata records
415hold important information about the database itself,
416and particularly the various cryptographic options
417chosen when the database was created,
418and the various internal keys used to secure the database;
419while
420.I password records
421actually store your encrypted passwords.
422The various backends store these kinds records in different ways;
423see below for the gory details.
424.
425.SS Metadata
426The metadata records are as follows.
427.TP
428.B cipher
429The symmetric cipher used to encrypt data.
430This names a Catacomb
431.B cipher
432class.
433.TP
434.B hash
435The hash function used in various places.
436This names a Catacomb
437.B hash
438class.
439.TP
440.B key
441A blob,
442protected by the
443.I derived
444keys (see below),
445containing the
446.I main
447secrecy and integrity keys.
448The blob payload consists of the main secrecy and integrity keys,
449each prefixed by its 16-bit length (in network byte order)
450and concatenated.
451.TP
452.B mac
453The message authentication code used to protect integrity.
454This names a Catacomb
455.B mac
456class.
457.TP
458.B magic
459A blob containing a string
460used to construct the database keys for password records;
461see below.
462The magic string is chosen at random
463when the database is created,
464and never changes;
465it is the same length as the chosen hash function's output.
466The blob is protected by the
467.I main
468keys.
469.TP
470.B salt
471A random string
472mixed into the key derivation process.
473.TP
474.B tag
475The passphrase tag,
476used to identify the master password
477to the passphrase
478.BR pixie (1).
479.
480.SS Keys
481The following keys are used.
482.TP
483The \fImaster password\fP
484Remembered (hopefully) by the user;
485used to unlock the
486.I main
487keys.
488.TP
489The \fIderived\fP keys
490A secrecy and integrity pair,
491derived from the
492.I master password
493and
494salt using a hash function.
495.TP
496The \fImain\fP keys
497A secrecy and integrity pair,
498kept in a blob in the database
499(the
500.B key
501metadata item)
502protected by the
503.I derived
504keys.
505The main keys are generated at random
506when the database is created
507and they never change;
508the Catacomb default key lengths are used.
509.
510.SS Deriving keys from the master password
511The keys used for protecting the
512.I main
513secrecy and integrity keys
514are derived by hashing strings of the form
515.IB purpose : password \e0 salt \fR,
516where
517.I purpose
518is
519.B cipher
520or
521.B mac
522to derive the secrecy and integrity keys, respectively.
523The
524.I salt
525string is the value of the
526.B salt
527metadata item described below.
528.PP
529No attempt is made to make the key derivation slow;
530.B pwsafe
531takes the view that you are have been specifically targetted for attack
532by a well-resourced adversary,
533and that you
534.I will
535lose if your password is guessable.
536.
537.SS Making a blob
538A
539.I blob
540contains a
541.IR payload ,
542protecting its secrecy and integrity.
543A blob is constructed using a pair of secrecy and integrity keys;
544most blobs are protected with the
545.I main
546keys;
547the main keys themselves are protected with the
548.I derived
549keys.
550.PP
551The steps to construct a blob are as follows.
552.hP 1.
553Choose a random IV of the appropriate length for the chosen
554.BR cipher .
555.hP 2.
556Encrypt the blob payload
557using the chosen
558.B cipher
559with the secrecy key
560and the IV from step 1,
561to form a ciphertext.
562Prefix the ciphertext with the IV
563to form an augmented ciphertext.
564.hP 3.
565Compute a tag over the augmented ciphertext from step 2
566using the chosen
567.B mac
568with the integrity key.
569Prefix the augmented ciphertext with the tag
570to form the blob.
571.PP
572(It seems more usual to put the tag on the end of the ciphertext,
573but that turned out to be pointlessly harder to implement.)
574.
575.SS Password records
576Conceptually,
577password records are indexed with a textual
578.I label
579chosen by the user.
580But users may want to not only keep their passwords secret,
581but also information about
582.I which
583passwords they have.
584The
585.B pwsafe
586program attempts to maintain the privacy of password record labels,
587but it isn't completely successful, as we shall see.
588Most critically,
589the database backends tend to leak information about
590the
591.I order
592in which records were added into the database.
593.PP
594At the database backend,
595the key used for looking up a password record is a hash,
596in binary:
597specifically, it's a hash of
598the record label
599prefixed by the
600.I magic
601string which is the payload of the blob stored in the
602.B magic
603metadata record.
604.PP
605The value of the password record is a blob,
606protected by the
607.I main
608keys,
609whose payload consists of
610.hP \*o
611the 16-bit network-byte-order length of the record label;
612.hP \*o
613the record label itself;
614.hP \*o
615the 16-bit network-byte-order length of the password;
616.hP \*o
617the password itself; and
618.hP \*o
619zero or more zero-valued octets,
620so as to make the payload a multiple of 256 octets long.
621.PP
622The padding serves to conceal the length of the label and password
623from an adversary who has obtained a copy of the database.
624.
625.SS Backend formats
626The various password-database backends
627represent the records described above as follows.
628.TP
629.B gdbm
630A GDBM-backed database is stored in a single file.
631A metadata record with key
632.I r
633and value
634.I v
635is stored in a GDBM record also named
636.IR r ,
637and with value
638.I v ;
639a password record with hash
640.I h
641and blob
642.I b
643is stored in a GDBM record named
644.BI $ h
645with value
646.IR b ,
647both in raw binary.
648.TP
649.B sqlite
650A SQLite-backed database is stored in a single file.
651It contains two tables,
652named
653.B meta
654and
655.BR passwd .
656The
657.B meta
658table has a primary key
659.B name
660and a further column
661.BR value ;
662a metadata record with key
663.I r
664and value
665.I v
666is held in a
667.B meta
668record
669with
670.B name
671.I r
672and
673.B value
674.IR v ;
675additionally, there is a record with
676.B name
677.B $version
678whose
679.B value
680is the schema version;
681this is currently always 0.
682The
683.B passwd
684table has a primary key
685.B label
686and a further column
687.BR payload ;
688a password record with hash
689.I h
690and blob
691.I b
692is stored in a
693.B passwd
694record with
695.B label
696.IR h
697and
698.B payload
699.IR b ,
700both in raw binary.
701.TP
702.B flat
703A flat-file-backed database is stored in a single file,
704with one record per line.
705The first line must be exactly
706.RS
707.IP
708.B "### pwsafe password database"
709.PP
710Blank lines and lines beginning with a
711.RB ` # '
712are ignored.
713.PP
714A metadata record named
715.I r
716with value
717.I v
718is stored as a line of the form
719.IB r\fR\(fm = v\fR\(fm
720where
721.IR r \fR\(fm
722and
723.IR v \fR\(fm
724are encodings of the strings
725.I r
726and
727.I v
728respectively.
729If
730.I r
731consists only of letters, digits,
732and the punctuation characters
733.RB ` \- ',
734.RB ` _ ',
735.RB ` : ',
736.RB ` . ',
737and
738.RB ` / '
739then
740.IR r \fR\(fm
741is simply
742.IR r ;
743otherwise
744.IR r \fR\(fm
745is formed by (simultaneously) replacing
746each space character in
747.I r
748with
749.RB ` + '
750and each other character
751which is not a letter, digit, or
752one of the punctuation characters listed above
753with
754.RB ` % '
755followed by that character's ASCII code in hex,
756and prefixing the whole lot by
757.RB ` ! '.
758Similarly,
759if
760.I v
761consists of letters, digits,
762and the punctuation characters listed above,
763then
764.IR v \fR\(fm
765is simply
766.IR v ;
767otherwise
768.IR v \fR\(fm
769consists of a
770.RB ` ? '
771followed by the base64 encoding of
772.IR v ,
773without any trailing
774.RB ` = '
775characters.
776.PP
777A password record with hash
778.I h
779and blob
780.I b
781is stored as a line of the form
782.BI $ h\fR\(fm = b\fR\(fm
783where
784.IR h \(fm
785and
786.IR b \(fm
787are the base64 encodings of
788.I h
789and
790.I b
791respectively,
792without trailing
793.RB ` = '
794characters.
795.PP
796The records may appear in any order.
797The file is completely rewritten when any change is made;
798if the file is named
799.I f
800then this is done by writing the new contents to
801.IB f .new
802and then renaming
803.IB f .new
804to
805.IR f .
806.RE
807.TP
808.B dir
809A directory-backed database is stored as a directory,
810named
811.I d
812in the sequel.
813The directory must contain a file
814.IB d /meta
815whose first line is
816.RS
817.IP
818.B "### pwsafe password directory metadata"
819.PP
820and directories
821.IB d /pw
822and
823.IB d /tmp \fR.
824.PP
825Metadata records are stored in file
826.IB d /meta
827with one record per line,
828exactly as for the
829.B file
830backend described above.
831.PP
832A password record with hash
833.I h
834and blob
835.I b
836is stored as file named
837.IB d /pw/ h \fR\(fm
838where
839.IR h \(fm
840is the base64 encodings of
841.I h
842without trailing
843.RB ` = '
844characters,
845and with all
846.RB ` / '
847characters
848replaced by
849.RB ` . 's,
850whose content is
851.IR b .
852.PP
853The directory
854.IB d /tmp/
855is used in an unspecified manner
856when creating new password-record files.
857The
858.IB d /meta
859and
860.IB d /pw/ h \fR\(fm
861files are updated by creating a new temporary file and renaming.
862.RE
863.
864.\"--------------------------------------------------------------------------
865.
866.SH BUGS
867This is quite an old program,
868though the manpage is new.
869It provides more footguns than is ideal.
870.
871.SH SEE ALSO
872.BR catcrypt (1),
873.BR pixie (1).
874.
875.SH AUTHOR
876Mark Wooding, <mdw@distorted.org.uk>
877.
878.\"----- That's all, folks --------------------------------------------------