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

Side by Side Diff: chrome/browser/chromeos/web_socket_proxy.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed bugs + added apitest + rebased Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "web_socket_proxy.h" 5 #include "web_socket_proxy.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 12 matching lines...) Expand all
23 #include <sys/types.h> 23 #include <sys/types.h>
24 #include <sys/wait.h> 24 #include <sys/wait.h>
25 25
26 #include "base/base64.h" 26 #include "base/base64.h"
27 #include "base/basictypes.h" 27 #include "base/basictypes.h"
28 #include "base/logging.h" 28 #include "base/logging.h"
29 #include "base/md5.h" 29 #include "base/md5.h"
30 #include "base/memory/scoped_ptr.h" 30 #include "base/memory/scoped_ptr.h"
31 #include "base/string_number_conversions.h" 31 #include "base/string_number_conversions.h"
32 #include "base/string_util.h" 32 #include "base/string_util.h"
33 #include "chrome/browser/internal_auth.h"
33 #include "content/browser/browser_thread.h" 34 #include "content/browser/browser_thread.h"
34 #include "content/common/notification_service.h" 35 #include "content/common/notification_service.h"
35 #include "content/common/notification_type.h" 36 #include "content/common/notification_type.h"
36 // TODO(dilmah): enable this once webSocketProxyPrivate.getToken is wired.
37 #if 0
38 #include "chrome/browser/internal_auth.h"
39 #endif
40 #include "third_party/libevent/evdns.h" 37 #include "third_party/libevent/evdns.h"
41 #include "third_party/libevent/event.h" 38 #include "third_party/libevent/event.h"
42 39
43 namespace chromeos { 40 namespace chromeos {
44 41
45 namespace { 42 namespace {
46 43
47 const uint8 kCRLF[] = "\r\n"; 44 const uint8 kCRLF[] = "\r\n";
48 const uint8 kCRLFCRLF[] = "\r\n\r\n"; 45 const uint8 kCRLFCRLF[] = "\r\n\r\n";
49 46
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 *result *= 10; 95 *result *= 10;
99 int digit = s[i] - '0'; 96 int digit = s[i] - '0';
100 if (*result > std::numeric_limits<uint32>::max() - digit) 97 if (*result > std::numeric_limits<uint32>::max() - digit)
101 return false; 98 return false;
102 *result += digit; 99 *result += digit;
103 } 100 }
104 } 101 }
105 return got_something; 102 return got_something;
106 } 103 }
107 104
108 // Parses "token:hostname:port:" string. Returns true on success. 105 // Parses "passport:hostname:port:" string. Returns true on success.
109 bool FetchTokenNamePort( 106 bool FetchPassportNamePort(
110 uint8* begin, uint8* end, 107 uint8* begin, uint8* end,
111 std::string* token, std::string* name, uint32* port) { 108 std::string* passport, std::string* name, uint32* port) {
112 std::string input(begin, end); 109 std::string input(begin, end);
113 if (input[input.size() - 1] != ':') 110 if (input[input.size() - 1] != ':')
114 return false; 111 return false;
115 input.resize(input.size() - 1); 112 input.resize(input.size() - 1);
116 113
117 size_t pos = input.find_last_of(':'); 114 size_t pos = input.find_last_of(':');
118 if (pos == std::string::npos) 115 if (pos == std::string::npos)
119 return false; 116 return false;
120 std::string port_str(input, pos + 1); 117 std::string port_str(input, pos + 1);
121 if (port_str.empty()) 118 if (port_str.empty())
122 return false; 119 return false;
123 const char kAsciiDigits[] = "0123456789"; 120 const char kAsciiDigits[] = "0123456789";
124 COMPILE_ASSERT(sizeof(kAsciiDigits) == 10 + 1, mess_with_digits); 121 COMPILE_ASSERT(sizeof(kAsciiDigits) == 10 + 1, mess_with_digits);
125 if (port_str.find_first_not_of(kAsciiDigits) != std::string::npos) 122 if (port_str.find_first_not_of(kAsciiDigits) != std::string::npos)
126 return false; 123 return false;
127 if (!FetchDecimalDigits(port_str, port) || 124 if (!FetchDecimalDigits(port_str, port) ||
128 *port <= 0 || 125 *port <= 0 ||
129 *port >= (1 << 16)) { 126 *port >= (1 << 16)) {
130 return false; 127 return false;
131 } 128 }
132 input.resize(pos); 129 input.resize(pos);
133 130
134 pos = input.find_first_of(':'); 131 pos = input.find_first_of(':');
135 if (pos == std::string::npos) 132 if (pos == std::string::npos)
136 return false; 133 return false;
137 token->assign(input, 0, pos); 134 passport->assign(input, 0, pos);
138 name->assign(input, pos + 1, std::string::npos); 135 name->assign(input, pos + 1, std::string::npos);
139 return !name->empty(); 136 return !name->empty();
140 } 137 }
141 138
142 std::string FetchExtensionIdFromOrigin(const std::string origin) { 139 std::string FetchExtensionIdFromOrigin(const std::string origin) {
143 // Origin of extension looks like "chrome-extension://EXTENSION_ID". 140 // Origin of extension looks like "chrome-extension://EXTENSION_ID".
144 return origin.substr(origin.find_last_of('/')); 141 size_t pos = origin.find_last_of('/');
142 if (pos != std::string::npos)
143 pos += 1;
144 return origin.substr(pos);
145 } 145 }
146 146
147 inline size_t strlen(const uint8* s) { 147 inline size_t strlen(const uint8* s) {
148 return ::strlen(reinterpret_cast<const char*>(s)); 148 return ::strlen(reinterpret_cast<const char*>(s));
149 } 149 }
150 150
151 void SendNotification() { 151 void SendNotification() {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
153 NotificationService::current()->Notify( 153 NotificationService::current()->Notify(
154 NotificationType::WEB_SOCKET_PROXY_STARTED, 154 NotificationType::WEB_SOCKET_PROXY_STARTED,
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 uint8* buf_end = buf + buf_size; 821 uint8* buf_end = buf + buf_size;
822 uint8* term_pos = std::find(buf + 1, buf_end, 0xff); 822 uint8* term_pos = std::find(buf + 1, buf_end, 0xff);
823 if (term_pos == buf_end) { 823 if (term_pos == buf_end) {
824 if (buf_size >= WebSocketProxy::kHeaderLimit) { 824 if (buf_size >= WebSocketProxy::kHeaderLimit) {
825 // So big and still worth nothing. 825 // So big and still worth nothing.
826 return STATUS_ABORT; 826 return STATUS_ABORT;
827 } 827 }
828 return STATUS_INCOMPLETE; 828 return STATUS_INCOMPLETE;
829 } 829 }
830 830
831 std::string token; 831 std::string passport;
832 if (!FetchTokenNamePort(buf + 1, term_pos, &token, &destname_, &destport_)) 832 if (!FetchPassportNamePort(
833 buf + 1, term_pos, &passport, &destname_, &destport_)) {
833 return STATUS_ABORT; 834 return STATUS_ABORT;
834 // TODO(dilmah): enable this once webSocketProxyPrivate.getToken is wired. 835 }
835 #if 0
836 std::map<std::string, std::string> map; 836 std::map<std::string, std::string> map;
837 map["hostname"] = destname_; 837 map["hostname"] = destname_;
838 map["port"] = base::IntToString(destport_); 838 map["port"] = base::IntToString(destport_);
839 map["extension_id"] = FetchExtensionIdFromOrigin(header_fields_["origin"]); 839 map["extension_id"] = FetchExtensionIdFromOrigin(header_fields_["origin"]);
840 if (!browser::InternalAuthVerification::VerifyToken( 840 if (!browser::InternalAuthVerification::VerifyPassport(
841 "web_socket_proxy", token, map)) { 841 passport, "web_socket_proxy", map)) {
842 return STATUS_ABORT; 842 return STATUS_ABORT;
843 } 843 }
844 #endif
845 844
846 evbuffer_drain(evb, term_pos - buf + 1); 845 evbuffer_drain(evb, term_pos - buf + 1);
847 return STATUS_OK; 846 return STATUS_OK;
848 } 847 }
849 848
850 Conn::Status Conn::ConsumeFrameHeader(struct evbuffer* evb) { 849 Conn::Status Conn::ConsumeFrameHeader(struct evbuffer* evb) {
851 uint8* buf = EVBUFFER_DATA(evb); 850 uint8* buf = EVBUFFER_DATA(evb);
852 size_t buf_size = EVBUFFER_LENGTH(evb); 851 size_t buf_size = EVBUFFER_LENGTH(evb);
853 852
854 if (buf_size < 1) 853 if (buf_size < 1)
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 void WebSocketProxy::Run() { 1280 void WebSocketProxy::Run() {
1282 static_cast<Serv*>(impl_)->Run(); 1281 static_cast<Serv*>(impl_)->Run();
1283 } 1282 }
1284 1283
1285 void WebSocketProxy::Shutdown() { 1284 void WebSocketProxy::Shutdown() {
1286 static_cast<Serv*>(impl_)->Shutdown(); 1285 static_cast<Serv*>(impl_)->Shutdown();
1287 } 1286 }
1288 1287
1289 } // namespace chromeos 1288 } // namespace chromeos
1290 1289
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698