pluto and scepclient use the random plugin from libstrongswan

This commit is contained in:
Andreas Steffen
2009-04-30 18:31:48 +00:00
parent 8af25c56af
commit bc2e33ca96
28 changed files with 381 additions and 2075 deletions
+2 -4
View File
@@ -20,6 +20,7 @@ AM_CFLAGS = \
-DIPSEC_PLUGINDIR=\"${plugindir}\" \
-DPLUGINS=\""${pluto_plugins}\"" \
-DSTRONGSWAN_CONF=\"${strongswan_conf}\" \
-DNO_CREDENTIAL_FACTORY \
-DDEBUG -DNO_PLUTO
LIBSTRONGSWANBUILDDIR=$(top_builddir)/src/libstrongswan
@@ -28,7 +29,7 @@ LIBCRYPTOBUILDDIR=$(top_builddir)/src/libcrypto
scepclient_LDADD = \
ca.o crl.o certs.o constants.o defs.o fetch.o id.o keys.o lex.o \
md2.o md5.o mp_defs.o ocsp.o pem.o pgp.o pkcs1.o pkcs7.o rnd.o sha1.o \
md2.o md5.o mp_defs.o ocsp.o pem.o pgp.o pkcs1.o pkcs7.o sha1.o \
smartcard.o x509.o \
$(LIBSTRONGSWANBUILDDIR)/libstrongswan.la \
$(LIBFREESWANBUILDDIR)/libfreeswan.a \
@@ -94,9 +95,6 @@ pkcs1.o : $(PLUTODIR)/pkcs1.c $(PLUTODIR)/pkcs1.h
pkcs7.o : $(PLUTODIR)/pkcs7.c $(PLUTODIR)/pkcs7.h
$(COMPILE) $(INCLUDES) -c -o $@ $<
rnd.o : $(PLUTODIR)/rnd.c $(PLUTODIR)/rnd.h
$(COMPILE) $(INCLUDES) -c -o $@ $<
sha1.o : $(PLUTODIR)/sha1.c $(PLUTODIR)/sha1.h
$(COMPILE) $(INCLUDES) -c -o $@ $<
+14 -49
View File
@@ -30,6 +30,9 @@
#include <freeswan.h>
#include <library.h>
#include <crypto/rngs/rng.h>
#include "../pluto/constants.h"
#include "../pluto/defs.h"
#include "../pluto/mp_defs.h"
@@ -58,45 +61,6 @@
* @return TRUE, if succeeded, FALSE otherwise
*/
static bool
get_true_random_bytes(size_t nbytes, char *buf)
{
size_t ndone;
size_t got;
char *device = DEV_RANDOM;
int dev = open(DEV_RANDOM, 0);
if (dev < 0)
{
fprintf(stderr, "could not open random device %s", device);
return FALSE;
}
DBG(DBG_CONTROL,
DBG_log("getting %d bytes from %s...", (int) nbytes, device)
)
ndone = 0;
while (ndone < nbytes)
{
got = read(dev, buf + ndone, nbytes - ndone);
if (got < 0)
{
fprintf(stderr, "read error on %s", device);
return FALSE;
}
if (got == 0)
{
fprintf(stderr, "eof on %s", device);
return FALSE;
}
ndone += got;
}
close(dev);
return TRUE;
}
/**
* @brief initialize an mpz_t to a random number, specified bit count
*
@@ -110,17 +74,20 @@ get_true_random_bytes(size_t nbytes, char *buf)
* @param[in] nbits length of var in bits (known to be a multiple of BITS_PER_BYTE)
* @return TRUE on success, FALSE otherwise
*/
static bool
init_random(mpz_t var, int nbits)
static bool init_random(mpz_t var, int nbits)
{
size_t nbytes = (size_t)(nbits/BITS_PER_BYTE);
char random_buf[RSA_MAX_OCTETS/2];
rng_t *rng = lib->crypto->create_rng(lib->crypto, RNG_TRUE);
assert(nbytes <= sizeof(random_buf));
if (!get_true_random_bytes(nbytes, random_buf))
if (!rng)
{
return FALSE;
}
assert(nbytes <= sizeof(random_buf));
rng->get_bytes(rng, nbytes, random_buf);
rng->destroy(rng);
random_buf[0] |= 01 << (BITS_PER_BYTE-1); /* force high bit on */
random_buf[nbytes-1] |= 01; /* force low bit on */
n_to_mpz(var, random_buf, nbytes);
@@ -138,8 +105,7 @@ init_random(mpz_t var, int nbits)
* @param[in] eval E-Value, 0 means don't bother w. tweak
* @return 1 on success, 0 otherwise
*/
static bool
init_prime(mpz_t var, int nbits, int eval)
static bool init_prime(mpz_t var, int nbits, int eval)
{
unsigned long tries;
size_t len;
@@ -194,8 +160,7 @@ init_prime(mpz_t var, int nbits, int eval)
* @param[in] nbits size of rsa key in bits
* @return RSA_public_key_t containing the generated RSA key
*/
err_t
generate_rsa_private_key(int nbits, RSA_private_key_t *key)
err_t generate_rsa_private_key(int nbits, RSA_private_key_t *key)
{
mpz_t p, q, n, e, d, exp1, exp2, coeff;
mpz_t m, q1, t; /* temporary variables*/
+5 -2
View File
@@ -29,10 +29,10 @@
#include <asn1/asn1.h>
#include <asn1/asn1_parser.h>
#include <asn1/oid.h>
#include <crypto/rngs/rng.h>
#include "../pluto/constants.h"
#include "../pluto/defs.h"
#include "../pluto/rnd.h"
#include "../pluto/pkcs1.h"
#include "../pluto/fetch.h"
#include "../pluto/log.h"
@@ -355,8 +355,11 @@ chunk_t scep_senderNonce_attribute(void)
const size_t nonce_len = 16;
u_char nonce_buf[nonce_len];
chunk_t senderNonce = { nonce_buf, nonce_len };
rng_t *rng;
get_rnd_bytes(nonce_buf, nonce_len);
rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK);
rng->get_bytes(rng, nonce_len, nonce_buf);
rng->destroy(rng);
return asn1_wrap(ASN1_SEQUENCE, "cm"
, ASN1_senderNonce_oid
+1 -4
View File
@@ -35,6 +35,7 @@
#include <gmp.h>
#include <freeswan.h>
#include <library.h>
#include <debug.h>
#include <asn1/asn1.h>
@@ -48,7 +49,6 @@
#include "../pluto/pkcs1.h"
#include "../pluto/pkcs7.h"
#include "../pluto/certs.h"
#include "../pluto/rnd.h"
#include "rsakey.h"
#include "pkcs10.h"
@@ -747,9 +747,6 @@ int main(int argc, char **argv)
lib->settings->get_str(lib->settings, "scepclient.load", PLUGINS));
print_plugins();
init_rnd_pool();
init_fetch();
if ((filetype_out == 0) && (!request_ca_certificate))
{
usage ("--out filetype required");