Bug 1304920: remove fingerprint attribute from plain binding requests. r=bwc draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Thu, 22 Sep 2016 17:56:29 -0700
changeset 431150 976af858b54a6ddda23b19310352359659260b71
parent 431012 1561c917ee27c3ea04bd69467e5b8c7c08102f2a
child 535369 8840117402aebb0efb545dbeb35c7b1e4ac51a4a
push id34008
push userdrno@ohlmeier.org
push dateFri, 28 Oct 2016 20:57:03 +0000
reviewersbwc
bugs1304920
milestone52.0a1
Bug 1304920: remove fingerprint attribute from plain binding requests. r=bwc MozReview-Commit-ID: KpqQfHzv7zn
media/mtransport/third_party/nICEr/src/stun/nr_socket_buffered_stun.c
media/mtransport/third_party/nICEr/src/stun/stun_build.c
media/mtransport/third_party/nICEr/src/stun/stun_build.h
--- a/media/mtransport/third_party/nICEr/src/stun/nr_socket_buffered_stun.c
+++ b/media/mtransport/third_party/nICEr/src/stun/nr_socket_buffered_stun.c
@@ -280,61 +280,60 @@ static int nr_socket_buffered_stun_recvf
   nr_socket_buffered_stun *sock = (nr_socket_buffered_stun *)obj;
   nr_frame_header *frame = (nr_frame_header *)sock->buffer;
   size_t skip_hdr_size = (sock->framing_type == ICE_TCP_FRAMING) ? sizeof(nr_frame_header) : 0;
 
   if (sock->read_state == NR_ICE_SOCKET_READ_FAILED) {
     ABORT(R_FAILED);
   }
 
-reread:
-  /* Read all the expected bytes */
-  assert(sock->bytes_needed <= sock->buffer_size - sock->bytes_read);
+  while (sock->bytes_needed) {
+    /* Read all the expected bytes */
+    assert(sock->bytes_needed <= sock->buffer_size - sock->bytes_read);
 
-  if(r=nr_socket_read(sock->inner,
-                      sock->buffer + sock->bytes_read,
-                      sock->bytes_needed, &bytes_read, 0))
-    ABORT(r);
+    if(r=nr_socket_read(sock->inner,
+                        sock->buffer + sock->bytes_read,
+                        sock->bytes_needed, &bytes_read, 0))
+      ABORT(r);
+
+    assert(bytes_read <= sock->bytes_needed);
+    sock->bytes_needed -= bytes_read;
+    sock->bytes_read += bytes_read;
+
+    /* Unfinished */
+    if (sock->bytes_needed)
+      ABORT(R_WOULDBLOCK);
 
-  assert(bytes_read <= sock->bytes_needed);
-  sock->bytes_needed -= bytes_read;
-  sock->bytes_read += bytes_read;
+    /* No more bytes expected */
+    if (sock->read_state == NR_ICE_SOCKET_READ_NONE) {
+      size_t remaining_length;
+      if (sock->framing_type == ICE_TCP_FRAMING) {
+        if (sock->bytes_read < sizeof(nr_frame_header))
+          ABORT(R_BAD_DATA);
+        remaining_length = ntohs(frame->frame_length);
+      } else {
+        int tmp_length;
 
-  /* Unfinished */
-  if (sock->bytes_needed)
-    ABORT(R_WOULDBLOCK);
+        /* Parse the header */
+        if (r = nr_stun_message_length(sock->buffer, sock->bytes_read, &tmp_length))
+          ABORT(r);
+        assert(tmp_length >= 0);
+        if (tmp_length < 0)
+          ABORT(R_BAD_DATA);
+        remaining_length = tmp_length;
 
-  /* No more bytes expected */
-  if (sock->read_state == NR_ICE_SOCKET_READ_NONE) {
-    size_t remaining_length;
-    if (sock->framing_type == ICE_TCP_FRAMING) {
-      if (sock->bytes_read < sizeof(nr_frame_header))
+      }
+      /* Check to see if we have enough room */
+      if ((sock->buffer_size - sock->bytes_read) < remaining_length)
         ABORT(R_BAD_DATA);
-      remaining_length = ntohs(frame->frame_length);
-    } else {
-      int tmp_length;
 
-      /* Parse the header */
-      if (r = nr_stun_message_length(sock->buffer, sock->bytes_read, &tmp_length))
-        ABORT(r);
-      assert(tmp_length >= 0);
-      if (tmp_length < 0)
-        ABORT(R_BAD_DATA);
-      remaining_length = tmp_length;
-
+      sock->read_state = NR_ICE_SOCKET_READ_HDR;
+      /* Set ourselves up to read the rest of the data */
+      sock->bytes_needed = remaining_length;
     }
-    /* Check to see if we have enough room */
-    if ((sock->buffer_size - sock->bytes_read) < remaining_length)
-      ABORT(R_BAD_DATA);
-
-    /* Set ourselves up to read the rest of the data */
-    sock->bytes_needed = remaining_length;
-
-    sock->read_state = NR_ICE_SOCKET_READ_HDR;
-    goto reread;
   }
 
   assert(skip_hdr_size <= sock->bytes_read);
   if (skip_hdr_size > sock->bytes_read)
     ABORT(R_BAD_DATA);
   sock->bytes_read -= skip_hdr_size;
 
   if (maxlen < sock->bytes_read)
--- a/media/mtransport/third_party/nICEr/src/stun/stun_build.c
+++ b/media/mtransport/third_party/nICEr/src/stun/stun_build.c
@@ -70,21 +70,21 @@ nr_stun_form_request_or_indication(int m
        ABORT(r);
 
    req->header.type = msg_type;
 
    nr_crypto_random_bytes((UCHAR*)&req->header.id,sizeof(req->header.id));
 
    switch (mode) {
    default:
-       req->header.magic_cookie = NR_STUN_MAGIC_COOKIE;
-
        if ((r=nr_stun_message_add_fingerprint_attribute(req)))
            ABORT(r);
-
+       /* fall through */
+   case NR_STUN_MODE_STUN_NO_AUTH:
+       req->header.magic_cookie = NR_STUN_MAGIC_COOKIE;
        break;
 
 #ifdef USE_STUND_0_96
    case NR_STUN_MODE_STUND_0_96:
        req->header.magic_cookie = NR_STUN_MAGIC_COOKIE2;
 
        /* actually, stund 0.96 just ignores the fingerprint
         * attribute, but don't bother to send it */
@@ -159,17 +159,17 @@ nr_stun_build_req_st_auth(nr_stun_client
 }
 
 int
 nr_stun_build_req_no_auth(nr_stun_client_stun_binding_request_params *params, nr_stun_message **msg)
 {
    int r,_status;
    nr_stun_message *req = 0;
 
-   if ((r=nr_stun_form_request_or_indication(NR_STUN_MODE_STUN, NR_STUN_MSG_BINDING_REQUEST, &req)))
+   if ((r=nr_stun_form_request_or_indication(NR_STUN_MODE_STUN_NO_AUTH, NR_STUN_MSG_BINDING_REQUEST, &req)))
        ABORT(r);
 
    *msg = req;
 
    _status=0;
  abort:
    if (_status) nr_stun_message_destroy(&req);
    return _status;
--- a/media/mtransport/third_party/nICEr/src/stun/stun_build.h
+++ b/media/mtransport/third_party/nICEr/src/stun/stun_build.h
@@ -35,16 +35,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 #define _stun_build_h
 
 #include "stun.h"
 
 #define NR_STUN_MODE_STUN               1
 #ifdef USE_STUND_0_96
 #define NR_STUN_MODE_STUND_0_96         2    /* backwards compatibility mode */
 #endif /* USE_STUND_0_96 */
+#define NR_STUN_MODE_STUN_NO_AUTH       3
 int nr_stun_form_request_or_indication(int mode, int msg_type, nr_stun_message **msg);
 
 typedef struct nr_stun_client_stun_binding_request_params_ {
     char *username;
     Data *password;
     char *nonce;
     char *realm;
 } nr_stun_client_stun_binding_request_params;