Warn is passphrase file is world-readable

This commit is contained in:
Juhani Krekelä 2021-04-09 23:08:22 +03:00
parent 41a74402f0
commit a3079f5eda
1 changed files with 11 additions and 0 deletions

11
puer.c
View File

@ -546,6 +546,17 @@ ssize_t passphrase_prompt(unsigned char *passphrase, size_t size, const char *pr
ssize_t passphrase_file(char *passfilepath, unsigned char passphrase[], size_t size) {
int file = open(passfilepath, O_RDONLY);
// Check permissions
struct stat statbuf;
if (fstat(file, &statbuf) != 0) {
perror("Could not stat passphrase file");
close(file);
return -1;
}
if (statbuf.st_mode & S_IROTH) {
fprintf(stderr, "Warning: Passphrase file is world-readable\n");
}
// Read until newline
size_t index = 0;
for (;;) {