summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2018-11-14 13:56:52 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2018-11-15 13:48:37 +0100
commite1cd3313acb4c15ffc0f009c89a859e1f9b3bed4 (patch)
tree0901e4a012cbcc0ae3c59975914b46b1b4443da2 /tests
parent048dc3177c0f542c66e55472e4d5db1c1d2f3e0e (diff)
downloadgnutls-e1cd3313acb4c15ffc0f009c89a859e1f9b3bed4.tar.gz
anti_replay: moved new add function into anti_replay structure
The new function was not sharing anything with the existing gnutls_db_* backend, and moving it to anti_replay structure is more clean and allows for deviations from the old API conventions (e.g., now we can pass pointers for efficiency and pass the expiration time as part of the call). Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/tls13-early-data-neg.c18
-rw-r--r--tests/tls13-early-data.c17
-rw-r--r--tests/tls13/anti_replay.c32
3 files changed, 34 insertions, 33 deletions
diff --git a/tests/tls13-early-data-neg.c b/tests/tls13-early-data-neg.c
index 6c7a1f492d..35c635f63c 100644
--- a/tests/tls13-early-data-neg.c
+++ b/tests/tls13-early-data-neg.c
@@ -235,15 +235,15 @@ struct storage_st {
};
static int
-storage_add(void *ptr, gnutls_datum_t key, gnutls_datum_t value)
+storage_add(void *ptr, time_t expires, const gnutls_datum_t *key, const gnutls_datum_t *value)
{
struct storage_st *storage = ptr;
gnutls_datum_t *datum;
size_t i;
for (i = 0; i < storage->num_entries; i++) {
- if (key.size == storage->entries[i].size &&
- memcmp(storage->entries[i].data, key.data, key.size) == 0) {
+ if (key->size == storage->entries[i].size &&
+ memcmp(storage->entries[i].data, key->data, key->size) == 0) {
return GNUTLS_E_DB_ENTRY_EXISTS;
}
}
@@ -255,11 +255,11 @@ storage_add(void *ptr, gnutls_datum_t key, gnutls_datum_t value)
return GNUTLS_E_DB_ERROR;
datum = &storage->entries[storage->num_entries];
- datum->data = gnutls_malloc(key.size);
+ datum->data = gnutls_malloc(key->size);
if (!datum->data)
return GNUTLS_E_MEMORY_ERROR;
- memcpy(datum->data, key.data, key.size);
- datum->size = key.size;
+ memcpy(datum->data, key->data, key->size);
+ datum->size = key->size;
storage->num_entries++;
@@ -308,6 +308,8 @@ static void server(int sds[])
ret = gnutls_anti_replay_init(&anti_replay);
if (ret < 0)
fail("server: failed to initialize anti-replay\n");
+ gnutls_anti_replay_set_add_function(anti_replay, storage_add);
+ gnutls_anti_replay_set_ptr(anti_replay, &storage);
for (t = 0; t < SESSIONS; t++) {
int sd = sds[t];
@@ -323,8 +325,6 @@ static void server(int sds[])
gnutls_session_ticket_enable_server(session,
&session_ticket_key);
- gnutls_db_set_add_function(session, storage_add);
- gnutls_db_set_ptr(session, &storage);
gnutls_anti_replay_enable(session, anti_replay);
gnutls_transport_set_int(session, sd);
@@ -435,7 +435,7 @@ static void server(int sds[])
void doit(void)
{
int client_sds[SESSIONS], server_sds[SESSIONS];
- int i, status;
+ int i, status = 0;
int ret;
signal(SIGCHLD, SIG_IGN);
diff --git a/tests/tls13-early-data.c b/tests/tls13-early-data.c
index f23aec77fa..c922ae0ba6 100644
--- a/tests/tls13-early-data.c
+++ b/tests/tls13-early-data.c
@@ -201,15 +201,15 @@ struct storage_st {
};
static int
-storage_add(void *ptr, gnutls_datum_t key, gnutls_datum_t value)
+storage_add(void *ptr, time_t expires, const gnutls_datum_t *key, const gnutls_datum_t *value)
{
struct storage_st *storage = ptr;
gnutls_datum_t *datum;
size_t i;
for (i = 0; i < storage->num_entries; i++) {
- if (key.size == storage->entries[i].size &&
- memcmp(storage->entries[i].data, key.data, key.size) == 0) {
+ if (key->size == storage->entries[i].size &&
+ memcmp(storage->entries[i].data, key->data, key->size) == 0) {
return GNUTLS_E_DB_ENTRY_EXISTS;
}
}
@@ -221,11 +221,11 @@ storage_add(void *ptr, gnutls_datum_t key, gnutls_datum_t value)
return GNUTLS_E_DB_ERROR;
datum = &storage->entries[storage->num_entries];
- datum->data = gnutls_malloc(key.size);
+ datum->data = gnutls_malloc(key->size);
if (!datum->data)
return GNUTLS_E_MEMORY_ERROR;
- memcpy(datum->data, key.data, key.size);
- datum->size = key.size;
+ memcpy(datum->data, key->data, key->size);
+ datum->size = key->size;
storage->num_entries++;
@@ -275,6 +275,9 @@ static void server(int sds[])
if (ret < 0)
fail("server: failed to initialize anti-replay\n");
+ gnutls_anti_replay_set_add_function(anti_replay, storage_add);
+ gnutls_anti_replay_set_ptr(anti_replay, &storage);
+
for (t = 0; t < SESSIONS; t++) {
int sd = sds[t];
@@ -287,8 +290,6 @@ static void server(int sds[])
gnutls_session_ticket_enable_server(session,
&session_ticket_key);
- gnutls_db_set_add_function(session, storage_add);
- gnutls_db_set_ptr(session, &storage);
gnutls_anti_replay_enable(session, anti_replay);
gnutls_transport_set_int(session, sd);
diff --git a/tests/tls13/anti_replay.c b/tests/tls13/anti_replay.c
index 090dcabbdb..31ab517151 100644
--- a/tests/tls13/anti_replay.c
+++ b/tests/tls13/anti_replay.c
@@ -37,15 +37,15 @@ struct storage_st {
};
static int
-storage_add(void *ptr, gnutls_datum_t key, gnutls_datum_t value)
+storage_add(void *ptr, time_t expires, const gnutls_datum_t *key, const gnutls_datum_t *value)
{
struct storage_st *storage = ptr;
gnutls_datum_t *datum;
size_t i;
for (i = 0; i < storage->num_entries; i++) {
- if (key.size == storage->entries[i].size &&
- memcmp(storage->entries[i].data, key.data, key.size) == 0) {
+ if (key->size == storage->entries[i].size &&
+ memcmp(storage->entries[i].data, key->data, key->size) == 0) {
return GNUTLS_E_DB_ENTRY_EXISTS;
}
}
@@ -57,11 +57,11 @@ storage_add(void *ptr, gnutls_datum_t key, gnutls_datum_t value)
return GNUTLS_E_DB_ERROR;
datum = &storage->entries[storage->num_entries];
- datum->data = gnutls_malloc(key.size);
+ datum->data = gnutls_malloc(key->size);
if (!datum->data)
return GNUTLS_E_MEMORY_ERROR;
- memcpy(datum->data, key.data, key.size);
- datum->size = key.size;
+ memcpy(datum->data, key->data, key->size);
+ datum->size = key->size;
storage->num_entries++;
@@ -94,12 +94,12 @@ void doit(void)
ret = gnutls_anti_replay_init(&anti_replay);
assert(ret == 0);
gnutls_anti_replay_set_window(anti_replay, 10000);
+ gnutls_anti_replay_set_add_function(anti_replay, storage_add);
+ gnutls_anti_replay_set_ptr(anti_replay, &storage);
gnutls_init(&session, GNUTLS_SERVER);
- gnutls_db_set_add_function(session, storage_add);
- gnutls_db_set_ptr(session, &storage);
gnutls_anti_replay_enable(session, anti_replay);
mygettime(&creation_time);
- ret = _gnutls_anti_replay_check(session, 10000, &creation_time, &key);
+ ret = _gnutls_anti_replay_check(anti_replay, 10000, &creation_time, &key);
if (ret != GNUTLS_E_ILLEGAL_PARAMETER)
fail("error is not returned, while server_ticket_age < client_ticket_age\n");
gnutls_deinit(session);
@@ -109,14 +109,14 @@ void doit(void)
/* server_ticket_age - client_ticket_age > window */
ret = gnutls_anti_replay_init(&anti_replay);
assert(ret == 0);
+ gnutls_anti_replay_set_add_function(anti_replay, storage_add);
+ gnutls_anti_replay_set_ptr(anti_replay, &storage);
gnutls_anti_replay_set_window(anti_replay, 10000);
gnutls_init(&session, GNUTLS_SERVER);
- gnutls_db_set_add_function(session, storage_add);
- gnutls_db_set_ptr(session, &storage);
gnutls_anti_replay_enable(session, anti_replay);
mygettime(&creation_time);
virt_sec_sleep(30);
- ret = _gnutls_anti_replay_check(session, 10000, &creation_time, &key);
+ ret = _gnutls_anti_replay_check(anti_replay, 10000, &creation_time, &key);
if (ret != GNUTLS_E_EARLY_DATA_REJECTED)
fail("early data is NOT rejected, while freshness check fails\n");
gnutls_deinit(session);
@@ -126,17 +126,17 @@ void doit(void)
/* server_ticket_age - client_ticket_age < window */
ret = gnutls_anti_replay_init(&anti_replay);
assert(ret == 0);
+ gnutls_anti_replay_set_add_function(anti_replay, storage_add);
+ gnutls_anti_replay_set_ptr(anti_replay, &storage);
gnutls_anti_replay_set_window(anti_replay, 10000);
gnutls_init(&session, GNUTLS_SERVER);
- gnutls_db_set_add_function(session, storage_add);
- gnutls_db_set_ptr(session, &storage);
gnutls_anti_replay_enable(session, anti_replay);
mygettime(&creation_time);
virt_sec_sleep(15);
- ret = _gnutls_anti_replay_check(session, 10000, &creation_time, &key);
+ ret = _gnutls_anti_replay_check(anti_replay, 10000, &creation_time, &key);
if (ret != 0)
fail("early data is rejected, while freshness check succeeds\n");
- ret = _gnutls_anti_replay_check(session, 10000, &creation_time, &key);
+ ret = _gnutls_anti_replay_check(anti_replay, 10000, &creation_time, &key);
if (ret != GNUTLS_E_EARLY_DATA_REJECTED)
fail("early data is NOT rejected for a duplicate key\n");
gnutls_deinit(session);