Merge branch 'develop'

master v0.2.0
Damien Goutte-Gattat 8 years ago
commit bdaf058766
  1. 4
      NEWS
  2. 2
      configure.ac
  3. 55
      src/scdrand.c

@ -0,0 +1,4 @@
Changes in scdrand 0.2.0
* Support GnuPG Agent standard socket.
* Decrement loop counter only when adding entropy.

@ -1,6 +1,6 @@
dnl Configure template for the scdrand package
AC_INIT([scdrand], [0.1.0],
AC_INIT([scdrand], [0.2.0],
[dgouttegattat@incenp.org])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])

@ -32,6 +32,7 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <pwd.h>
#include <linux/random.h>
@ -101,14 +102,22 @@ See the COPYING file or <http://www.gnu.org/licenses/gpl.html>.\n\
static char *
get_gpg_agent_socket_name(void)
{
char *agent_info, *socket_name, *colon_index;
char *env_info, *socket_name, *colon_index;
struct passwd *pwd;
if ( ! (agent_info = getenv("GPG_AGENT_INFO")) )
errx(EXIT_FAILURE, "No running GPG Agent found");
socket_name = xstrdup(agent_info);
if ( (colon_index = strchr(socket_name, ':')) )
*colon_index = '\0';
if ( (env_info = getenv("GPG_AGENT_INFO")) ) {
socket_name = xstrdup(env_info);
if ( (colon_index = strchr(socket_name, ':')) )
*colon_index = '\0';
}
else if ( (env_info = getenv("GNUPGHOME")) )
asprintf(&socket_name, "%s/S.gpg-agent", env_info);
else if ( (env_info = getenv("HOME")) )
asprintf(&socket_name, "%s/.gnupg/S.gpg-agent", env_info);
else if ( (pwd = getpwuid(getuid())) )
asprintf(&socket_name, "%s/.gnupg/S.gpg-agent", pwd->pw_dir);
else
errx(EXIT_FAILURE, "Cannot locate GPG Agent socket");
return socket_name;
}
@ -252,20 +261,29 @@ connect_to_scdaemon(void)
return ctx;
}
static int
get_available_entropy(void)
/*
* Wait until the available entropy falls below the specified threshold.
* Available entropy is checked regularly at the specified interval.
*/
static void
wait_for_threshold(unsigned threshold, unsigned interval)
{
int random_fd, entropy;
int entropy, random_fd, loop = 1;
if ( (random_fd = open("/dev/random", O_RDONLY)) == -1 )
err(EXIT_FAILURE, "Cannot open /dev/random");
if ( ioctl(random_fd, RNDGETENTCNT, &entropy) == -1 )
err(EXIT_FAILURE, "Cannot get available entropy");
while ( loop ) {
if ( ioctl(random_fd, RNDGETENTCNT, &entropy) == -1 )
err(EXIT_FAILURE, "Cannot get available entropy");
close(random_fd);
if ( entropy < threshold )
loop = 0;
else
sleep(interval);
}
return entropy;
close(random_fd);
}
/*
@ -424,10 +442,11 @@ main(int argc, char **argv)
ctx = connect_to_scdaemon();
while ( loop == -1 || loop-- > 0 ) {
if ( threshold == 0 || get_available_entropy() < threshold ) {
n = get_challenge(ctx, random_buffer, nbytes);
write(fd, random_buffer, n);
}
if ( threshold != 0 )
wait_for_threshold(threshold, interval);
n = get_challenge(ctx, random_buffer, nbytes);
write(fd, random_buffer, n);
if ( loop != 0 )
sleep(interval);

Loading…
Cancel
Save