2016-05-17 18:18:30 +00:00
|
|
|
/*
|
2018-11-20 13:13:00 +00:00
|
|
|
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
1999-10-26 01:59:11 +00:00
|
|
|
*
|
2018-12-06 12:00:26 +00:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 18:18:30 +00:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1999-10-26 01:59:11 +00:00
|
|
|
*/
|
|
|
|
|
1999-11-08 13:58:08 +00:00
|
|
|
#include "apps.h"
|
1999-10-26 01:59:11 +00:00
|
|
|
#include <openssl/bio.h>
|
2017-07-17 01:05:13 +00:00
|
|
|
#include <openssl/err.h>
|
1999-10-26 01:59:11 +00:00
|
|
|
#include <openssl/rand.h>
|
2017-07-05 14:58:48 +00:00
|
|
|
#include <openssl/conf.h>
|
1999-10-26 01:59:11 +00:00
|
|
|
|
2017-07-17 06:52:26 +00:00
|
|
|
static char *save_rand_file;
|
1999-10-26 01:59:11 +00:00
|
|
|
|
2017-07-05 14:58:48 +00:00
|
|
|
void app_RAND_load_conf(CONF *c, const char *section)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-07-05 14:58:48 +00:00
|
|
|
const char *randfile = NCONF_get_string(c, section, "RANDFILE");
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2017-07-05 14:58:48 +00:00
|
|
|
if (randfile == NULL) {
|
|
|
|
ERR_clear_error();
|
|
|
|
return;
|
2017-06-12 17:24:02 +00:00
|
|
|
}
|
2017-07-05 14:58:48 +00:00
|
|
|
if (RAND_load_file(randfile, -1) < 0) {
|
|
|
|
BIO_printf(bio_err, "Can't load %s into RNG\n", randfile);
|
|
|
|
ERR_print_errors(bio_err);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2017-07-05 14:58:48 +00:00
|
|
|
if (save_rand_file == NULL)
|
2017-07-17 06:52:26 +00:00
|
|
|
save_rand_file = OPENSSL_strdup(randfile);
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1999-10-26 01:59:11 +00:00
|
|
|
|
2017-07-05 14:58:48 +00:00
|
|
|
static int loadfiles(char *name)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-07-17 01:05:13 +00:00
|
|
|
char *p;
|
2017-07-05 14:58:48 +00:00
|
|
|
int last, ret = 1;
|
1999-10-26 01:59:11 +00:00
|
|
|
|
2017-07-05 14:58:48 +00:00
|
|
|
for ( ; ; ) {
|
2015-01-22 03:40:55 +00:00
|
|
|
last = 0;
|
2017-07-05 14:58:48 +00:00
|
|
|
for (p = name; *p != '\0' && *p != LIST_SEPARATOR_CHAR; p++)
|
|
|
|
continue;
|
2015-01-22 03:40:55 +00:00
|
|
|
if (*p == '\0')
|
|
|
|
last = 1;
|
|
|
|
*p = '\0';
|
2017-07-05 14:58:48 +00:00
|
|
|
if (RAND_load_file(name, -1) < 0) {
|
|
|
|
BIO_printf(bio_err, "Can't load %s into RNG\n", name);
|
|
|
|
ERR_print_errors(bio_err);
|
|
|
|
ret = 0;
|
|
|
|
}
|
2015-01-22 03:40:55 +00:00
|
|
|
if (last)
|
|
|
|
break;
|
2017-07-05 14:58:48 +00:00
|
|
|
name = p + 1;
|
|
|
|
if (*name == '\0')
|
|
|
|
break;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2017-07-05 14:58:48 +00:00
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1999-10-26 01:59:11 +00:00
|
|
|
|
2017-07-05 14:58:48 +00:00
|
|
|
void app_RAND_write(void)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-07-05 14:58:48 +00:00
|
|
|
if (save_rand_file == NULL)
|
|
|
|
return;
|
|
|
|
if (RAND_write_file(save_rand_file) == -1) {
|
|
|
|
BIO_printf(bio_err, "Cannot write random bytes:\n");
|
|
|
|
ERR_print_errors(bio_err);
|
2017-06-26 16:02:57 +00:00
|
|
|
}
|
2017-07-17 06:52:26 +00:00
|
|
|
OPENSSL_free(save_rand_file);
|
|
|
|
save_rand_file = NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
1999-10-26 01:59:11 +00:00
|
|
|
|
2017-07-05 14:58:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* See comments in opt_verify for explanation of this.
|
|
|
|
*/
|
|
|
|
enum r_range { OPT_R_ENUM };
|
|
|
|
|
|
|
|
int opt_rand(int opt)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2017-07-05 14:58:48 +00:00
|
|
|
switch ((enum r_range)opt) {
|
|
|
|
case OPT_R__FIRST:
|
|
|
|
case OPT_R__LAST:
|
|
|
|
break;
|
|
|
|
case OPT_R_RAND:
|
|
|
|
return loadfiles(opt_arg());
|
|
|
|
break;
|
|
|
|
case OPT_R_WRITERAND:
|
2017-07-17 06:52:26 +00:00
|
|
|
OPENSSL_free(save_rand_file);
|
|
|
|
save_rand_file = OPENSSL_strdup(opt_arg());
|
2017-07-05 14:58:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|