diff options
author | Olivier CrĂȘte <olivier.crete@collabora.co.uk> | 2008-05-08 19:03:29 -0400 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.co.uk> | 2008-05-08 19:03:29 -0400 |
commit | 1aeb122c0c558c5b2baa07cf92b77833ffe4b9fa (patch) | |
tree | 528302730bee6dc241ff883c6b8d3d356f7e0332 | |
parent | dfd0ec14650a2a8fd8281c23b58ac6643e469e72 (diff) | |
download | libnice-1aeb122c0c558c5b2baa07cf92b77833ffe4b9fa.tar.gz |
Put the fingerprint only when not in google compat mode
-rw-r--r-- | agent/conncheck.c | 3 | ||||
-rw-r--r-- | agent/discovery.c | 5 | ||||
-rw-r--r-- | stun/bind.c | 19 | ||||
-rw-r--r-- | stun/bind.h | 9 | ||||
-rw-r--r-- | stun/stun-ice.c | 12 | ||||
-rw-r--r-- | stun/stun-msg.h | 6 | ||||
-rw-r--r-- | stun/stunbdc.c | 2 | ||||
-rw-r--r-- | stun/stund.c | 2 | ||||
-rw-r--r-- | stun/stunsend.c | 12 | ||||
-rw-r--r-- | stun/tests/test-bind.c | 30 | ||||
-rw-r--r-- | stun/tests/test-conncheck.c | 18 | ||||
-rw-r--r-- | stun/tests/test-format.c | 12 |
12 files changed, 67 insertions, 63 deletions
diff --git a/agent/conncheck.c b/agent/conncheck.c index 6ff6fcb..ac1413e 100644 --- a/agent/conncheck.c +++ b/agent/conncheck.c @@ -430,7 +430,8 @@ static gboolean priv_conn_keepalive_tick (gpointer pointer) nice_address_copy_to_sockaddr (&p->remote->addr, &sockaddr); res = stun_bind_keepalive (p->local->sockptr->fileno, - &sockaddr, sizeof (sockaddr)); + &sockaddr, sizeof (sockaddr), + agent->compatibility); g_debug ("Agent %p : stun_bind_keepalive for pair %p res %d (%s).", agent, p, res, strerror (res)); if (res < 0) ++errors; diff --git a/agent/discovery.c b/agent/discovery.c index 68e8e6a..028ea6d 100644 --- a/agent/discovery.c +++ b/agent/discovery.c @@ -502,8 +502,9 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer) cand->component->id, NICE_COMPONENT_STATE_GATHERING); - res = stun_bind_start (&cand->stun_ctx, cand->socket, - &stun_server.s.addr, sizeof(stun_server.s)); + res = stun_bind_start (&cand->stun_ctx, cand->socket, + &stun_server.s.addr, sizeof(stun_server.s), + agent->compatibility); if (res == 0) { /* case: success, start waiting for the result */ g_get_current_time (&cand->next_tick); diff --git a/stun/bind.c b/stun/bind.c index 9d59380..9af4bfd 100644 --- a/stun/bind.c +++ b/stun/bind.c @@ -108,7 +108,7 @@ stun_bind_alloc (stun_bind_t **restrict context, int fd, int stun_bind_start (stun_bind_t **restrict context, int fd, const struct sockaddr *restrict srv, - socklen_t srvlen) + socklen_t srvlen, int compat) { stun_bind_t *ctx; @@ -117,7 +117,7 @@ int stun_bind_start (stun_bind_t **restrict context, int fd, return val; ctx = *context; - val = stun_finish (ctx->trans.msg.buf, &ctx->trans.msg.length); + val = stun_finish (ctx->trans.msg.buf, &ctx->trans.msg.length, compat); if (val) goto error; @@ -205,13 +205,13 @@ int stun_bind_process (stun_bind_t *restrict ctx, int stun_bind_run (int fd, const struct sockaddr *restrict srv, socklen_t srvlen, - struct sockaddr *restrict addr, socklen_t *addrlen) + struct sockaddr *restrict addr, socklen_t *addrlen, int compat) { stun_bind_t *ctx; uint8_t buf[STUN_MAXMSG]; ssize_t val; - val = stun_bind_start (&ctx, fd, srv, srvlen); + val = stun_bind_start (&ctx, fd, srv, srvlen, compat); if (val) return val; @@ -236,14 +236,14 @@ int stun_bind_run (int fd, int stun_bind_keepalive (int fd, const struct sockaddr *restrict srv, - socklen_t srvlen) + socklen_t srvlen, int compat) { uint8_t buf[28]; size_t len = sizeof (buf); int val; stun_init_indication (buf, STUN_BINDING); - val = stun_finish (buf, &len); + val = stun_finish (buf, &len, compat); assert (val == 0); (void)val; @@ -310,7 +310,7 @@ stun_conncheck_start (stun_bind_t **restrict context, int fd, } val = stun_finish_short (ctx->trans.msg.buf, &ctx->trans.msg.length, - username, compat == 1 ? NULL : password, NULL); + username, compat == 1 ? NULL : password, NULL, compat); if (val) goto error; @@ -339,7 +339,7 @@ struct stun_nested_s int stun_nested_start (stun_nested_t **restrict context, int fd, const struct sockaddr *restrict mapad, const struct sockaddr *restrict natad, - socklen_t adlen, uint32_t refresh) + socklen_t adlen, uint32_t refresh, int compat) { stun_nested_t *ctx; int val; @@ -366,7 +366,8 @@ int stun_nested_start (stun_nested_t **restrict context, int fd, goto error; val = stun_finish (ctx->bind->trans.msg.buf, - &ctx->bind->trans.msg.length); + &ctx->bind->trans.msg.length, + compat); if (val) goto error; diff --git a/stun/bind.h b/stun/bind.h index 8c37332..408fe98 100644 --- a/stun/bind.h +++ b/stun/bind.h @@ -71,7 +71,7 @@ extern "C" { */ int stun_bind_run (int fd, const struct sockaddr *restrict srv, socklen_t srvlen, - struct sockaddr *restrict addr, socklen_t *addrlen); + struct sockaddr *restrict addr, socklen_t *addrlen, int compat); /** * Starts STUN Binding discovery in non-blocking mode. @@ -85,7 +85,8 @@ int stun_bind_run (int fd, * @return 0 on success, a standard error value otherwise. */ int stun_bind_start (stun_bind_t **restrict context, int fd, - const struct sockaddr *restrict srv, socklen_t srvlen); + const struct sockaddr *restrict srv, socklen_t srvlen, + int compat); /** * Aborts a running STUN Binding discovery. @@ -157,7 +158,7 @@ int stun_bind_process (stun_bind_t *restrict context, * @return 0 on success, an error code from sendto() otherwise. */ int stun_bind_keepalive (int fd, const struct sockaddr *restrict srv, - socklen_t srvlen); + socklen_t srvlen, int compat); /** @@ -169,7 +170,7 @@ typedef struct stun_nested_s stun_nested_t; int stun_nested_start (stun_nested_t **restrict context, int fd, const struct sockaddr *restrict mapad, const struct sockaddr *restrict natad, - socklen_t adlen, uint32_t refresh); + socklen_t adlen, uint32_t refresh, int compat); int stun_nested_process (stun_nested_t *restrict ctx, const void *restrict buf, size_t len, diff --git a/stun/stun-ice.c b/stun/stun-ice.c index c0333a7..0f07cd9 100644 --- a/stun/stun-ice.c +++ b/stun/stun-ice.c @@ -52,7 +52,7 @@ static int stun_bind_error (uint8_t *buf, size_t *plen, const uint8_t *req, - stun_error_t code, const char *pass) + stun_error_t code, const char *pass, int compat) { size_t len = *plen; int val; @@ -64,7 +64,7 @@ stun_bind_error (uint8_t *buf, size_t *plen, const uint8_t *req, if (val) return val; - val = stun_finish_short (buf, &len, NULL, pass, NULL); + val = stun_finish_short (buf, &len, NULL, pass, NULL, compat); if (val) return val; @@ -89,7 +89,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen, int val, ret = 0; #define err( code ) \ - stun_bind_error (buf, &len, msg, code, pass); \ + stun_bind_error (buf, &len, msg, code, pass, compat); \ *plen = len *plen = 0; @@ -113,7 +113,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen, DBG (" Unknown mandatory attributes in message.\n"); val = stun_init_error_unknown (buf, len, msg); if (!val) - val = stun_finish_short (buf, &len, NULL, pass, NULL); + val = stun_finish_short (buf, &len, NULL, pass, NULL, compat); if (val) goto failure; @@ -143,7 +143,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen, if (val) { - stun_bind_error (buf, &len, msg, val, NULL); + stun_bind_error (buf, &len, msg, val, NULL, compat); *plen = len; return EPERM; } @@ -201,7 +201,7 @@ stun_conncheck_reply (uint8_t *restrict buf, size_t *restrict plen, } val = stun_finish_short (buf, &len, compat == 1 ? username : NULL, - compat == 1 ? NULL : pass, NULL); + compat == 1 ? NULL : pass, NULL, compat); if (val) goto failure; diff --git a/stun/stun-msg.h b/stun/stun-msg.h index 0449f4d..6d8d4d5 100644 --- a/stun/stun-msg.h +++ b/stun/stun-msg.h @@ -583,7 +583,7 @@ int stun_init_error_unknown (uint8_t *ans, size_t msize, const uint8_t *req); size_t stun_finish_long (uint8_t *msg, size_t *restrict plen, const char *realm, const char *username, const char *nonce, - const void *restrict key, size_t keylen); + const void *restrict key, size_t keylen, int compat); /** * Completes a STUN message structure before sending it, and @@ -600,7 +600,7 @@ stun_finish_long (uint8_t *msg, size_t *restrict plen, */ size_t stun_finish_short (uint8_t *msg, size_t *restrict plen, const char *username, const char *password, - const char *nonce); + const char *nonce, int compat); /** * Completes a STUN message structure before sending it. @@ -611,7 +611,7 @@ size_t stun_finish_short (uint8_t *msg, size_t *restrict plen, * * @return 0 on success, ENOBUFS on error. */ -size_t stun_finish (uint8_t *restrict msg, size_t *restrict plen); +size_t stun_finish (uint8_t *restrict msg, size_t *restrict plen, int compat); void *stun_append (uint8_t *msg, size_t msize, stun_attr_type_t type, diff --git a/stun/stunbdc.c b/stun/stunbdc.c index 04a80a8..a2d4c4b 100644 --- a/stun/stunbdc.c +++ b/stun/stunbdc.c @@ -98,7 +98,7 @@ static int run (int family, const char *hostname, const char *service) printaddr ("Server address", ptr->ai_addr, ptr->ai_addrlen); val = stun_bind_run (-1, ptr->ai_addr, ptr->ai_addrlen, - (struct sockaddr *)&addr, &addrlen); + (struct sockaddr *)&addr, &addrlen, 0); if (val) fprintf (stderr, "%s\n", strerror (val)); else diff --git a/stun/stund.c b/stun/stund.c index be89054..cc91a5f 100644 --- a/stun/stund.c +++ b/stun/stund.c @@ -235,7 +235,7 @@ static int dgram_process (int sock) } finish: - stun_finish (buf, &iov.iov_len); + stun_finish (buf, &iov.iov_len, 0); len = send_safe (sock, &mh); return (len < iov.iov_len) ? -1 : 0; diff --git a/stun/stunsend.c b/stun/stunsend.c index 18c8878..1d8929b 100644 --- a/stun/stunsend.c +++ b/stun/stunsend.c @@ -441,7 +441,7 @@ int stun_append_xor_addr (uint8_t *restrict msg, size_t msize, size_t stun_finish_long (uint8_t *msg, size_t *restrict plen, const char *realm, const char *username, const char *nonce, - const void *restrict key, size_t keylen) + const void *restrict key, size_t keylen, int compat) { size_t len = *plen; uint8_t *ptr; @@ -494,7 +494,7 @@ stun_finish_long (uint8_t *msg, size_t *restrict plen, } - if (0) { + if (compat != 1) { /* * NOTE: we always add a FINGERPRINT, even when it's not needed. * This is OK, as it is an optional attribute. It also makes my @@ -515,14 +515,14 @@ stun_finish_long (uint8_t *msg, size_t *restrict plen, size_t stun_finish_short (uint8_t *msg, size_t *restrict plen, const char *username, const char *restrict password, - const char *nonce) + const char *nonce, int compat) { return stun_finish_long (msg, plen, NULL, username, nonce, - password, password ? strlen (password) : 0); + password, password ? strlen (password) : 0, compat); } -size_t stun_finish (uint8_t *msg, size_t *restrict plen) +size_t stun_finish (uint8_t *msg, size_t *restrict plen, int compat) { - return stun_finish_short (msg, plen, NULL, NULL, NULL); + return stun_finish_short (msg, plen, NULL, NULL, NULL, compat); } diff --git a/stun/tests/test-bind.c b/stun/tests/test-bind.c index 16841b9..ed97996 100644 --- a/stun/tests/test-bind.c +++ b/stun/tests/test-bind.c @@ -98,7 +98,7 @@ static void bad_family (void) #endif val = stun_bind_run (-1, &addr, sizeof (addr), - &dummy, &(socklen_t){ sizeof (dummy) }); + &dummy, &(socklen_t){ sizeof (dummy) }, 0); assert (val != 0); } @@ -116,7 +116,7 @@ static void small_srv_addr (void) #endif val = stun_bind_run (-1, &addr, 1, - &dummy, &(socklen_t){ sizeof (dummy) }); + &dummy, &(socklen_t){ sizeof (dummy) }, 0); assert (val == EINVAL); } @@ -133,7 +133,7 @@ static void big_srv_addr (void) memset (buf, 0, sizeof (buf)); val = stun_bind_run (fd, (struct sockaddr *)buf, sizeof (buf), - &dummy, &(socklen_t){ sizeof (dummy) }); + &dummy, &(socklen_t){ sizeof (dummy) }, 0); assert (val == ENOBUFS); close (fd); } @@ -155,7 +155,7 @@ static void timeout (void) assert (val == 0); val = stun_bind_run (-1, (struct sockaddr *)&srv, srvlen, - &dummy, &(socklen_t){ sizeof (dummy) }); + &dummy, &(socklen_t){ sizeof (dummy) }, 0); assert (val == ETIMEDOUT); close (servfd); @@ -181,7 +181,7 @@ static void bad_responses (void) fd = socket (addr.ss_family, SOCK_DGRAM, 0); assert (fd != -1); - val = stun_bind_start (&ctx, fd, (struct sockaddr *)&addr, addrlen); + val = stun_bind_start (&ctx, fd, (struct sockaddr *)&addr, addrlen, 0); assert (val == 0); /* Send to/receive from our client instance only */ @@ -260,7 +260,7 @@ static void responses (void) assert (val == 0); /* Send error response */ - val = stun_bind_start (&ctx, fd, NULL, 0); + val = stun_bind_start (&ctx, fd, NULL, 0, 0); assert (val == 0); val = recv (servfd, buf, 1000, MSG_DONTWAIT); @@ -268,7 +268,7 @@ static void responses (void) stun_init_error (buf, sizeof (buf), buf, STUN_SERVER_ERROR); len = sizeof (buf); - val = stun_finish (buf, &len); + val = stun_finish (buf, &len, 0); assert (val == 0); val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen); @@ -278,7 +278,7 @@ static void responses (void) assert (val == ECONNREFUSED); /* Send response with an unknown attribute */ - val = stun_bind_start (&ctx, fd, NULL, 0); + val = stun_bind_start (&ctx, fd, NULL, 0, 0); assert (val == 0); val = recv (servfd, buf, 1000, MSG_DONTWAIT); @@ -289,7 +289,7 @@ static void responses (void) "This is an unknown attribute!"); assert (val == 0); len = sizeof (buf); - val = stun_finish (buf, &len); + val = stun_finish (buf, &len, 0); assert (val == 0); val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen); @@ -300,7 +300,7 @@ static void responses (void) assert (val == EPROTO); /* Send response with a no mapped address at all */ - val = stun_bind_start (&ctx, fd, NULL, 0); + val = stun_bind_start (&ctx, fd, NULL, 0, 0); assert (val == 0); val = recv (servfd, buf, 1000, MSG_DONTWAIT); @@ -308,7 +308,7 @@ static void responses (void) stun_init_response (buf, sizeof (buf), buf); len = sizeof (buf); - val = stun_finish (buf, &len); + val = stun_finish (buf, &len, 0); assert (val == 0); val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen); @@ -319,7 +319,7 @@ static void responses (void) assert (val == ENOENT); /* Send old-style response */ - val = stun_bind_start (&ctx, fd, NULL, 0); + val = stun_bind_start (&ctx, fd, NULL, 0, 0); assert (val == 0); val = recv (servfd, buf, 1000, MSG_DONTWAIT); @@ -330,7 +330,7 @@ static void responses (void) (struct sockaddr *)&addr, addrlen); assert (val == 0); len = sizeof (buf); - val = stun_finish (buf, &len); + val = stun_finish (buf, &len, 0); assert (val == 0); val = getsockname (servfd, (struct sockaddr *)&addr, &addrlen); @@ -366,12 +366,12 @@ static void keepalive (void) assert (fd != -1); /* Keep alive sending smoke test */ - val = stun_bind_keepalive (fd, (struct sockaddr *)&addr, addrlen); + val = stun_bind_keepalive (fd, (struct sockaddr *)&addr, addrlen, 0); assert (val == 0); /* Wrong address family test */ addr.ss_family = addr.ss_family == AF_INET ? AF_INET6 : AF_INET; - val = stun_bind_keepalive (fd, (struct sockaddr *)&addr, addrlen); + val = stun_bind_keepalive (fd, (struct sockaddr *)&addr, addrlen, 0); assert (val != 0); /* End */ diff --git a/stun/tests/test-conncheck.c b/stun/tests/test-conncheck.c index 00523d0..3adee92 100644 --- a/stun/tests/test-conncheck.c +++ b/stun/tests/test-conncheck.c @@ -77,7 +77,7 @@ int main (void) stun_init_request (req, STUN_BINDING); stun_init_response (req, sizeof (req), req); len = sizeof (req); - val = stun_finish (req, &len); + val = stun_finish (req, &len, 0); assert (val == 0); len = sizeof (resp); @@ -89,7 +89,7 @@ int main (void) /* Incorrect message method */ stun_init_request (req, 0x666); len = sizeof (req); - val = stun_finish_short (req, &len, username, pass, NULL); + val = stun_finish_short (req, &len, username, pass, NULL, 0); assert (val == 0); len = sizeof (resp); @@ -104,7 +104,7 @@ int main (void) "The evil unknown attribute!"); assert (val == 0); len = sizeof (req); - val = stun_finish (req, &len); + val = stun_finish (req, &len, 0); assert (val == 0); len = sizeof (resp); @@ -116,7 +116,7 @@ int main (void) /* Unauthenticated message */ stun_init_request (req, STUN_BINDING); len = sizeof (req); - val = stun_finish (req, &len); + val = stun_finish (req, &len, 0); assert (val == 0); len = sizeof (resp); @@ -130,7 +130,7 @@ int main (void) /* No username */ stun_init_request (req, STUN_BINDING); len = sizeof (req); - val = stun_finish_short (req, &len, NULL, pass, NULL); + val = stun_finish_short (req, &len, NULL, pass, NULL, 0); assert (val == 0); len = sizeof (resp); @@ -150,7 +150,7 @@ int main (void) val = stun_append_flag (req, sizeof (req), STUN_USE_CANDIDATE); assert (val == 0); len = sizeof (req); - val = stun_finish_short (req, &len, username, pass, NULL); + val = stun_finish_short (req, &len, username, pass, NULL, 0); assert (val == 0); len = sizeof (resp); @@ -195,7 +195,7 @@ int main (void) /* Bad CRC32 */ stun_init_request (req, STUN_BINDING); len = sizeof (req); - val = stun_finish_short (req, &len, ufrag, pass, NULL); + val = stun_finish_short (req, &len, ufrag, pass, NULL, 0); assert (val == 0); ((uint8_t *)stun_find (req, STUN_FINGERPRINT, &alen))[0] ^= 1; @@ -210,7 +210,7 @@ int main (void) val = stun_append64 (req, sizeof (req), STUN_ICE_CONTROLLING, tie + 1); assert (val == 0); len = sizeof (req); - val = stun_finish_short (req, &len, username, pass, NULL); + val = stun_finish_short (req, &len, username, pass, NULL, 0); assert (val == 0); len = sizeof (resp); @@ -229,7 +229,7 @@ int main (void) val = stun_append64 (req, sizeof (req), STUN_ICE_CONTROLLED, tie - 1); assert (val == 0); len = sizeof (req); - val = stun_finish_short (req, &len, username, pass, NULL); + val = stun_finish_short (req, &len, username, pass, NULL, 0); assert (val == 0); len = sizeof (resp); diff --git a/stun/tests/test-format.c b/stun/tests/test-format.c index 2e017b9..4a29d65 100644 --- a/stun/tests/test-format.c +++ b/stun/tests/test-format.c @@ -82,14 +82,14 @@ finish_check (uint8_t *msg) size_t len = sizeof (stun_msg_t); memcpy (mshort, msg, sizeof (mshort)); - if (stun_finish (msg, &len)) + if (stun_finish (msg, &len, 0)) fatal ("Cannot finish message"); dynamic_check (msg, len); len = sizeof (mshort); if (stun_verify_password (mshort, "toto") != ENOENT) fatal ("Missing HMAC test failed"); - if (stun_finish_short (mshort, &len, "ABCDE", "admin", "ABC")) + if (stun_finish_short (mshort, &len, "ABCDE", "admin", "ABC", 0)) fatal ("Cannot finish message with short-term creds"); dynamic_check (mshort, len); if (stun_verify_password (mshort, "admin") != 0) @@ -197,16 +197,16 @@ int main (void) sizeof (addr)) != ENOBUFS) fatal ("Address overflow test failed"); len = sizeof (msg); - if (stun_finish (msg, &len) != ENOBUFS) + if (stun_finish (msg, &len, 0) != ENOBUFS) fatal ("Fingerprint overflow test failed"); len = sizeof (msg); - if (stun_finish_short (msg, &len, NULL, "secret", NULL) != ENOBUFS) + if (stun_finish_short (msg, &len, NULL, "secret", NULL, 0) != ENOBUFS) fatal ("Message integrity overflow test failed"); len = sizeof (msg); - if (stun_finish_short (msg, &len, "login", "secret", NULL) != ENOBUFS) + if (stun_finish_short (msg, &len, "login", "secret", NULL, 0) != ENOBUFS) fatal ("Username overflow test failed"); len = sizeof (msg); - if (stun_finish_short (msg, &len, NULL, "secret", "foobar") != ENOBUFS) + if (stun_finish_short (msg, &len, NULL, "secret", "foobar", 0) != ENOBUFS) fatal ("Nonce overflow test failed"); /* Address attributes tests */ |