Switched to /dev/random instead of time(NULL) in secrets.c

This commit is contained in:
Markus Makela
2014-11-25 11:37:21 +02:00
parent e4c379bbdc
commit 30c928c326

View File

@ -227,7 +227,8 @@ static int reported = 0;
*/ */
int secrets_writeKeys(char *secret_file) int secrets_writeKeys(char *secret_file)
{ {
int fd; int fd,randfd;
unsigned int randval;
MAXKEYS key; MAXKEYS key;
/* Open for writing | Create | Truncate the file for writing */ /* Open for writing | Create | Truncate the file for writing */
@ -243,7 +244,28 @@ MAXKEYS key;
return 1; return 1;
} }
srand(time(NULL)); /* Open for writing | Create | Truncate the file for writing */
if ((randfd = open("/dev/random", O_RDONLY)) < 0)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : failed opening /dev/random. Error %d, %s.",
errno,
strerror(errno))));
return 1;
}
if(read(randfd,(void*)&randval,sizeof(unsigned int)) < 1)
{
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : failed to read /dev/random.")));
close(randfd);
return 1;
}
close(randfd);
srand(randval);
secrets_random_str(key.enckey, MAXSCALE_KEYLEN); secrets_random_str(key.enckey, MAXSCALE_KEYLEN);
secrets_random_str(key.initvector, MAXSCALE_IV_LEN); secrets_random_str(key.initvector, MAXSCALE_IV_LEN);