summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2011-05-26 07:59:40 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2011-05-26 08:06:40 +0200
commitc0d9ae7f9444e828b17f68d34361ea9fe77fe6a0 (patch)
treed7624a7b57db30d28e1537054792706cfe8314d8
parenta027093ede7b22289350b5cba15956de7ea0ed8e (diff)
downloadgnutls-c0d9ae7f9444e828b17f68d34361ea9fe77fe6a0.tar.gz
Added gnutls_global_set_time_function() that allows overriding the
default system time() function.
-rw-r--r--lib/ext_session_ticket.c3
-rw-r--r--lib/gnutls_db.c2
-rw-r--r--lib/gnutls_global.c17
-rw-r--r--lib/gnutls_handshake.c7
-rw-r--r--lib/gnutls_int.h1
-rw-r--r--lib/gnutls_session_pack.c2
-rw-r--r--lib/gnutls_v2_compat.c2
-rw-r--r--lib/includes/gnutls/gnutls.h.in3
-rw-r--r--lib/libgnutls.map1
-rw-r--r--lib/nettle/rnd.c6
-rw-r--r--lib/opencdk/keydb.c5
-rw-r--r--lib/opencdk/literal.c3
-rw-r--r--lib/opencdk/read-packet.c2
-rw-r--r--lib/opencdk/sig-check.c3
-rw-r--r--lib/openpgp/gnutls_openpgp.c1
-rw-r--r--lib/system.c1
-rw-r--r--lib/system.h1
-rw-r--r--lib/x509/common.c1
-rw-r--r--lib/x509/verify.c2
19 files changed, 41 insertions, 22 deletions
diff --git a/lib/ext_session_ticket.c b/lib/ext_session_ticket.c
index 3c778689bd..b2bf933655 100644
--- a/lib/ext_session_ticket.c
+++ b/lib/ext_session_ticket.c
@@ -35,6 +35,7 @@
#include <gnutls_mbuffers.h>
#include <gnutls_extensions.h>
#include <gnutls_constate.h>
+#include <system.h>
#ifdef ENABLE_SESSION_TICKET
@@ -128,7 +129,7 @@ decrypt_ticket (gnutls_session_t session, session_ticket_ext_st * priv,
cipher_hd_st cipher_hd;
gnutls_datum_t key, IV, mac_secret, state;
opaque final[MAC_SECRET_SIZE];
- time_t timestamp = time (0);
+ time_t timestamp = gnutls_time (0);
int ret;
/* Check the integrity of ticket using HMAC-SHA-256. */
diff --git a/lib/gnutls_db.c b/lib/gnutls_db.c
index 1c26ffb8c7..9946c8e88b 100644
--- a/lib/gnutls_db.c
+++ b/lib/gnutls_db.c
@@ -153,7 +153,7 @@ gnutls_db_check_entry (gnutls_session_t session, gnutls_datum_t session_entry)
{
time_t timestamp;
- timestamp = time (0);
+ timestamp = gnutls_time (0);
if (session_entry.data != NULL)
if (timestamp -
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index 1a59bdfc19..60656d62d3 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -33,6 +33,7 @@
#include <gnutls_extensions.h> /* for _gnutls_ext_init */
#include <gnutls_cryptodev.h>
#include <locks.h>
+#include <system.h>
#include "sockets.h"
#include "gettext.h"
@@ -69,6 +70,22 @@ gnutls_global_set_log_function (gnutls_log_func log_func)
}
/**
+ * gnutls_global_set_time_function:
+ * @time_func: it's the system time function
+ *
+ * This is the function where you can override the default system
+ * time function.
+ *
+ * gnutls_time_func is of the form,
+ * time_t (*gnutls_time_func)( time*);
+ **/
+void
+gnutls_global_set_time_function (gnutls_time_func time_func)
+{
+ gnutls_time = time_func;
+}
+
+/**
* gnutls_global_set_log_level:
* @level: it's an integer from 0 to 9.
*
diff --git a/lib/gnutls_handshake.c b/lib/gnutls_handshake.c
index a4a3aeb4f9..986d11ba24 100644
--- a/lib/gnutls_handshake.c
+++ b/lib/gnutls_handshake.c
@@ -322,7 +322,7 @@ _gnutls_tls_create_random (opaque * dst)
* system's time.
*/
- tim = time (NULL);
+ tim = gnutls_time (NULL);
/* generate server random value */
_gnutls_write_uint32 (tim, dst);
@@ -442,7 +442,7 @@ _gnutls_read_client_hello (gnutls_session_t session, opaque * data,
_gnutls_tls_create_random (rnd);
_gnutls_set_server_random (session, rnd);
- session->security_parameters.timestamp = time (NULL);
+ session->security_parameters.timestamp = gnutls_time (NULL);
DECR_LEN (len, 1);
session_id_len = data[pos++];
@@ -2091,7 +2091,7 @@ _gnutls_send_client_hello (gnutls_session_t session, int again)
/* In order to know when this session was initiated.
*/
- session->security_parameters.timestamp = time (NULL);
+ session->security_parameters.timestamp = gnutls_time (NULL);
/* Generate random data
*/
@@ -2855,7 +2855,6 @@ _gnutls_send_handshake_final (gnutls_session_t session, int init)
case STATE20:
STATE = STATE20;
-
ret = _gnutls_handshake_io_write_flush (session);
if (ret < 0)
{
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index f41f7cf04a..cafaa914b3 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -58,6 +58,7 @@ typedef struct
} uint64;
#include <gnutls/gnutls.h>
+#include <system.h>
/*
* They are not needed any more. You can simply enable
diff --git a/lib/gnutls_session_pack.c b/lib/gnutls_session_pack.c
index 1f4dec18fd..a305a8b2bd 100644
--- a/lib/gnutls_session_pack.c
+++ b/lib/gnutls_session_pack.c
@@ -803,7 +803,7 @@ unpack_security_parameters (gnutls_session_t session, gnutls_buffer_st * ps)
{
size_t pack_size;
int ret;
- time_t timestamp = time (0);
+ time_t timestamp = gnutls_time (0);
BUFFER_POP_NUM (ps, pack_size);
diff --git a/lib/gnutls_v2_compat.c b/lib/gnutls_v2_compat.c
index d92892bd73..64fd6d336a 100644
--- a/lib/gnutls_v2_compat.c
+++ b/lib/gnutls_v2_compat.c
@@ -226,7 +226,7 @@ _gnutls_read_client_hello_v2 (gnutls_session_t session, opaque * data,
_gnutls_tls_create_random (rnd);
_gnutls_set_server_random (session, rnd);
- session->security_parameters.timestamp = time (NULL);
+ session->security_parameters.timestamp = gnutls_time (NULL);
/* RESUME SESSION */
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 20e5c502e6..9512ece8c5 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -1106,6 +1106,7 @@ extern "C"
int gnutls_global_init (void);
void gnutls_global_deinit (void);
+ typedef time_t (*gnutls_time_func) (time_t *t);
typedef int (*mutex_init_func) (void **mutex);
typedef int (*mutex_lock_func) (void **mutex);
typedef int (*mutex_unlock_func) (void **mutex);
@@ -1127,6 +1128,8 @@ extern "C"
gnutls_realloc_function realloc_func,
gnutls_free_function free_func);
+ void gnutls_global_set_time_function (gnutls_time_func);
+
/* For use in callbacks */
extern gnutls_alloc_function gnutls_malloc;
extern gnutls_alloc_function gnutls_secure_malloc;
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index 23a2d81e2f..8ebbae471f 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -691,6 +691,7 @@ GNUTLS_2_12
gnutls_pubkey_verify_data;
gnutls_certificate_get_issuer;
gnutls_x509_crq_verify;
+ gnutls_global_set_time_function;
} GNUTLS_2_10;
GNUTLS_PRIVATE {
diff --git a/lib/nettle/rnd.c b/lib/nettle/rnd.c
index 8af0adde57..2278c7cf1e 100644
--- a/lib/nettle/rnd.c
+++ b/lib/nettle/rnd.c
@@ -94,7 +94,7 @@ do_trivia_source (int init)
static int
do_device_source (int init)
{
- time_t now = time (NULL);
+ time_t now = gnutls_time (NULL);
int read_size = DEVICE_READ_SIZE;
if (init)
@@ -226,7 +226,7 @@ do_trivia_source (int init)
static int
do_device_source_urandom (int init)
{
- time_t now = time (NULL);
+ time_t now = gnutls_time (NULL);
int read_size = DEVICE_READ_SIZE;
if (init)
@@ -291,7 +291,7 @@ do_device_source_urandom (int init)
static int
do_device_source_egd (int init)
{
- time_t now = time (NULL);
+ time_t now = gnutls_time (NULL);
int read_size = DEVICE_READ_SIZE;
if (init)
diff --git a/lib/opencdk/keydb.c b/lib/opencdk/keydb.c
index 7ef91e4caf..5be3129c8a 100644
--- a/lib/opencdk/keydb.c
+++ b/lib/opencdk/keydb.c
@@ -29,7 +29,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include <ctype.h>
#include "opencdk.h"
@@ -1677,7 +1676,7 @@ keydb_merge_selfsig (cdk_kbnode_t key, u32 * keyid)
if (key_expire)
{
pk->expiredate = pk->timestamp + key_expire;
- pk->has_expired = pk->expiredate > (u32) time (NULL) ? 0 : 1;
+ pk->has_expired = pk->expiredate > (u32) gnutls_time (NULL) ? 0 : 1;
}
pk->is_invalid = 0;
@@ -1694,7 +1693,7 @@ keydb_parse_allsigs (cdk_kbnode_t knode, cdk_keydb_hd_t hd, int check)
cdk_pkt_signature_t sig;
cdk_pkt_pubkey_t pk;
cdk_subpkt_t s = NULL;
- u32 expiredate = 0, curtime = (u32) time (NULL);
+ u32 expiredate = 0, curtime = (u32) gnutls_time (NULL);
u32 keyid[2];
if (!knode)
diff --git a/lib/opencdk/literal.c b/lib/opencdk/literal.c
index a36921c0d7..3ad1c2b5f8 100644
--- a/lib/opencdk/literal.c
+++ b/lib/opencdk/literal.c
@@ -26,7 +26,6 @@
#include <config.h>
#endif
#include <stdio.h>
-#include <time.h>
#include "opencdk.h"
#include "main.h"
@@ -211,7 +210,7 @@ literal_encode (void *data, FILE * in, FILE * out)
memcpy (pt->name, pfx->filename, filelen);
pt->namelen = filelen;
pt->name[pt->namelen] = '\0';
- pt->timestamp = (u32) time (NULL);
+ pt->timestamp = (u32) gnutls_time (NULL);
pt->mode = intmode_to_char (pfx->mode);
pt->len = cdk_stream_get_length (si);
pt->buf = si;
diff --git a/lib/opencdk/read-packet.c b/lib/opencdk/read-packet.c
index 03395b3335..a49d4fee94 100644
--- a/lib/opencdk/read-packet.c
+++ b/lib/opencdk/read-packet.c
@@ -676,7 +676,7 @@ parse_sig_subpackets (cdk_pkt_signature_t sig)
else if (node->type == CDK_SIGSUBPKT_SIG_EXPIRE && node->size >= 4)
{
sig->expiredate = _cdk_buftou32 (node->d);
- if (sig->expiredate > 0 && sig->expiredate < (u32) time (NULL))
+ if (sig->expiredate > 0 && sig->expiredate < (u32) gnutls_time (NULL))
sig->flags.expired = 1;
}
else if (node->type == CDK_SIGSUBPKT_POLICY)
diff --git a/lib/opencdk/sig-check.c b/lib/opencdk/sig-check.c
index c1a9154396..75f0d9bdce 100644
--- a/lib/opencdk/sig-check.c
+++ b/lib/opencdk/sig-check.c
@@ -26,7 +26,6 @@
#include <config.h>
#endif
#include <stdio.h>
-#include <time.h>
#include <assert.h>
#include "opencdk.h"
@@ -236,7 +235,7 @@ _cdk_sig_check (cdk_pubkey_t pk, cdk_pkt_signature_t sig,
{
cdk_error_t rc;
byte md[MAX_DIGEST_LEN];
- time_t cur_time = (u32) time (NULL);
+ time_t cur_time = (u32) gnutls_time (NULL);
if (!pk || !sig || !digest)
{
diff --git a/lib/openpgp/gnutls_openpgp.c b/lib/openpgp/gnutls_openpgp.c
index 8175a9dda0..5e13fd42fd 100644
--- a/lib/openpgp/gnutls_openpgp.c
+++ b/lib/openpgp/gnutls_openpgp.c
@@ -35,7 +35,6 @@
#include <gnutls_str.h>
#include <gnutls_sig.h>
#include <stdio.h>
-#include <time.h>
#include <sys/stat.h>
#define datum_append(x, y, z) _gnutls_datum_append_m (x, y, z, gnutls_realloc)
diff --git a/lib/system.c b/lib/system.c
index 81fe97b969..9f3253463d 100644
--- a/lib/system.c
+++ b/lib/system.c
@@ -259,6 +259,7 @@ _gnutls_atfork (void (*prepare) (void), void (*parent) (void),
#endif /* NO_LOCKS */
+gnutls_time_func gnutls_time = time;
mutex_init_func gnutls_mutex_init = gnutls_system_mutex_init;
mutex_deinit_func gnutls_mutex_deinit = gnutls_system_mutex_deinit;
mutex_lock_func gnutls_mutex_lock = gnutls_system_mutex_lock;
diff --git a/lib/system.h b/lib/system.h
index 860bca80f9..0cedded6c6 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -33,5 +33,6 @@ ssize_t system_read_peek (gnutls_transport_ptr ptr, void *data,
int _gnutls_atfork (void (*prepare) (void), void (*parent) (void),
void (*child) (void));
+extern gnutls_time_func gnutls_time;
#endif /* SYSTEM_H */
diff --git a/lib/x509/common.c b/lib/x509/common.c
index 80af4a0168..1825261359 100644
--- a/lib/x509/common.c
+++ b/lib/x509/common.c
@@ -34,7 +34,6 @@
#include <x509_b64.h>
#include "x509_int.h"
#include <common.h>
-#include <time.h>
struct oid2string
{
diff --git a/lib/x509/verify.c b/lib/x509/verify.c
index ff732f8777..86f7f76b32 100644
--- a/lib/x509/verify.c
+++ b/lib/x509/verify.c
@@ -471,7 +471,7 @@ _gnutls_x509_verify_certificate (const gnutls_x509_crt_t * certificate_list,
{
int i = 0, ret;
unsigned int status = 0, output;
- time_t now = time (0);
+ time_t now = gnutls_time (0);
gnutls_x509_crt_t issuer = NULL;
if (clist_size > 1)