Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add openconnect_random() function
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed May 29, 2012
1 parent af19e15 commit e4ca865
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cstp.c
Expand Up @@ -35,7 +35,6 @@

#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rand.h>

#include "openconnect-internal.h"

Expand Down Expand Up @@ -108,7 +107,7 @@ static int start_cstp_connection(struct openconnect_info *vpninfo)
/* Create (new) random master key for DTLS connection, if needed */
if (vpninfo->dtls_times.last_rekey + vpninfo->dtls_times.rekey <
time(NULL) + 300 &&
RAND_bytes(vpninfo->dtls_secret, sizeof(vpninfo->dtls_secret)) != 1) {
openconnect_random(vpninfo->dtls_secret, sizeof(vpninfo->dtls_secret))) {
fprintf(stderr, _("Failed to initialise DTLS secret\n"));
exit(1);
}
Expand Down
1 change: 1 addition & 0 deletions libopenconnect.map.in
Expand Up @@ -56,4 +56,5 @@ OPENCONNECT_PRIVATE {
openconnect_get_cert_details;
openconnect_get_cert_DER;
openconnect_sha1;
openconnect_random;
};
1 change: 1 addition & 0 deletions openconnect-internal.h
Expand Up @@ -293,6 +293,7 @@ void openconnect_report_ssl_errors(struct openconnect_info *vpninfo);

/* ${SSL_LIBRARY}.c */
int openconnect_sha1(unsigned char *result, void *data, int len);
int openconnect_random(void *bytes, int len);

/* mainloop.c */
int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
Expand Down
8 changes: 8 additions & 0 deletions openssl.c
Expand Up @@ -25,6 +25,7 @@
#include <errno.h>

#include <openssl/evp.h>
#include <openssl/rand.h>

#include "openconnect-internal.h"

Expand Down Expand Up @@ -62,3 +63,10 @@ int openconnect_get_cert_DER(struct openconnect_info *vpninfo,
BIO_free(bp);
return l;
}

int openconnect_random(void *bytes, int len)
{
if (RAND_bytes(bytes, len) != 1)
return -EIO;
return 0;
}

0 comments on commit e4ca865

Please sign in to comment.