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

Unified Diff: content/browser/renderer_host/p2p_socket_host.cc

Issue 6800023: Security restrictions for P2P UDP Sockets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/p2p_socket_host.cc
diff --git a/content/browser/renderer_host/p2p_socket_host.cc b/content/browser/renderer_host/p2p_socket_host.cc
index c1e8849e97f2634ea001626426af4c7e2c1d3707..38e2684388a5dcf15bd1d71d7e21e8492b186d41 100644
--- a/content/browser/renderer_host/p2p_socket_host.cc
+++ b/content/browser/renderer_host/p2p_socket_host.cc
@@ -4,26 +4,78 @@
#include "content/browser/renderer_host/p2p_socket_host.h"
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include <winsock2.h> // for htonl
+#else
+#include <arpa/inet.h>
+#endif
+
#include "content/browser/renderer_host/p2p_socket_host_udp.h"
-P2PSocketHost::P2PSocketHost(P2PSocketsHost* host, int routing_id, int id)
- : host_(host), routing_id_(routing_id), id_(id) {
+namespace {
+const int kStunHeaderSize = 20;
+const uint16 kStunBindingRequest = 0x0001;
+const uint16 kStunBindingResponse = 0x0102;
+const uint16 kStunBindingError = 0x0111;
+const uint32 kStunMagicCookie = 0x2112A442;
+} // namespace
+
+P2PSocketHost::P2PSocketHost(IPC::Message::Sender* message_sender,
+ int routing_id, int id)
+ : message_sender_(message_sender), routing_id_(routing_id), id_(id) {
}
P2PSocketHost::~P2PSocketHost() { }
+// Verifies that the packet |data| has a valid STUN header.
+P2PSocketHost::StunPacketType P2PSocketHost::GetStunPacketType(
+ const char* data, int data_size) {
+
+ if (data_size < kStunHeaderSize)
+ return STUN_INVALID_PACKET;
+
+ // TODO(sergeyu): Fix libjingle to format STUN message according to
+ // RFC5389 and validate STUN magic cookie here.
+ //
+ // uint32 cookie = ntohl(*reinterpret_cast<const uint32*>(data + 4));
+ // if (cookie != kStunMagicCookie)
+ // return STUN_INVALID_PACKET;
+
+ uint16 type = ntohs(*reinterpret_cast<const uint16*>(data));
+
+ uint16 length = ntohs(*reinterpret_cast<const uint16*>(data + 2));
+ if (length != data_size - kStunHeaderSize)
+ return STUN_INVALID_PACKET;
+
+ switch (type) {
+ case kStunBindingRequest:
+ return STUN_BINDING_REQUEST;
+ case kStunBindingResponse:
+ return STUN_BINDING_RESPONSE;
+ case kStunBindingError:
+ return STUN_BINDING_ERROR;
+ default:
+ return STUN_UNKNOWN_TYPE;
+ }
+}
+
// static
P2PSocketHost* P2PSocketHost::Create(
- P2PSocketsHost* host, int routing_id, int id, P2PSocketType type) {
+ IPC::Message::Sender* message_sender, int routing_id, int id,
+ P2PSocketType type) {
switch (type) {
case P2P_SOCKET_UDP:
- return new P2PSocketHostUdp(host, routing_id, id);
+ return new P2PSocketHostUdp(message_sender, routing_id, id);
case P2P_SOCKET_TCP_SERVER:
// TODO(sergeyu): Implement TCP sockets support.
+ NOTIMPLEMENTED();
return NULL;
case P2P_SOCKET_TCP_CLIENT:
+ NOTIMPLEMENTED();
return NULL;
}

Powered by Google App Engine
This is Rietveld 408576698