Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: content/browser/renderer_host/p2p/socket_host.cc

Issue 450463002: Update webrtc&libjingle 6774:6825. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/p2p/socket_host.h" 5 #include "content/browser/renderer_host/p2p/socket_host.h"
6 6
7 #include "base/sys_byteorder.h" 7 #include "base/sys_byteorder.h"
8 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" 8 #include "content/browser/renderer_host/p2p/socket_host_tcp.h"
9 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" 9 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h"
10 #include "content/browser/renderer_host/p2p/socket_host_udp.h" 10 #include "content/browser/renderer_host/p2p/socket_host_udp.h"
11 #include "content/browser/renderer_host/render_process_host_impl.h" 11 #include "content/browser/renderer_host/render_process_host_impl.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "crypto/hmac.h" 13 #include "crypto/hmac.h"
14 #include "third_party/libjingle/source/talk/base/asyncpacketsocket.h"
15 #include "third_party/libjingle/source/talk/base/byteorder.h"
16 #include "third_party/libjingle/source/talk/base/messagedigest.h"
17 #include "third_party/libjingle/source/talk/p2p/base/stun.h" 14 #include "third_party/libjingle/source/talk/p2p/base/stun.h"
15 #include "third_party/webrtc/base/asyncpacketsocket.h"
16 #include "third_party/webrtc/base/byteorder.h"
17 #include "third_party/webrtc/base/messagedigest.h"
18 18
19 namespace { 19 namespace {
20 20
21 const uint32 kStunMagicCookie = 0x2112A442; 21 const uint32 kStunMagicCookie = 0x2112A442;
22 const int kMinRtpHdrLen = 12; 22 const int kMinRtpHdrLen = 12;
23 const int kRtpExtnHdrLen = 4; 23 const int kRtpExtnHdrLen = 4;
24 const int kDtlsRecordHeaderLen = 13; 24 const int kDtlsRecordHeaderLen = 13;
25 const int kTurnChannelHdrLen = 4; 25 const int kTurnChannelHdrLen = 4;
26 const int kAbsSendTimeExtnLen = 3; 26 const int kAbsSendTimeExtnLen = 3;
27 const int kOneByteHdrLen = 1; 27 const int kOneByteHdrLen = 1;
(...skipping 13 matching lines...) Expand all
41 const uint8* u = reinterpret_cast<const uint8*>(data); 41 const uint8* u = reinterpret_cast<const uint8*>(data);
42 return (len >= kDtlsRecordHeaderLen && (u[0] > 19 && u[0] < 64)); 42 return (len >= kDtlsRecordHeaderLen && (u[0] > 19 && u[0] < 64));
43 } 43 }
44 44
45 bool IsRtcpPacket(const char* data) { 45 bool IsRtcpPacket(const char* data) {
46 int type = (static_cast<uint8>(data[1]) & 0x7F); 46 int type = (static_cast<uint8>(data[1]) & 0x7F);
47 return (type >= 64 && type < 96); 47 return (type >= 64 && type < 96);
48 } 48 }
49 49
50 bool IsTurnSendIndicationPacket(const char* data) { 50 bool IsTurnSendIndicationPacket(const char* data) {
51 uint16 type = talk_base::GetBE16(data); 51 uint16 type = rtc::GetBE16(data);
52 return (type == cricket::TURN_SEND_INDICATION); 52 return (type == cricket::TURN_SEND_INDICATION);
53 } 53 }
54 54
55 bool IsRtpPacket(const char* data, int len) { 55 bool IsRtpPacket(const char* data, int len) {
56 return ((*data & 0xC0) == 0x80); 56 return ((*data & 0xC0) == 0x80);
57 } 57 }
58 58
59 // Verifies rtp header and message length. 59 // Verifies rtp header and message length.
60 bool ValidateRtpHeader(const char* rtp, int length, size_t* header_length) { 60 bool ValidateRtpHeader(const char* rtp, int length, size_t* header_length) {
61 if (header_length) 61 if (header_length)
(...skipping 11 matching lines...) Expand all
73 if (header_length) 73 if (header_length)
74 *header_length = rtp_hdr_len_without_extn; 74 *header_length = rtp_hdr_len_without_extn;
75 75
76 return true; 76 return true;
77 } 77 }
78 78
79 rtp += rtp_hdr_len_without_extn; 79 rtp += rtp_hdr_len_without_extn;
80 80
81 // Getting extension profile length. 81 // Getting extension profile length.
82 // Length is in 32 bit words. 82 // Length is in 32 bit words.
83 uint16 extn_length = talk_base::GetBE16(rtp + 2) * 4; 83 uint16 extn_length = rtc::GetBE16(rtp + 2) * 4;
84 84
85 // Verify input length against total header size. 85 // Verify input length against total header size.
86 if (rtp_hdr_len_without_extn + kRtpExtnHdrLen + extn_length > length) { 86 if (rtp_hdr_len_without_extn + kRtpExtnHdrLen + extn_length > length) {
87 return false; 87 return false;
88 } 88 }
89 89
90 if (header_length) 90 if (header_length)
91 *header_length = rtp_hdr_len_without_extn + kRtpExtnHdrLen + extn_length; 91 *header_length = rtp_hdr_len_without_extn + kRtpExtnHdrLen + extn_length;
92 return true; 92 return true;
93 } 93 }
(...skipping 28 matching lines...) Expand all
122 } 122 }
123 // TODO(mallinath) - Add SetBE24 to byteorder.h in libjingle. 123 // TODO(mallinath) - Add SetBE24 to byteorder.h in libjingle.
124 extn_data[0] = static_cast<uint8>(now_second >> 16); 124 extn_data[0] = static_cast<uint8>(now_second >> 16);
125 extn_data[1] = static_cast<uint8>(now_second >> 8); 125 extn_data[1] = static_cast<uint8>(now_second >> 8);
126 extn_data[2] = static_cast<uint8>(now_second); 126 extn_data[2] = static_cast<uint8>(now_second);
127 } 127 }
128 128
129 // Assumes |len| is actual packet length + tag length. Updates HMAC at end of 129 // Assumes |len| is actual packet length + tag length. Updates HMAC at end of
130 // the RTP packet. 130 // the RTP packet.
131 void UpdateRtpAuthTag(char* rtp, int len, 131 void UpdateRtpAuthTag(char* rtp, int len,
132 const talk_base::PacketOptions& options) { 132 const rtc::PacketOptions& options) {
133 // If there is no key, return. 133 // If there is no key, return.
134 if (options.packet_time_params.srtp_auth_key.empty()) 134 if (options.packet_time_params.srtp_auth_key.empty())
135 return; 135 return;
136 136
137 size_t tag_length = options.packet_time_params.srtp_auth_tag_len; 137 size_t tag_length = options.packet_time_params.srtp_auth_tag_len;
138 char* auth_tag = rtp + (len - tag_length); 138 char* auth_tag = rtp + (len - tag_length);
139 139
140 // We should have a fake HMAC value @ auth_tag. 140 // We should have a fake HMAC value @ auth_tag.
141 DCHECK_EQ(0, memcmp(auth_tag, kFakeAuthTag, tag_length)); 141 DCHECK_EQ(0, memcmp(auth_tag, kFakeAuthTag, tag_length));
142 142
(...skipping 26 matching lines...) Expand all
169 memcpy(auth_tag, output, tag_length); 169 memcpy(auth_tag, output, tag_length);
170 } 170 }
171 171
172 } // namespace 172 } // namespace
173 173
174 namespace content { 174 namespace content {
175 175
176 namespace packet_processing_helpers { 176 namespace packet_processing_helpers {
177 177
178 bool ApplyPacketOptions(char* data, int length, 178 bool ApplyPacketOptions(char* data, int length,
179 const talk_base::PacketOptions& options, 179 const rtc::PacketOptions& options,
180 uint32 abs_send_time) { 180 uint32 abs_send_time) {
181 DCHECK(data != NULL); 181 DCHECK(data != NULL);
182 DCHECK(length > 0); 182 DCHECK(length > 0);
183 // if there is no valid |rtp_sendtime_extension_id| and |srtp_auth_key| in 183 // if there is no valid |rtp_sendtime_extension_id| and |srtp_auth_key| in
184 // PacketOptions, nothing to be updated in this packet. 184 // PacketOptions, nothing to be updated in this packet.
185 if (options.packet_time_params.rtp_sendtime_extension_id == -1 && 185 if (options.packet_time_params.rtp_sendtime_extension_id == -1 &&
186 options.packet_time_params.srtp_auth_key.empty()) { 186 options.packet_time_params.srtp_auth_key.empty()) {
187 return true; 187 return true;
188 } 188 }
189 189
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 232 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
233 // | | 233 // | |
234 // / Application Data / 234 // / Application Data /
235 // / / 235 // / /
236 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 236 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237 if (length < kTurnChannelHdrLen) { 237 if (length < kTurnChannelHdrLen) {
238 return false; 238 return false;
239 } 239 }
240 240
241 rtp_begin = kTurnChannelHdrLen; 241 rtp_begin = kTurnChannelHdrLen;
242 rtp_length = talk_base::GetBE16(&packet[2]); 242 rtp_length = rtc::GetBE16(&packet[2]);
243 if (length < rtp_length + kTurnChannelHdrLen) { 243 if (length < rtp_length + kTurnChannelHdrLen) {
244 return false; 244 return false;
245 } 245 }
246 } else if (IsTurnSendIndicationPacket(packet)) { 246 } else if (IsTurnSendIndicationPacket(packet)) {
247 if (length <= P2PSocketHost::kStunHeaderSize) { 247 if (length <= P2PSocketHost::kStunHeaderSize) {
248 // Message must be greater than 20 bytes, if it's carrying any payload. 248 // Message must be greater than 20 bytes, if it's carrying any payload.
249 return false; 249 return false;
250 } 250 }
251 // Validate STUN message length. 251 // Validate STUN message length.
252 int stun_msg_len = talk_base::GetBE16(&packet[2]); 252 int stun_msg_len = rtc::GetBE16(&packet[2]);
253 if (stun_msg_len + P2PSocketHost::kStunHeaderSize != length) { 253 if (stun_msg_len + P2PSocketHost::kStunHeaderSize != length) {
254 return false; 254 return false;
255 } 255 }
256 256
257 // First skip mandatory stun header which is of 20 bytes. 257 // First skip mandatory stun header which is of 20 bytes.
258 rtp_begin = P2PSocketHost::kStunHeaderSize; 258 rtp_begin = P2PSocketHost::kStunHeaderSize;
259 // Loop through STUN attributes until we find STUN DATA attribute. 259 // Loop through STUN attributes until we find STUN DATA attribute.
260 const char* start = packet + rtp_begin; 260 const char* start = packet + rtp_begin;
261 bool data_attr_present = false; 261 bool data_attr_present = false;
262 while ((packet + rtp_begin) - start < stun_msg_len) { 262 while ((packet + rtp_begin) - start < stun_msg_len) {
263 // Keep reading STUN attributes until we hit DATA attribute. 263 // Keep reading STUN attributes until we hit DATA attribute.
264 // Attribute will be a TLV structure. 264 // Attribute will be a TLV structure.
265 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 265 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
266 // | Type | Length | 266 // | Type | Length |
267 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 267 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
268 // | Value (variable) .... 268 // | Value (variable) ....
269 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 269 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
270 // The value in the length field MUST contain the length of the Value 270 // The value in the length field MUST contain the length of the Value
271 // part of the attribute, prior to padding, measured in bytes. Since 271 // part of the attribute, prior to padding, measured in bytes. Since
272 // STUN aligns attributes on 32-bit boundaries, attributes whose content 272 // STUN aligns attributes on 32-bit boundaries, attributes whose content
273 // is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of 273 // is not a multiple of 4 bytes are padded with 1, 2, or 3 bytes of
274 // padding so that its value contains a multiple of 4 bytes. The 274 // padding so that its value contains a multiple of 4 bytes. The
275 // padding bits are ignored, and may be any value. 275 // padding bits are ignored, and may be any value.
276 uint16 attr_type, attr_length; 276 uint16 attr_type, attr_length;
277 // Getting attribute type and length. 277 // Getting attribute type and length.
278 attr_type = talk_base::GetBE16(&packet[rtp_begin]); 278 attr_type = rtc::GetBE16(&packet[rtp_begin]);
279 attr_length = talk_base::GetBE16( 279 attr_length = rtc::GetBE16(
280 &packet[rtp_begin + sizeof(attr_type)]); 280 &packet[rtp_begin + sizeof(attr_type)]);
281 // Checking for bogus attribute length. 281 // Checking for bogus attribute length.
282 if (length < attr_length + rtp_begin) { 282 if (length < attr_length + rtp_begin) {
283 return false; 283 return false;
284 } 284 }
285 285
286 if (attr_type != cricket::STUN_ATTR_DATA) { 286 if (attr_type != cricket::STUN_ATTR_DATA) {
287 rtp_begin += sizeof(attr_type) + sizeof(attr_length) + attr_length; 287 rtp_begin += sizeof(attr_type) + sizeof(attr_length) + attr_length;
288 if ((attr_length % 4) != 0) { 288 if ((attr_length % 4) != 0) {
289 rtp_begin += (4 - (attr_length % 4)); 289 rtp_begin += (4 - (attr_length % 4));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (!(rtp[0] & 0x10)) { 346 if (!(rtp[0] & 0x10)) {
347 return true; 347 return true;
348 } 348 }
349 349
350 int cc_count = rtp[0] & 0x0F; 350 int cc_count = rtp[0] & 0x0F;
351 int rtp_hdr_len_without_extn = kMinRtpHdrLen + 4 * cc_count; 351 int rtp_hdr_len_without_extn = kMinRtpHdrLen + 4 * cc_count;
352 352
353 rtp += rtp_hdr_len_without_extn; 353 rtp += rtp_hdr_len_without_extn;
354 354
355 // Getting extension profile ID and length. 355 // Getting extension profile ID and length.
356 uint16 profile_id = talk_base::GetBE16(rtp); 356 uint16 profile_id = rtc::GetBE16(rtp);
357 // Length is in 32 bit words. 357 // Length is in 32 bit words.
358 uint16 extn_length = talk_base::GetBE16(rtp + 2) * 4; 358 uint16 extn_length = rtc::GetBE16(rtp + 2) * 4;
359 359
360 rtp += kRtpExtnHdrLen; // Moving past extn header. 360 rtp += kRtpExtnHdrLen; // Moving past extn header.
361 361
362 bool found = false; 362 bool found = false;
363 // WebRTC is using one byte header extension. 363 // WebRTC is using one byte header extension.
364 // TODO(mallinath) - Handle two byte header extension. 364 // TODO(mallinath) - Handle two byte header extension.
365 if (profile_id == 0xBEDE) { // OneByte extension header 365 if (profile_id == 0xBEDE) { // OneByte extension header
366 // 0 366 // 0
367 // 0 1 2 3 4 5 6 7 367 // 0 1 2 3 4 5 6 7
368 // +-+-+-+-+-+-+-+-+ 368 // +-+-+-+-+-+-+-+-+
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 BrowserThread::PostTask(BrowserThread::UI, 577 BrowserThread::PostTask(BrowserThread::UI,
578 FROM_HERE, 578 FROM_HERE,
579 base::Bind(packet_dump_callback_, 579 base::Bind(packet_dump_callback_,
580 Passed(&packet_header), 580 Passed(&packet_header),
581 header_length, 581 header_length,
582 packet_length, 582 packet_length,
583 incoming)); 583 incoming));
584 } 584 }
585 585
586 } // namespace content 586 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/p2p/socket_host.h ('k') | content/browser/renderer_host/p2p/socket_host_tcp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698