aboutsummaryrefslogtreecommitdiff
path: root/debian/patches/0019-password-encrypt.patch
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2024-05-15 11:43:01 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2024-05-15 11:43:01 -0300
commit6e039fc6475d1dec21f7aa280c13f1c0b071f56c (patch)
tree22ced3820ff2b0dc302856c7fcd62f079c7708df /debian/patches/0019-password-encrypt.patch
parent677b3a938f2f714109b47880fdf364183fdb61b2 (diff)
attached patches from Bill MacAllister
Diffstat (limited to 'debian/patches/0019-password-encrypt.patch')
-rw-r--r--debian/patches/0019-password-encrypt.patch122
1 files changed, 122 insertions, 0 deletions
diff --git a/debian/patches/0019-password-encrypt.patch b/debian/patches/0019-password-encrypt.patch
new file mode 100644
index 0000000..36d2366
--- /dev/null
+++ b/debian/patches/0019-password-encrypt.patch
@@ -0,0 +1,122 @@
+--- a/perl/lib/Wallet/Object/File.pm
++++ b/perl/lib/Wallet/Object/File.pm
+@@ -249,8 +249,9 @@ sub _file_crypt {
+ return $return_string;
+ }
+
+-sub file_decrypt {
+- my ($self, $data, $user, $host, $time) = @_;
++# Given a string decrypt it.
++sub string_decrypt {
++ my ($self, $data) = @_;
+ my $key = $self->_get_crypt_key();
+ my $undata;
+ if (defined (&Wallet::Config::file_crypt)) {
+@@ -264,6 +265,15 @@ sub file_decrypt {
+ }
+ $undata = $self->_file_crypt('decrypt', $key, $data);
+ }
++ return $undata;
++}
++
++# Given a string decrypt it. If the string is not encrypted then the
++# input string string will match the decrypted string and the string
++# will be encrypted and stored to disk.
++sub file_decrypt {
++ my ($self, $data, $user, $host, $time) = @_;
++ my $undata = $self->string_decrypt($data);
+ if ($undata eq $data) {
+ $self->store($data, $user, $host, $time);
+ }
+--- a/perl/lib/Wallet/Object/Password.pm
++++ b/perl/lib/Wallet/Object/Password.pm
+@@ -84,6 +84,44 @@ sub _pwd_xkcd {
+ return $pass;
+ }
+
++# Read the password file to disk.
++sub _read_pw_file {
++ my ($self, $path) = @_;
++ my $id = $self->{type} . ':' . $self->{name};
++
++ unless (open (FILE, '<', $path)) {
++ $self->error ("cannot get $id: object has not been stored");
++ return;
++ }
++ local $/;
++ my $data = <FILE>;
++ unless (close FILE) {
++ $self->error ("cannot get $id: $!");
++ return;
++ }
++ return $data;
++}
++
++# Write the password file to disk.
++sub _write_pw_file {
++ my ($self, $path, $data) = @_;
++ my $id = $self->{type} . ':' . $self->{name};
++
++ unless (open (FILE, '>', $path)) {
++ $self->error ("cannot open $path $!\n");
++ return 1;
++ }
++ if ($Wallet::Config::LDAP_SECRET) {
++ $data = Wallet::Object::File->file_encrypt($data);
++ }
++ print FILE $data;
++ unless (close FILE) {
++ $self->error ("cannot store $id: $!");
++ return 1;
++ }
++ return 0;
++}
++
+ ##############################################################################
+ # Shared methods
+ ##############################################################################
+@@ -135,34 +173,25 @@ sub retrieve {
+ }
+ return;
+ }
+- unless (open (FILE, '>', $path)) {
+- $self->error ("cannot open $path $!\n");
++ if ($self->_write_pw_file($path, $pass)) {
+ return;
+ }
+- if ($Wallet::Config::LDAP_SECRET) {
+- $pass = Wallet::Object::File->file_encrypt($pass);
+- }
+- print FILE $pass;
+ $self->log_action ('store', $user, $host, $time);
+- unless (close FILE) {
+- $self->error ("cannot get $id: $!");
+- return;
+- }
+ }
+
+- unless (open (FILE, '<', $path)) {
+- $self->error ("cannot get $id: object has not been stored");
+- return;
+- }
+- local $/;
+- my $data = <FILE>;
+- unless (close FILE) {
+- $self->error ("cannot get $id: $!");
++ my $data = $self->_read_pw_file($path);
++ if (!$data) {
+ return;
+ }
+ $self->log_action ($operation, $user, $host, $time);
+ if ($Wallet::Config::LDAP_SECRET) {
+- $data = Wallet::Object::File->file_decrypt($data);
++ my $undata = Wallet::Object::File->string_decrypt($data);
++ if ($undata eq $data) {
++ my $endata = Wallet::Object::File->file_encrypt($data);
++ $self->_write_pw_file($path, $endata);
++ $self->log_action ($operation, $user, $host, $time);
++ }
++ $data = $undata;
+ }
+ return $data;
+ }