aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/random/random_plugin.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2012-05-02 11:12:31 +0200
committerMartin Willi <martin@revosec.ch>2012-05-02 11:12:31 +0200
commitb24be29646442210f43b100d2282b6c0a0e52e09 (patch)
tree5cdc2dbda7cb5881c2c2fa7a90ab6729112fd4c4 /src/libstrongswan/plugins/random/random_plugin.c
parentf99d8b10c9f5b5024b4b1e5f5d1e56e2519cdadc (diff)
parent8c35f5d460baf0ee7f25669620ee234a0176681f (diff)
downloadstrongswan-b24be29646442210f43b100d2282b6c0a0e52e09.tar.bz2
strongswan-b24be29646442210f43b100d2282b6c0a0e52e09.tar.xz
Merge branch 'ikev1'
Conflicts: configure.in man/ipsec.conf.5.in src/libcharon/encoding/generator.c src/libcharon/encoding/payloads/notify_payload.c src/libcharon/encoding/payloads/notify_payload.h src/libcharon/encoding/payloads/payload.c src/libcharon/network/receiver.c src/libcharon/sa/authenticator.c src/libcharon/sa/authenticator.h src/libcharon/sa/ikev2/tasks/ike_init.c src/libcharon/sa/task_manager.c src/libstrongswan/credentials/auth_cfg.c
Diffstat (limited to 'src/libstrongswan/plugins/random/random_plugin.c')
-rw-r--r--src/libstrongswan/plugins/random/random_plugin.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/libstrongswan/plugins/random/random_plugin.c b/src/libstrongswan/plugins/random/random_plugin.c
index 7f81e2622..418eeae28 100644
--- a/src/libstrongswan/plugins/random/random_plugin.c
+++ b/src/libstrongswan/plugins/random/random_plugin.c
@@ -15,9 +15,24 @@
#include "random_plugin.h"
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
#include <library.h>
+#include <debug.h>
#include "random_rng.h"
+#ifndef DEV_RANDOM
+# define DEV_RANDOM "/dev/random"
+#endif
+
+#ifndef DEV_URANDOM
+# define DEV_URANDOM "/dev/urandom"
+#endif
+
typedef struct private_random_plugin_t private_random_plugin_t;
/**
@@ -31,6 +46,41 @@ struct private_random_plugin_t {
random_plugin_t public;
};
+/** /dev/random file descriptor */
+static int dev_random = -1;
+/** /dev/urandom file descriptor */
+static int dev_urandom = -1;
+
+/**
+ * See header.
+ */
+int random_plugin_get_dev_random()
+{
+ return dev_random;
+}
+
+/**
+ * See header.
+ */
+int random_plugin_get_dev_urandom()
+{
+ return dev_urandom;
+}
+
+/**
+ * Open a random device file
+ */
+static bool open_dev(char *file, int *fd)
+{
+ *fd = open(file, O_RDONLY);
+ if (*fd == -1)
+ {
+ DBG1(DBG_LIB, "opening \"%s\" failed: %s", file, strerror(errno));
+ return FALSE;
+ }
+ return TRUE;
+}
+
METHOD(plugin_t, get_name, char*,
private_random_plugin_t *this)
{
@@ -52,6 +102,14 @@ METHOD(plugin_t, get_features, int,
METHOD(plugin_t, destroy, void,
private_random_plugin_t *this)
{
+ if (dev_random != -1)
+ {
+ close(dev_random);
+ }
+ if (dev_urandom != -1)
+ {
+ close(dev_urandom);
+ }
free(this);
}
@@ -72,6 +130,13 @@ plugin_t *random_plugin_create()
},
);
+ if (!open_dev(DEV_URANDOM, &dev_urandom) ||
+ !open_dev(DEV_RANDOM, &dev_random))
+ {
+ destroy(this);
+ return NULL;
+ }
+
return &this->public.plugin;
}