Skip to content

Commit

Permalink
Refuse empty keys
Browse files Browse the repository at this point in the history
Signed-off-by: Adrien Gallouët <[email protected]>
  • Loading branch information
angt committed Apr 30, 2020
1 parent b256e45 commit 79e0df2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define S_VER_MINOR 2U
#define S_ENTRYSIZE 512U
#define S_PWDGENLEN 25U
#define S_KEYLENMAX 255U
#define S_ENV_AGENT "SECRET_AGENT"
#define S_ENV_STORE "SECRET_STORE"

Expand Down Expand Up @@ -261,16 +262,16 @@ s_print_keys(int use_tty)
static size_t
s_keylen(const char *str)
{
if (!str)
s_fatal("Empty key!");
if (!str || !str[0])
s_fatal("Empty keys are not allowed");

for (size_t i = 0; i < 256; i++) {
for (size_t i = 0; i <= S_KEYLENMAX; i++) {
if (!str[i])
return i;
if (str[i] > 0 && str[i] <= ' ')
s_fatal("Malformed key");
s_fatal("Special characaters are not allowed in keys");
}
s_fatal("Key too big!");
s_fatal("Keys are limited to %u bytes", S_KEYLENMAX);
}

static const char *
Expand Down Expand Up @@ -458,7 +459,7 @@ s_pass(int argc, char **argv, void *data)

for (int i = 1; i < argc; i++) {
int r = hydro_pwhash_deterministic(buf, sizeof(buf),
argv[i], strlen(argv[i]),
argv[i], s_keylen(argv[i]),
s.ctx_passwd, key,
load64_le(s.hdr.opslimit), 0, 1);
memcpy(key, buf, sizeof(key));
Expand Down

0 comments on commit 79e0df2

Please sign in to comment.