OLD | NEW |
---|---|
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 "chrome/browser/chromeos/cros/onc_network_parser.h" | 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h" |
6 | 6 |
7 #include <keyhi.h> | |
7 #include <pk11pub.h> | 8 #include <pk11pub.h> |
8 #include <keyhi.h> | |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/json/json_value_serializer.h" | 11 #include "base/json/json_value_serializer.h" |
12 #include "base/json/json_writer.h" // for debug output only. | 12 #include "base/json/json_writer.h" // for debug output only. |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/chromeos/cros/native_network_constants.h" | 15 #include "chrome/browser/chromeos/cros/native_network_constants.h" |
16 #include "chrome/browser/chromeos/cros/native_network_parser.h" | 16 #include "chrome/browser/chromeos/cros/native_network_parser.h" |
17 #include "chrome/browser/chromeos/cros/network_library.h" | 17 #include "chrome/browser/chromeos/cros/network_library.h" |
18 #include "net/base/cert_database.h" | 18 #include "net/base/cert_database.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 std::string ConvertValueToString(const base::Value& value) { | 176 std::string ConvertValueToString(const base::Value& value) { |
177 std::string value_json; | 177 std::string value_json; |
178 base::JSONWriter::Write(&value, false, &value_json); | 178 base::JSONWriter::Write(&value, false, &value_json); |
179 return value_json; | 179 return value_json; |
180 } | 180 } |
181 | 181 |
182 } // namespace | 182 } // namespace |
183 | 183 |
184 // -------------------- OncNetworkParser -------------------- | 184 // -------------------- OncNetworkParser -------------------- |
185 | 185 |
186 OncNetworkParser::OncNetworkParser(const std::string& onc_blob) | 186 OncNetworkParser::OncNetworkParser(const std::string& onc_blob, |
187 NetworkUIData::ONCSource onc_source) | |
187 : NetworkParser(get_onc_mapper()), | 188 : NetworkParser(get_onc_mapper()), |
189 onc_source_(onc_source), | |
188 network_configs_(NULL), | 190 network_configs_(NULL), |
189 certificates_(NULL) { | 191 certificates_(NULL) { |
190 VLOG(2) << __func__ << ": OncNetworkParser called on " << onc_blob; | 192 VLOG(2) << __func__ << ": OncNetworkParser called on " << onc_blob; |
191 JSONStringValueSerializer deserializer(onc_blob); | 193 JSONStringValueSerializer deserializer(onc_blob); |
192 deserializer.set_allow_trailing_comma(true); | 194 deserializer.set_allow_trailing_comma(true); |
193 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &parse_error_)); | 195 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &parse_error_)); |
194 | 196 |
195 if (!root.get() || root->GetType() != base::Value::TYPE_DICTIONARY) { | 197 if (!root.get() || root->GetType() != base::Value::TYPE_DICTIONARY) { |
196 LOG(WARNING) << "OncNetworkParser received bad ONC file: " << parse_error_; | 198 LOG(WARNING) << "OncNetworkParser received bad ONC file: " << parse_error_; |
197 } else { | 199 } else { |
(...skipping 21 matching lines...) Expand all Loading... | |
219 | 221 |
220 // static | 222 // static |
221 const EnumMapper<PropertyIndex>* OncNetworkParser::property_mapper() { | 223 const EnumMapper<PropertyIndex>* OncNetworkParser::property_mapper() { |
222 return get_onc_mapper(); | 224 return get_onc_mapper(); |
223 } | 225 } |
224 | 226 |
225 int OncNetworkParser::GetNetworkConfigsSize() const { | 227 int OncNetworkParser::GetNetworkConfigsSize() const { |
226 return network_configs_ ? network_configs_->GetSize() : 0; | 228 return network_configs_ ? network_configs_->GetSize() : 0; |
227 } | 229 } |
228 | 230 |
231 Network* OncNetworkParser::ParseNetwork(int n) { | |
232 if (!network_configs_) | |
233 return NULL; | |
234 DictionaryValue* info = NULL; | |
235 if (!network_configs_->GetDictionary(n, &info)) | |
236 return NULL; | |
237 if (VLOG_IS_ON(2)) { | |
238 std::string network_json; | |
239 base::JSONWriter::Write(static_cast<base::Value*>(info), | |
240 true, &network_json); | |
241 VLOG(2) << "Parsing network at index " << n | |
242 << ": " << network_json; | |
243 } | |
244 | |
245 return CreateNetworkFromInfo(std::string(), *info); | |
246 } | |
247 | |
229 int OncNetworkParser::GetCertificatesSize() const { | 248 int OncNetworkParser::GetCertificatesSize() const { |
230 return certificates_ ? certificates_->GetSize() : 0; | 249 return certificates_ ? certificates_->GetSize() : 0; |
231 } | 250 } |
232 | 251 |
233 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate( | 252 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseCertificate( |
234 int cert_index) { | 253 int cert_index) { |
235 CHECK(certificates_); | 254 CHECK(certificates_); |
236 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); | 255 CHECK(static_cast<size_t>(cert_index) < certificates_->GetSize()); |
237 CHECK(cert_index >= 0); | 256 CHECK(cert_index >= 0); |
238 base::DictionaryValue* certificate = NULL; | 257 base::DictionaryValue* certificate = NULL; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 } | 294 } |
276 if (cert_type == "Client") { | 295 if (cert_type == "Client") { |
277 return ParseClientCertificate(cert_index, guid, certificate); | 296 return ParseClientCertificate(cert_index, guid, certificate); |
278 } | 297 } |
279 | 298 |
280 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type | 299 LOG(WARNING) << "ONC File: certificate of unknown type: " << cert_type |
281 << " at index " << cert_index; | 300 << " at index " << cert_index; |
282 return NULL; | 301 return NULL; |
283 } | 302 } |
284 | 303 |
285 Network* OncNetworkParser::ParseNetwork(int n) { | |
286 if (!network_configs_) | |
287 return NULL; | |
288 DictionaryValue* info = NULL; | |
289 if (!network_configs_->GetDictionary(n, &info)) | |
290 return NULL; | |
291 if (VLOG_IS_ON(2)) { | |
292 std::string network_json; | |
293 base::JSONWriter::Write(static_cast<base::Value*>(info), | |
294 true, &network_json); | |
295 VLOG(2) << "Parsing network at index " << n | |
296 << ": " << network_json; | |
297 } | |
298 | |
299 return CreateNetworkFromInfo(std::string(), *info); | |
300 } | |
301 | |
302 Network* OncNetworkParser::CreateNetworkFromInfo( | 304 Network* OncNetworkParser::CreateNetworkFromInfo( |
303 const std::string& service_path, | 305 const std::string& service_path, |
304 const DictionaryValue& info) { | 306 const DictionaryValue& info) { |
305 ConnectionType type = ParseTypeFromDictionary(info); | 307 ConnectionType type = ParseTypeFromDictionary(info); |
306 if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type. | 308 if (type == TYPE_UNKNOWN) // Return NULL if cannot parse network type. |
307 return NULL; | 309 return NULL; |
308 scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); | 310 scoped_ptr<Network> network(CreateNewNetwork(type, service_path)); |
311 | |
312 // Initialize UI data. | |
313 NetworkUIData ui_data; | |
314 ui_data.set_onc_source(onc_source_); | |
315 ui_data.FillDictionary(network->ui_data()); | |
316 | |
317 // Copy ONC to the network object. | |
318 network->onc()->MergeDictionary(&info); | |
319 | |
320 // Parse all properties recursively. | |
309 if (!ParseNestedObject(network.get(), | 321 if (!ParseNestedObject(network.get(), |
310 "NetworkConfiguration", | 322 "NetworkConfiguration", |
311 static_cast<const base::Value&>(info), | 323 static_cast<const base::Value&>(info), |
312 network_configuration_signature, | 324 network_configuration_signature, |
313 ParseNetworkConfigurationValue)) { | 325 ParseNetworkConfigurationValue)) { |
314 LOG(WARNING) << "Network " << network->name() << " failed to parse."; | 326 LOG(WARNING) << "Network " << network->name() << " failed to parse."; |
315 return NULL; | 327 return NULL; |
316 } | 328 } |
329 | |
330 // Update the UI data property. | |
331 std::string ui_data_json; | |
332 base::JSONWriter::Write(network->ui_data(), false, &ui_data_json); | |
333 base::StringValue ui_data_string_value(ui_data_json); | |
334 network->UpdatePropertyMap(PROPERTY_INDEX_UI_DATA, ui_data_string_value); | |
335 | |
317 if (VLOG_IS_ON(2)) { | 336 if (VLOG_IS_ON(2)) { |
318 VLOG(2) << "Created Network '" << network->name() | 337 VLOG(2) << "Created Network '" << network->name() |
319 << "' from info. Path:" << service_path | 338 << "' from info. Path:" << service_path |
320 << " Type:" << ConnectionTypeToString(type); | 339 << " Type:" << ConnectionTypeToString(type); |
321 } | 340 } |
341 | |
322 return network.release(); | 342 return network.release(); |
323 } | 343 } |
324 | 344 |
345 bool OncNetworkParser::ParseNestedObject(Network* network, | |
346 const std::string& onc_type, | |
347 const base::Value& value, | |
348 OncValueSignature* signature, | |
349 ParserPointer parser) { | |
350 bool any_errors = false; | |
351 if (!value.IsType(base::Value::TYPE_DICTIONARY)) { | |
352 VLOG(1) << network->name() << ": expected object of type " << onc_type; | |
353 return false; | |
354 } | |
355 VLOG(2) << "Parsing nested object of type " << onc_type; | |
356 const DictionaryValue* dict = NULL; | |
357 value.GetAsDictionary(&dict); | |
358 for (DictionaryValue::key_iterator iter = dict->begin_keys(); | |
359 iter != dict->end_keys(); ++iter) { | |
360 const std::string& key = *iter; | |
361 | |
362 // The list of Recommended key is only of interest to the UI code and the UI | |
stevenjb
2011/12/14 00:27:38
nit: s/The list of Recommended key is/Recommended
Mattias Nissler (ping if slow)
2011/12/14 20:46:38
Done.
| |
363 // reads it directly from the ONC blob. | |
364 if (key == "Recommended") | |
365 continue; | |
366 | |
367 base::Value* inner_value = NULL; | |
368 dict->GetWithoutPathExpansion(key, &inner_value); | |
369 CHECK(inner_value != NULL); | |
370 int field_index; | |
371 for (field_index = 0; signature[field_index].field != NULL; ++field_index) { | |
372 if (key == signature[field_index].field) | |
373 break; | |
374 } | |
375 if (signature[field_index].field == NULL) { | |
376 VLOG(1) << network->name() << ": unexpected field: " | |
377 << key << ", in type: " << onc_type; | |
378 any_errors = true; | |
379 continue; | |
380 } | |
381 if (!inner_value->IsType(signature[field_index].type)) { | |
382 VLOG(1) << network->name() << ": field with wrong type: " << key | |
383 << ", actual type: " << inner_value->GetType() | |
384 << ", expected type: " << signature[field_index].type; | |
385 any_errors = true; | |
386 continue; | |
387 } | |
388 PropertyIndex index = signature[field_index].index; | |
389 // We need to UpdatePropertyMap now since parser might want to | |
390 // change the mapped value. | |
391 network->UpdatePropertyMap(index, *inner_value); | |
392 if (!parser(this, index, *inner_value, network)) { | |
393 VLOG(1) << network->name() << ": field not parsed: " << key; | |
394 any_errors = true; | |
395 continue; | |
396 } | |
397 | |
398 if (VLOG_IS_ON(2)) { | |
399 std::string value_json; | |
400 base::JSONWriter::Write(inner_value, true, &value_json); | |
401 VLOG(2) << network->name() << ": Successfully parsed [" << key | |
402 << "(" << index << ")] = " << value_json; | |
403 } | |
404 } | |
405 return !any_errors; | |
406 } | |
407 | |
325 Network* OncNetworkParser::CreateNewNetwork( | 408 Network* OncNetworkParser::CreateNewNetwork( |
326 ConnectionType type, const std::string& service_path) { | 409 ConnectionType type, const std::string& service_path) { |
327 Network* network = NetworkParser::CreateNewNetwork(type, service_path); | 410 Network* network = NetworkParser::CreateNewNetwork(type, service_path); |
328 if (network) { | 411 if (network) { |
329 if (type == TYPE_WIFI) | 412 if (type == TYPE_WIFI) |
330 network->SetNetworkParser(new OncWifiNetworkParser()); | 413 network->SetNetworkParser(new OncWifiNetworkParser()); |
331 else if (type == TYPE_VPN) | 414 else if (type == TYPE_VPN) |
332 network->SetNetworkParser(new OncVirtualNetworkParser()); | 415 network->SetNetworkParser(new OncVirtualNetworkParser()); |
333 } | 416 } |
334 return network; | 417 return network; |
(...skipping 15 matching lines...) Expand all Loading... | |
350 return type_string; | 433 return type_string; |
351 } | 434 } |
352 | 435 |
353 std::string OncNetworkParser::GetGuidFromDictionary( | 436 std::string OncNetworkParser::GetGuidFromDictionary( |
354 const base::DictionaryValue& info) { | 437 const base::DictionaryValue& info) { |
355 std::string guid_string; | 438 std::string guid_string; |
356 info.GetString("GUID", &guid_string); | 439 info.GetString("GUID", &guid_string); |
357 return guid_string; | 440 return guid_string; |
358 } | 441 } |
359 | 442 |
443 // static | |
444 bool OncNetworkParser::ParseNetworkConfigurationValue( | |
445 OncNetworkParser* parser, | |
446 PropertyIndex index, | |
447 const base::Value& value, | |
448 Network* network) { | |
449 switch (index) { | |
450 case PROPERTY_INDEX_ONC_WIFI: { | |
451 return parser->ParseNestedObject(network, | |
452 "WiFi", | |
453 value, | |
454 wifi_signature, | |
455 OncWifiNetworkParser::ParseWifiValue); | |
456 } | |
457 case PROPERTY_INDEX_ONC_VPN: { | |
458 if (!CheckNetworkType(network, TYPE_VPN, "VPN")) | |
459 return false; | |
460 VirtualNetwork* virtual_network = static_cast<VirtualNetwork*>(network); | |
461 // Got the "VPN" field. Immediately store the VPN.Type field | |
462 // value so that we can properly validate fields in the VPN | |
463 // object based on the type. | |
464 const DictionaryValue* dict = NULL; | |
465 CHECK(value.GetAsDictionary(&dict)); | |
466 std::string provider_type_string; | |
467 if (!dict->GetString("Type", &provider_type_string)) { | |
468 VLOG(1) << network->name() << ": VPN.Type is missing"; | |
469 return false; | |
470 } | |
471 ProviderType provider_type = | |
472 OncVirtualNetworkParser::ParseProviderType(provider_type_string); | |
473 virtual_network->set_provider_type(provider_type); | |
474 return parser->ParseNestedObject(network, | |
475 "VPN", | |
476 value, | |
477 vpn_signature, | |
478 OncVirtualNetworkParser::ParseVPNValue); | |
479 return true; | |
480 } | |
481 case PROPERTY_INDEX_ONC_REMOVE: | |
482 VLOG(1) << network->name() << ": Remove field not yet implemented"; | |
483 return false; | |
484 case PROPERTY_INDEX_TYPE: { | |
485 // Update property with native value for type. | |
486 std::string str = | |
487 NativeNetworkParser::network_type_mapper()->GetKey(network->type()); | |
488 scoped_ptr<StringValue> val(Value::CreateStringValue(str)); | |
489 network->UpdatePropertyMap(PROPERTY_INDEX_TYPE, *val.get()); | |
490 return true; | |
491 } | |
492 case PROPERTY_INDEX_GUID: | |
493 case PROPERTY_INDEX_NAME: | |
494 // Fall back to generic parser for these. | |
495 return parser->ParseValue(index, value, network); | |
496 default: | |
497 break; | |
498 } | |
499 return false; | |
500 } | |
501 | |
502 // static | |
503 bool OncNetworkParser::CheckNetworkType(Network* network, | |
504 ConnectionType expected, | |
505 const std::string& onc_type) { | |
506 if (expected != network->type()) { | |
507 LOG(WARNING) << network->name() << ": " | |
508 << onc_type << " field unexpected for this type network"; | |
509 return false; | |
510 } | |
511 return true; | |
512 } | |
513 | |
360 scoped_refptr<net::X509Certificate> | 514 scoped_refptr<net::X509Certificate> |
361 OncNetworkParser::ParseServerOrCaCertificate( | 515 OncNetworkParser::ParseServerOrCaCertificate( |
362 int cert_index, | 516 int cert_index, |
363 const std::string& cert_type, | 517 const std::string& cert_type, |
364 const std::string& guid, | 518 const std::string& guid, |
365 base::DictionaryValue* certificate) { | 519 base::DictionaryValue* certificate) { |
366 net::CertDatabase cert_database; | 520 net::CertDatabase cert_database; |
367 bool web_trust = false; | 521 bool web_trust = false; |
368 base::ListValue* trust_list = NULL; | 522 base::ListValue* trust_list = NULL; |
369 if (certificate->GetList("Trust", &trust_list)) { | 523 if (certificate->GetList("Trust", &trust_list)) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 } else { | 653 } else { |
500 LOG(WARNING) << "ONC File: Unable to find private key for cert at index" | 654 LOG(WARNING) << "ONC File: Unable to find private key for cert at index" |
501 << cert_index; | 655 << cert_index; |
502 } | 656 } |
503 | 657 |
504 VLOG(2) << "Successfully imported client certificate at index " | 658 VLOG(2) << "Successfully imported client certificate at index " |
505 << cert_index; | 659 << cert_index; |
506 return cert_result; | 660 return cert_result; |
507 } | 661 } |
508 | 662 |
509 bool OncNetworkParser::ParseNestedObject(Network* network, | |
510 const std::string& onc_type, | |
511 const base::Value& value, | |
512 OncValueSignature* signature, | |
513 ParserPointer parser) { | |
514 bool any_errors = false; | |
515 if (!value.IsType(base::Value::TYPE_DICTIONARY)) { | |
516 VLOG(1) << network->name() << ": expected object of type " << onc_type; | |
517 return false; | |
518 } | |
519 VLOG(2) << "Parsing nested object of type " << onc_type; | |
520 const DictionaryValue* dict = NULL; | |
521 value.GetAsDictionary(&dict); | |
522 for (DictionaryValue::key_iterator iter = dict->begin_keys(); | |
523 iter != dict->end_keys(); ++iter) { | |
524 const std::string& key = *iter; | |
525 base::Value* inner_value = NULL; | |
526 dict->GetWithoutPathExpansion(key, &inner_value); | |
527 CHECK(inner_value != NULL); | |
528 int field_index; | |
529 for (field_index = 0; signature[field_index].field != NULL; ++field_index) { | |
530 if (key == signature[field_index].field) | |
531 break; | |
532 } | |
533 if (signature[field_index].field == NULL) { | |
534 VLOG(1) << network->name() << ": unexpected field: " | |
535 << key << ", in type: " << onc_type; | |
536 any_errors = true; | |
537 continue; | |
538 } | |
539 if (!inner_value->IsType(signature[field_index].type)) { | |
540 VLOG(1) << network->name() << ": field with wrong type: " << key | |
541 << ", actual type: " << inner_value->GetType() | |
542 << ", expected type: " << signature[field_index].type; | |
543 any_errors = true; | |
544 continue; | |
545 } | |
546 PropertyIndex index = signature[field_index].index; | |
547 // We need to UpdatePropertyMap now since parser might want to | |
548 // change the mapped value. | |
549 network->UpdatePropertyMap(index, *inner_value); | |
550 if (!parser(this, index, *inner_value, network)) { | |
551 VLOG(1) << network->name() << ": field not parsed: " << key; | |
552 any_errors = true; | |
553 continue; | |
554 } | |
555 if (VLOG_IS_ON(2)) { | |
556 std::string value_json; | |
557 base::JSONWriter::Write(inner_value, true, &value_json); | |
558 VLOG(2) << network->name() << ": Successfully parsed [" << key | |
559 << "(" << index << ")] = " << value_json; | |
560 } | |
561 } | |
562 return !any_errors; | |
563 } | |
564 | |
565 // static | |
566 bool OncNetworkParser::CheckNetworkType(Network* network, | |
567 ConnectionType expected, | |
568 const std::string& onc_type) { | |
569 if (expected != network->type()) { | |
570 LOG(WARNING) << network->name() << ": " | |
571 << onc_type << " field unexpected for this type network"; | |
572 return false; | |
573 } | |
574 return true; | |
575 } | |
576 | |
577 // static | |
578 bool OncNetworkParser::ParseNetworkConfigurationValue( | |
579 OncNetworkParser* parser, | |
580 PropertyIndex index, | |
581 const base::Value& value, | |
582 Network* network) { | |
583 switch (index) { | |
584 case PROPERTY_INDEX_ONC_WIFI: { | |
585 return parser->ParseNestedObject(network, | |
586 "WiFi", | |
587 value, | |
588 wifi_signature, | |
589 OncWifiNetworkParser::ParseWifiValue); | |
590 } | |
591 case PROPERTY_INDEX_ONC_VPN: { | |
592 if (!CheckNetworkType(network, TYPE_VPN, "VPN")) | |
593 return false; | |
594 VirtualNetwork* virtual_network = static_cast<VirtualNetwork*>(network); | |
595 // Got the "VPN" field. Immediately store the VPN.Type field | |
596 // value so that we can properly validate fields in the VPN | |
597 // object based on the type. | |
598 const DictionaryValue* dict = NULL; | |
599 CHECK(value.GetAsDictionary(&dict)); | |
600 std::string provider_type_string; | |
601 if (!dict->GetString("Type", &provider_type_string)) { | |
602 VLOG(1) << network->name() << ": VPN.Type is missing"; | |
603 return false; | |
604 } | |
605 ProviderType provider_type = | |
606 OncVirtualNetworkParser::ParseProviderType(provider_type_string); | |
607 virtual_network->set_provider_type(provider_type); | |
608 return parser->ParseNestedObject(network, | |
609 "VPN", | |
610 value, | |
611 vpn_signature, | |
612 OncVirtualNetworkParser::ParseVPNValue); | |
613 return true; | |
614 } | |
615 case PROPERTY_INDEX_ONC_REMOVE: | |
616 VLOG(1) << network->name() << ": Remove field not yet implemented"; | |
617 return false; | |
618 case PROPERTY_INDEX_TYPE: { | |
619 // Update property with native value for type. | |
620 std::string str = | |
621 NativeNetworkParser::network_type_mapper()->GetKey(network->type()); | |
622 scoped_ptr<StringValue> val(Value::CreateStringValue(str)); | |
623 network->UpdatePropertyMap(PROPERTY_INDEX_TYPE, *val.get()); | |
624 return true; | |
625 } | |
626 case PROPERTY_INDEX_GUID: | |
627 case PROPERTY_INDEX_NAME: | |
628 // Fall back to generic parser for these. | |
629 return parser->ParseValue(index, value, network); | |
630 default: | |
631 break; | |
632 } | |
633 return false; | |
634 } | |
635 | |
636 // static | |
637 bool OncNetworkParser::DeleteCertAndKeyByNickname(const std::string& label) { | |
638 net::CertificateList cert_list; | |
639 ListCertsWithNickname(label, &cert_list); | |
640 net::CertDatabase cert_db; | |
641 bool result = true; | |
642 for (net::CertificateList::iterator iter = cert_list.begin(); | |
643 iter != cert_list.end(); ++iter) { | |
644 // If we fail, we try and delete the rest still. | |
645 // TODO(gspencer): this isn't very "transactional". If we fail on some, but | |
646 // not all, then it's possible to leave things in a weird state. | |
647 // Luckily there should only be one cert with a particular | |
648 // label, and the cert not being found is one of the few reasons the | |
649 // delete could fail, but still... The other choice is to return | |
650 // failure immediately, but that doesn't seem to do what is intended. | |
651 if (!cert_db.DeleteCertAndKey(iter->get())) | |
652 result = false; | |
653 } | |
654 return result; | |
655 } | |
656 | |
657 // static | 663 // static |
658 void OncNetworkParser::ListCertsWithNickname(const std::string& label, | 664 void OncNetworkParser::ListCertsWithNickname(const std::string& label, |
659 net::CertificateList* result) { | 665 net::CertificateList* result) { |
660 net::CertificateList all_certs; | 666 net::CertificateList all_certs; |
661 net::CertDatabase cert_db; | 667 net::CertDatabase cert_db; |
662 cert_db.ListCerts(&all_certs); | 668 cert_db.ListCerts(&all_certs); |
663 result->clear(); | 669 result->clear(); |
664 for (net::CertificateList::iterator iter = all_certs.begin(); | 670 for (net::CertificateList::iterator iter = all_certs.begin(); |
665 iter != all_certs.end(); ++iter) { | 671 iter != all_certs.end(); ++iter) { |
666 if (iter->get()->os_cert_handle()->nickname) { | 672 if (iter->get()->os_cert_handle()->nickname) { |
(...skipping 19 matching lines...) Expand all Loading... | |
686 if (private_key) { | 692 if (private_key) { |
687 char* private_key_nickname = PK11_GetPrivateKeyNickname(private_key); | 693 char* private_key_nickname = PK11_GetPrivateKeyNickname(private_key); |
688 if (private_key_nickname && private_key_nickname == label) | 694 if (private_key_nickname && private_key_nickname == label) |
689 result->push_back(*iter); | 695 result->push_back(*iter); |
690 PORT_Free(private_key_nickname); | 696 PORT_Free(private_key_nickname); |
691 SECKEY_DestroyPrivateKey(private_key); | 697 SECKEY_DestroyPrivateKey(private_key); |
692 } | 698 } |
693 } | 699 } |
694 } | 700 } |
695 | 701 |
702 // static | |
703 bool OncNetworkParser::DeleteCertAndKeyByNickname(const std::string& label) { | |
704 net::CertificateList cert_list; | |
705 ListCertsWithNickname(label, &cert_list); | |
706 net::CertDatabase cert_db; | |
707 bool result = true; | |
708 for (net::CertificateList::iterator iter = cert_list.begin(); | |
709 iter != cert_list.end(); ++iter) { | |
710 // If we fail, we try and delete the rest still. | |
711 // TODO(gspencer): this isn't very "transactional". If we fail on some, but | |
712 // not all, then it's possible to leave things in a weird state. | |
713 // Luckily there should only be one cert with a particular | |
714 // label, and the cert not being found is one of the few reasons the | |
715 // delete could fail, but still... The other choice is to return | |
716 // failure immediately, but that doesn't seem to do what is intended. | |
717 if (!cert_db.DeleteCertAndKey(iter->get())) | |
718 result = false; | |
719 } | |
720 return result; | |
721 } | |
722 | |
696 // -------------------- OncWirelessNetworkParser -------------------- | 723 // -------------------- OncWirelessNetworkParser -------------------- |
697 | 724 |
698 OncWirelessNetworkParser::OncWirelessNetworkParser() {} | 725 OncWirelessNetworkParser::OncWirelessNetworkParser() {} |
699 OncWirelessNetworkParser::~OncWirelessNetworkParser() {} | 726 OncWirelessNetworkParser::~OncWirelessNetworkParser() {} |
700 | 727 |
701 // -------------------- OncWifiNetworkParser -------------------- | 728 // -------------------- OncWifiNetworkParser -------------------- |
702 | 729 |
703 OncWifiNetworkParser::OncWifiNetworkParser() {} | 730 OncWifiNetworkParser::OncWifiNetworkParser() {} |
704 | 731 |
705 OncWifiNetworkParser::~OncWifiNetworkParser() {} | 732 OncWifiNetworkParser::~OncWifiNetworkParser() {} |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1150 // on the value of AuthenticationType. | 1177 // on the value of AuthenticationType. |
1151 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, | 1178 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, |
1152 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, | 1179 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, |
1153 }; | 1180 }; |
1154 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, | 1181 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, |
1155 (table, arraysize(table), PROVIDER_TYPE_MAX)); | 1182 (table, arraysize(table), PROVIDER_TYPE_MAX)); |
1156 return parser.Get(type); | 1183 return parser.Get(type); |
1157 } | 1184 } |
1158 | 1185 |
1159 } // namespace chromeos | 1186 } // namespace chromeos |
OLD | NEW |