jirka-h / haveged

Entropy daemon ![Continuous Integration](https://github.com/jirka-h/haveged/workflows/Continuous%20Integration/badge.svg)
GNU General Public License v3.0
273 stars 34 forks source link

haveged cannot be run as an application if also running as a daemon #66

Closed guenther-brunthaler closed 3 years ago

guenther-brunthaler commented 3 years ago

It is often useful to run use haveged directly for creating secure cryptographic keys or passwords, no matter whether the program is also running as a daemon at the same time.

For instance, I frequently use

$ /usr/sbin/haveged -f - -n 32 2> /dev/null | base64 | tr -d =
7/W6YAML1rUHj1J44/vl0n1JcYQ5ijuZ8cQ27r2uHv4

in order to create a password equivalent to a key strength of 256 bit.

Unfortunately, this fails if a daemon (or just another instance of the program as a regular user application) is running at the same time.

The enclosed patch fixes the problem.

Without this patch, the application tries to create the command 
socket, even when running as a regular user application for 
harvesting entropy independent of any daemon.

This will fail if another instance of haveged is already running, 
no matter whether that other instance is a daemon or not.

This patch will make the application ignore the socket when run 
as a regular user application, thus avoiding the problem.

(Patch created 2021-11-03 by Guenther Brunthaler.)

Index: haveged-1.9.14/src/haveged.c
===================================================================
--- haveged-1.9.14.orig/src/haveged.c
+++ haveged-1.9.14/src/haveged.c
@@ -429,7 +429,7 @@ int main(int argc, char **argv)
       close(socket_fd);
       return ret;
       }
-   else {
+   else if (!(params->setup & RUN_AS_APP)){
       socket_fd = cmd_listen(params);
       if (socket_fd >= 0)
          fprintf(stderr, "%s: command socket is listening at fd %d\n", params->daemon, socket_fd);
jirka-h commented 3 years ago

Vielen Dank for the patch!

I have merged it here: https://github.com/jirka-h/haveged/commit/a4b69d65a8dfc5a9f52ff8505c7f58dcf8b9234f