1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/cros/network_library.h"
#include <dbus/dbus-glib.h>
#include "base/i18n/icu_encoding_detection.h"
#include "base/i18n/icu_string_conversions.h"
#include "base/i18n/time_formatting.h"
#include "base/json/json_writer.h" // for debug output only.
#include "base/string_number_conversions.h"
#include "base/utf_string_conversion_utils.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/cros/certificate_pattern.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/native_network_constants.h"
#include "chrome/browser/chromeos/cros/native_network_parser.h"
#include "chrome/browser/chromeos/cros/network_library_impl_cros.h"
#include "chrome/browser/chromeos/cros/network_library_impl_stub.h"
#include "chrome/common/net/url_util.h"
#include "chrome/common/net/x509_certificate_model.h"
#include "content/public/browser/browser_thread.h"
#include "grit/generated_resources.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
////////////////////////////////////////////////////////////////////////////////
// Implementation notes.
// NetworkLibraryImpl manages a series of classes that describe network devices
// and services:
//
// NetworkDevice: e.g. ethernet, wifi modem, cellular modem
// device_map_: canonical map<path, NetworkDevice*> for devices
//
// Network: a network service ("network").
// network_map_: canonical map<path, Network*> for all visible networks.
// EthernetNetwork
// ethernet_: EthernetNetwork* to the active ethernet network in network_map_.
// WirelessNetwork: a WiFi or Cellular Network.
// WifiNetwork
// active_wifi_: WifiNetwork* to the active wifi network in network_map_.
// wifi_networks_: ordered vector of WifiNetwork* entries in network_map_,
// in descending order of importance.
// CellularNetwork
// active_cellular_: Cellular version of wifi_.
// cellular_networks_: Cellular version of wifi_.
// network_unique_id_map_: map<unique_id, Network*> for all visible networks.
// remembered_network_map_: a canonical map<path, Network*> for all networks
// remembered in the active Profile ("favorites").
// remembered_network_unique_id_map_: map<unique_id, Network*> for all
// remembered networks.
// remembered_wifi_networks_: ordered vector of WifiNetwork* entries in
// remembered_network_map_, in descending order of preference.
// remembered_virtual_networks_: ordered vector of VirtualNetwork* entries in
// remembered_network_map_, in descending order of preference.
//
// network_manager_monitor_: a handle to the libcros network Manager handler.
// NetworkManagerStatusChanged: This handles all messages from the Manager.
// Messages are parsed here and the appropriate updates are then requested.
//
// UpdateNetworkServiceList: This is the primary Manager handler. It handles
// the "Services" message which list all visible networks. The handler
// rebuilds the network lists without destroying existing Network structures,
// then requests neccessary updates to be fetched asynchronously from
// libcros (RequestNetworkServiceProperties).
//
// TODO(stevenjb): Document cellular data plan handlers.
//
// AddNetworkObserver: Adds an observer for a specific network.
// UpdateNetworkStatus: This handles changes to a monitored service, typically
// changes to transient states like Strength. (Note: also updates State).
//
// AddNetworkDeviceObserver: Adds an observer for a specific device.
// Will be called on any device property change.
// UpdateNetworkDeviceStatus: Handles changes to a monitored device, like
// SIM lock state and updates device state.
//
// All *Pin(...) methods use internal callback that would update cellular
// device state once async call is completed and notify all device observers.
//
////////////////////////////////////////////////////////////////////////////////
namespace chromeos {
// Local constants.
namespace {
// Default value of the SIM unlock retries count. It is updated to the real
// retries count once cellular device with SIM card is initialized.
// If cellular device doesn't have SIM card, then retries are never used.
const int kDefaultSimUnlockRetriesCount = 999;
// Redirect extension url for POST-ing url parameters to mobile account status
// sites.
const char kRedirectExtensionPage[] =
"chrome-extension://iadeocfgjdjdmpenejdbfeaocpbikmab/redirect.html?"
"autoPost=1";
////////////////////////////////////////////////////////////////////////////////
// Misc.
// Erase the memory used by a string, then clear it.
void WipeString(std::string* str) {
str->assign(str->size(), '\0');
str->clear();
}
bool EnsureCrosLoaded() {
if (!CrosLibrary::Get()->libcros_loaded()) {
return false;
} else {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI))
<< "chromeos_network calls made from non UI thread!";
return true;
}
}
void ValidateUTF8(const std::string& str, std::string* output) {
output->clear();
for (int32 index = 0; index < static_cast<int32>(str.size()); ++index) {
uint32 code_point_out;
bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(),
&index, &code_point_out);
if (is_unicode_char && (code_point_out >= 0x20))
base::WriteUnicodeCharacter(code_point_out, output);
else
// Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8
base::WriteUnicodeCharacter(0xFFFD, output);
}
}
std::string ConnectionStateString(ConnectionState state) {
switch (state) {
case STATE_UNKNOWN:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_UNKNOWN);
case STATE_IDLE:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_IDLE);
case STATE_CARRIER:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_CARRIER);
case STATE_ASSOCIATION:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_ASSOCIATION);
case STATE_CONFIGURATION:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_CONFIGURATION);
case STATE_READY:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_READY);
case STATE_DISCONNECT:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_DISCONNECT);
case STATE_FAILURE:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_FAILURE);
case STATE_ACTIVATION_FAILURE:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_STATE_ACTIVATION_FAILURE);
case STATE_PORTAL:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_PORTAL);
case STATE_ONLINE:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_ONLINE);
case STATE_CONNECT_REQUESTED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_STATE_CONNECT_REQUESTED);
}
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
// FoundCellularNetwork
FoundCellularNetwork::FoundCellularNetwork() {}
FoundCellularNetwork::~FoundCellularNetwork() {}
////////////////////////////////////////////////////////////////////////////////
// NetworkDevice
NetworkDevice::NetworkDevice(const std::string& device_path)
: device_path_(device_path),
type_(TYPE_UNKNOWN),
scanning_(false),
sim_lock_state_(SIM_UNKNOWN),
sim_retries_left_(kDefaultSimUnlockRetriesCount),
sim_pin_required_(SIM_PIN_REQUIRE_UNKNOWN),
prl_version_(0),
data_roaming_allowed_(false),
support_network_scan_(false),
device_parser_(new NativeNetworkDeviceParser) {
}
NetworkDevice::~NetworkDevice() {}
void NetworkDevice::SetNetworkDeviceParser(NetworkDeviceParser* parser) {
device_parser_.reset(parser);
}
void NetworkDevice::ParseInfo(const DictionaryValue& info) {
if (device_parser_.get())
device_parser_->UpdateDeviceFromInfo(info, this);
}
bool NetworkDevice::UpdateStatus(const std::string& key,
const base::Value& value,
PropertyIndex* index) {
if (device_parser_.get())
return device_parser_->UpdateStatus(key, value, this, index);
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Network
Network::Network(const std::string& service_path,
ConnectionType type)
: state_(STATE_UNKNOWN),
error_(ERROR_NO_ERROR),
connectable_(true),
connection_started_(false),
is_active_(false),
priority_(kPriorityNotSet),
auto_connect_(false),
save_credentials_(false),
priority_order_(0),
added_(false),
notify_failure_(false),
profile_type_(PROFILE_NONE),
service_path_(service_path),
type_(type) {
}
Network::~Network() {
for (PropertyMap::const_iterator props = property_map_.begin();
props != property_map_.end(); ++props) {
delete props->second;
}
}
Network::ProxyOncConfig::ProxyOncConfig() : type(PROXY_ONC_DIRECT) {}
void Network::SetNetworkParser(NetworkParser* parser) {
network_parser_.reset(parser);
}
void Network::UpdatePropertyMap(PropertyIndex index, const base::Value* value) {
if (!value) {
// Clear the property if |value| is NULL.
PropertyMap::iterator iter(property_map_.find(index));
if (iter != property_map_.end()) {
delete iter->second;
property_map_.erase(iter);
}
return;
}
// Add the property to property_map_. Delete previous value if necessary.
Value*& entry = property_map_[index];
delete entry;
entry = value->DeepCopy();
if (VLOG_IS_ON(3)) {
std::string value_json;
base::JSONWriter::WriteWithOptions(value,
base::JSONWriter::OPTIONS_PRETTY_PRINT,
&value_json);
VLOG(3) << "Updated property map on network: "
<< unique_id() << "[" << index << "] = " << value_json;
}
}
bool Network::GetProperty(PropertyIndex index,
const base::Value** value) const {
PropertyMap::const_iterator i = property_map_.find(index);
if (i == property_map_.end())
return false;
if (value != NULL)
*value = i->second;
return true;
}
// static
Network* Network::CreateForTesting(ConnectionType type) {
return new Network("fake_service_path", type);
}
void Network::SetState(ConnectionState new_state) {
if (new_state == state_)
return;
if (state_ == STATE_CONNECT_REQUESTED && new_state == STATE_IDLE) {
// CONNECT_REQUESTED is set internally. Shill/flimflam do not update the
// state immediately, so ignore any Idle state updates sent while a
// connection attempt is in progress.
VLOG(2) << "Ignoring idle state change after connection request.";
return;
}
ConnectionState old_state = state_;
VLOG(2) << "Entering new state: " << ConnectionStateString(new_state);
state_ = new_state;
if (!IsConnectingState(new_state))
set_connection_started(false);
if (new_state == STATE_FAILURE) {
VLOG(2) << "Detected Failure state.";
if (old_state != STATE_UNKNOWN && old_state != STATE_IDLE) {
// New failure, the user needs to be notified.
// Transition STATE_IDLE -> STATE_FAILURE sometimes happens on resume
// but is not an actual failure as network device is not ready yet.
notify_failure_ = true;
// Normally error_ should be set, but if it is not we need to set it to
// something here so that the retry logic will be triggered.
if (error_ == ERROR_NO_ERROR) {
VLOG(2) << "Detected NO_ERROR error state. Setting to UNKNOWN.";
error_ = ERROR_UNKNOWN;
}
}
} else if (new_state != STATE_UNKNOWN) {
notify_failure_ = false;
// State changed, so refresh IP address.
// Note: blocking DBus call. TODO(stevenjb): refactor this.
InitIPAddress();
}
VLOG(1) << name() << ".State [" << service_path() << "]: " << GetStateString()
<< " (was: " << ConnectionStateString(old_state) << ")";
}
void Network::SetError(ConnectionError error) {
error_ = error;
if (error == ERROR_NO_ERROR)
notify_failure_ = false;
}
void Network::SetName(const std::string& name) {
std::string name_utf8;
ValidateUTF8(name, &name_utf8);
set_name(name_utf8);
}
void Network::ParseInfo(const DictionaryValue& info) {
if (network_parser_.get())
network_parser_->UpdateNetworkFromInfo(info, this);
}
void Network::EraseCredentials() {
}
void Network::CalculateUniqueId() {
unique_id_ = name_;
}
bool Network::RequiresUserProfile() const {
return false;
}
void Network::CopyCredentialsFromRemembered(Network* remembered) {
}
void Network::SetValueProperty(const char* prop, Value* value) {
DCHECK(prop);
DCHECK(value);
if (!EnsureCrosLoaded())
return;
CrosSetNetworkServiceProperty(service_path_, prop, *value);
}
void Network::ClearProperty(const char* prop) {
DCHECK(prop);
if (!EnsureCrosLoaded())
return;
CrosClearNetworkServiceProperty(service_path_, prop);
}
void Network::SetStringProperty(
const char* prop, const std::string& str, std::string* dest) {
if (dest)
*dest = str;
scoped_ptr<Value> value(Value::CreateStringValue(str));
SetValueProperty(prop, value.get());
}
void Network::SetOrClearStringProperty(const char* prop,
const std::string& str,
std::string* dest) {
if (str.empty()) {
ClearProperty(prop);
if (dest)
dest->clear();
} else {
SetStringProperty(prop, str, dest);
}
}
void Network::SetBooleanProperty(const char* prop, bool b, bool* dest) {
if (dest)
*dest = b;
scoped_ptr<Value> value(Value::CreateBooleanValue(b));
SetValueProperty(prop, value.get());
}
void Network::SetIntegerProperty(const char* prop, int i, int* dest) {
if (dest)
*dest = i;
scoped_ptr<Value> value(Value::CreateIntegerValue(i));
SetValueProperty(prop, value.get());
}
void Network::SetPreferred(bool preferred) {
if (preferred) {
SetIntegerProperty(
flimflam::kPriorityProperty, kPriorityPreferred, &priority_);
} else {
ClearProperty(flimflam::kPriorityProperty);
priority_ = kPriorityNotSet;
}
}
void Network::SetAutoConnect(bool auto_connect) {
SetBooleanProperty(
flimflam::kAutoConnectProperty, auto_connect, &auto_connect_);
}
void Network::SetSaveCredentials(bool save_credentials) {
SetBooleanProperty(
flimflam::kSaveCredentialsProperty, save_credentials, &save_credentials_);
}
void Network::ClearUIData() {
ui_data_ = NetworkUIData();
ClearProperty(flimflam::kUIDataProperty);
}
void Network::AttemptConnection(const base::Closure& closure) {
// By default, just invoke the closure right away. Some subclasses
// (Wifi, VPN, etc.) override to do more work.
closure.Run();
}
void Network::SetProfilePath(const std::string& profile_path) {
VLOG(1) << "Setting profile for: " << name_ << " to: " << profile_path;
SetOrClearStringProperty(
flimflam::kProfileProperty, profile_path, &profile_path_);
}
std::string Network::GetStateString() const {
return ConnectionStateString(state_);
}
std::string Network::GetErrorString() const {
switch (error_) {
case ERROR_NO_ERROR:
// TODO(nkostylev): Introduce new error message "None" instead.
return std::string();
case ERROR_OUT_OF_RANGE:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
case ERROR_PIN_MISSING:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING);
case ERROR_DHCP_FAILED:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED);
case ERROR_CONNECT_FAILED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED);
case ERROR_BAD_PASSPHRASE:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE);
case ERROR_BAD_WEPKEY:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY);
case ERROR_ACTIVATION_FAILED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED);
case ERROR_NEED_EVDO:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO);
case ERROR_NEED_HOME_NETWORK:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK);
case ERROR_OTASP_FAILED:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED);
case ERROR_AAA_FAILED:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED);
case ERROR_INTERNAL:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL);
case ERROR_DNS_LOOKUP_FAILED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED);
case ERROR_HTTP_GET_FAILED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED);
case ERROR_IPSEC_PSK_AUTH_FAILED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED);
case ERROR_IPSEC_CERT_AUTH_FAILED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_IPSEC_CERT_AUTH_FAILED);
case ERROR_PPP_AUTH_FAILED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED);
case ERROR_UNKNOWN:
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
}
return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED);
}
void Network::SetProxyConfig(const std::string& proxy_config) {
SetOrClearStringProperty(
flimflam::kProxyConfigProperty, proxy_config, &proxy_config_);
}
void Network::InitIPAddress() {
ip_address_.clear();
if (!EnsureCrosLoaded())
return;
// If connected, get ip config.
if (connected() && !device_path_.empty()) {
NetworkIPConfigVector ipconfigs;
if (CrosListIPConfigs(device_path_, &ipconfigs, NULL, NULL)) {
for (size_t i = 0; i < ipconfigs.size(); ++i) {
const NetworkIPConfig& ipconfig = ipconfigs[i];
if (ipconfig.address.size() > 0) {
ip_address_ = ipconfig.address;
break;
}
}
}
}
}
bool Network::UpdateStatus(const std::string& key,
const Value& value,
PropertyIndex* index) {
if (network_parser_.get())
return network_parser_->UpdateStatus(key, value, this, index);
return false;
}
////////////////////////////////////////////////////////////////////////////////
// EthernetNetwork
EthernetNetwork::EthernetNetwork(const std::string& service_path)
: Network(service_path, TYPE_ETHERNET) {
}
////////////////////////////////////////////////////////////////////////////////
// VirtualNetwork
VirtualNetwork::VirtualNetwork(const std::string& service_path)
: Network(service_path, TYPE_VPN),
provider_type_(PROVIDER_TYPE_L2TP_IPSEC_PSK),
// Assume PSK and user passphrase are not available initially
psk_passphrase_required_(true),
user_passphrase_required_(true),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_pointer_factory_(this)) {
}
VirtualNetwork::~VirtualNetwork() {}
void VirtualNetwork::EraseCredentials() {
WipeString(&ca_cert_nss_);
WipeString(&psk_passphrase_);
WipeString(&client_cert_id_);
WipeString(&user_passphrase_);
}
void VirtualNetwork::CalculateUniqueId() {
std::string provider_type(ProviderTypeToString(provider_type_));
set_unique_id(provider_type + "|" + server_hostname_);
}
bool VirtualNetwork::RequiresUserProfile() const {
return true;
}
void VirtualNetwork::AttemptConnection(const base::Closure& connect) {
if (client_cert_type() == CLIENT_CERT_TYPE_PATTERN) {
MatchCertificatePattern(true, connect);
} else {
connect.Run();
}
}
void VirtualNetwork::CopyCredentialsFromRemembered(Network* remembered) {
CHECK_EQ(remembered->type(), TYPE_VPN);
VirtualNetwork* remembered_vpn = static_cast<VirtualNetwork*>(remembered);
VLOG(1) << "Copy VPN credentials: " << name()
<< " username: " << remembered_vpn->username();
if (ca_cert_nss_.empty())
ca_cert_nss_ = remembered_vpn->ca_cert_nss();
if (psk_passphrase_.empty())
psk_passphrase_ = remembered_vpn->psk_passphrase();
if (client_cert_id_.empty())
client_cert_id_ = remembered_vpn->client_cert_id();
if (username_.empty())
username_ = remembered_vpn->username();
if (user_passphrase_.empty())
user_passphrase_ = remembered_vpn->user_passphrase();
}
bool VirtualNetwork::NeedMoreInfoToConnect() const {
if (server_hostname_.empty() || username_.empty() ||
IsUserPassphraseRequired())
return true;
if (error() != ERROR_NO_ERROR)
return true;
switch (provider_type_) {
case PROVIDER_TYPE_L2TP_IPSEC_PSK:
if (IsPSKPassphraseRequired())
return true;
break;
case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT:
if (client_cert_id_.empty() &&
client_cert_type() != CLIENT_CERT_TYPE_PATTERN)
return true;
break;
case PROVIDER_TYPE_OPEN_VPN:
if (client_cert_id_.empty())
return true;
// For now we always need additional info for OpenVPN.
// TODO(stevenjb): Check connectable() once flimflam sets that state
// properly, or define another mechanism to determine when additional
// credentials are required.
return true;
break;
case PROVIDER_TYPE_MAX:
NOTREACHED();
break;
}
return false;
}
std::string VirtualNetwork::GetProviderTypeString() const {
switch (provider_type_) {
case PROVIDER_TYPE_L2TP_IPSEC_PSK:
return l10n_util::GetStringUTF8(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_PSK);
break;
case PROVIDER_TYPE_L2TP_IPSEC_USER_CERT:
return l10n_util::GetStringUTF8(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_USER_CERT);
break;
case PROVIDER_TYPE_OPEN_VPN:
return l10n_util::GetStringUTF8(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN);
break;
default:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN);
break;
}
}
bool VirtualNetwork::IsPSKPassphraseRequired() const {
return psk_passphrase_required_ && psk_passphrase_.empty();
}
bool VirtualNetwork::IsUserPassphraseRequired() const {
return user_passphrase_required_ && user_passphrase_.empty();
}
void VirtualNetwork::SetCACertNSS(const std::string& ca_cert_nss) {
if (provider_type_ == PROVIDER_TYPE_OPEN_VPN) {
SetStringProperty(
flimflam::kOpenVPNCaCertNSSProperty, ca_cert_nss, &ca_cert_nss_);
} else {
SetStringProperty(
flimflam::kL2tpIpsecCaCertNssProperty, ca_cert_nss, &ca_cert_nss_);
}
}
void VirtualNetwork::SetL2TPIPsecPSKCredentials(
const std::string& psk_passphrase,
const std::string& username,
const std::string& user_passphrase,
const std::string& group_name) {
if (!psk_passphrase.empty()) {
SetStringProperty(flimflam::kL2tpIpsecPskProperty,
psk_passphrase, &psk_passphrase_);
}
SetStringProperty(flimflam::kL2tpIpsecUserProperty, username, &username_);
if (!user_passphrase.empty()) {
SetStringProperty(flimflam::kL2tpIpsecPasswordProperty,
user_passphrase, &user_passphrase_);
}
SetStringProperty(flimflam::kL2tpIpsecGroupNameProperty,
group_name, &group_name_);
}
void VirtualNetwork::SetL2TPIPsecCertCredentials(
const std::string& client_cert_id,
const std::string& username,
const std::string& user_passphrase,
const std::string& group_name) {
SetStringProperty(flimflam::kL2tpIpsecClientCertIdProperty,
client_cert_id, &client_cert_id_);
SetStringProperty(flimflam::kL2tpIpsecUserProperty, username, &username_);
if (!user_passphrase.empty()) {
SetStringProperty(flimflam::kL2tpIpsecPasswordProperty,
user_passphrase, &user_passphrase_);
}
SetStringProperty(flimflam::kL2tpIpsecGroupNameProperty,
group_name, &group_name_);
}
void VirtualNetwork::SetOpenVPNCredentials(
const std::string& client_cert_id,
const std::string& username,
const std::string& user_passphrase,
const std::string& otp) {
SetStringProperty(flimflam::kOpenVPNClientCertIdProperty,
client_cert_id, &client_cert_id_);
SetStringProperty(flimflam::kOpenVPNUserProperty, username, &username_);
if (!user_passphrase.empty()) {
SetStringProperty(flimflam::kOpenVPNPasswordProperty,
user_passphrase, &user_passphrase_);
}
SetStringProperty(flimflam::kOpenVPNOTPProperty, otp, NULL);
}
void VirtualNetwork::SetCertificateSlotAndPin(
const std::string& slot, const std::string& pin) {
if (provider_type() == PROVIDER_TYPE_OPEN_VPN) {
SetOrClearStringProperty(flimflam::kOpenVPNClientCertSlotProperty,
slot, NULL);
SetOrClearStringProperty(flimflam::kOpenVPNPinProperty, pin, NULL);
} else {
SetOrClearStringProperty(flimflam::kL2tpIpsecClientCertSlotProperty,
slot, NULL);
SetOrClearStringProperty(flimflam::kL2tpIpsecPinProperty, pin, NULL);
}
}
void VirtualNetwork::MatchCertificatePattern(bool allow_enroll,
const base::Closure& connect) {
DCHECK(client_cert_type() == CLIENT_CERT_TYPE_PATTERN);
DCHECK(!client_cert_pattern().Empty());
if (client_cert_pattern().Empty()) {
connect.Run();
return;
}
scoped_refptr<net::X509Certificate> matching_cert =
client_cert_pattern().GetMatch();
if (matching_cert.get()) {
std::string client_cert_id =
x509_certificate_model::GetPkcs11Id(matching_cert->os_cert_handle());
if (provider_type() == PROVIDER_TYPE_OPEN_VPN) {
SetStringProperty(flimflam::kOpenVPNClientCertIdProperty,
client_cert_id, &client_cert_id_);
} else {
SetStringProperty(flimflam::kL2tpIpsecClientCertIdProperty,
client_cert_id, &client_cert_id_);
}
} else {
if (allow_enroll && enrollment_delegate()) {
// Wrap the closure in another callback so that we can retry the
// certificate match again before actually connecting.
base::Closure wrapped_connect =
base::Bind(&VirtualNetwork::MatchCertificatePattern,
weak_pointer_factory_.GetWeakPtr(),
false,
connect);
enrollment_delegate()->Enroll(client_cert_pattern().enrollment_uri_list(),
wrapped_connect);
// Enrollment delegate will take care of running the closure at the
// appropriate time, if the user doesn't cancel.
return;
}
}
connect.Run();
}
////////////////////////////////////////////////////////////////////////////////
// WirelessNetwork
////////////////////////////////////////////////////////////////////////////////
// CellTower
CellTower::CellTower() {}
////////////////////////////////////////////////////////////////////////////////
// WifiAccessPoint
WifiAccessPoint::WifiAccessPoint() {}
////////////////////////////////////////////////////////////////////////////////
// CellularApn
CellularApn::CellularApn() {}
CellularApn::CellularApn(
const std::string& apn, const std::string& network_id,
const std::string& username, const std::string& password)
: apn(apn), network_id(network_id),
username(username), password(password) {
}
CellularApn::~CellularApn() {}
void CellularApn::Set(const DictionaryValue& dict) {
if (!dict.GetStringWithoutPathExpansion(flimflam::kApnProperty, &apn))
apn.clear();
if (!dict.GetStringWithoutPathExpansion(flimflam::kApnNetworkIdProperty,
&network_id))
network_id.clear();
if (!dict.GetStringWithoutPathExpansion(flimflam::kApnUsernameProperty,
&username))
username.clear();
if (!dict.GetStringWithoutPathExpansion(flimflam::kApnPasswordProperty,
&password))
password.clear();
if (!dict.GetStringWithoutPathExpansion(flimflam::kApnNameProperty, &name))
name.clear();
if (!dict.GetStringWithoutPathExpansion(flimflam::kApnLocalizedNameProperty,
&localized_name))
localized_name.clear();
if (!dict.GetStringWithoutPathExpansion(flimflam::kApnLanguageProperty,
&language))
language.clear();
}
////////////////////////////////////////////////////////////////////////////////
// CellularNetwork
CellularNetwork::CellularNetwork(const std::string& service_path)
: WirelessNetwork(service_path, TYPE_CELLULAR),
activation_state_(ACTIVATION_STATE_UNKNOWN),
network_technology_(NETWORK_TECHNOLOGY_UNKNOWN),
roaming_state_(ROAMING_STATE_UNKNOWN),
using_post_(false),
data_left_(DATA_UNKNOWN) {
}
CellularNetwork::~CellularNetwork() {
}
bool CellularNetwork::StartActivation() {
if (!EnsureCrosLoaded())
return false;
if (!CrosActivateCellularModem(service_path(), ""))
return false;
// Don't wait for flimflam to tell us that we are really activating since
// other notifications in the message loop might cause us to think that
// the process hasn't started yet.
activation_state_ = ACTIVATION_STATE_ACTIVATING;
return true;
}
void CellularNetwork::RefreshDataPlansIfNeeded() const {
if (!EnsureCrosLoaded())
return;
if (connected() && activated())
CrosRequestCellularDataPlanUpdate(service_path());
}
void CellularNetwork::SetApn(const CellularApn& apn) {
if (!apn.apn.empty()) {
DictionaryValue value;
// Only use the fields that are needed for establishing
// connections, and ignore the rest.
value.SetString(flimflam::kApnProperty, apn.apn);
value.SetString(flimflam::kApnNetworkIdProperty, apn.network_id);
value.SetString(flimflam::kApnUsernameProperty, apn.username);
value.SetString(flimflam::kApnPasswordProperty, apn.password);
SetValueProperty(flimflam::kCellularApnProperty, &value);
} else {
ClearProperty(flimflam::kCellularApnProperty);
}
}
bool CellularNetwork::SupportsActivation() const {
return SupportsDataPlan();
}
bool CellularNetwork::NeedsActivation() const {
return (activation_state() != ACTIVATION_STATE_ACTIVATED &&
activation_state() != ACTIVATION_STATE_UNKNOWN) ||
needs_new_plan();
}
bool CellularNetwork::SupportsDataPlan() const {
// TODO(nkostylev): Are there cases when only one of this is defined?
return !usage_url().empty() || !payment_url().empty();
}
GURL CellularNetwork::GetAccountInfoUrl() const {
if (!post_data_.length())
return GURL(payment_url());
GURL base_url(kRedirectExtensionPage);
GURL temp_url = chrome_common_net::AppendQueryParameter(base_url,
"post_data",
post_data_);
GURL redir_url = chrome_common_net::AppendQueryParameter(temp_url,
"formUrl",
payment_url());
return redir_url;
}
std::string CellularNetwork::GetNetworkTechnologyString() const {
// No need to localize these cellular technology abbreviations.
switch (network_technology_) {
case NETWORK_TECHNOLOGY_1XRTT:
return "1xRTT";
break;
case NETWORK_TECHNOLOGY_EVDO:
return "EVDO";
break;
case NETWORK_TECHNOLOGY_GPRS:
return "GPRS";
break;
case NETWORK_TECHNOLOGY_EDGE:
return "EDGE";
break;
case NETWORK_TECHNOLOGY_UMTS:
return "UMTS";
break;
case NETWORK_TECHNOLOGY_HSPA:
return "HSPA";
break;
case NETWORK_TECHNOLOGY_HSPA_PLUS:
return "HSPA Plus";
break;
case NETWORK_TECHNOLOGY_LTE:
return "LTE";
break;
case NETWORK_TECHNOLOGY_LTE_ADVANCED:
return "LTE Advanced";
break;
case NETWORK_TECHNOLOGY_GSM:
return "GSM";
break;
default:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_CELLULAR_TECHNOLOGY_UNKNOWN);
break;
}
}
std::string CellularNetwork::ActivationStateToString(
ActivationState activation_state) {
switch (activation_state) {
case ACTIVATION_STATE_ACTIVATED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_ACTIVATED);
break;
case ACTIVATION_STATE_ACTIVATING:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_ACTIVATING);
break;
case ACTIVATION_STATE_NOT_ACTIVATED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_NOT_ACTIVATED);
break;
case ACTIVATION_STATE_PARTIALLY_ACTIVATED:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_PARTIALLY_ACTIVATED);
break;
default:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_UNKNOWN);
break;
}
}
std::string CellularNetwork::GetActivationStateString() const {
return ActivationStateToString(this->activation_state_);
}
std::string CellularNetwork::GetRoamingStateString() const {
switch (this->roaming_state_) {
case ROAMING_STATE_HOME:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ROAMING_STATE_HOME);
break;
case ROAMING_STATE_ROAMING:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ROAMING_STATE_ROAMING);
break;
default:
return l10n_util::GetStringUTF8(
IDS_CHROMEOS_NETWORK_ROAMING_STATE_UNKNOWN);
break;
}
}
////////////////////////////////////////////////////////////////////////////////
// WifiNetwork
WifiNetwork::WifiNetwork(const std::string& service_path)
: WirelessNetwork(service_path, TYPE_WIFI),
encryption_(SECURITY_NONE),
passphrase_required_(false),
hidden_ssid_(false),
frequency_(0),
eap_method_(EAP_METHOD_UNKNOWN),
eap_phase_2_auth_(EAP_PHASE_2_AUTH_AUTO),
eap_use_system_cas_(true),
eap_save_credentials_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_pointer_factory_(this)) {
}
WifiNetwork::~WifiNetwork() {}
void WifiNetwork::CalculateUniqueId() {
ConnectionSecurity encryption = encryption_;
// Flimflam treats wpa and rsn as psk internally, so convert those types
// to psk for unique naming.
if (encryption == SECURITY_WPA || encryption == SECURITY_RSN)
encryption = SECURITY_PSK;
std::string security = std::string(SecurityToString(encryption));
set_unique_id(security + "|" + name());
}
bool WifiNetwork::SetSsid(const std::string& ssid) {
// Detects encoding and convert to UTF-8.
std::string ssid_utf8;
if (!IsStringUTF8(ssid)) {
std::string encoding;
if (base::DetectEncoding(ssid, &encoding)) {
if (!base::ConvertToUtf8AndNormalize(ssid, encoding, &ssid_utf8)) {
ssid_utf8.clear();
}
}
}
if (ssid_utf8.empty())
SetName(ssid);
else
SetName(ssid_utf8);
return true;
}
bool WifiNetwork::SetHexSsid(const std::string& ssid_hex) {
// Converts ascii hex dump (eg. "49656c6c6f") to string (eg. "Hello").
std::vector<uint8> ssid_raw;
if (!base::HexStringToBytes(ssid_hex, &ssid_raw)) {
LOG(ERROR) << "Illegal hex char is found in WiFi.HexSSID.";
ssid_raw.clear();
return false;
}
return SetSsid(std::string(ssid_raw.begin(), ssid_raw.end()));
}
const std::string& WifiNetwork::GetPassphrase() const {
if (!user_passphrase_.empty())
return user_passphrase_;
return passphrase_;
}
void WifiNetwork::SetPassphrase(const std::string& passphrase) {
// Set the user_passphrase_ only; passphrase_ stores the flimflam value.
// If the user sets an empty passphrase, restore it to the passphrase
// remembered by flimflam.
if (!passphrase.empty()) {
user_passphrase_ = passphrase;
passphrase_ = passphrase;
} else {
user_passphrase_ = passphrase_;
}
// Send the change to flimflam. If the format is valid, it will propagate to
// passphrase_ with a service update.
SetOrClearStringProperty(flimflam::kPassphraseProperty, passphrase, NULL);
}
// See src/third_party/flimflam/doc/service-api.txt for properties that
// flimflam will forget when SaveCredentials is false.
void WifiNetwork::EraseCredentials() {
WipeString(&passphrase_);
WipeString(&user_passphrase_);
WipeString(&eap_client_cert_pkcs11_id_);
WipeString(&eap_identity_);
WipeString(&eap_anonymous_identity_);
WipeString(&eap_passphrase_);
}
void WifiNetwork::SetIdentity(const std::string& identity) {
SetStringProperty(flimflam::kIdentityProperty, identity, &identity_);
}
void WifiNetwork::SetHiddenSSID(bool hidden_ssid) {
SetBooleanProperty(flimflam::kWifiHiddenSsid, hidden_ssid, &hidden_ssid_);
}
void WifiNetwork::SetEAPMethod(EAPMethod method) {
eap_method_ = method;
switch (method) {
case EAP_METHOD_PEAP:
SetStringProperty(
flimflam::kEapMethodProperty, flimflam::kEapMethodPEAP, NULL);
break;
case EAP_METHOD_TLS:
SetStringProperty(
flimflam::kEapMethodProperty, flimflam::kEapMethodTLS, NULL);
break;
case EAP_METHOD_TTLS:
SetStringProperty(
flimflam::kEapMethodProperty, flimflam::kEapMethodTTLS, NULL);
break;
case EAP_METHOD_LEAP:
SetStringProperty(
flimflam::kEapMethodProperty, flimflam::kEapMethodLEAP, NULL);
break;
default:
ClearProperty(flimflam::kEapMethodProperty);
break;
}
}
void WifiNetwork::SetEAPPhase2Auth(EAPPhase2Auth auth) {
eap_phase_2_auth_ = auth;
bool is_peap = (eap_method_ == EAP_METHOD_PEAP);
switch (auth) {
case EAP_PHASE_2_AUTH_AUTO:
ClearProperty(flimflam::kEapPhase2AuthProperty);
break;
case EAP_PHASE_2_AUTH_MD5:
SetStringProperty(flimflam::kEapPhase2AuthProperty,
is_peap ? flimflam::kEapPhase2AuthPEAPMD5
: flimflam::kEapPhase2AuthTTLSMD5,
NULL);
break;
case EAP_PHASE_2_AUTH_MSCHAPV2:
SetStringProperty(flimflam::kEapPhase2AuthProperty,
is_peap ? flimflam::kEapPhase2AuthPEAPMSCHAPV2
: flimflam::kEapPhase2AuthTTLSMSCHAPV2,
NULL);
break;
case EAP_PHASE_2_AUTH_MSCHAP:
SetStringProperty(flimflam::kEapPhase2AuthProperty,
flimflam::kEapPhase2AuthTTLSMSCHAP, NULL);
break;
case EAP_PHASE_2_AUTH_PAP:
SetStringProperty(flimflam::kEapPhase2AuthProperty,
flimflam::kEapPhase2AuthTTLSPAP, NULL);
break;
case EAP_PHASE_2_AUTH_CHAP:
SetStringProperty(flimflam::kEapPhase2AuthProperty,
flimflam::kEapPhase2AuthTTLSCHAP, NULL);
break;
}
}
void WifiNetwork::SetEAPServerCaCertNssNickname(
const std::string& nss_nickname) {
VLOG(1) << "SetEAPServerCaCertNssNickname " << nss_nickname;
SetOrClearStringProperty(flimflam::kEapCaCertNssProperty,
nss_nickname, &eap_server_ca_cert_nss_nickname_);
}
void WifiNetwork::SetEAPClientCertPkcs11Id(const std::string& pkcs11_id) {
VLOG(1) << "SetEAPClientCertPkcs11Id " << pkcs11_id;
SetOrClearStringProperty(
flimflam::kEapCertIdProperty, pkcs11_id, &eap_client_cert_pkcs11_id_);
// flimflam requires both CertID and KeyID for TLS connections, despite
// the fact that by convention they are the same ID.
SetOrClearStringProperty(flimflam::kEapKeyIdProperty, pkcs11_id, NULL);
}
void WifiNetwork::SetEAPUseSystemCAs(bool use_system_cas) {
SetBooleanProperty(flimflam::kEapUseSystemCasProperty, use_system_cas,
&eap_use_system_cas_);
}
void WifiNetwork::SetEAPIdentity(const std::string& identity) {
SetOrClearStringProperty(
flimflam::kEapIdentityProperty, identity, &eap_identity_);
}
void WifiNetwork::SetEAPAnonymousIdentity(const std::string& identity) {
SetOrClearStringProperty(flimflam::kEapAnonymousIdentityProperty, identity,
&eap_anonymous_identity_);
}
void WifiNetwork::SetEAPPassphrase(const std::string& passphrase) {
SetOrClearStringProperty(
flimflam::kEapPasswordProperty, passphrase, &eap_passphrase_);
}
std::string WifiNetwork::GetEncryptionString() const {
switch (encryption_) {
case SECURITY_UNKNOWN:
break;
case SECURITY_NONE:
return "";
case SECURITY_WEP:
return "WEP";
case SECURITY_WPA:
return "WPA";
case SECURITY_RSN:
return "RSN";
case SECURITY_8021X: {
std::string result("8021X");
switch (eap_method_) {
case EAP_METHOD_PEAP:
result += "+PEAP";
break;
case EAP_METHOD_TLS:
result += "+TLS";
break;
case EAP_METHOD_TTLS:
result += "+TTLS";
break;
case EAP_METHOD_LEAP:
result += "+LEAP";
break;
default:
break;
}
return result;
}
case SECURITY_PSK:
return "PSK";
}
return "Unknown";
}
bool WifiNetwork::IsPassphraseRequired() const {
// TODO(stevenjb): Remove error_ tests when fixed in flimflam
// (http://crosbug.com/10135).
if (error() == ERROR_BAD_PASSPHRASE || error() == ERROR_BAD_WEPKEY)
return true;
// For 802.1x networks, configuration is required if connectable is false
// unless we're using a certificate pattern.
if (encryption_ == SECURITY_8021X) {
if (eap_method_ != EAP_METHOD_TLS ||
client_cert_type() != CLIENT_CERT_TYPE_PATTERN)
return !connectable();
return false;
}
return passphrase_required_;
}
bool WifiNetwork::RequiresUserProfile() const {
// 8021X requires certificates which are only stored for individual users.
if (encryption_ != SECURITY_8021X)
return false;
if (eap_method_ != EAP_METHOD_TLS)
return false;
if (eap_client_cert_pkcs11_id().empty() &&
client_cert_type() != CLIENT_CERT_TYPE_PATTERN)
return false;
return true;
}
void WifiNetwork::AttemptConnection(const base::Closure& connect) {
if (client_cert_type() == CLIENT_CERT_TYPE_PATTERN) {
MatchCertificatePattern(true, connect);
} else {
connect.Run();
}
}
void WifiNetwork::SetCertificatePin(const std::string& pin) {
SetOrClearStringProperty(flimflam::kEapPinProperty, pin, NULL);
}
void WifiNetwork::MatchCertificatePattern(bool allow_enroll,
const base::Closure& connect) {
DCHECK(client_cert_type() == CLIENT_CERT_TYPE_PATTERN);
DCHECK(!client_cert_pattern().Empty());
if (client_cert_pattern().Empty()) {
connect.Run();
return;
}
scoped_refptr<net::X509Certificate> matching_cert =
client_cert_pattern().GetMatch();
if (matching_cert.get()) {
SetEAPClientCertPkcs11Id(
x509_certificate_model::GetPkcs11Id(matching_cert->os_cert_handle()));
} else {
if (allow_enroll && enrollment_delegate()) {
// Wrap the closure in another callback so that we can retry the
// certificate match again before actually connecting.
base::Closure wrapped_connect =
base::Bind(&WifiNetwork::MatchCertificatePattern,
weak_pointer_factory_.GetWeakPtr(),
false,
connect);
enrollment_delegate()->Enroll(client_cert_pattern().enrollment_uri_list(),
wrapped_connect);
// Enrollment delegate should take care of running the closure at the
// appropriate time, if the user doesn't cancel.
return;
}
}
connect.Run();
}
////////////////////////////////////////////////////////////////////////////////
// WimaxNetwork
WimaxNetwork::WimaxNetwork(const std::string& service_path)
: WirelessNetwork(service_path, TYPE_WIMAX),
passphrase_required_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_pointer_factory_(this)) {
}
WimaxNetwork::~WimaxNetwork() {
}
void WimaxNetwork::EraseCredentials() {
WipeString(&eap_passphrase_);
WipeString(&eap_identity_);
}
void WimaxNetwork::SetEAPPassphrase(const std::string& passphrase) {
SetOrClearStringProperty(
flimflam::kEapPasswordProperty, passphrase, &eap_passphrase_);
}
void WimaxNetwork::SetEAPIdentity(const std::string& identity) {
SetOrClearStringProperty(
flimflam::kEapIdentityProperty, identity, &eap_identity_);
}
void WimaxNetwork::CalculateUniqueId() {
set_unique_id(name() + "|" + eap_identity());
}
NetworkLibrary::EAPConfigData::EAPConfigData()
: method(EAP_METHOD_UNKNOWN),
auth(EAP_PHASE_2_AUTH_AUTO),
use_system_cas(true) {
}
NetworkLibrary::EAPConfigData::~EAPConfigData() {}
NetworkLibrary::VPNConfigData::VPNConfigData() {}
NetworkLibrary::VPNConfigData::~VPNConfigData() {}
// static
NetworkLibrary* NetworkLibrary::GetImpl(bool stub) {
NetworkLibrary* impl;
if (stub)
impl = new NetworkLibraryImplStub();
else
impl = new NetworkLibraryImplCros();
impl->Init();
return impl;
}
} // namespace chromeos
|