-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Adrien Gallouët <[email protected]>
- Loading branch information
Showing
9 changed files
with
773 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "libhydrogen"] | ||
path = libhydrogen | ||
url = https://github.com/jedisct1/libhydrogen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CC = cc | ||
CFLAGS = -Wall -O2 | ||
prefix = /usr/local | ||
|
||
secret: | ||
$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) secret.c -o secret | ||
|
||
install: secret | ||
mkdir -p $(DESTDIR)$(prefix)/bin | ||
cp -f secret $(DESTDIR)$(prefix)/bin | ||
|
||
uninstall: | ||
rm -f $(DESTDIR)$(prefix)/bin/secret | ||
|
||
clean: | ||
rm -f secret | ||
|
||
.PHONY: secret install uninstall clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# secret | ||
|
||
Keep your little secrets, publicly. | ||
|
||
## Features | ||
|
||
- Only one file to backup: `~/.secret`. | ||
- No configuration: get back your file and you're done. | ||
- URLs/logins/scopes are encrypted too. | ||
- Secret agent that allows shell completion (only `bash` for now). | ||
- Support many passwords (a visual hash might be required). | ||
- Depends only on the [libhydrogen](https://libhydrogen.org/) library. | ||
- Small, simple and non obfuscated C code. | ||
|
||
## Build and install | ||
|
||
$ make install prefix=/usr | ||
|
||
## Commands | ||
|
||
$ secret | ||
Available commands: | ||
init Init secret storage | ||
list List all secrets | ||
add Add a new secret | ||
show Show a secret | ||
change Change a secret | ||
agent Exec in secret zone | ||
|
||
## Examples | ||
|
||
Initialize secret: | ||
|
||
$ secret init | ||
|
||
Add a new generated secret called 'test': | ||
|
||
$ secret add test | ||
Password: | ||
Secret [random]: | ||
9{6u0ue>5&W2+z#OR:`X<@-# | ||
|
||
Show secret 'test': | ||
|
||
$ secret show test | ||
Password: | ||
9{6u0ue>5&W2+z#OR:`X<@-# | ||
|
||
Start a secret zone: | ||
|
||
$ secret agent bash | ||
Password: | ||
|
||
You can now manipulate your secrets easily and with completion: | ||
|
||
$ ./secret show test | ||
9{6u0ue>5&W2+z#OR:`X<@-# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <ctype.h> | ||
#include <errno.h> | ||
#include <limits.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
|
||
#include "argz.h" | ||
|
||
static int | ||
argz_help(int argc, char **argv) | ||
{ | ||
return argc >= 2 && !strcmp(argv[1], "help"); | ||
} | ||
|
||
static int | ||
argz_cmp(struct argz *z, char *name) | ||
{ | ||
if (!strcmp(z->name, name)) | ||
return 0; | ||
if (z->alt) for (unsigned k = 0; z->alt[k]; k++) { | ||
if (!strcmp(z->alt[k], name)) | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
static int | ||
argz_is_available(struct argz *z, unsigned i, unsigned *ret) | ||
{ | ||
if (z[i].set) | ||
return 0; | ||
if (z[i].grp) for (unsigned k = 0; z[k].name; k++) { | ||
if (z[k].set && z[k].grp == z[i].grp) { | ||
if (ret) *ret = k; | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
void | ||
argz_print(struct argz *z) | ||
{ | ||
int len = 0; | ||
|
||
for (int i = 0; z[i].name; i++) { | ||
if (!argz_is_available(z, i, NULL)) | ||
continue; | ||
int nlen = strlen(z[i].name); | ||
if (len < nlen) | ||
len = nlen; | ||
} | ||
|
||
for (int i = 0; z[i].name; i++) { | ||
if (!argz_is_available(z, i, NULL)) | ||
continue; | ||
printf(" %-*s %s\n", len, z[i].name, z[i].help ?: ""); | ||
} | ||
} | ||
|
||
int | ||
argz(int argc, char **argv, void *data) | ||
{ | ||
struct argz *z = (struct argz *)data; | ||
|
||
if (argz_help(argc, argv)) { | ||
argz_print(z); | ||
return 0; | ||
} | ||
|
||
if (argc > 1) { | ||
for (unsigned i = 0; z[i].name; i++) { | ||
if (argz_cmp(&z[i], argv[1])) | ||
continue; | ||
unsigned k = 0; | ||
if (!argz_is_available(z, i, &k)) { | ||
fprintf(stderr, "cannot call %s because of %s\n", z[i].name, z[k].name); | ||
return 0; | ||
} | ||
int ret = argc - 1; | ||
if (z[i].f) | ||
ret = z[i].f(ret, argv + argc - ret, z[i].data); | ||
return argz(ret, argv + argc - ret, data); | ||
} | ||
fprintf(stderr, "Unknown: %s\n", argv[1]); | ||
} | ||
|
||
return argc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
struct argz { | ||
char *name; | ||
char *help; | ||
int (*f)(int, char **, void *); | ||
void *data; | ||
const char *const *alt; | ||
unsigned grp; | ||
int set; | ||
}; | ||
|
||
int argz (int, char **, void *); | ||
void argz_print (struct argz *); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
_argz() { | ||
local last opts | ||
last="${COMP_WORDS[COMP_CWORD]}" | ||
COMP_WORDS[COMP_CWORD]="help" | ||
opts="$("${COMP_WORDS[@]}" 2>/dev/null | awk '{print $1}' )" | ||
case "$opts" in | ||
'') ;; | ||
CMD) mapfile -t COMPREPLY < <(compgen -A command -- "$last") ;; | ||
DIR) mapfile -t COMPREPLY < <(compgen -A dir -- "$last") ;; | ||
FILE) mapfile -t COMPREPLY < <(compgen -A file -- "$last") ;; | ||
*) mapfile -t COMPREPLY < <(compgen -W "$opts" -- "$last") ;; | ||
esac | ||
} |
Submodule libhydrogen
added at
3de3ef
Oops, something went wrong.