Commit 23545569 authored by Olivier Crête's avatar Olivier Crête

stun tests: Fix a bunch of issues found by more aggressive GCC warnings

parent bcfe6960
......@@ -70,21 +70,23 @@ int main (void)
struct sockaddr_in ip4;
uint8_t req_buf[STUN_MAX_MESSAGE_SIZE];
uint8_t resp_buf[STUN_MAX_MESSAGE_SIZE];
const uint64_t tie = 0x8000000000000000LL;
const const uint64_t tie = 0x8000000000000000LL;
StunMessageReturn val;
StunUsageIceReturn val2;
size_t len;
size_t rlen;
static char username[] = "L:R", ufrag[] = "L", pass[] = "secret";
static char username[] = "L:R";
static uint8_t ufrag[] = "L", pass[] = "secret";
size_t ufrag_len = strlen ((char*) ufrag);
size_t pass_len = strlen ((char*) pass);
int code;
uint16_t alen;
bool control = false;
StunAgent agent;
StunMessage req;
StunMessage resp;
StunDefaultValidaterData validater_data[] = {
{ufrag, strlen (ufrag), pass, strlen (pass)},
{username, strlen (username), pass, strlen (pass)},
{ufrag, ufrag_len, pass, pass_len},
{(uint8_t *) username, strlen (username), pass, pass_len},
{NULL, 0, NULL, 0}};
StunValidationStatus valid;
......@@ -119,7 +121,7 @@ int main (void)
assert (stun_agent_init_request (&agent, &req, req_buf, sizeof(req_buf), 0x666));
val = stun_message_append_string (&req, STUN_ATTRIBUTE_USERNAME, username);
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
rlen = stun_agent_finish_message (&agent, &req, pass, strlen (pass));
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0);
len = sizeof (resp_buf);
......@@ -135,7 +137,7 @@ int main (void)
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
val = stun_message_append_string (&req, STUN_ATTRIBUTE_USERNAME, username);
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
rlen = stun_agent_finish_message (&agent, &req, pass, strlen (pass));
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0);
valid = stun_agent_validate (&agent, &req, req_buf, rlen,
......@@ -155,7 +157,7 @@ int main (void)
/* No username */
assert (stun_agent_init_request (&agent, &req, req_buf, sizeof(req_buf), STUN_BINDING));
rlen = stun_agent_finish_message (&agent, &req, pass, strlen (pass));
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0);
valid = stun_agent_validate (&agent, &req, req_buf, rlen,
......@@ -171,16 +173,17 @@ int main (void)
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
val = stun_message_append_flag (&req, STUN_ATTRIBUTE_USE_CANDIDATE);
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
val = stun_message_append_string (&req, STUN_ATTRIBUTE_USERNAME, ufrag);
val = stun_message_append_string (&req, STUN_ATTRIBUTE_USERNAME,
(char*) ufrag);
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
rlen = stun_agent_finish_message (&agent, &req, pass, strlen (pass));
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0);
len = sizeof (resp_buf);
val2 = stun_usage_ice_conncheck_create_reply (&agent, &req,
&resp, resp_buf, &len, (struct sockaddr *)&ip4,
sizeof (ip4), &control, tie, STUN_USAGE_ICE_COMPATIBILITY_RFC5245);
assert (val == STUN_USAGE_ICE_RETURN_SUCCESS);
assert (val2 == STUN_USAGE_ICE_RETURN_SUCCESS);
assert (len > 0);
assert (stun_agent_validate (&agent, &resp, resp_buf, len,
stun_agent_default_validater, validater_data) == STUN_VALIDATION_SUCCESS);
......@@ -192,7 +195,7 @@ int main (void)
assert (stun_agent_init_request (&agent, &req, req_buf, sizeof(req_buf), STUN_BINDING));
val = stun_message_append_string (&req, STUN_ATTRIBUTE_USERNAME, ufrag);
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
rlen = stun_agent_finish_message (&agent, &req, pass, strlen (pass));
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0);
ip4.sin_family = AF_UNSPEC;
......@@ -211,7 +214,7 @@ int main (void)
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
val = stun_message_append_string (&req, STUN_ATTRIBUTE_USERNAME, ufrag);
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
rlen = stun_agent_finish_message (&agent, &req, pass, strlen (pass));
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0);
......@@ -233,7 +236,7 @@ int main (void)
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
val = stun_message_append_string (&req, STUN_ATTRIBUTE_USERNAME, ufrag);
assert (val == STUN_MESSAGE_RETURN_SUCCESS);
rlen = stun_agent_finish_message (&agent, &req, pass, strlen (pass));
rlen = stun_agent_finish_message (&agent, &req, pass, pass_len);
assert (rlen > 0);
len = sizeof (resp_buf);
......
......@@ -66,20 +66,20 @@ static void fatal (const char *msg, ...)
exit (1);
}
static const char usr[] = "admin";
static const char pwd[] = "s3kr3t";
static const uint8_t usr[] = "admin";
static const uint8_t pwd[] = "s3kr3t";
bool dynamic_check_validater (StunAgent *agent,
static bool dynamic_check_validater (StunAgent *agent,
StunMessage *message, uint8_t *username, uint16_t username_len,
uint8_t **password, size_t *password_len, void *user_data)
{
if (username_len != strlen (usr) ||
memcmp (username, usr, strlen (usr)) != 0)
if (username_len != strlen ((char *) usr) ||
memcmp (username, usr, strlen ((char *) usr)) != 0)
fatal ("vector test : Validater received wrong username!");
*password = (uint8_t *) pwd;
*password_len = strlen (pwd);
*password_len = strlen ((char *) pwd);
return true;
......@@ -117,9 +117,9 @@ finish_check (StunAgent *agent, StunMessage *msg)
if (stun_message_find (&msg2, STUN_ATTRIBUTE_MESSAGE_INTEGRITY, &plen) != NULL)
fatal ("Missing HMAC test failed");
stun_message_append_string (&msg2, STUN_ATTRIBUTE_USERNAME, usr);
stun_message_append_string (&msg2, STUN_ATTRIBUTE_USERNAME, (char *) usr);
len = stun_agent_finish_message (agent, &msg2, pwd, strlen (pwd));
len = stun_agent_finish_message (agent, &msg2, pwd, strlen ((char *) pwd));
if (len <= 0)
fatal ("Cannot finish message with short-term creds");
......@@ -250,7 +250,7 @@ int main (void)
len = sizeof (msg);
if (stun_agent_finish_message (&agent, &msg, NULL, 0) != 0)
fatal ("Fingerprint overflow test failed");
if (stun_agent_finish_message (&agent, &msg, pwd, strlen (pwd)) != 0)
if (stun_agent_finish_message (&agent, &msg, pwd, strlen ((char *) pwd)) != 0)
fatal ("Message integrity overflow test failed");
/* Address attributes tests */
......
......@@ -45,7 +45,7 @@
#include <stdlib.h>
#include <assert.h>
void print_bytes (uint8_t *bytes, int len)
static void print_bytes (const uint8_t *bytes, int len)
{
int i;
......@@ -55,12 +55,12 @@ void print_bytes (uint8_t *bytes, int len)
printf ("\n");
}
void test_sha1 (uint8_t *str, uint8_t *expected) {
static void test_sha1 (const uint8_t *str, const uint8_t *expected) {
SHA1_CTX ctx;
uint8_t sha1[20];
SHA1Init(&ctx);
SHA1Update(&ctx, str, strlen (str));
SHA1Update(&ctx, str, strlen ((char *) str));
SHA1Final(sha1, &ctx);
printf ("SHA1 of '%s' : ", str);
......@@ -73,10 +73,11 @@ void test_sha1 (uint8_t *str, uint8_t *expected) {
}
void test_hmac (uint8_t *key, uint8_t *str, uint8_t *expected) {
static void test_hmac (const uint8_t *key, const uint8_t *str,
const uint8_t *expected) {
uint8_t hmac[20];
hmac_sha1(key, strlen (key), str, strlen (str), hmac);
hmac_sha1(key, strlen ((char *) key), str, strlen ((char *) str), hmac);
printf ("HMAC of '%s' with key '%s' is : ", str, key);
print_bytes (hmac, SHA1_MAC_LEN);
printf ("Expected : ");
......@@ -86,13 +87,12 @@ void test_hmac (uint8_t *key, uint8_t *str, uint8_t *expected) {
exit (1);
}
void test_md5 (uint8_t *str, uint8_t *expected) {
static void test_md5 (const uint8_t *str, const uint8_t *expected) {
MD5_CTX ctx;
uint8_t md5[20];
int i;
MD5Init(&ctx);
MD5Update(&ctx, str, strlen (str));
MD5Update(&ctx, str, strlen ((char *) str));
MD5Final(md5, &ctx);
printf ("MD5 of '%s' : 0x", str);
......@@ -128,15 +128,16 @@ int main (void)
0xaa, 0xe1, 0x16, 0xd3,
0x87, 0x6c, 0x66, 0x4a};
test_hmac ("hello", "world", hello_world_hmac);
test_hmac ((const uint8_t *) "hello", (const uint8_t*) "world",
hello_world_hmac);
test_sha1 ("abc", abc_sha1);
test_md5 ("abc", abc_md5);
test_sha1 ((const uint8_t *) "abc", abc_sha1);
test_md5 ((const uint8_t *) "abc", abc_md5);
test_sha1 ("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
abcd_etc_sha1);
test_md5 ("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
abcd_etc_md5);
test_sha1 ((const uint8_t *)
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", abcd_etc_sha1);
test_md5 ((const uint8_t *)
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", abcd_etc_md5);
return 0;
}
......@@ -285,18 +285,18 @@ static void test_message (void)
}
bool test_attribute_validater (StunAgent *agent,
static bool test_attribute_validater (StunAgent *agent,
StunMessage *message, uint8_t *username, uint16_t username_len,
uint8_t **password, size_t *password_len, void *user_data)
{
char *pwd = (char *) user_data;
uint8_t *pwd = user_data;
if (username_len != 4 ||
memcmp (username, "ABCD", 4) != 0)
return false;
*password = pwd;
*password_len = strlen (pwd);
*password_len = strlen ((char *) pwd);
return true;
}
......@@ -368,7 +368,7 @@ static void test_attribute (void)
StunMessage msg;
uint16_t known_attributes[] = {STUN_ATTRIBUTE_MESSAGE_INTEGRITY, STUN_ATTRIBUTE_USERNAME, 0};
printf ("Attribute test message length: %lu\n", sizeof (acme));
printf ("Attribute test message length: %zd\n", sizeof (acme));
stun_agent_init (&agent, known_attributes,
STUN_COMPATIBILITY_RFC5389, STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS);
......@@ -378,11 +378,11 @@ static void test_attribute (void)
fatal ("Unauthorized validation failed");
if (stun_agent_validate (&agent, &msg, acme, sizeof(acme),
test_attribute_validater, "bad__guy") != STUN_VALIDATION_UNAUTHORIZED)
test_attribute_validater, (void *) "bad__guy") != STUN_VALIDATION_UNAUTHORIZED)
fatal ("invalid password validation failed");
if (stun_agent_validate (&agent, &msg, acme, sizeof(acme),
test_attribute_validater, "good_guy") != STUN_VALIDATION_SUCCESS)
test_attribute_validater, (void *) "good_guy") != STUN_VALIDATION_SUCCESS)
fatal ("good password validation failed");
if (stun_message_has_attribute (&msg, 0xff00))
......@@ -451,9 +451,9 @@ static void test_attribute (void)
}
static const char vector_username[] = "evtj:h6vY";
static const char vector_password[] = "VOkJxbRl1RmTxUk/WvJxBt";
static uint8_t vector_password[] = "VOkJxbRl1RmTxUk/WvJxBt";
bool test_vector_validater (StunAgent *agent,
static bool test_vector_validater (StunAgent *agent,
StunMessage *message, uint8_t *username, uint16_t username_len,
uint8_t **password, size_t *password_len, void *user_data)
{
......@@ -466,8 +466,8 @@ bool test_vector_validater (StunAgent *agent,
memcmp (username, vector_username, strlen (vector_username)) != 0)
fatal ("vector test : Validater received wrong username!");
*password = (uint8_t *) vector_password;
*password_len = strlen (vector_password);
*password = vector_password;
*password_len = strlen ((char *) vector_password);
return true;
......@@ -635,7 +635,8 @@ static void test_vectors (void)
if (stun_message_length (&msg) != sizeof(req) - 32)
fatal ("vector test: removing attributes failed");
stun_agent_finish_message (&agent, &msg, vector_password, strlen (vector_password));
stun_agent_finish_message (&agent, &msg, vector_password,
strlen ((char *) vector_password));
if (stun_message_length (&msg) != stun_message_length (&msg2) ||
memcmp (req, req2, sizeof(req)) != 0)
......@@ -710,9 +711,9 @@ static void test_hash_creds (void)
puts ("Testing long term credentials hash algorithm...");
stun_hash_creds ("realm", strlen ("realm"),
"user", strlen ("user"),
"pass", strlen ("pass"), md5);
stun_hash_creds ((uint8_t *) "realm", strlen ("realm"),
(uint8_t *) "user", strlen ("user"),
(uint8_t *) "pass", strlen ("pass"), md5);
stun_debug ("key for user:realm:pass is : ");
stun_debug_bytes (md5, 16);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment