apm

Minimalistic command line password manager and a rewrite of pass in C
git clone https://codeberg.org/night0721/apm
Log | Files | Refs | README | LICENSE

commit f418fec045772c94db459bc9da8c813fb803ee0b
parent 57ffcff2f1d8b00e08053f11bd2a8bccc85bbd25
Author: night0721 <[email protected]>
Date:   Wed, 10 Apr 2024 17:00:59 +0100

add multiline option and fix fread params

Diffstat:
MREADME.md | 2+-
Margon.c | 22++++++++++++++++++----
2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/README.md b/README.md @@ -24,7 +24,7 @@ $ make # Usage ``` -Usage: ./argon [-vheRIQLG] [-v] [-h] [-e <password>] [-R <password>] [-I <password>] [-Q <password>] [-L] [-G <password> <length>] +Usage: argon [-vhL] [[-e | -R | -I | -Q] <password>] [-M <file>] [-G <password> <length>] ``` # Contributions diff --git a/argon.c b/argon.c @@ -33,7 +33,7 @@ char *get_master_key(); void usage() { - printf("Usage: %s [-vhL] [[-e | -R | -I | -Q] <password>] [-G <password> <length>]\n", argv0); + printf("Usage: %s [-vhL] [[-e | -R | -I | -Q] <password>] [-M <file>] [-G <password> <length>]\n", argv0); exit(EXIT_SUCCESS); } @@ -214,15 +214,15 @@ void decrypt_password(const char *name, int open) } /* get salt and nonce from file */ - fread(salt, sizeof(salt), 1, file); - fread(nonce, sizeof(nonce), 1, file); + fread(salt, sizeof(char), sizeof(salt), file); + fread(nonce, sizeof(char), sizeof(nonce), file); fseek(file, 0, SEEK_END); size_t ciphered_len = ftell(file) - sizeof(salt) - sizeof(nonce); fseek(file, sizeof(salt) + sizeof(nonce), SEEK_SET); char ciphered[ciphered_len]; - fread(ciphered, 1, ciphered_len, file); + fread(ciphered, sizeof(char), ciphered_len, file); if (crypto_pwhash(key, sizeof(key), m_key, strlen(m_key), salt, crypto_pwhash_OPSLIMIT_INTERACTIVE, crypto_pwhash_MEMLIMIT_INTERACTIVE, @@ -371,6 +371,20 @@ int main(int argc, char *argv[]) free(argon); exit(EXIT_SUCCESS); break; + case 'M':; + char *filename = EARGF(usage()); + FILE *file = fopen(filename, "r"); + if (file == NULL) { + die("Cannot open file to read"); + } + fseek(file, 0, SEEK_END); + long file_size = ftell(file); + fseek(file, 0, SEEK_SET); + char *content = memalloc(file_size * sizeof(char)); + fread(content, sizeof(char), file_size, file); + encrypt_password(basename(filename), content); + exit(EXIT_SUCCESS); + break; case 'G':; if (argc > 0) --argc, ++argv;