Blame


1 5cdf5adc 2022-05-08 op #!/usr/bin/env perl
2 5cdf5adc 2022-05-08 op #
3 5cdf5adc 2022-05-08 op # Copyright (c) 2022 Omar Polo <op@omarpolo.com>
4 5cdf5adc 2022-05-08 op #
5 5cdf5adc 2022-05-08 op # Permission to use, copy, modify, and distribute this software for any
6 5cdf5adc 2022-05-08 op # purpose with or without fee is hereby granted, provided that the above
7 5cdf5adc 2022-05-08 op # copyright notice and this permission notice appear in all copies.
8 5cdf5adc 2022-05-08 op #
9 5cdf5adc 2022-05-08 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 5cdf5adc 2022-05-08 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 5cdf5adc 2022-05-08 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 5cdf5adc 2022-05-08 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 5cdf5adc 2022-05-08 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 5cdf5adc 2022-05-08 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 5cdf5adc 2022-05-08 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 5cdf5adc 2022-05-08 op
17 5cdf5adc 2022-05-08 op use strict;
18 5cdf5adc 2022-05-08 op use warnings;
19 5cdf5adc 2022-05-08 op use v5.32;
20 5cdf5adc 2022-05-08 op
21 5cdf5adc 2022-05-08 op use open ":std", ":encoding(UTF-8)";
22 5cdf5adc 2022-05-08 op
23 5cdf5adc 2022-05-08 op use Getopt::Long qw(:config bundling require_order);
24 5cdf5adc 2022-05-08 op use Pod::Usage;
25 5cdf5adc 2022-05-08 op use File::Basename;
26 5cdf5adc 2022-05-08 op use File::Find;
27 5cdf5adc 2022-05-08 op
28 5cdf5adc 2022-05-08 op my $store = $ENV{'PLASS_STORE'} || $ENV{'HOME'}.'/.password-store';
29 5cdf5adc 2022-05-08 op
30 5cdf5adc 2022-05-08 op my $got = $ENV{'PLASS_GOT'} || 'got';
31 5cdf5adc 2022-05-08 op my $tog = $ENV{'PLASS_TOG'} || 'tog';
32 5cdf5adc 2022-05-08 op
33 5cdf5adc 2022-05-08 op my $gpg = $ENV{'PLASS_GPG'} || 'gpg2';
34 5cdf5adc 2022-05-08 op my @gpg_flags = qw(--quiet --compress-algo=none --no-encrypt-to);
35 5cdf5adc 2022-05-08 op
36 5bbf948d 2022-05-15 op my $default_chars = $ENV{'PLASS_CHARS'} || '!-~';
37 5cdf5adc 2022-05-08 op my $default_length = $ENV{'PLASS_LENGTH'};
38 5cdf5adc 2022-05-08 op if (!defined($default_length) || $default_length lt 0) {
39 5cdf5adc 2022-05-08 op $default_length = 32;
40 5cdf5adc 2022-05-08 op }
41 5cdf5adc 2022-05-08 op
42 5cdf5adc 2022-05-08 op GetOptions(
43 5cdf5adc 2022-05-08 op "h|?" => sub { pod2usage(0) },
44 5cdf5adc 2022-05-08 op ) or pod2usage(1);
45 5cdf5adc 2022-05-08 op
46 5cdf5adc 2022-05-08 op my $cmd = shift or pod2usage(1);
47 5cdf5adc 2022-05-08 op
48 5cdf5adc 2022-05-08 op my %subcmd = (
49 5cdf5adc 2022-05-08 op cat => [\&cmd_cat, "entries..."],
50 5cdf5adc 2022-05-08 op find => [\&cmd_find, "[pattern]"],
51 5cdf5adc 2022-05-08 op gen => [\&cmd_gen, "[-c chars] [-l length] entry"],
52 5cdf5adc 2022-05-08 op got => [\&cmd_got, "arguments ..."],
53 5cdf5adc 2022-05-08 op mv => [\&cmd_mv, "from to"],
54 5cdf5adc 2022-05-08 op oneshot => [\&cmd_oneshot, "[-c chars] [-l length]"],
55 5cdf5adc 2022-05-08 op regen => [\&cmd_regen, "[-c chars] [-l length] entry"],
56 5cdf5adc 2022-05-08 op rm => [\&cmd_rm, "entry"],
57 afdbc7b0 2022-06-29 op tee => [\&cmd_tee, "[-q] entry"],
58 5cdf5adc 2022-05-08 op tog => [\&cmd_tog, "arguments ..."],
59 5cdf5adc 2022-05-08 op );
60 5cdf5adc 2022-05-08 op pod2usage(1) unless defined $subcmd{$cmd};
61 5cdf5adc 2022-05-08 op my ($fn, $usage) = @{$subcmd{$cmd}};
62 5cdf5adc 2022-05-08 op chdir $store;
63 5cdf5adc 2022-05-08 op $fn->();
64 5cdf5adc 2022-05-08 op exit 0;
65 5cdf5adc 2022-05-08 op
66 5cdf5adc 2022-05-08 op
67 5cdf5adc 2022-05-08 op # utils
68 5cdf5adc 2022-05-08 op
69 5cdf5adc 2022-05-08 op sub usage {
70 5cdf5adc 2022-05-08 op my $prog = basename $0;
71 5cdf5adc 2022-05-08 op say STDERR "Usage: $prog $cmd $usage";
72 5cdf5adc 2022-05-08 op exit 1;
73 5cdf5adc 2022-05-08 op }
74 5cdf5adc 2022-05-08 op
75 5cdf5adc 2022-05-08 op sub name2file {
76 5cdf5adc 2022-05-08 op my $f = shift;
77 5cdf5adc 2022-05-08 op $f .= ".gpg" unless $f =~ m,\.gpg$,;
78 5cdf5adc 2022-05-08 op return $f;
79 5cdf5adc 2022-05-08 op }
80 5cdf5adc 2022-05-08 op
81 5cdf5adc 2022-05-08 op # tr -cd -- $chars < /dev/random | dd bs=$len count=1 status=none
82 5cdf5adc 2022-05-08 op sub gen {
83 5cdf5adc 2022-05-08 op my ($chars, $length) = @_;
84 5cdf5adc 2022-05-08 op my $pass = "";
85 5cdf5adc 2022-05-08 op
86 5cdf5adc 2022-05-08 op open(my $fh, '<:raw', '/dev/random')
87 5cdf5adc 2022-05-08 op or die "can't open /dev/random: $!";
88 5cdf5adc 2022-05-08 op my $l = $length;
89 5cdf5adc 2022-05-08 op while ($l gt 0) {
90 5cdf5adc 2022-05-08 op read($fh, my $t, $length * 4)
91 5cdf5adc 2022-05-08 op or die "failed to read /dev/random: $!";
92 5cdf5adc 2022-05-08 op $t =~ s/[^$chars]//g;
93 5cdf5adc 2022-05-08 op $l -= length($t);
94 5cdf5adc 2022-05-08 op $pass .= $t;
95 5cdf5adc 2022-05-08 op }
96 5cdf5adc 2022-05-08 op close($fh);
97 5cdf5adc 2022-05-08 op
98 5cdf5adc 2022-05-08 op return substr($pass, 0, $length);
99 5cdf5adc 2022-05-08 op }
100 5cdf5adc 2022-05-08 op
101 5cdf5adc 2022-05-08 op sub readpass {
102 5cdf5adc 2022-05-08 op # todo some stty black magic to avoid echo
103 5cdf5adc 2022-05-08 op print shift if -t;
104 5cdf5adc 2022-05-08 op my $pass = <>;
105 5cdf5adc 2022-05-08 op die "failed to read stdin: $!" unless defined($pass);
106 5cdf5adc 2022-05-08 op chomp $pass;
107 5cdf5adc 2022-05-08 op return $pass;
108 1f89d66a 2022-06-29 op }
109 1f89d66a 2022-06-29 op
110 1f89d66a 2022-06-29 op sub mkdirs {
111 1f89d66a 2022-06-29 op my $dir = shift;
112 1f89d66a 2022-06-29 op my $parent = dirname $dir;
113 1f89d66a 2022-06-29 op mkdirs($parent) unless -d $parent || $parent eq '/';
114 1f89d66a 2022-06-29 op mkdir $dir or die "mkdir $dir: $!"
115 1f89d66a 2022-06-29 op unless -d $dir;
116 5cdf5adc 2022-05-08 op }
117 5cdf5adc 2022-05-08 op
118 5cdf5adc 2022-05-08 op sub writepass {
119 5cdf5adc 2022-05-08 op my ($file, $pass) = @_;
120 1f89d66a 2022-06-29 op
121 1f89d66a 2022-06-29 op mkdirs(dirname $file);
122 5cdf5adc 2022-05-08 op
123 5cdf5adc 2022-05-08 op my @args = ($gpg, @gpg_flags, '-e', '-r', recipient(),
124 5cdf5adc 2022-05-08 op '-o', $file);
125 5cdf5adc 2022-05-08 op open my $fh, '|-', @args;
126 5cdf5adc 2022-05-08 op say $fh "$pass";
127 5cdf5adc 2022-05-08 op close($fh);
128 5cdf5adc 2022-05-08 op }
129 5cdf5adc 2022-05-08 op
130 5cdf5adc 2022-05-08 op sub recipient {
131 5cdf5adc 2022-05-08 op open my $fh, '<', "$store/.gpg-id"
132 5cdf5adc 2022-05-08 op or die "can't open recipient file";
133 5cdf5adc 2022-05-08 op my $r = <$fh>;
134 5cdf5adc 2022-05-08 op chomp $r;
135 5cdf5adc 2022-05-08 op close($fh);
136 5cdf5adc 2022-05-08 op return $r;
137 5cdf5adc 2022-05-08 op }
138 5cdf5adc 2022-05-08 op
139 5cdf5adc 2022-05-08 op sub passfind {
140 5cdf5adc 2022-05-08 op my $pattern = shift;
141 5cdf5adc 2022-05-08 op my @entries;
142 5cdf5adc 2022-05-08 op
143 5cdf5adc 2022-05-08 op find({
144 5cdf5adc 2022-05-08 op wanted => sub {
145 5cdf5adc 2022-05-08 op if (m,/.git$, || m,/.got$,) {
146 5cdf5adc 2022-05-08 op $File::Find::prune = 1;
147 5cdf5adc 2022-05-08 op return;
148 5cdf5adc 2022-05-08 op }
149 5cdf5adc 2022-05-08 op
150 5cdf5adc 2022-05-08 op return if defined($pattern) && ! m/$pattern/;
151 5cdf5adc 2022-05-08 op return unless -f && m,.gpg$,;
152 5cdf5adc 2022-05-08 op
153 5cdf5adc 2022-05-08 op s,^$store/*,,;
154 5cdf5adc 2022-05-08 op s,.gpg$,,;
155 5cdf5adc 2022-05-08 op push @entries, $_;
156 5cdf5adc 2022-05-08 op },
157 5cdf5adc 2022-05-08 op no_chdir => 1,
158 5cdf5adc 2022-05-08 op follow_fast => 1,
159 5cdf5adc 2022-05-08 op }, ($store));
160 5cdf5adc 2022-05-08 op return sort(@entries);
161 5cdf5adc 2022-05-08 op }
162 5cdf5adc 2022-05-08 op
163 5cdf5adc 2022-05-08 op sub got {
164 5cdf5adc 2022-05-08 op open my $fh, '-|', ($got, @_);
165 5cdf5adc 2022-05-08 op close($fh);
166 19df8a20 2022-06-29 op return !$?;
167 5cdf5adc 2022-05-08 op }
168 5cdf5adc 2022-05-08 op
169 5cdf5adc 2022-05-08 op sub got_add {
170 19df8a20 2022-06-29 op got 'add', '-I', shift
171 19df8a20 2022-06-29 op or exit 1;
172 5cdf5adc 2022-05-08 op }
173 5cdf5adc 2022-05-08 op
174 5cdf5adc 2022-05-08 op sub got_rm {
175 19df8a20 2022-06-29 op got 'remove', '-f', shift
176 19df8a20 2022-06-29 op or exit 1;
177 5cdf5adc 2022-05-08 op }
178 5cdf5adc 2022-05-08 op
179 5cdf5adc 2022-05-08 op sub got_ci {
180 afdbc7b0 2022-06-29 op my $pid = fork;
181 afdbc7b0 2022-06-29 op die "failed to fork: $!" unless defined $pid;
182 afdbc7b0 2022-06-29 op
183 afdbc7b0 2022-06-29 op if ($pid ne 0) {
184 afdbc7b0 2022-06-29 op wait;
185 afdbc7b0 2022-06-29 op die "failed to commit changes" if $?;
186 afdbc7b0 2022-06-29 op return;
187 afdbc7b0 2022-06-29 op }
188 afdbc7b0 2022-06-29 op
189 afdbc7b0 2022-06-29 op open (STDOUT, ">&", \*STDERR)
190 afdbc7b0 2022-06-29 op or die "can't redirect stdout to stderr";
191 afdbc7b0 2022-06-29 op exec ($got, 'commit', '-m', shift)
192 afdbc7b0 2022-06-29 op or die "failed to exec $got: $!";
193 5cdf5adc 2022-05-08 op }
194 5cdf5adc 2022-05-08 op
195 5cdf5adc 2022-05-08 op
196 5cdf5adc 2022-05-08 op # cmds
197 5cdf5adc 2022-05-08 op
198 5cdf5adc 2022-05-08 op sub cmd_cat {
199 5cdf5adc 2022-05-08 op GetOptions('h|?' => \&usage) or usage;
200 5cdf5adc 2022-05-08 op usage unless @ARGV;
201 5cdf5adc 2022-05-08 op
202 5cdf5adc 2022-05-08 op while (@ARGV) {
203 5cdf5adc 2022-05-08 op my $file = name2file(shift @ARGV);
204 5cdf5adc 2022-05-08 op system ($gpg, @gpg_flags, '-d', $file);
205 5cdf5adc 2022-05-08 op die "failed to exec $gpg: $!" if $? == -1;
206 5cdf5adc 2022-05-08 op }
207 5cdf5adc 2022-05-08 op }
208 5cdf5adc 2022-05-08 op
209 5cdf5adc 2022-05-08 op sub cmd_find {
210 5cdf5adc 2022-05-08 op GetOptions('h|?' => \&usage) or usage;
211 5cdf5adc 2022-05-08 op usage if @ARGV gt 1;
212 5cdf5adc 2022-05-08 op
213 5cdf5adc 2022-05-08 op map { say $_ } passfind(shift @ARGV);
214 5cdf5adc 2022-05-08 op }
215 5cdf5adc 2022-05-08 op
216 5cdf5adc 2022-05-08 op sub cmd_gen {
217 5cdf5adc 2022-05-08 op my $chars = $default_chars;
218 5cdf5adc 2022-05-08 op my $length = $default_length;
219 5cdf5adc 2022-05-08 op
220 5cdf5adc 2022-05-08 op GetOptions(
221 5cdf5adc 2022-05-08 op 'c=s' => sub { $chars = $_[1] },
222 5cdf5adc 2022-05-08 op 'h|?' => \&usage,
223 5cdf5adc 2022-05-08 op 'l=i' => sub { $length = $_[1] },
224 5cdf5adc 2022-05-08 op ) or usage;
225 5cdf5adc 2022-05-08 op usage if @ARGV ne 1;
226 5cdf5adc 2022-05-08 op
227 5cdf5adc 2022-05-08 op my $name = shift @ARGV;
228 5cdf5adc 2022-05-08 op my $file = name2file $name;
229 5cdf5adc 2022-05-08 op die "password already exists: $file\n" if -e $file;
230 5cdf5adc 2022-05-08 op
231 5cdf5adc 2022-05-08 op my $pass = gen($chars, $length);
232 5cdf5adc 2022-05-08 op writepass($file, $pass);
233 5cdf5adc 2022-05-08 op
234 5cdf5adc 2022-05-08 op got_add $file;
235 5cdf5adc 2022-05-08 op got_ci "+$name";
236 5cdf5adc 2022-05-08 op }
237 5cdf5adc 2022-05-08 op
238 5cdf5adc 2022-05-08 op sub cmd_got {
239 5cdf5adc 2022-05-08 op chdir $store;
240 5cdf5adc 2022-05-08 op exec $got, @ARGV;
241 5cdf5adc 2022-05-08 op }
242 5cdf5adc 2022-05-08 op
243 5cdf5adc 2022-05-08 op # TODO: handle moving directories?
244 5cdf5adc 2022-05-08 op sub cmd_mv {
245 5cdf5adc 2022-05-08 op GetOptions('h|?' => \&usage) or usage;
246 5cdf5adc 2022-05-08 op usage if @ARGV ne 2;
247 5cdf5adc 2022-05-08 op
248 5cdf5adc 2022-05-08 op my $a = shift @ARGV;
249 5cdf5adc 2022-05-08 op my $b = shift @ARGV;
250 5cdf5adc 2022-05-08 op
251 5cdf5adc 2022-05-08 op my $pa = name2file $a;
252 5cdf5adc 2022-05-08 op my $pb = name2file $b;
253 5cdf5adc 2022-05-08 op
254 5cdf5adc 2022-05-08 op die "source password doesn't exist" unless -f $pa;
255 5cdf5adc 2022-05-08 op die "target password exists" if -f $pb;
256 5cdf5adc 2022-05-08 op
257 5cdf5adc 2022-05-08 op rename $pa, $pb or die "can't rename $a to $b: $!";
258 5cdf5adc 2022-05-08 op
259 5cdf5adc 2022-05-08 op got_rm $pa;
260 5cdf5adc 2022-05-08 op got_add $pb;
261 5cdf5adc 2022-05-08 op got_ci "mv $a $b";
262 5cdf5adc 2022-05-08 op }
263 5cdf5adc 2022-05-08 op
264 5cdf5adc 2022-05-08 op sub cmd_oneshot {
265 5cdf5adc 2022-05-08 op my $chars = $default_chars;
266 5cdf5adc 2022-05-08 op my $length = $default_length;
267 5cdf5adc 2022-05-08 op
268 5cdf5adc 2022-05-08 op GetOptions(
269 5cdf5adc 2022-05-08 op 'c=s' => sub { $chars = $_[1] },
270 5cdf5adc 2022-05-08 op 'h|?' => \&usage,
271 5cdf5adc 2022-05-08 op 'l=i' => sub { $length = $_[1] },
272 5cdf5adc 2022-05-08 op ) or usage;
273 5cdf5adc 2022-05-08 op usage if @ARGV ne 0;
274 5cdf5adc 2022-05-08 op
275 5cdf5adc 2022-05-08 op say gen($chars, $length);
276 5cdf5adc 2022-05-08 op }
277 5cdf5adc 2022-05-08 op
278 5cdf5adc 2022-05-08 op sub cmd_regen {
279 5cdf5adc 2022-05-08 op my $chars = $default_chars;
280 5cdf5adc 2022-05-08 op my $length = $default_length;
281 5cdf5adc 2022-05-08 op
282 5cdf5adc 2022-05-08 op GetOptions(
283 5cdf5adc 2022-05-08 op 'c=s' => sub { $chars = $_[1] },
284 5cdf5adc 2022-05-08 op 'h|?' => \&usage,
285 5cdf5adc 2022-05-08 op 'l=i' => sub { $length = $_[1] },
286 5cdf5adc 2022-05-08 op ) or usage;
287 5cdf5adc 2022-05-08 op usage if @ARGV ne 1;
288 5cdf5adc 2022-05-08 op
289 5cdf5adc 2022-05-08 op my $name = shift @ARGV;
290 5cdf5adc 2022-05-08 op my $file = name2file $name;
291 5cdf5adc 2022-05-08 op die "password doesn't exist" unless -f $file;
292 5cdf5adc 2022-05-08 op
293 5cdf5adc 2022-05-08 op my $pass = gen($chars, $length);
294 5cdf5adc 2022-05-08 op writepass($file, $pass);
295 5cdf5adc 2022-05-08 op
296 5cdf5adc 2022-05-08 op got_add $file;
297 5cdf5adc 2022-05-08 op got_ci "regen $name";
298 5cdf5adc 2022-05-08 op }
299 5cdf5adc 2022-05-08 op
300 5cdf5adc 2022-05-08 op sub cmd_rm {
301 5cdf5adc 2022-05-08 op GetOptions('h|?' => \&usage) or usage;
302 5cdf5adc 2022-05-08 op usage if @ARGV ne 1;
303 5cdf5adc 2022-05-08 op
304 5cdf5adc 2022-05-08 op my $name = shift @ARGV;
305 5cdf5adc 2022-05-08 op my $file = name2file $name;
306 5cdf5adc 2022-05-08 op
307 5cdf5adc 2022-05-08 op got_rm $file;
308 5cdf5adc 2022-05-08 op got_ci "-$name";
309 5cdf5adc 2022-05-08 op }
310 5cdf5adc 2022-05-08 op
311 afdbc7b0 2022-06-29 op sub cmd_tee {
312 afdbc7b0 2022-06-29 op my $q;
313 afdbc7b0 2022-06-29 op GetOptions(
314 afdbc7b0 2022-06-29 op 'h|?' => \&usage,
315 afdbc7b0 2022-06-29 op 'q' => \$q,
316 afdbc7b0 2022-06-29 op ) or usage;
317 5cdf5adc 2022-05-08 op usage if @ARGV ne 1;
318 5cdf5adc 2022-05-08 op
319 5cdf5adc 2022-05-08 op my $name = shift @ARGV;
320 5cdf5adc 2022-05-08 op my $file = name2file $name;
321 5cdf5adc 2022-05-08 op
322 d69b7902 2022-05-15 op my $pass = readpass "Enter the password: ";
323 d69b7902 2022-05-15 op writepass($file, $pass);
324 afdbc7b0 2022-06-29 op say $pass unless $q;
325 5cdf5adc 2022-05-08 op
326 5cdf5adc 2022-05-08 op got_add $file;
327 afdbc7b0 2022-06-29 op got_ci (-f $file ? "update $name" : "+$name");
328 5cdf5adc 2022-05-08 op }
329 5cdf5adc 2022-05-08 op
330 afdbc7b0 2022-06-29 op sub cmd_tog {
331 afdbc7b0 2022-06-29 op chdir $store;
332 afdbc7b0 2022-06-29 op exec $tog, @ARGV;
333 afdbc7b0 2022-06-29 op }
334 afdbc7b0 2022-06-29 op
335 5cdf5adc 2022-05-08 op __END__
336 5cdf5adc 2022-05-08 op
337 5cdf5adc 2022-05-08 op =head1 NAME
338 5cdf5adc 2022-05-08 op
339 5cdf5adc 2022-05-08 op B<plass> - manage passwords
340 5cdf5adc 2022-05-08 op
341 5cdf5adc 2022-05-08 op =head1 SYNOPSIS
342 5cdf5adc 2022-05-08 op
343 5cdf5adc 2022-05-08 op B<plass> I<command> [-h] [arg ...]
344 5cdf5adc 2022-05-08 op
345 5cdf5adc 2022-05-08 op Valid subcommands are: cat, find, gen, got, mv, oneshot, regen, rm,
346 afdbc7b0 2022-06-29 op tee, tog.
347 5cdf5adc 2022-05-08 op
348 5cdf5adc 2022-05-08 op =head1 DESCRIPTION
349 5cdf5adc 2022-05-08 op
350 5cdf5adc 2022-05-08 op B<plass> is a simple password manager. It manages passwords stored in
351 5cdf5adc 2022-05-08 op a directory tree rooted at I<~/.password-store> (or I<$PLASS_STORE>),
352 5cdf5adc 2022-05-08 op where every password is a single file encrypted with gpg2(1).
353 5cdf5adc 2022-05-08 op
354 5cdf5adc 2022-05-08 op Passwords entries can be referenced using the path relative to the
355 5cdf5adc 2022-05-08 op store directory. The extension ".gpg" is optional.
356 5cdf5adc 2022-05-08 op
357 5cdf5adc 2022-05-08 op The whole store is supposed to be managed by the got(1) version
358 5cdf5adc 2022-05-08 op control system.
359 5cdf5adc 2022-05-08 op
360 5cdf5adc 2022-05-08 op The commands for B<plass> are as follows:
361 5cdf5adc 2022-05-08 op
362 5cdf5adc 2022-05-08 op =over
363 5cdf5adc 2022-05-08 op
364 5cdf5adc 2022-05-08 op =item B<cat> I<entries ...>
365 5cdf5adc 2022-05-08 op
366 5cdf5adc 2022-05-08 op Decrypt and print the passwords of the given I<entries>.
367 5cdf5adc 2022-05-08 op
368 5cdf5adc 2022-05-08 op =item B<find> [I<pattern>]
369 5cdf5adc 2022-05-08 op
370 5cdf5adc 2022-05-08 op Print one per line all the entries of the store, optionally filtered
371 5cdf5adc 2022-05-08 op by the given I<pattern>.
372 5cdf5adc 2022-05-08 op
373 5cdf5adc 2022-05-08 op =item B<gen> [B<-c> I<chars>] [B<-l> I<length>] I<entry>
374 5cdf5adc 2022-05-08 op
375 5cdf5adc 2022-05-08 op Generate and persist a password for the given I<entry> in the store.
376 5cdf5adc 2022-05-08 op B<-c> can be used to control the characters allowed in the password
377 5bbf948d 2022-05-15 op (by default I<!-~> i.e. all the printable ASCII character) and B<-l>
378 5bbf948d 2022-05-15 op the length (32 by default.)
379 5cdf5adc 2022-05-08 op
380 5cdf5adc 2022-05-08 op =item B<got> I<arguments ...>
381 5cdf5adc 2022-05-08 op
382 5cdf5adc 2022-05-08 op Execute got(1) in the password store directory with the given
383 5cdf5adc 2022-05-08 op I<arguments>.
384 5cdf5adc 2022-05-08 op
385 5cdf5adc 2022-05-08 op =item B<mv> I<from> I<to>
386 5cdf5adc 2022-05-08 op
387 5cdf5adc 2022-05-08 op Rename a password entry, doesn't work with directories. I<from> must
388 5cdf5adc 2022-05-08 op exist and I<to> mustn't.
389 5cdf5adc 2022-05-08 op
390 5cdf5adc 2022-05-08 op =item B<oneshot> [B<-c> I<chars>] [B<-l> I<length>]
391 5cdf5adc 2022-05-08 op
392 ddb01df7 2022-05-09 op Like B<gen> but prints the the generated password instead of persist
393 5cdf5adc 2022-05-08 op it.
394 5cdf5adc 2022-05-08 op
395 5cdf5adc 2022-05-08 op =item B<regen> [B<-c> I<chars>] [B<-l> I<length>] I<entry>
396 5cdf5adc 2022-05-08 op
397 5cdf5adc 2022-05-08 op Like B<gen> but re-generates a password in-place.
398 5cdf5adc 2022-05-08 op
399 5cdf5adc 2022-05-08 op =item B<rm> I<entry>
400 5cdf5adc 2022-05-08 op
401 5cdf5adc 2022-05-08 op Remove the password I<entry> from the store.
402 5cdf5adc 2022-05-08 op
403 afdbc7b0 2022-06-29 op =item B<tee> [B<-q>] I<entry>
404 afdbc7b0 2022-06-29 op
405 afdbc7b0 2022-06-29 op Prompt for a password, persist it in the store under the given
406 afdbc7b0 2022-06-29 op I<entry> name and then print it again to standard output.
407 afdbc7b0 2022-06-29 op
408 5cdf5adc 2022-05-08 op =item B<tog> I<arguments ...>
409 5cdf5adc 2022-05-08 op
410 5cdf5adc 2022-05-08 op Execute tog(1) in the password store directory with the given
411 5cdf5adc 2022-05-08 op I<arguments>.
412 5cdf5adc 2022-05-08 op
413 5cdf5adc 2022-05-08 op =back
414 5cdf5adc 2022-05-08 op
415 5cdf5adc 2022-05-08 op =head1 CREATING A PASSWORD STORE
416 5cdf5adc 2022-05-08 op
417 5cdf5adc 2022-05-08 op A password store is just a normal got(1) repository with a worktree
418 5cdf5adc 2022-05-08 op checked out in I<~/.password-store> (or I<$PLASS_STORE>). The only
419 5cdf5adc 2022-05-08 op restriction is that a file called I<.gpg-id> must exist in the root of
420 5cdf5adc 2022-05-08 op the work tree for most B<plass> commands to work.
421 5cdf5adc 2022-05-08 op
422 5cdf5adc 2022-05-08 op For example, a got repository and password store can be created as
423 5cdf5adc 2022-05-08 op follows:
424 5cdf5adc 2022-05-08 op
425 5cdf5adc 2022-05-08 op $ mkdir .password-store
426 5cdf5adc 2022-05-08 op $ cd .password-store
427 5cdf5adc 2022-05-08 op $ echo foo@example.com > .gpg-id
428 5cdf5adc 2022-05-08 op $ cd ~/git
429 5cdf5adc 2022-05-08 op $ got init pass.git
430 5cdf5adc 2022-05-08 op $ cd pass.git
431 5cdf5adc 2022-05-08 op $ got import -m 'initial import' ~/.password-store
432 5cdf5adc 2022-05-08 op $ cd ~/.password-store
433 5cdf5adc 2022-05-08 op $ got checkout -E ~/git/pass.git
434 5cdf5adc 2022-05-08 op
435 5cdf5adc 2022-05-08 op See got(1) for more information.
436 5cdf5adc 2022-05-08 op
437 5cdf5adc 2022-05-08 op Otherwise, if a repository already exists, a password-store can be
438 5cdf5adc 2022-05-08 op checked out more simply as:
439 5cdf5adc 2022-05-08 op
440 5cdf5adc 2022-05-08 op $ got checkout ~/git/pass.git ~/.password-store
441 5cdf5adc 2022-05-08 op
442 5cdf5adc 2022-05-08 op To migrate from pass(1), just delete I<~/.password-store> and checkout
443 5cdf5adc 2022-05-08 op it again usign got(1).
444 9944b08b 2022-05-08 op
445 9944b08b 2022-05-08 op =head1 ENVIRONMENT
446 9944b08b 2022-05-08 op
447 9944b08b 2022-05-08 op =over
448 9944b08b 2022-05-08 op
449 9944b08b 2022-05-08 op =item PLASS_CHARS
450 9944b08b 2022-05-08 op
451 9944b08b 2022-05-08 op Default range of characters to use to generate passwords.
452 9944b08b 2022-05-08 op
453 9944b08b 2022-05-08 op =item PLASS_GOT
454 9944b08b 2022-05-08 op
455 9944b08b 2022-05-08 op Path to the got(1) executable.
456 5cdf5adc 2022-05-08 op
457 9944b08b 2022-05-08 op =item PLASS_GPG
458 9944b08b 2022-05-08 op
459 9944b08b 2022-05-08 op Path to the gpg2(1) executable.
460 9944b08b 2022-05-08 op
461 9944b08b 2022-05-08 op =item PLASS_LENGTH
462 9944b08b 2022-05-08 op
463 9944b08b 2022-05-08 op Default length for the passwords generated.
464 9944b08b 2022-05-08 op
465 9944b08b 2022-05-08 op =item PLASS_STORE
466 9944b08b 2022-05-08 op
467 9944b08b 2022-05-08 op Path to the password-store directory tree. I<~/.password-store> by
468 9944b08b 2022-05-08 op default.
469 9944b08b 2022-05-08 op
470 9944b08b 2022-05-08 op =item PLASS_TOG
471 9944b08b 2022-05-08 op
472 9944b08b 2022-05-08 op Path to the tog(1) executable.
473 9944b08b 2022-05-08 op
474 9944b08b 2022-05-08 op =back
475 9944b08b 2022-05-08 op
476 9944b08b 2022-05-08 op =head1 FILES
477 9944b08b 2022-05-08 op
478 9944b08b 2022-05-08 op =over
479 9944b08b 2022-05-08 op
480 9944b08b 2022-05-08 op =item I<~/.password-store>
481 9944b08b 2022-05-08 op
482 9944b08b 2022-05-08 op Password store used by default.
483 9944b08b 2022-05-08 op
484 9944b08b 2022-05-08 op =item I<~/.password-store/.gpg-id>
485 9944b08b 2022-05-08 op
486 9944b08b 2022-05-08 op File containing the gpg recipient used to encrypt the passwords.
487 9944b08b 2022-05-08 op
488 9944b08b 2022-05-08 op =back
489 9944b08b 2022-05-08 op
490 5cdf5adc 2022-05-08 op =head1 ACKNOWLEDGEMENTS
491 5cdf5adc 2022-05-08 op
492 5cdf5adc 2022-05-08 op B<plass> was heavily influenced by pass(1) in the design, but it's a
493 5cdf5adc 2022-05-08 op complete different implementation with different tools involved.
494 5cdf5adc 2022-05-08 op
495 5cdf5adc 2022-05-08 op =head1 AUTHORS
496 5cdf5adc 2022-05-08 op
497 5cdf5adc 2022-05-08 op The B<plass> utility was written by Omar Polo <I<op@omarpolo.com>>.
498 5cdf5adc 2022-05-08 op
499 5cdf5adc 2022-05-08 op =head1 CAVEATS
500 5cdf5adc 2022-05-08 op
501 5cdf5adc 2022-05-08 op B<plass> B<find> output format isn't designed to handle files with
502 5cdf5adc 2022-05-08 op newlines in them. Use find(1) B<-print0> or similar if it's a
503 5cdf5adc 2022-05-08 op concern.
504 5cdf5adc 2022-05-08 op
505 5cdf5adc 2022-05-08 op There isn't a B<init> sub-command, the store initialisation must be
506 5cdf5adc 2022-05-08 op performed manually.
507 5cdf5adc 2022-05-08 op
508 5cdf5adc 2022-05-08 op =cut