commit rng-tools for openSUSE:Factory
Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package rng-tools for openSUSE:Factory checked in at 2024-07-01 11:20:41 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rng-tools (Old) and /work/SRC/openSUSE:Factory/.rng-tools.new.18349 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "rng-tools" Mon Jul 1 11:20:41 2024 rev:52 rq:1184075 version:6.17 Changes: -------- --- /work/SRC/openSUSE:Factory/rng-tools/rng-tools.changes 2023-04-16 16:08:01.621146128 +0200 +++ /work/SRC/openSUSE:Factory/.rng-tools.new.18349/rng-tools.changes 2024-07-01 11:21:09.684789610 +0200 @@ -1,0 +2,14 @@ +Sun Jun 30 07:56:27 UTC 2024 - Dirk Müller <dmueller@suse.com> + +- update to 6.17: + * mix data fed to the kernel byte-wise from multiple sources + * added option to attempt more persistent use of slow entropy + sources + * fix some missing m4 quotes + * improved debug output to show FIPS failures more clearly + * added a named pipe entropy source + * adjusted linux poolsize + * fixed some pkcs11 error messages + * fixed ignorefail and random_step options + +------------------------------------------------------------------- Old: ---- v6.16.tar.gz New: ---- v6.17.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rng-tools.spec ++++++ --- /var/tmp/diff_new_pack.0hu7Uw/_old 2024-07-01 11:21:10.320812779 +0200 +++ /var/tmp/diff_new_pack.0hu7Uw/_new 2024-07-01 11:21:10.320812779 +0200 @@ -1,7 +1,7 @@ # # spec file for package rng-tools # -# Copyright (c) 2023 SUSE LLC +# Copyright (c) 2024 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,7 +18,7 @@ %{!?_udevrulesdir: %global _udevrulesdir %(pkg-config --variable=udevdir udev)/rules.d } Name: rng-tools -Version: 6.16 +Version: 6.17 Release: 0 Summary: Support daemon for hardware random device License: GPL-3.0-or-later ++++++ v6.16.tar.gz -> v6.17.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/Makefile.am new/rng-tools-6.17/Makefile.am --- old/rng-tools-6.16/Makefile.am 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/Makefile.am 2024-05-23 20:16:00.000000000 +0200 @@ -9,7 +9,8 @@ noinst_LIBRARIES = librngd.a rngd_SOURCES = rngd.h rngd.c rngd_entsource.h rngd_entsource.c \ - rngd_linux.h rngd_linux.c util.c ossl_helpers.c + rngd_linux.h rngd_linux.c util.c ossl_helpers.c \ + rngd_namedpipe.c if NISTBEACON rngd_SOURCES += rngd_nistbeacon.c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/configure.ac new/rng-tools-6.17/configure.ac --- old/rng-tools-6.16/configure.ac 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/configure.ac 2024-05-23 20:16:00.000000000 +0200 @@ -17,7 +17,7 @@ dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA -AC_INIT(rng-tools, 6.16, [Neil Horman <nhorman@tuxdriver.com>]) +AC_INIT(rng-tools, 6.17, [Neil Horman <nhorman@tuxdriver.com>]) AC_PREREQ(2.52) AC_CONFIG_SRCDIR([rngd.c]) AC_CANONICAL_HOST @@ -196,7 +196,7 @@ AC_LINK_IFELSE( [AC_LANG_PROGRAM( [#include <argp.h>], - [int argc=1; char *argv[]={"test"}; argp_parse(0,argc,argv,0,0,0); return 0;] + [[int argc=1; char *argv[]={"test"}; argp_parse(0,argc,argv,0,0,0); return 0;]] )], [need_libargp=no], [need_libargp=yes diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/rngd.8.in new/rng-tools-6.17/rngd.8.in --- old/rng-tools-6.16/rngd.8.in 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/rngd.8.in 2024-05-23 20:16:00.000000000 +0200 @@ -22,6 +22,7 @@ [\fB\-t\fR, \fB\-\-test\fR] [\fB\-W\fR, \fB\-\-fill-watermark=\fInnn\fR] [\fB\-R\fR, \fB\-\-force-reseed=\fInnn\fR] +[\fB\-u\fR, \fB\-\-use-slow-sources\fR] [\fB\-D\fR, \fB\-\-drop-privileges=\fIuser:group\fR] [\fB\-q\fR, \fB\-\-quiet\fR] [\fB\-?\fR, \fB\-\-help\fR] @@ -108,7 +109,7 @@ Setting this too high will cause \fIrngd\fR to dominate the contents of the entropy pool. Low values will hurt system performance during entropy starves. Do not set \fIfill-watermark\fR above the size of the -entropy pool (usually 4096 bits). A value of 0 to this option will cause no +entropy pool (usually 256 bits). A value of 0 to this option will cause no watermark to be set. .TP \fB\-R\fI n\fR, \fB\-\-force-reseed=\fInnn\fR @@ -117,6 +118,11 @@ --force-reseed defines the number of seconds between which fresh entropy is added to the kernel entropy pool. Defaults to 5 minutes. .TP +\fB\-u\fR, \fB\-\-use-slow-sources\fR +The entropy sources nist, jitter and pkcs11 are considered to be slow in providing entropy. +By default their data is only used after all other sources failed to provide valid entropy +a 100 times over. With this option rngd always tries to gather entropy from these sources too. +.TP \fB\-D\fR, \fB\-\-drop-privileges=\fIuser:group\fR Drop privileges to a user and a group specified after initialization. A user and a group can be specified as a name or as a numerical id and must be separated @@ -134,7 +140,7 @@ .SH ENTROPY SOURCES .P - Rngd is made up of multiple entropy sources, the data from which is +Rngd is made up of multiple entropy sources, the data from which is aggregated and fed into the kernels entropy pool. Note that not all entropy sources are available on all systems, and if an entropy source is enabled for a system on which it is not appropriate (or possible) to use, it may fail @@ -235,7 +241,10 @@ .B PKCS11 (pkcs11) Entropy gathered via the opensc openssl engine, which can extract entropy from -various smart card readers +various smart card readers. Install a package for your distribution containing +pkcs11 endpoint library to gather smartcard entropy. This is \fBopensc\fR for +Fedora, \fBopensc-pkcs11\fR for Debian/Ubuntu or another package containing +opensc-pkcs11.so. .TP Options \fBengine_path - \fR Set the patch for the pkcs11 engine DSO to load @@ -263,6 +272,20 @@ \fBsample_max - \fR The maximum sample rate of the radio +.TP +.B +Named pipe (namedpipe) +Reads entropy from a named pipe (aka FIFO). Another program, for example a +driver reading and preparing data from an external hardware RNG, is expected +to feed entropy into this named pipe. Should the named pipe be closed, +rngd will try to reopen it. +.TP +Options +\fBpath - \fR Path of the named pipe. Required. + +\fBtimeout - \fR Maximum time in seconds rngd waits until a full FIPS test buffer +of entropy can be read. Defaults to 5. + .SH AUTHORS Philipp Rumpf .br diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/rngd.c new/rng-tools-6.17/rngd.c --- old/rng-tools-6.16/rngd.c 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/rngd.c 2024-05-23 20:16:00.000000000 +0200 @@ -120,7 +120,7 @@ "Number of bytes written to random-device at a time (default: 64)" }, { "fill-watermark", 'W', "n", 0, - "Do not stop feeding entropy to random-device until at least n bits of entropy are available in the pool (default: 3/4 of poolsize), 0 <= n <= 4096" }, + "Do not stop feeding entropy to random-device until at least n bits of entropy are available in the pool (default: 3/4 of poolsize), 0 <= n <= 256" }, { "quiet", 'q', 0, 0, "Suppress all messages" }, @@ -130,6 +130,8 @@ { "force-reseed", 'R', "n", 0, "Time in seconds to force adding entropy to the random device" }, + { "use-slow-sources", 'u', 0, 0, "Always gather entropy from sources considered as \"slow\" too" }, + { "drop-privileges", 'D', "user:group", 0, "Drop privileges to a user and group specified" }, { 0 }, @@ -146,6 +148,7 @@ .ignorefail = false, .entropy_count = 8, .force_reseed = 60 * 5, + .use_slow_sources = false, .drop_privs = false, }; struct arguments *arguments = &default_arguments; @@ -167,6 +170,7 @@ ENT_PKCS11, ENT_RTLSDR, ENT_QRYPT, + ENT_NAMEDPIPE, ENT_MAX } entropy_indexes __attribute__((used)); @@ -317,6 +321,22 @@ } }; +static struct rng_option namedpipe_options[] = { + [NAMEDPIPE_OPT_PATH] = { + .key = "path", + .type = VAL_STRING, + .str_val = "", + }, + [NAMEDPIPE_OPT_TIMEOUT] { + .key = "timeout", + .type = VAL_INT, + .int_val = 5, /* 5 seconds */ + }, + { + .key = NULL, + } +}; + static struct rng entropy_sources[ENT_MAX] = { /* Note, the special char dev must be the first entry */ { @@ -455,6 +475,15 @@ #endif .disabled = true, .rng_options = qrypt_options, + }, + { + .rng_name = "Named pipe entropy input", + .rng_sname = "namedpipe", + .rng_fd = -1, + .flags = { 0 }, + .xread = xread_namedpipe, + .init = init_namedpipe_entropy_source, + .rng_options = namedpipe_options, } }; @@ -623,10 +652,12 @@ case 's': if (sscanf(arg, "%i", &arguments->random_step) == 0) argp_usage(state); + if (arguments->random_step > FIPS_RNG_BUFFER_SIZE || arguments->random_step < 0) + arguments->random_step = FIPS_RNG_BUFFER_SIZE; break; case 'W': { int n; - if ((sscanf(arg, "%i", &n) == 0) || (n < 0) || (n > 4096)) + if ((sscanf(arg, "%i", &n) == 0) || (n < 0) || (n > 256)) argp_usage(state); else arguments->fill_watermark = n; @@ -655,6 +686,10 @@ arguments->force_reseed = R; break; } + case 'u': { + arguments->use_slow_sources = true; + break; + } case 'D': { struct passwd *usrent; struct group *grpent; @@ -724,45 +759,77 @@ static struct argp argp = { options, parse_opt, NULL, doc }; -static int update_kernel_random(struct rng *rng, int random_step, - unsigned char *buf, fips_ctx_t *fipsctx_in) +static int update_kernel_random(int random_step) { - unsigned char *p; - int fips; + unsigned char buf[FIPS_RNG_BUFFER_SIZE]; /* random_step was checked to be <= FIPS_RNG_BUFFER_SIZE */ int rc; + struct rng *iter; - fips = fips_run_rng_test(fipsctx_in, buf); - if (fips && !arguments->ignorefail) - return 1; + message(LOG_DAEMON|LOG_DEBUG, "entropy successfully gathered, preparing it for the kernel\n"); - for (p = buf; p + random_step <= &buf[FIPS_RNG_BUFFER_SIZE]; - p += random_step) { + while(true) { if (!server_running) return 0; if (do_reseed) { do_reseed = false; alarm(arguments->force_reseed); } - rc = random_add_entropy(p, random_step); - if (rc == -1) - return 1; + + /* mix the sources on byte-level: ensure we always feed data from all available sources to the kernel + * helps to mitigate problems should a source not be as random as expected */ + int p = 0; + while(p < random_step) { + int progress = p; + for (int i = 0; i < ENT_MAX; ++i) { + iter = &entropy_sources[i]; + if (!iter->entropy_buf.valid) + continue; + + buf[p++] = iter->entropy_buf.entropy[iter->entropy_buf.used_pos++]; + + if (iter->entropy_buf.used_pos == FIPS_RNG_BUFFER_SIZE) + iter->entropy_buf.valid = false; + + if(p >= random_step) + break; + } + + /* abort data preparation when no data was added to the buffer in one loop = no valid sources left + * this wastes a few bytes when FIPS_RNG_BUFFER_SIZE is not a multiple of random_step + * but it makes the logic easier to implement and read */ + if (p == progress) + return 0; + } + + rc = random_add_entropy(buf, random_step); + if (rc == -1) { + /* feeding the entropy to the kernel failed, not much we can do, wait and try again later */ + random_sleep(); + continue; + } message(LOG_DAEMON|LOG_DEBUG, "Added %d/%d bits entropy\n", rc, kent_pool_size); + if (rc >= kent_pool_size-64) { message(LOG_DAEMON|LOG_DEBUG, "Pool full at %d, sleeping!\n", kent_pool_size); random_sleep(); } } - - return 0; } -static int random_test_sink(struct rng *rng, int random_step, - unsigned char *buf, fips_ctx_t *fipsctx_in) +static int random_test_sink(int random_step) { + struct rng *iter; + if (!ent_gathered) alarm(1); - ent_gathered += FIPS_RNG_BUFFER_SIZE; + + for (int i = 0; i < ENT_MAX; ++i) { + iter = &entropy_sources[i]; + if (iter->entropy_buf.valid) + ent_gathered += FIPS_RNG_BUFFER_SIZE; + } + return 0; } @@ -873,7 +940,7 @@ static void do_loop(int random_step) { - unsigned char buf[FIPS_RNG_BUFFER_SIZE]; + int buffers_filled; int no_work; bool work_done; int sources_left; @@ -882,8 +949,7 @@ struct rng *iter; bool try_slow_sources = false; - int (*random_add_fn)(struct rng *rng, int random_step, - unsigned char *buf, fips_ctx_t *fipsctx_in); + int (*random_add_fn)(int random_step); random_add_fn = arguments->test ? random_test_sink : update_kernel_random; @@ -891,6 +957,7 @@ for (no_work = 0; no_work < 100; no_work = (work_done ? 0 : no_work+1)) { work_done = false; + buffers_filled = 0; /* * Exclude slow sources when faster sources are working well @@ -901,17 +968,22 @@ * entropy from the fast sources, then iff that fails, start including the slower * sources as well. Once we get some entropy, return to only using fast sources */ - if (no_work) + if (no_work) { + message(LOG_DAEMON|LOG_DEBUG, "Couldn't get entropy in last loop, enabling slow sources\n"); try_slow_sources = true; - else + } else { try_slow_sources = false; + } - for (i = 0; i < ENT_MAX; ++i) - { - int rc; + for (i = 0; i < ENT_MAX; ++i) { /*message(LOG_CONS|LOG_INFO, "I is %d\n", i);*/ iter = &entropy_sources[i]; - if (!try_slow_sources && iter->flags.slow_source) + + /* empty the buffer for each source before gathering new entropy, even when some bytes are left */ + iter->entropy_buf.valid = false; + iter->entropy_buf.used_pos = 0; + + if (!try_slow_sources && !arguments->use_slow_sources && iter->flags.slow_source) continue; retry_same: @@ -923,16 +995,26 @@ message(LOG_DAEMON|LOG_DEBUG, "Reading entropy from %s\n", iter->rng_name); - retval = iter->xread(buf, sizeof buf, iter); + retval = iter->xread(iter->entropy_buf.entropy, sizeof(iter->entropy_buf.entropy), iter); if (retval) continue; /* failed, no work */ work_done = true; - rc = random_add_fn(iter, random_step, buf, iter->fipsctx); + if (arguments->ignorefail || arguments->test) { + iter->entropy_buf.valid = true; + } else { + message(LOG_DAEMON|LOG_DEBUG, "Running FIPS test on entropy\n"); + int fipsret = fips_run_rng_test(iter->fipsctx, iter->entropy_buf.entropy); + if (fipsret) + message(LOG_DAEMON|LOG_DEBUG, "FIPS test failed (return code %d)\n", fipsret); + else + iter->entropy_buf.valid = true; + } - if (rc == 0) { + if (iter->entropy_buf.valid) { iter->success++; + buffers_filled++; if (iter->success >= RNG_OK_CREDIT) { if (iter->failures) iter->failures--; @@ -945,18 +1027,24 @@ iter->failures++; if (iter->failures <= MAX_RNG_FAILURES/4) { /* FIPS tests have false positives */ + message(LOG_DAEMON|LOG_DEBUG, "FIPS failure from %s, retrying\n", iter->rng_name); goto retry_same; } if (iter->failures >= MAX_RNG_FAILURES && !ignorefail) { message(LOG_DAEMON|LOG_ERR, - "too many FIPS failures, disabling entropy source\n"); + "too many FIPS failures, disabling entropy source %s\n", iter->rng_name); if (iter->close) iter->close(iter); iter->disabled = true; } } + if (buffers_filled) { + /* we got some entropy, now mix it and feed it to the kernel */ + random_add_fn(random_step); + } + /* Don't hog the CPU if no sources have returned data */ if (!work_done) sched_yield(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/rngd.h new/rng-tools-6.17/rngd.h --- old/rng-tools-6.16/rngd.h 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/rngd.h 2024-05-23 20:16:00.000000000 +0200 @@ -59,6 +59,7 @@ bool enable_tpm; int entropy_count; int force_reseed; + bool use_slow_sources; bool drop_privs; uid_t drop_uid; @@ -134,6 +135,15 @@ QRYPT_OPT_MAX, }; +/* + * NAMEDPIPE options + */ +enum { + NAMEDPIPE_OPT_PATH = 0, + NAMEDPIPE_OPT_TIMEOUT = 1, + NAMEDPIPE_OPT_MAX, +}; + enum option_val_type { VAL_INT = 0, VAL_STRING = 1, @@ -166,6 +176,12 @@ /* Intermittent sources - may sometimes fail to produce entropy */ unsigned int intermittent_source : 1; } flags; + struct entropy_buf { + /* structure to store entropy from a source before mixing it with other sources */ + unsigned char entropy[FIPS_RNG_BUFFER_SIZE]; + bool valid; + int used_pos; + } entropy_buf; int (*xread) (void *buf, size_t size, struct rng *ent_src); int (*init) (struct rng *ent_src); void (*close) (struct rng *end_src); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/rngd_entsource.h new/rng-tools-6.17/rngd_entsource.h --- old/rng-tools-6.16/rngd_entsource.h 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/rngd_entsource.h 2024-05-23 20:16:00.000000000 +0200 @@ -102,4 +102,7 @@ extern int xread_tpm(void *buf, size_t size, struct rng *ent_src); +extern int init_namedpipe_entropy_source(struct rng *ent_src); +extern int xread_namedpipe(void *buf, size_t size, struct rng *ent_src); + #endif /* RNGD_ENTSOURCE__H */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/rngd_linux.c new/rng-tools-6.17/rngd_linux.c --- old/rng-tools-6.16/rngd_linux.c 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/rngd_linux.c 2024-05-23 20:16:00.000000000 +0200 @@ -60,7 +60,7 @@ * randomdev is the path to the random device */ -#define DEFAULT_WATERMARK_GUESS 4096 +#define DEFAULT_WATERMARK_GUESS 256 void init_kernel_rng(const char* randomdev) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/rngd_namedpipe.c new/rng-tools-6.17/rngd_namedpipe.c --- old/rng-tools-6.16/rngd_namedpipe.c 1970-01-01 01:00:00.000000000 +0100 +++ new/rng-tools-6.17/rngd_namedpipe.c 2024-05-23 20:16:00.000000000 +0200 @@ -0,0 +1,148 @@ +/* + * rngd_namedpipe.c -- Named pipe entropy input + * + * Copyright (C) 2023 Gerd v. Egidy + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA + */ + +#define _GNU_SOURCE + +#ifndef HAVE_CONFIG_H +#error Invalid or missing autoconf build environment +#endif + +#include "rng-tools-config.h" + +#include <unistd.h> +#include <stdint.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <syslog.h> +#include <string.h> +#include <stddef.h> +#include <sys/select.h> +#include <sys/time.h> + +#include "rngd.h" +#include "fips.h" +#include "exits.h" +#include "rngd_entsource.h" + + +/* Read data from named pipes, with timeout & reopening */ +int xread_namedpipe(void *buf, size_t size, struct rng *ent_src) +{ + size_t off = 0; + ssize_t r; + int sr; + + fd_set readfds; + int maxfds; + + // we init the timeout structure once, select will reduce it when it was waiting + struct timeval tval; + tval.tv_sec = ent_src->rng_options[NAMEDPIPE_OPT_TIMEOUT].int_val; + tval.tv_usec = 0; + + while (size > 0) { + // prepare fd set for select + FD_ZERO(&readfds); + if (ent_src->rng_fd >= FD_SETSIZE) { + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "file descriptor exceeds FD_SETSIZE limit\n"); + return -1; + } + FD_SET(ent_src->rng_fd, &readfds); + maxfds = ent_src->rng_fd + 1; + + sr = select (maxfds, &readfds, NULL, NULL, &tval); + if (sr == 1) { + // our fd has something to read + r = read(ent_src->rng_fd, buf + off, size); + + if (r > 0) { + // we could read something + off += r; + size -= r; + continue; + } else if (r == 0) { + // EOF: try to re-open the pipe + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "EOF, reopening named pipe\n"); + close(ent_src->rng_fd); + ent_src->rng_fd = open(ent_src->rng_options[NAMEDPIPE_OPT_PATH].str_val, O_RDONLY | O_NOCTTY | O_NONBLOCK); + if (ent_src->rng_fd == -1) { + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "Unable to open named pipe (%i): %s\n", errno, + ent_src->rng_options[NAMEDPIPE_OPT_PATH].str_val); + ent_src->disabled = true; + return -1; + } + continue; + } else { + // read error + if (errno == EINTR || errno == EAGAIN) + continue; + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "read error (%i)\n", errno); + return -1; + } + } else if (sr == 0) { + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "timeout\n"); + return -1; + } else { + // select error + if (errno == EINTR) + continue; + + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "select error %i\n", errno); + return -1; + } + } + return 0; +} + +/* + * init named pipe entropy source: check option and open pipe + */ +int init_namedpipe_entropy_source(struct rng *ent_src) +{ + char buf[16]; + + if (!ent_src->rng_options[NAMEDPIPE_OPT_PATH].str_val || + strlen(ent_src->rng_options[NAMEDPIPE_OPT_PATH].str_val) == 0) + { + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "No named pipe path configured\n"); + return 1; + } + + ent_src->rng_fd = open(ent_src->rng_options[NAMEDPIPE_OPT_PATH].str_val, O_RDONLY | O_NOCTTY | O_NONBLOCK); + if (ent_src->rng_fd == -1) { + message_entsrc(ent_src,LOG_DAEMON|LOG_DEBUG, "Unable to open named pipe (%i): %s\n", errno, + ent_src->rng_options[NAMEDPIPE_OPT_PATH].str_val); + return 1; + } + + /* Try to read some data from the entropy source. */ + if (ent_src->xread(buf, sizeof(buf), ent_src) != 0) + return -1; + + /* the read didn't return an error -> assume its ok to use */ + + /* Bootstrap FIPS tests */ + ent_src->fipsctx = malloc(sizeof(fips_ctx_t)); + return 0; +} + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/rng-tools-6.16/rngd_pkcs11.c new/rng-tools-6.17/rngd_pkcs11.c --- old/rng-tools-6.16/rngd_pkcs11.c 2023-01-10 13:45:31.000000000 +0100 +++ new/rng-tools-6.17/rngd_pkcs11.c 2024-05-23 20:16:00.000000000 +0200 @@ -67,19 +67,25 @@ struct stat sbuf; if (stat(ent_src->rng_options[PKCS11_OPT_ENGINE].str_val, &sbuf) == -1) { - message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING, "PKCS11 Engine %s Error: %s\n", - ent_src->rng_options[PKCS11_OPT_ENGINE].str_val, - strerror(errno)); + if (errno == ENOENT) { + message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING,"No PKCS11 endpoint %s found\n", + ent_src->rng_options[PKCS11_OPT_ENGINE].str_val); + message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING,"Install opensc/opensc-pkcs11/etc" + " if you would like to gather smartcard entropy\n"); + } else + message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING, "PKCS11 Engine %s Error: %s\n", + ent_src->rng_options[PKCS11_OPT_ENGINE].str_val, + strerror(errno)); return 1; } if (!ent_src->rng_options[PKCS11_OPT_CHUNK].int_val) { - message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING, "PKCS11 Engine chunk size cannot be 0\n"); + message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING, "PKCS11 Engine: chunk size cannot be 0\n"); return 1; } if (ent_src->rng_options[PKCS11_OPT_CHUNK].int_val > FIPS_RNG_BUFFER_SIZE) { - message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING, "PKCS11 Engine chunk size cannot be larger than %d\n", + message_entsrc(ent_src,LOG_DAEMON|LOG_WARNING, "PKCS11 Engine: chunk size cannot be larger than %d\n", FIPS_RNG_BUFFER_SIZE); return 1; }
participants (1)
-
Source-Sync