From e762f76c0bcd6398065404e119171b7480697ed8 Mon Sep 17 00:00:00 2001 From: night0721 Date: Sun, 19 May 2024 16:52:18 +0100 Subject: [PATCH] change argon to apm --- .gitignore | 2 +- Makefile | 63 ++++++++++++++++++++++++++---------------------- README.md | 20 +++++++++------ apm.1 | 58 ++++++++++++++++++++++++++++++++++++++++++++ argon.c => apm.c | 56 +++++++++++++++++++++--------------------- argon.1 | 53 ---------------------------------------- 6 files changed, 133 insertions(+), 119 deletions(-) create mode 100644 apm.1 rename argon.c => apm.c (91%) delete mode 100644 argon.1 diff --git a/.gitignore b/.gitignore index b751fb3..04c7f45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -argon +apm *.o *.tar.gz diff --git a/Makefile b/Makefile index cb9a90f..f156f35 100644 --- a/Makefile +++ b/Makefile @@ -1,40 +1,45 @@ .POSIX: .SUFFIXES: -CC=cc +CC = cc +VERSION = 1.0 +TARGET = apm +MANPAGE = $(TARGET).1 +PREFIX ?= /usr/local +BINDIR = $(PREFIX)/bin +MANDIR = $(PREFIX)/share/man/man1 -VERSION=1.0.0 -PREFIX = /usr/local -MANPREFIX = ${PREFIX}/share/man +# Flags +LDFLAGS = $(shell pkg-config --libs libsodium) +CFLAGS = -O3 -march=native -mtune=native -pipe -s -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -CFLAGS = -O3 -march=native -mtune=native -pipe -s -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -lsodium +SRC = apm.c -SRC = argon.c +$(TARGET): $(SRC) + $(CC) $(SRC) -o $@ $(CFLAGS) $(LDFLAGS) -argon: argon.c - ${CC} ${SRC} -o $@ ${CFLAGS} +dist: + mkdir -p $(TARGET)-$(VERSION) + cp -R README.md $(MANPAGE) $(TARGET) $(TARGET)-$(VERSION) + tar -cf $(TARGET)-$(VERSION).tar $(TARGET)-$(VERSION) + gzip $(TARGET)-$(VERSION).tar + rm -rf $(TARGET)-$(VERSION) -clean: - rm -rf argon - -dist: version argon - mkdir -p argon-${VERSION} - cp -R LICENSE README.md argon.1 argon argon-${VERSION} - tar -cf argon-${VERSION}.tar argon-${VERSION} - gzip argon-${VERSION}.tar - rm -rf argon-${VERSION} - -install: all - mkdir -p ${DESTDIR}${PREFIX}/bin - cp -f argon ${DESTDIR}${PREFIX}/bin - chmod 755 ${DESTDIR}${PREFIX}/bin/argon - mkdir -p ${DESTDIR}${MANPREFIX}/man1 - cp argon.1 ${DESTDIR}${MANPREFIX}/man1/argon.1 - chmod 644 ${DESTDIR}${MANPREFIX}/man1/argon.1 +install: $(TARGET) + mkdir -p $(DESTDIR)$(BINDIR) + mkdir -p $(DESTDIR)$(MANDIR) + cp -p $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET) + chmod 755 $(DESTDIR)$(BINDIR)/$(TARGET) + cp -p $(MANPAGE) $(DESTDIR)$(MANDIR)/$(MANPAGE) + chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE) uninstall: - rm -f ${DESTDIR}${PREFIX}/bin/argon\ - ${DESTDIR}${MANPREFIX}/man1/argon.1 -all: argon + $(RM) $(DESTDIR)$(BINDIR)/$(TARGET) + $(RM) $(DESTDIR)$(MANDIR)/$(MANPAGE) -.PHONY: all clean dist install uninstall argon +clean: + $(RM) $(TARGET) + +all: $(TARGET) + +.PHONY: all dist install uninstall clean diff --git a/README.md b/README.md index d6607f4..1f9d8c6 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,26 @@ -# argon +# apm -A minimalistic command line password manager and a rewrite of [pass](https://www.passwordstore.org/) in C. It uses a unique key to encrypt every password, it provides functionality to edit, add, generate, show, list, remove passwords. It uses argon2 to create hash of master password and uses XSalsa20 to encrypt the password. +apm, argon password manager; a minimalistic command line password manager and a rewrite of [pass](https://www.passwordstore.org/) in C. It uses a unique key to encrypt every password, it provides functionality to edit, add, generate, show, list, remove passwords. It uses argon2 to create hash of master password and uses XSalsa20 to encrypt the password. > The name "argon" is chosen as it uses argon2 algorithm and sodium(library) is stored with argon. -Before using argon, you must export 2 environment variables in order to make it work +Before using apm, you must export 2 environment variables in order to make it work ```sh -export ARGON_DIR=~/secret/argon -export ARGON_KEY=~/secret/argon_key +export APM_DIR=~/secret/apm +export APM_KEY=~/secret/apm_key ``` -`ARGON_DIR` is the directory where passwords are stored and `ARGON_KEY` is the path to the master key file. +`APM_DIR` is the directory where passwords are stored and `APM_KEY` is the path to the master key file. # Dependencies + - libsodium - gcc # Building + +You will need to run these with elevated privilages. + ```sh $ make # make install @@ -24,11 +28,11 @@ $ make # Usage ``` -Usage: argon [-vhL] [[-e | -R | -I | -Q] ] [-M ] [-G ] +Usage: apm [-vhL] [[-e | -R | -I | -Q] ] [-M ] [-G ] ``` # Contributions Contributions are welcomed, feel free to open a pull request. # License -This project is licensed under the GNU Public License v3.0. See [LICENSE](https://github.com/night0721/argon/blob/master/LICENSE) for more information. +This project is licensed under the GNU Public License v3.0. See [LICENSE](https://github.com/night0721/apm/blob/master/LICENSE) for more information. diff --git a/apm.1 b/apm.1 new file mode 100644 index 0000000..8b3b0b3 --- /dev/null +++ b/apm.1 @@ -0,0 +1,58 @@ +.TH apm 1 apm\-1.0.0 +.SH NAME +apm \- Minimalistic password manager +.SH SYNOPSIS +.B apm +.RB [ \-v ] +.RB [ \-h ] +.RB [ \-e ] +.RB [ \-R ] +.RB [ \-I ] +.RB [ \-Q ] +.RB [ \-L ] +.RB [ \-M ] +.RB [ \-G ] + +.SH DESCRIPTION +apm is a minimalistic command line password manager and a rewrite of pass in C. It uses a unique key to encrypt every password, it provides functionality to edit, add, generate, show, list, remove passwords. It uses argon2 to create hash of master password and uses XSalsa20 to encrypt the password. + +.SH OPTIONS +.TP +.B \-v +Prints the version of the program. + +.TP +.B \-h +Shows the help message. + +.TP +.B \-e +Edits the password using EDITOR. + +.TP +.B \-R +Removes password from APM_DIR. + +.TP +.B \-I +Insert password to APM_DIR. + +.TP +.B \-Q +Show password from APM_DIR. + +.TP +.B \-L +Lists the passwords in APM_DIR in a tree format. + +.TP +.B \-M +Insert password from a file, in order to fix -I can't take multi line input. + +.TP +.B \-G +Generate a password with specific length to add to APM_DIR. + +.SH AUTHOR +Made by Night Kaly +.B diff --git a/argon.c b/apm.c similarity index 91% rename from argon.c rename to apm.c index b766615..4cc3b79 100644 --- a/argon.c +++ b/apm.c @@ -23,7 +23,7 @@ void *memalloc(size_t size) { void *ptr = malloc(size); if (!ptr) { - perror("argon"); + perror("apm"); exit(EXIT_FAILURE); } return ptr; @@ -87,17 +87,17 @@ void tree(const char *basepath, int depth) closedir(dir); } -char *get_argon() +char *get_apm() { - char dirname[] = "argon"; - const char *argon_dir = getenv("ARGON_DIR"); + char dirname[] = "apm"; + const char *apm_dir = getenv("APM_DIR"); /* for / and null */ size_t len = 2; - if (argon_dir == NULL) { - argon_dir = getenv("XDG_DATA_HOME"); - if (argon_dir == NULL) { - argon_dir = getenv("HOME"); - if (argon_dir == NULL) { + if (apm_dir == NULL) { + apm_dir = getenv("XDG_DATA_HOME"); + if (apm_dir == NULL) { + apm_dir = getenv("HOME"); + if (apm_dir == NULL) { die("HOME not defined"); } } @@ -106,15 +106,15 @@ char *get_argon() /* no / */ len -= 1; } - size_t dir_len = strlen(argon_dir); + size_t dir_len = strlen(apm_dir); len += dir_len; char *dir = memalloc(len * sizeof(char)); - /* check if it is ARGON_DIR or other */ + /* check if it is apm_DIR or other */ if (len > dir_len) { - snprintf(dir, len, "%s/%s", argon_dir, dirname); + snprintf(dir, len, "%s/%s", apm_dir, dirname); } else { - strncpy(dir, argon_dir, len); + strncpy(dir, apm_dir, len); } struct stat stats; /* check defined path is directory */ @@ -128,7 +128,7 @@ char *get_argon() char *get_passfile(const char *key) { - char *dir = get_argon(); + char *dir = get_apm(); /* concat file name */ /* / and null */ size_t len = strlen(dir) + strlen(key) + 2; @@ -165,7 +165,7 @@ void encrypt_password(const char *name, char *password) crypto_pwhash_MEMLIMIT_INTERACTIVE, crypto_pwhash_ALG_DEFAULT) != 0) { sodium_free(m_key); - perror("argon"); + perror("apm"); die("Cannot create key"); } size_t pw_len = strlen(password); @@ -229,7 +229,7 @@ void decrypt_password(const char *name, int open) crypto_pwhash_ALG_DEFAULT) != 0) { sodium_free(m_key); free(filepath); - perror("argon"); + perror("apm"); die("Cannot create key"); } /* take authentication bytes away */ @@ -249,7 +249,7 @@ void decrypt_password(const char *name, int open) if (editor == NULL) { die("EDITOR not defined"); } - char tmp_f[] = "/tmp/argon"; + char tmp_f[] = "/tmp/apm"; FILE *tmp = fopen(tmp_f, "w+"); fprintf(tmp, "%s\n", deciphered); fclose(tmp); @@ -275,12 +275,12 @@ void decrypt_password(const char *name, int open) char *get_master_key() { - char *key_path = getenv("ARGON_KEY"); + char *key_path = getenv("APM_KEY"); char *m_key = NULL; if (key_path != NULL) { FILE *key_file = fopen(key_path, "r"); if (key_file == NULL) { - perror("argon"); + perror("apm"); exit(EXIT_FAILURE); } struct stat st; @@ -288,16 +288,16 @@ char *get_master_key() size_t pass_size = st.st_size; m_key = (char *) sodium_malloc(pass_size * sizeof(char)); if (m_key == NULL) { - perror("argon"); + perror("apm"); exit(EXIT_FAILURE); } if (fgets(m_key, pass_size, key_file) == NULL) { - perror("argon"); + perror("apm"); exit(EXIT_FAILURE); } } } else { - fprintf(stderr, "argon: You are required to set ARGON_KEY to pass file\n"); + fprintf(stderr, "apm: You are required to set APM_KEY to pass file\n"); exit(EXIT_FAILURE); } return m_key; @@ -320,7 +320,7 @@ void generate_password(char*name, int length) void die(char *str) { - fprintf(stderr, "argon: %s\n", str); + fprintf(stderr, "apm: %s\n", str); exit(EXIT_FAILURE); } @@ -338,7 +338,7 @@ int main(int argc, char *argv[]) usage(); break; case 'v': - printf("argon 1.0.0\n"); + printf("apm 1.0.0\n"); exit(EXIT_SUCCESS); break; case 'e': @@ -348,7 +348,7 @@ int main(int argc, char *argv[]) case 'R':; char *pass_file = get_passfile(EARGF(usage())); if (remove(pass_file)) { - perror("argon"); + perror("apm"); } else { printf("Removed %s\n", basename(pass_file)); } @@ -366,9 +366,9 @@ int main(int argc, char *argv[]) exit(EXIT_SUCCESS); break; case 'L':; - char *argon = get_argon(); - tree(argon, 0); - free(argon); + char *apm = get_apm(); + tree(apm, 0); + free(apm); exit(EXIT_SUCCESS); break; case 'M':; diff --git a/argon.1 b/argon.1 deleted file mode 100644 index edd4154..0000000 --- a/argon.1 +++ /dev/null @@ -1,53 +0,0 @@ -.TH argon 1 argon\-1.0.0 -.SH NAME -argon \- Minimalistic password manager -.SH SYNOPSIS -.B argon -.RB [ \-v ] -.RB [ \-h ] -.RB [ \-e ] -.RB [ \-R ] -.RB [ \-I ] -.RB [ \-Q ] -.RB [ \-L ] -.RB [ \-G ] - -.SH DESCRIPTION -argon is a minimalistic command line password manager and a rewrite of pass in C. It uses a unique key to encrypt every password, it provides functionality to edit, add, generate, show, list, remove passwords. It uses argon2 to create hash of master password and uses XSalsa20 to encrypt the password. - -.SH OPTIONS -.TP -.B \-v -Prints the version of the program. - -.TP -.B \-h -Shows the help message. - -.TP -.B \-e -Edits the password using EDITOR. - -.TP -.B \-R -Removes password from ARGON_DIR. - -.TP -.B \-I -Insert password to ARGON_DIR. - -.TP -.B \-Q -Show password from ARGON_DIR. - -.TP -.B \-L -Lists the passwords in ARGON_DIR in a tree format. - -.TP -.B \-G -Generate a password with specific length to add to ARGON_DIR. - -.SH AUTHOR -Made by Night Kaly -.B