safe

Password protected secret keeper
git clone git://git.z3bra.org/safe.git
Log | Files | Refs | README | LICENSE

commit 7a35319955c94c158db21a7e368e58f974830d05
parent 788fd208467d17a169a655453b20510ba6245cfb
Author: Willy Goiffon <dev@z3bra.org>
Date:   Wed,  5 Jun 2019 18:13:30 +0200

Force checking master password regardless of operation

Diffstat:
safe.c | 28++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/safe.c b/safe.c @@ -400,21 +400,21 @@ main(int argc, char *argv[]) close(fd); } - if (aflag) { - fd = open(MASTER, O_RDONLY); - if (fd < 0) - err(1, "%s", MASTER); - xread(fd, s.salt, sizeof(s.salt), NULL); - deriv((char *)passphrase, &s); - - /* do not store secret if master password mismatch */ - if (trydecrypt(&s, fd) < 0) { - fprintf(stderr, "incorrect master password\n"); - close(fd); - return -1; - } + fd = open(MASTER, O_RDONLY); + if (fd < 0) + err(1, "%s", MASTER); + xread(fd, s.salt, sizeof(s.salt), NULL); + deriv((char *)passphrase, &s); + + /* do not store secret if master password mismatch */ + if (trydecrypt(&s, fd) < 0) { + fprintf(stderr, "incorrect master password\n"); close(fd); + return -1; + } + close(fd); + if (aflag) { mkdir_p(dirname(secret), 0700); fd = open(secret, O_WRONLY | O_CREAT | O_EXCL, 0600); if (fd < 0) @@ -429,7 +429,7 @@ main(int argc, char *argv[]) err(1, "%s", secret); /* Read salt from the beginning of the file */ - xread(fd, s.salt, sizeof(s.salt), NULL); + lseek(fd, sizeof(s.salt), SEEK_SET); deriv((char *)passphrase, &s); readsecret(&s, fd, STDOUT_FILENO); close(fd);