Commit 02b14e38 authored by Antonin Décimo's avatar Antonin Décimo Committed by Juliusz Chroboczek

Helpful error messages in key configuration.

parent d763f3e0
...@@ -755,8 +755,10 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return) ...@@ -755,8 +755,10 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return)
struct key *key; struct key *key;
key = calloc(1, sizeof(struct key)); key = calloc(1, sizeof(struct key));
if(key == NULL) if(key == NULL) {
perror("calloc(key)");
return -2; return -2;
}
while(1) { while(1) {
c = skip_whitespace(c, gnc, closure); c = skip_whitespace(c, gnc, closure);
if(c < 0 || c == '\n' || c == '#') { if(c < 0 || c == '\n' || c == '#') {
...@@ -786,32 +788,43 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return) ...@@ -786,32 +788,43 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return)
} else if(strcmp(auth_type, "blake2s") == 0) { } else if(strcmp(auth_type, "blake2s") == 0) {
key->type = AUTH_TYPE_BLAKE2S; key->type = AUTH_TYPE_BLAKE2S;
} else { } else {
fprintf(stderr, "Key type '%s' isn't supported.\n", auth_type);
free(auth_type); free(auth_type);
goto error; goto error;
} }
free(auth_type); free(auth_type);
} else if(strcmp(token, "value") == 0) { } else if(strcmp(token, "value") == 0) {
c = gethex(c, &key->value, &key->len, gnc, closure); c = gethex(c, &key->value, &key->len, gnc, closure);
if(c < -1 || key->value == NULL) if(c < -1 || key->value == NULL) {
fprintf(stderr, "Couldn't parse key value.\n");
goto error; goto error;
}
} else { } else {
fprintf(stderr, "Unrecognized keyword '%s'.\n", token);
goto error; goto error;
} }
free(token); free(token);
token = NULL; token = NULL;
} }
if(key->id == NULL) if(key->id == NULL) {
fprintf(stderr, "No key id was given.\n");
goto error; goto error;
}
switch(key->type) { switch(key->type) {
case AUTH_TYPE_SHA256: { case AUTH_TYPE_SHA256: {
if(key->len > 64) if(key->len > 64) {
fprintf(stderr, "Key length is %d, expected at most %d.\n",
key->len, 64);
goto error; goto error;
}
if(key->len < 64) { if(key->len < 64) {
unsigned char *v = realloc(key->value, 64); unsigned char *v = realloc(key->value, 64);
if(v == NULL) if(v == NULL) {
perror("realloc(key->value)");
goto error; goto error;
}
memset(v + key->len, 0, 64 - key->len); memset(v + key->len, 0, 64 - key->len);
key->value = v; key->value = v;
key->len = 64; key->len = 64;
...@@ -819,10 +832,14 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return) ...@@ -819,10 +832,14 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return)
break; break;
} }
case AUTH_TYPE_BLAKE2S: case AUTH_TYPE_BLAKE2S:
if(key->len != 16) if(key->len != 16) {
fprintf(stderr, "Key length is %d, expected %d.\n",
key->len, 16);
goto error; goto error;
}
break; break;
default: default:
fprintf(stderr, "Key type 'none' isn't supported.\n");
goto error; goto error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment