summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-05-17 14:20:14 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-05-17 14:21:15 +0200
commit391929448038a478f23cfa28db528e1f4a1e60d9 (patch)
tree956c28ac7ead9b0852dbe2b716eff4fa8b356a6c
parent86d8310d5724632f2cd54723e9a2ced66bb80ba9 (diff)
Add "raps2 edit"
-rw-r--r--Changelog1
-rwxr-xr-xbin/raps29
-rw-r--r--lib/App/Raps2.pm76
-rw-r--r--lib/App/Raps2/UI.pm4
4 files changed, 76 insertions, 14 deletions
diff --git a/Changelog b/Changelog
index 4936b47..9aa5ac1 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,7 @@
git HEAD
* Terminal input is now read via Term::ReadLine (included in perl core)
+ * New commands: "raps2 del <account>" and "raps2 edit <account>"
raps2 0.2 - Fri May 13 2011
diff --git a/bin/raps2 b/bin/raps2
index 3847457..4c35592 100755
--- a/bin/raps2
+++ b/bin/raps2
@@ -21,6 +21,7 @@ given ($action) {
when ('add') { $raps2->cmd_add(@args) }
when ('del') { $raps2->cmd_remove(@args) }
when ('dump') { $raps2->cmd_dump(@args) }
+ when ('edit') { $raps2->cmd_edit(@args) }
when ('get') { $raps2->cmd_get(@args) }
when ('info') { $raps2->cmd_info(@args) }
when ('list') { $raps2->cmd_list(@args) }
@@ -50,6 +51,9 @@ accountname >> and paste the corresponding password into whatever application
requires it. B<raps2> will automatically initialize its store when used for
the first time.
+Supported metadata are "URL", "Login" and the multiline "Extra" field. URL
+and Login will be saved as plaintext, Extra is encrypted like the password.
+
=head1 ACTIONS
=over
@@ -69,6 +73,11 @@ Remove I<account> from the store.
Dump everything saved for I<account>, including the clear-text password, to
stdout.
+=item B<edit> I<account>
+
+Edit saved data for I<account>. Note that editing the multiline "extra" field
+is not yet possible.
+
=item B<get> I<account>
Decrypt I<account>'s password and store it in the X Clipboard. Note that it
diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm
index 32e46f6..9d43364 100644
--- a/lib/App/Raps2.pm
+++ b/lib/App/Raps2.pm
@@ -197,6 +197,17 @@ sub load_config {
$self->{default}->{cost} //= $cfg{cost};
}
+=item $raps2->pw()
+
+Returns the App::Raps2::Password(3pm) object.
+
+=cut
+
+sub pw {
+ my ($self) = @_;
+ return $self->{pass};
+}
+
=item $raps2->ui()
Returns the App::Raps2::UI(3pm) object.
@@ -230,11 +241,11 @@ sub cmd_add {
my $pass = $self->ui->read_pw('Password', 1);
my $extra = $self->ui->read_multiline('Additional content');
- $self->{pass}->salt($salt);
- my $pass_hash = $self->{pass}->encrypt($pass);
+ $self->pw->salt($salt);
+ my $pass_hash = $self->pw->encrypt($pass);
my $extra_hash = (
$extra ?
- $self->{pass}->encrypt($extra) :
+ $self->pw->encrypt($extra) :
q{}
);
@@ -249,9 +260,9 @@ sub cmd_add {
);
}
-=item $raps2->cmd_dump(I<$name>)
+=item $raps2->cmd_dump(I<$account>)
-Dumps the content of $name.
+Dumps the content of I<account>
=cut
@@ -267,16 +278,59 @@ sub cmd_dump {
$self->get_master_password();
- $self->{pass}->salt($key{salt});
+ $self->pw->salt($key{salt});
$self->ui()->output(
['URL', $key{url}],
['Login', $key{login}],
- ['Password', $self->{pass}->decrypt($key{hash})],
+ ['Password', $self->pw->decrypt($key{hash})],
);
if ($key{extra}) {
- print $self->{pass}->decrypt($key{extra});
+ print $self->pw->decrypt($key{extra});
+ }
+}
+
+=item $raps2->cmd_edit(I<$acount>)
+
+Edit I<account>.
+
+=cut
+
+sub cmd_edit {
+ my ($self, $name) = @_;
+ my $pwfile = $self->{xdg_data} . "/${name}";
+ my $pass_hash;
+
+ if (not -e $pwfile) {
+ confess('Password file does not exist');
+ }
+
+ my %key = $self->file_to_hash($pwfile);
+
+ $self->get_master_password();
+ $self->pw->salt($key{salt});
+
+ my $salt = $key{salt};
+ my $url = $self->ui->read_line('URL', $key{url});
+ my $login = $self->ui->read_line('Login', $key{login});
+ my $pass = $self->ui->read_pw('New password (empty to keep old)', 1);
+ my $extra = $key{extra} // q{};
+
+ if (length($pass)) {
+ $pass_hash = $self->pw->encrypt($pass);
+ }
+ else {
+ $pass_hash = $key{hash};
}
+
+ write_file(
+ $pwfile,
+ "url ${url}\n",
+ "login ${login}\n",
+ "salt ${salt}\n",
+ "hash ${pass_hash}\n",
+ "extra ${extra}\n",
+ );
}
=item $raps2->cmd_get(I<$name>)
@@ -297,12 +351,12 @@ sub cmd_get {
$self->get_master_password();
- $self->{pass}->salt($key{salt});
+ $self->pw->salt($key{salt});
- $self->ui()->to_clipboard($self->{pass}->decrypt($key{hash}));
+ $self->ui()->to_clipboard($self->pw->decrypt($key{hash}));
if ($key{extra}) {
- print $self->{pass}->decrypt($key{extra})
+ print $self->pw->decrypt($key{extra})
}
}
diff --git a/lib/App/Raps2/UI.pm b/lib/App/Raps2/UI.pm
index 089290b..9807f52 100644
--- a/lib/App/Raps2/UI.pm
+++ b/lib/App/Raps2/UI.pm
@@ -32,9 +32,7 @@ sub list {
sub read_line {
my ($self, $str, $pre) = @_;
- $pre //= q{};
-
- my $input = $self->{term_readline}->readline("${str}: ${pre}");
+ my $input = $self->{term_readline}->readline("${str}: ", $pre);
return $input;
}