Commit f453ae43 authored by Jan Včelák's avatar Jan Včelák 🚀

tests: cleanup cookie tests

parent 39a7f601
......@@ -46,16 +46,9 @@ static int init_sa6(struct sockaddr_in6 *sa, uint16_t port, const char *addr)
return ret;
}
#define PORT 0
#define A4_0 "127.0.0.1"
#define A4_1 "10.0.0.1"
#define A6_0 "2001:db8:8714:3a90::12"
#define A6_1 "::1"
int main(int argc, char *argv[])
{
plan(22);
plan_lazy();
int ret;
......@@ -65,24 +58,22 @@ int main(int argc, char *argv[])
struct sockaddr_in c4_sa, s4_sa;
struct sockaddr_in6 c6_sa, s6_sa;
#define SECRET_LEN 8
const uint8_t secret[SECRET_LEN] = { 0, 1, 2, 3, 4, 5, 6, 7 };
const uint8_t secret[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
#define HASH_MAX 32
uint8_t hash[HASH_MAX];
uint8_t hash[32] = { 0 };
uint16_t hash_len;
struct knot_cc_input cc_in = { 0 };
init_sa4(&c4_sa, PORT, A4_0);
init_sa4(&s4_sa, PORT, A4_1);
init_sa4(&c4_sa, 0, "127.0.0.1");
init_sa4(&s4_sa, 0, "10.0.0.1");
init_sa6(&c6_sa, PORT, A6_0);
init_sa6(&s6_sa, PORT, A6_1);
init_sa6(&c6_sa, 0, "2001:db8:8714:3a90::12");
init_sa6(&s6_sa, 0, "::1");
/* Client cookie hash algorithm. */
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(NULL, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie no input");
......@@ -91,7 +82,7 @@ int main(int argc, char *argv[])
cc_in.srvr_sockaddr = NULL;
cc_in.secret_data = NULL;
cc_in.secret_len = 0;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie input no data");
......@@ -100,7 +91,7 @@ int main(int argc, char *argv[])
cc_in.srvr_sockaddr = (struct sockaddr *)&s4_sa;
cc_in.secret_data = NULL;
cc_in.secret_len = 0;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie input no secret");
......@@ -108,8 +99,8 @@ int main(int argc, char *argv[])
cc_in.clnt_sockaddr = NULL;
cc_in.srvr_sockaddr = NULL;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
hash_len = HASH_MAX;
cc_in.secret_len = sizeof(secret);
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie input no socket");
......@@ -117,8 +108,8 @@ int main(int argc, char *argv[])
cc_in.clnt_sockaddr = (struct sockaddr *)&c4_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s4_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
hash_len = HASH_MAX;
cc_in.secret_len = sizeof(secret);
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, NULL, NULL);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie output no hash");
......@@ -126,7 +117,7 @@ int main(int argc, char *argv[])
cc_in.clnt_sockaddr = (struct sockaddr *)&c4_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s4_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
cc_in.secret_len = sizeof(secret);
hash_len = 1;
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie hash no space");
......@@ -135,80 +126,65 @@ int main(int argc, char *argv[])
cc_in.clnt_sockaddr = (struct sockaddr *)&c4_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s4_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
hash_len = HASH_MAX;
cc_in.secret_len = sizeof(secret);
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EOK && hash_len == knot_cc_alg_fnv64.cc_size, "cookies: FNV64 client cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x74, 0x31, 0xf9, 0xa8, 0x03, 0xef, 0x15, 0xb1 };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x74, 0x31, 0xf9, 0xa8, 0x03, 0xef, 0x15, 0xb1 };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = NULL;
cc_in.srvr_sockaddr = (struct sockaddr *)&s4_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
hash_len = HASH_MAX;
cc_in.secret_len = sizeof(secret);
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EOK && hash_len == knot_cc_alg_fnv64.cc_size, "cookies: FNV64 client cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x7c, 0x62, 0x25, 0xd2, 0x43, 0xdd, 0x09, 0xe7 };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x7c, 0x62, 0x25, 0xd2, 0x43, 0xdd, 0x09, 0xe7 };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = (struct sockaddr *)&unspec_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s4_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
hash_len = HASH_MAX;
cc_in.secret_len = sizeof(secret);
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EOK && hash_len == knot_cc_alg_fnv64.cc_size, "cookies: FNV64 client cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x7c, 0x62, 0x25, 0xd2, 0x43, 0xdd, 0x09, 0xe7 };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x7c, 0x62, 0x25, 0xd2, 0x43, 0xdd, 0x09, 0xe7 };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = (struct sockaddr *)&c4_sa;
cc_in.srvr_sockaddr = NULL;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
hash_len = HASH_MAX;
cc_in.secret_len = sizeof(secret);
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EOK && hash_len == knot_cc_alg_fnv64.cc_size, "cookies: FNV64 client cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x05, 0xa9, 0xd1, 0x08, 0x1b, 0x98, 0xe0, 0xaa };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x05, 0xa9, 0xd1, 0x08, 0x1b, 0x98, 0xe0, 0xaa };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = (struct sockaddr *)&c4_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&unspec_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
hash_len = HASH_MAX;
cc_in.secret_len = sizeof(secret);
hash_len = sizeof(hash);
ret = knot_cc_alg_fnv64.gen_func(&cc_in, hash, &hash_len);
ok(ret == KNOT_EOK && hash_len == knot_cc_alg_fnv64.cc_size, "cookies: FNV64 client cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x05, 0xa9, 0xd1, 0x08, 0x1b, 0x98, 0xe0, 0xaa };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x05, 0xa9, 0xd1, 0x08, 0x1b, 0x98, 0xe0, 0xaa };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 client cookie content");
}
/* Client cookie check. */
......@@ -217,74 +193,59 @@ int main(int argc, char *argv[])
cc_in.clnt_sockaddr = (struct sockaddr *)&c6_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s6_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
cc_in.secret_len = sizeof(secret);
{
ret = knot_cc_check(NULL, 0, &cc_in, &knot_cc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie check no cookie");
}
{
#define COOKIE_LEN 8
uint8_t cookie[COOKIE_LEN] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, COOKIE_LEN, NULL, &knot_cc_alg_fnv64);
uint8_t cookie[] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, sizeof(cookie), NULL, &knot_cc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie check no input");
#undef COOKIE_LEN
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = (struct sockaddr *)&c6_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s6_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
cc_in.secret_len = sizeof(secret);
{
#define COOKIE_LEN 8
uint8_t cookie[COOKIE_LEN] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, COOKIE_LEN, &cc_in, NULL);
uint8_t cookie[] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, sizeof(cookie), &cc_in, NULL);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie check no algorithm");
#undef COOKIE_LEN
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = (struct sockaddr *)&c6_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s6_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
cc_in.secret_len = sizeof(secret);
{
#define COOKIE_LEN 8
uint8_t cookie[COOKIE_LEN] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, COOKIE_LEN, &cc_in, &knot_cc_alg_fnv64);
uint8_t cookie[] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, sizeof(cookie), &cc_in, &knot_cc_alg_fnv64);
ok(ret == KNOT_EOK, "cookies: FNV64 client good cookie check");
#undef COOKIE_LEN
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = (struct sockaddr *)&c6_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s6_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
cc_in.secret_len = sizeof(secret);
{
#define COOKIE_LEN 8
uint8_t cookie[COOKIE_LEN] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, COOKIE_LEN - 1, &cc_in, &knot_cc_alg_fnv64);
uint8_t cookie[] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xaf };
ret = knot_cc_check(cookie, sizeof(cookie) - 1, &cc_in, &knot_cc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie check invalid length");
#undef COOKIE_LEN
}
memset(&cc_in, 0, sizeof(cc_in));
cc_in.clnt_sockaddr = (struct sockaddr *)&c6_sa;
cc_in.srvr_sockaddr = (struct sockaddr *)&s6_sa;
cc_in.secret_data = secret;
cc_in.secret_len = SECRET_LEN;
cc_in.secret_len = sizeof(secret);
{
#define COOKIE_LEN 8
uint8_t cookie[COOKIE_LEN] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xae };
ret = knot_cc_check(cookie, COOKIE_LEN, &cc_in, &knot_cc_alg_fnv64);
uint8_t cookie[] = { 0x33, 0x0c, 0xa6, 0x80, 0x94, 0x17, 0xe5, 0xae };
ret = knot_cc_check(cookie, sizeof(cookie), &cc_in, &knot_cc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 client cookie check invalid cookie");
#undef COOKIE_LEN
}
}
......@@ -24,9 +24,7 @@
#include "libknot/rrtype/opt.h"
#include "libknot/rrtype/opt-cookie.h"
#define OPTCOUNT 9
const char *cookie_opts[OPTCOUNT] = {
const char *cookie_opts[] = {
"\x00\x0a" "\x00\x00", /* Zero length cookie. */
"\x00\x0a" "\x00\x01" "\x00", /* Short client cookie. */
"\x00\x0a" "\x00\x07" "\x00\x01\x02\x03\x04\x05\x06", /* Short client cookie. */
......@@ -54,7 +52,7 @@ static void get_opt_data(const uint8_t *opt,
int main(int argc, char *argv[])
{
plan(17);
plan_lazy();
uint16_t code;
uint16_t data_len;
......@@ -126,8 +124,8 @@ int main(int argc, char *argv[])
/* Valid cookies. */
#define DUMMYPTR ((void *)0x01)
#define DUMMYVAL 1
const void *DUMMYPTR = (void *)1;
const int DUMMYVAL = 1;
cc = sc = DUMMYPTR;
cc_len = sc_len = DUMMYVAL;
......
......@@ -28,9 +28,7 @@
#include "libknot/rrtype/opt.h"
#include "libknot/rrtype/opt-cookie.h"
#define OPTCOUNT 4
const char *cookie_opts[OPTCOUNT] = {
const char *cookie_opts[] = {
"\x00\x0a" "\x00\x10" "\x00\x01\x02\x03\x04\x05\x06\x07" "\xe0\xd9\x95\x4e\xbc\xc3\x99\x18", /* 8 octets long wrong server cookie. */
"\x00\x0a" "\x00\x10" "\x00\x01\x02\x03\x04\x05\x06\x07" "\xe0\xd9\x95\x4e\xbc\xc3\x99\x19", /* 8 octets long OK server cookie. */
"\x00\x0a" "\x00\x18" "\x00\x01\x02\x03\x04\x05\x06\x07" "\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\xc0\xbd\xdb\xec\x19\x78\x88\x38", /* 8B nonce 8B hash long wrong server cookie. */
......@@ -84,7 +82,7 @@ static int init_sa6(struct sockaddr_in6 *sa, uint16_t port, const char *addr)
int main(int argc, char *argv[])
{
plan(38);
plan_lazy();
int ret;
......@@ -94,22 +92,16 @@ int main(int argc, char *argv[])
struct sockaddr_in c4_sa, s4_sa;
struct sockaddr_in6 c6_sa, s6_sa;
#define SC0_LEN 8
const uint8_t sc0[SC0_LEN] = { 0, 1, 2, 3, 4, 5, 6, 7 };
#define SC1_LEN 16
const uint8_t sc1[SC1_LEN] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17 };
const uint8_t sc0[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
const uint8_t sc1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17 };
#define CC_LEN 8
const uint8_t cc[CC_LEN] = { 0, 1, 2, 3, 4, 5, 6, 7 };
const uint8_t cc[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
#define SECRET_LEN 8
const uint8_t secret[SECRET_LEN] = { 0, 1, 2, 3, 4, 5, 6, 7 };
const uint8_t secret[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
#define NONCE_LEN 8
const uint8_t nonce[NONCE_LEN] = { 10, 11, 12, 13, 14, 15, 16, 17 };
const uint8_t nonce[] = { 10, 11, 12, 13, 14, 15, 16, 17 };
#define HASH_MAX 32
uint8_t hash[HASH_MAX];
uint8_t hash[32] = { 0 };
uint16_t hash_len;
struct knot_sc_content sc_content;
......@@ -127,7 +119,7 @@ int main(int argc, char *argv[])
/* Server cookie hash algorithm. */
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(NULL, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie no input");
......@@ -137,7 +129,7 @@ int main(int argc, char *argv[])
sc_in.nonce = NULL;
sc_in.nonce_len = 0;
sc_in.srvr_data = NULL;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie input no data");
......@@ -150,20 +142,20 @@ int main(int argc, char *argv[])
sc_in.nonce = NULL;
sc_in.nonce_len = 0;
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie input no data");
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = NULL;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, NULL, NULL);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie output no socket");
......@@ -172,45 +164,45 @@ int main(int argc, char *argv[])
srvr_data.secret_data = NULL;
srvr_data.secret_len = 0;
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, NULL, NULL);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie output no secret");
memset(&sc_in, 0, sizeof(sc_in));
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = NULL;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, NULL, NULL);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie output no server data");
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&c4_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, NULL, NULL);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie output no hash");
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&c4_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = 1;
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
......@@ -219,147 +211,129 @@ int main(int argc, char *argv[])
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&c4_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EOK, "cookies: FNV64 server cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x75, 0x45, 0x7c, 0x9a, 0xe0, 0x13, 0xa8, 0xea };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x75, 0x45, 0x7c, 0x9a, 0xe0, 0x13, 0xa8, 0xea };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
}
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&c6_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EOK, "cookies: FNV64 server cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0xc0, 0xbd, 0xdb, 0xec, 0x19, 0x78, 0x88, 0x39 };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0xc0, 0xbd, 0xdb, 0xec, 0x19, 0x78, 0x88, 0x39 };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
}
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&c6_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = NULL;
sc_in.nonce_len = 0;
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EOK, "cookies: FNV64 server cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0xe0, 0xd9, 0x95, 0x4e, 0xbc, 0xc3, 0x99, 0x19 };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0xe0, 0xd9, 0x95, 0x4e, 0xbc, 0xc3, 0x99, 0x19 };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
}
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&unspec_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EOK, "cookies: FNV64 server cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x4d, 0xde, 0xfa, 0x22, 0xb9, 0x0a, 0xcc, 0xd8 };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x4d, 0xde, 0xfa, 0x22, 0xb9, 0x0a, 0xcc, 0xd8 };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
}
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&unspec_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN - 1;
sc_in.cc_len = sizeof(cc) - 1;
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN;
sc_in.nonce_len = sizeof(nonce);
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EOK, "cookies: FNV64 server cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0xa0, 0x35, 0xe3, 0xe0, 0x78, 0x7a, 0x91, 0xaf };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0xa0, 0x35, 0xe3, 0xe0, 0x78, 0x7a, 0x91, 0xaf };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
}
memset(&sc_in, 0, sizeof(sc_in));
srvr_data.clnt_sockaddr = (struct sockaddr *)&unspec_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
sc_in.cc = cc;
sc_in.cc_len = CC_LEN;
sc_in.cc_len = sizeof(cc);
sc_in.nonce = nonce;
sc_in.nonce_len = NONCE_LEN - 1;
sc_in.nonce_len = sizeof(nonce) - 1;
sc_in.srvr_data = &srvr_data;
hash_len = HASH_MAX;
hash_len = sizeof(hash);
ret = knot_sc_alg_fnv64.hash_func(&sc_in, hash, &hash_len);
ok(ret == KNOT_EOK, "cookies: FNV64 server cookie output");
{
#define EXPECTED_LEN 8
uint8_t expected[EXPECTED_LEN] = { 0x8e, 0xa3, 0xf8, 0x97, 0x84, 0x0a, 0x3d, 0x8b };
ok(EXPECTED_LEN == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
#undef EXPECTED_LEN
uint8_t expected[] = { 0x8e, 0xa3, 0xf8, 0x97, 0x84, 0x0a, 0x3d, 0x8b };
ok(sizeof(expected) == hash_len && 0 == memcmp(expected, hash, hash_len), "cookies: FNV64 server cookie content");
}
/* Server cookie parse. */
#define DUMMYPTR ((void *)0x01)
#define DUMMYVAL 1
const void *DUMMYPTR = (void *)1;
const int DUMMYVAL = 1;
ret = knot_sc_parse(0, NULL, 0, &sc_content);
ok(ret == KNOT_EINVAL, "cookies: parse server cookie no cookie");
ret = knot_sc_parse(0, sc0, SC0_LEN, NULL);
ret = knot_sc_parse(0, sc0, sizeof(sc0), NULL);
ok(ret == KNOT_EINVAL, "cookies: parse server cookie no content");
ret = knot_sc_parse(SC0_LEN, sc0, SC0_LEN, &sc_content);
ret = knot_sc_parse(sizeof(sc0), sc0, sizeof(sc0), &sc_content);
ok(ret == KNOT_EINVAL, "cookies: parse server cookie too large nonce");
sc_content.nonce = sc_content.hash = DUMMYPTR;
sc_content.nonce_len = sc_content.hash_len = DUMMYVAL;
ret = knot_sc_parse(0, sc0, SC0_LEN, &sc_content);
ret = knot_sc_parse(0, sc0, sizeof(sc0), &sc_content);
ok(ret == KNOT_EOK &&
sc_content.nonce == NULL && sc_content.nonce_len == 0 &&
sc_content.hash == sc0 && sc_content.hash_len == SC0_LEN, "cookies: parse server cookie 0B nonce");
sc_content.hash == sc0 && sc_content.hash_len == sizeof(sc0), "cookies: parse server cookie 0B nonce");
sc_content.nonce = sc_content.hash = DUMMYPTR;
sc_content.nonce_len = sc_content.hash_len = DUMMYVAL;
ret = knot_sc_parse(8, sc1, SC1_LEN, &sc_content);
ret = knot_sc_parse(8, sc1, sizeof(sc1), &sc_content);
ok(ret == KNOT_EOK &&
sc_content.nonce == sc1 && sc_content.nonce_len == 8 &&
sc_content.hash == (sc1 + 8) && sc_content.hash_len == 8, "cookies: parse server cookie 8B nonce");
......@@ -369,21 +343,21 @@ int main(int argc, char *argv[])
get_opt_cookies(ROPT(1), &cookies);
srvr_data.clnt_sockaddr = (struct sockaddr *)&c6_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
ret = knot_sc_check(1, &cookies, &srvr_data, &knot_sc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie check - wrong nonce length");
get_opt_cookies(ROPT(1), &cookies);
srvr_data.clnt_sockaddr = (struct sockaddr *)&c6_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
ret = knot_sc_check(17, &cookies, &srvr_data, &knot_sc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie check - too long nonce");
get_opt_cookies(ROPT(1), &cookies);
srvr_data.clnt_sockaddr = (struct sockaddr *)&c6_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
ret = knot_sc_check(0, NULL, &srvr_data, &knot_sc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie check - no cookies");
......@@ -392,7 +366,7 @@ int main(int argc, char *argv[])
cookies.cc_len = 0;
srvr_data.clnt_sockaddr = (struct sockaddr *)&c6_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
ret = knot_sc_check(0, NULL, &srvr_data, &knot_sc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie check - no client cookie");
......@@ -401,14 +375,14 @@ int main(int argc, char *argv[])
cookies.sc_len = 0;
srvr_data.clnt_sockaddr = (struct sockaddr *)&c6_sa;
srvr_data.secret_data = secret;
srvr_data.secret_len = SECRET_LEN;
srvr_data.secret_len = sizeof(secret);
ret = knot_sc_check(0, NULL, &srvr_data, &knot_sc_alg_fnv64);
ok(ret == KNOT_EINVAL, "cookies: FNV64 server cookie check - no server cookie");
get_opt_cookies(ROPT(1), &cookies);