Compare commits

...

2 Commits

Author SHA1 Message Date
Érico Nogueira 599b7f431e Support alternative finders.
ef is my own attempt at one :P
2021-10-24 23:13:28 -03:00
Érico Nogueira 9592de802c Always restore termios in cbc-file. 2021-10-24 23:12:27 -03:00
2 changed files with 23 additions and 7 deletions

View File

@ -50,6 +50,8 @@ static void usage(void)
static int read_password(uint8_t *key, const uint8_t *salt)
{
int rv = -1;
fprintf(stderr, "input password (up to %d): ", KEY_LENGTH);
struct termios old, t;
@ -61,17 +63,21 @@ static int read_password(uint8_t *key, const uint8_t *salt)
char pass[PASS_LENGTH];
if (fgets(pass, PASS_LENGTH, stdin) == NULL) {
return -1;
// echo should always be turned off at exit
goto end;
}
rv = 0;
argon2id_hash_raw(
TIME_COST, MEM_COST, PARALLEL,
pass, strlen(pass), salt, SALT_LENGTH,
key, KEY_LENGTH);
end:
// restore previous attributes
tcsetattr(STDIN_FILENO, TCSANOW, &old);
argon2id_hash_raw(TIME_COST, MEM_COST, PARALLEL,
pass, strlen(pass), salt, SALT_LENGTH,
key, KEY_LENGTH);
return 0;
return rv;
}
static off_t file_size(int fd)

View File

@ -3,9 +3,19 @@ file="${OTP_ACCOUNTS:-$HOME/.local/share/otp_accounts}"
json="$(@PREFIX@/bin/cbc-file unlock "$file")"
[ -z "$json" ] && exit 1
finder=
if command -v ef >/dev/null; then
finder="ef -c -1"
elif command -v fzf >/dev/null; then
finder="fzf --cycle -1"
else
echo "couldn't find finder" >&2
exit 1
fi
label="$(printf %s "$json" |
jq '.[].label' 2>/dev/null |
fzf --cycle -1 ${1:+--query "$1"}
$finder ${1:+-q "$1"}
)"
[ -z "$label" ] && exit 1