commit b53b2ab

Emilia Smólska  ·  2026-06-15 21:47:19 +0000 UTC
parent 9d6ba5c
BREAKING CHANGE: encode password targets with base32

this is done to allow targets with slashes in them
run perl migrate.pl to migrate your existing passwords (no warranty :p)
4 files changed,  +28, -3
M README
M haslo
+1, -1
1@@ -11,7 +11,7 @@ MAN1=${MANDIR}/man1
2 
3 PERLSHEBANG=/usr/bin/env perl
4 
5-PERLMODS=MIME::Base64 Term::ReadKey
6+PERLMODS=MIME::Base32 MIME::Base64 Term::ReadKey
7 
8 all: checkmods
9 
M README
+1, -1
1@@ -2,7 +2,7 @@ Haslo is a simple password manager.
2 
3 Dependencies:
4 - Perl,
5-- The Perl modules MIME::Base64 and Term::ReadKey (may already be included in your system's Perl distribution),
6+- The Perl modules MIME::Base32, MIME::Base64 and Term::ReadKey (some may already be included in your system's Perl distribution),
7 - GnuPG.
8 
9 Installation:
M haslo
+7, -1
 1@@ -4,6 +4,7 @@
 2 
 3 use strict;
 4 use warnings;
 5+use MIME::Base32 qw(decode_base32 encode_base32);
 6 use MIME::Base64 qw(encode_base64);
 7 use Term::ReadKey qw(ReadMode ReadLine);
 8 
 9@@ -33,6 +34,7 @@ sub writegpgpassword
10 sub dogen
11 {
12 	my $target = $ARGV[1] or usage;
13+	$target = encode_base32 $target;
14 	my $buf = '';
15 	open URANDOM, '<', '/dev/urandom' or die "couldn't open /dev/urandom: $!\n";
16 	read URANDOM, $buf, 128 or die "couldn't read from /dev/urandom: $!\n";
17@@ -44,6 +46,7 @@ sub dogen
18 sub doget
19 {
20 	my $target = $ARGV[1] or usage;
21+	$target = encode_base32 $target;
22 	open GPG, '-|', 'gpg', '-qd', "$haslodir/$target.gpg" or die "couldn't open pipe to gpg: $!\n";
23 	my $password = <GPG>;
24 	close GPG or die "gpg failed with exit code $?\n";
25@@ -54,7 +57,9 @@ sub dolist
26 {
27 	opendir DIR, $haslodir or die "couldn't open $haslodir: $!\n";
28 	for(readdir DIR){
29-		print "$_\n" if s/.gpg$//;
30+		next unless s/.gpg$//;
31+		my $decoded = decode_base32 $_;
32+		print "$decoded\n";
33 	}
34 	close DIR;
35 }
36@@ -62,6 +67,7 @@ sub dolist
37 sub doput
38 {
39 	my $target = $ARGV[1] or usage;
40+	$target = encode_base32 $target;
41 	my($password, $confirm);
42 	do{
43 		ReadMode 'noecho';
+19, -0
 1@@ -0,0 +1,19 @@
 2+#!/usr/bin/env perl
 3+
 4+use strict;
 5+use warnings;
 6+use MIME::Base32 qw(encode_base32);
 7+
 8+my $home = $ENV{'HOME'} or die "\$HOME not set\n";
 9+my $haslodir = $ENV{'HASLODIR'} || "$home/.haslo";
10+
11+chdir $haslodir or die "couldn't chdir to $haslodir: $!\n";
12+opendir DIR, '.' or die "couldn't open $haslodir: $!\n";
13+for(readdir DIR){
14+	next if -d;
15+	next unless s/\.gpg$//;
16+	my $encoded = encode_base32 $_;
17+	print "renaming $_ to $encoded\n";
18+	rename "$_.gpg", "$encoded.gpg" or die "couldn't rename $_ to $encoded: $!\n";
19+}
20+close DIR;