Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/vpn_provider/vpn_provider_api.h" | 5 #include "extensions/browser/api/vpn_provider/vpn_provider_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "extensions/browser/api/vpn_provider/vpn_service.h" | 14 #include "extensions/browser/api/vpn_provider/vpn_service.h" |
| 15 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" | 15 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" |
| 16 #include "extensions/common/api/vpn_provider.h" | 16 #include "extensions/common/api/vpn_provider.h" |
| 17 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 namespace api_vpn = extensions::core_api::vpn_provider; | 23 namespace api_vpn = extensions::core_api::vpn_provider; |
| 24 | 24 |
| 25 const char kCIDRSeperator[] = "/"; | 25 const char kCIDRSeperator[] = "/"; |
|
bartfab (slow)
2015/02/19 13:10:13
Why is this a string and not a single-char constan
kaliamoorthi
2015/02/19 16:20:05
This is due to tokenize below.
| |
| 26 | 26 |
| 27 bool CheckIPCIDR(const std::string& value, bool cidr, bool ipv6) { | |
|
not at google - send to devlin
2015/02/18 19:14:04
You should test this.
kaliamoorthi
2015/02/19 12:53:59
I am working on the test.
bartfab (slow)
2015/02/19 13:10:14
I think it would be better to implement this diffe
kaliamoorthi
2015/02/19 16:20:05
I am doing a simple sanity check here in a single
| |
| 28 int dots = !ipv6 ? 3 : 0; | |
| 29 int sep = cidr ? 1 : 0; | |
| 30 int colon = ipv6 ? 7 : 0; | |
| 31 | |
| 32 for (auto elem : value) { | |
|
bartfab (slow)
2015/02/19 13:10:14
Nit: const auto&
kaliamoorthi
2015/02/19 16:20:05
Done.
| |
| 33 if (base::IsAsciiDigit(*elem)) { | |
| 34 continue; | |
| 35 } else if (*elem == '.' && !dots) { | |
|
bartfab (slow)
2015/02/19 13:10:14
Nit: No else after continue.
kaliamoorthi
2015/02/19 16:20:05
Done.
| |
| 36 return false; | |
| 37 } else if (*elem == '.') { | |
|
bartfab (slow)
2015/02/19 13:10:14
Nit: No else after return.
kaliamoorthi
2015/02/19 16:20:05
Done.
| |
| 38 dots--; | |
| 39 } else if (*elem == kCIDRSeperator[0] && !sep) { | |
| 40 return false; | |
| 41 } else if (*elem == kCIDRSeperator[0]) { | |
|
bartfab (slow)
2015/02/19 13:10:13
Nit: No else after return.
kaliamoorthi
2015/02/19 16:20:05
Done.
| |
| 42 sep--; | |
| 43 } else if (*elem == ':' && !colon) { | |
| 44 return false; | |
| 45 } else if (*elem == ':') { | |
|
bartfab (slow)
2015/02/19 13:10:14
Nit: No else after return.
kaliamoorthi
2015/02/19 16:20:05
Done.
| |
| 46 colon--; | |
|
bartfab (slow)
2015/02/19 13:10:13
You are not checking that IPv6 starts with a colon
kaliamoorthi
2015/02/19 16:20:04
It need not start with a colon.
| |
| 47 } else if (ipv6 && base::IsHexDigit(*elem)) { | |
| 48 continue; | |
| 49 } else { | |
|
bartfab (slow)
2015/02/19 13:10:14
Nit: No else after continue.
kaliamoorthi
2015/02/19 16:20:05
Done.
| |
| 50 return false; | |
| 51 } | |
| 52 } | |
| 53 return !sep && !dots && (colon < 7); | |
|
bartfab (slow)
2015/02/19 13:10:14
Is the number of colons not fixed?
kaliamoorthi
2015/02/19 16:20:05
Acknowledged.
| |
| 54 } | |
| 55 | |
| 27 void ConvertParameters(const api_vpn::Parameters& parameters, | 56 void ConvertParameters(const api_vpn::Parameters& parameters, |
| 28 base::DictionaryValue* parameter_value, | 57 base::DictionaryValue* parameter_value, |
| 29 std::string* error) { | 58 std::string* error) { |
| 30 std::vector<std::string> cidr_parts; | 59 if (!CheckIPCIDR(parameters.address, true, false)) { |
| 31 if (Tokenize(parameters.address, kCIDRSeperator, &cidr_parts) != 2) { | |
| 32 *error = "Invalid CIDR address."; | 60 *error = "Invalid CIDR address."; |
| 33 return; | 61 return; |
| 34 } | 62 } |
| 35 | 63 |
| 64 for (auto address : parameters.exclusion_list) { | |
| 65 if (!CheckIPCIDR(*address, true, false)) { | |
| 66 *error = "Invalid CIDR in exclusion list."; | |
| 67 return; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 for (auto address : parameters.inclusion_list) { | |
| 72 if (!CheckIPCIDR(*address, true, false)) { | |
| 73 *error = "Invalid CIDR in inclusion list."; | |
| 74 return; | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 for (auto address : parameters.dns_servers) { | |
| 79 if (!CheckIPCIDR(*address, false, false)) { | |
| 80 *error = "Invalid IP in DNS servers."; | |
| 81 return; | |
| 82 } | |
| 83 } | |
|
not at google - send to devlin
2015/02/18 19:14:04
Could you pull each of these into a CheckIPCIDRLis
kaliamoorthi
2015/02/19 12:53:59
Done.
| |
| 84 | |
| 85 std::vector<std::string> cidr_parts; | |
| 86 Tokenize(parameters.address, kCIDRSeperator, &cidr_parts); | |
| 87 | |
| 36 parameter_value->SetStringWithoutPathExpansion( | 88 parameter_value->SetStringWithoutPathExpansion( |
| 37 shill::kAddressParameterThirdPartyVpn, cidr_parts[0]); | 89 shill::kAddressParameterThirdPartyVpn, cidr_parts[0]); |
| 38 | 90 |
| 39 parameter_value->SetStringWithoutPathExpansion( | 91 parameter_value->SetStringWithoutPathExpansion( |
| 40 shill::kSubnetPrefixParameterThirdPartyVpn, cidr_parts[1]); | 92 shill::kSubnetPrefixParameterThirdPartyVpn, cidr_parts[1]); |
| 41 | 93 |
| 42 parameter_value->SetStringWithoutPathExpansion( | 94 parameter_value->SetStringWithoutPathExpansion( |
| 43 shill::kBypassTunnelForIpParameterThirdPartyVpn, | 95 "exclusion_list", |
| 44 JoinString(parameters.bypass_tunnel_for_ip, shill::kIPDelimiter)); | 96 JoinString(parameters.exclusion_list, shill::kIPDelimiter)); |
| 97 | |
| 98 parameter_value->SetStringWithoutPathExpansion( | |
| 99 "inclusion_list", | |
| 100 JoinString(parameters.inclusion_list, shill::kIPDelimiter)); | |
| 45 | 101 |
| 46 if (parameters.mtu) { | 102 if (parameters.mtu) { |
| 47 parameter_value->SetStringWithoutPathExpansion( | 103 parameter_value->SetStringWithoutPathExpansion( |
| 48 shill::kMtuParameterThirdPartyVpn, *parameters.mtu); | 104 shill::kMtuParameterThirdPartyVpn, *parameters.mtu); |
| 49 } | 105 } |
| 50 | 106 |
| 51 if (parameters.broadcast_address) { | 107 if (parameters.broadcast_address) { |
| 52 parameter_value->SetStringWithoutPathExpansion( | 108 parameter_value->SetStringWithoutPathExpansion( |
| 53 shill::kBroadcastAddressParameterThirdPartyVpn, | 109 shill::kBroadcastAddressParameterThirdPartyVpn, |
| 54 *parameters.broadcast_address); | 110 *parameters.broadcast_address); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 SignalCallCompletionSuccess, | 283 SignalCallCompletionSuccess, |
| 228 this), | 284 this), |
| 229 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 285 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 230 SignalCallCompletionFailure, | 286 SignalCallCompletionFailure, |
| 231 this)); | 287 this)); |
| 232 | 288 |
| 233 return RespondLater(); | 289 return RespondLater(); |
| 234 } | 290 } |
| 235 | 291 |
| 236 } // namespace extensions | 292 } // namespace extensions |
| OLD | NEW |