Replace all random functions with isc_random, isc_random_buf and isc_random_uniform API.
The three functions has been modeled after the arc4random family of functions, and they will always return random bytes. The isc_random family of functions internally use these CSPRNG (if available): 1. getrandom() libc call (might be available on Linux and Solaris) 2. SYS_getrandom syscall (might be available on Linux, detected at runtime) 3. arc4random(), arc4random_buf() and arc4random_uniform() (available on BSDs and Mac OS X) 4. crypto library function: 4a. RAND_bytes in case OpenSSL 4b. pkcs_C_GenerateRandom() in case PKCS#11 library
This commit is contained in:
committed by
Witold Kręcicki
parent
74dd289a1c
commit
3a4f820d62
@@ -17,11 +17,11 @@
|
||||
|
||||
#include <isc/app.h>
|
||||
#include <isc/base64.h>
|
||||
#include <isc/entropy.h>
|
||||
#include <isc/hash.h>
|
||||
#include <isc/log.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/task.h>
|
||||
@@ -136,7 +136,6 @@ sendquery(isc_task_t *task, isc_event_t *event) {
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
char *keyname;
|
||||
char *randomfile;
|
||||
isc_taskmgr_t *taskmgr;
|
||||
isc_timermgr_t *timermgr;
|
||||
isc_socketmgr_t *socketmgr;
|
||||
@@ -146,7 +145,6 @@ main(int argc, char **argv) {
|
||||
dns_dispatchmgr_t *dispatchmgr;
|
||||
dns_dispatch_t *dispatchv4;
|
||||
dns_view_t *view;
|
||||
isc_entropy_t *ectx;
|
||||
dns_tkeyctx_t *tctx;
|
||||
dst_key_t *dstkey;
|
||||
isc_log_t *log;
|
||||
@@ -157,21 +155,14 @@ main(int argc, char **argv) {
|
||||
|
||||
RUNCHECK(isc_app_start());
|
||||
|
||||
randomfile = NULL;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "I:no key to delete\n");
|
||||
exit(-1);
|
||||
}
|
||||
if (strcmp(argv[1], "-r") == 0) {
|
||||
if (argc < 4) {
|
||||
fprintf(stderr, "I:no DH key provided\n");
|
||||
exit(-1);
|
||||
}
|
||||
randomfile = argv[2];
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
POST(argc);
|
||||
fprintf(stderr, "I:The -r options has been deprecated\n");
|
||||
exit(-1);
|
||||
}
|
||||
keyname = argv[1];
|
||||
|
||||
@@ -180,20 +171,11 @@ main(int argc, char **argv) {
|
||||
mctx = NULL;
|
||||
RUNCHECK(isc_mem_create(0, 0, &mctx));
|
||||
|
||||
ectx = NULL;
|
||||
RUNCHECK(isc_entropy_create(mctx, &ectx));
|
||||
if (randomfile == NULL) {
|
||||
isc_entropy_usehook(ectx, ISC_TRUE);
|
||||
}
|
||||
if (randomfile != NULL) {
|
||||
RUNCHECK(isc_entropy_createfilesource(ectx, randomfile));
|
||||
}
|
||||
|
||||
log = NULL;
|
||||
logconfig = NULL;
|
||||
RUNCHECK(isc_log_create(mctx, &log, &logconfig));
|
||||
|
||||
RUNCHECK(dst_lib_init(mctx, ectx, NULL, ISC_ENTROPY_GOODONLY));
|
||||
RUNCHECK(dst_lib_init(mctx, NULL));
|
||||
|
||||
taskmgr = NULL;
|
||||
RUNCHECK(isc_taskmgr_create(mctx, 1, 0, &taskmgr));
|
||||
@@ -204,7 +186,7 @@ main(int argc, char **argv) {
|
||||
socketmgr = NULL;
|
||||
RUNCHECK(isc_socketmgr_create(mctx, &socketmgr));
|
||||
dispatchmgr = NULL;
|
||||
RUNCHECK(dns_dispatchmgr_create(mctx, NULL, &dispatchmgr));
|
||||
RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr));
|
||||
isc_sockaddr_any(&bind_any);
|
||||
attrs = DNS_DISPATCHATTR_UDP |
|
||||
DNS_DISPATCHATTR_MAKEQUERY |
|
||||
@@ -225,7 +207,7 @@ main(int argc, char **argv) {
|
||||
ring = NULL;
|
||||
RUNCHECK(dns_tsigkeyring_create(mctx, &ring));
|
||||
tctx = NULL;
|
||||
RUNCHECK(dns_tkeyctx_create(mctx, ectx, &tctx));
|
||||
RUNCHECK(dns_tkeyctx_create(mctx, &tctx));
|
||||
|
||||
view = NULL;
|
||||
RUNCHECK(dns_view_create(mctx, 0, "_test", &view));
|
||||
@@ -277,7 +259,6 @@ main(int argc, char **argv) {
|
||||
isc_log_destroy(&log);
|
||||
|
||||
dst_lib_destroy();
|
||||
isc_entropy_detach(&ectx);
|
||||
|
||||
isc_mem_destroy(&mctx);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user