OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/mac/keychain_reauthorize.h" | 5 #include "chrome/browser/mac/keychain_reauthorize.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 #include <Security/Security.h> | 8 #include <Security/Security.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 SecKeychainItemRef old_item = item_and_reauthorized_access.item(); | 448 SecKeychainItemRef old_item = item_and_reauthorized_access.item(); |
449 base::mac::ScopedCFTypeRef<SecKeychainRef> keychain( | 449 base::mac::ScopedCFTypeRef<SecKeychainRef> keychain( |
450 CrSKeychainItemCopyKeychain(old_item)); | 450 CrSKeychainItemCopyKeychain(old_item)); |
451 | 451 |
452 ScopedCrSKeychainItemAttributesAndData old_attributes_and_data( | 452 ScopedCrSKeychainItemAttributesAndData old_attributes_and_data( |
453 CrSKeychainItemCopyAttributesAndData(keychain, old_item)); | 453 CrSKeychainItemCopyAttributesAndData(keychain, old_item)); |
454 if (!old_attributes_and_data.get()) { | 454 if (!old_attributes_and_data.get()) { |
455 return; | 455 return; |
456 } | 456 } |
457 | 457 |
| 458 // CrSKeychainItemCreateFromContent (SecKeychainItemCreateFromContent) |
| 459 // returns errKCNoSuchAttr (errSecNoSuchAttr) when asked to add an item of |
| 460 // type kSecPrivateKeyItemClass. This would happen after the original |
| 461 // private key was deleted, resulting in data loss. I can't figure out how |
| 462 // SecKeychainItemCreateFromContent wants private keys added. Skip them, |
| 463 // only doing the reauthorization for Keychain item types known to work, |
| 464 // the item types expected to be used by most users and those that are |
| 465 // synced. See http://crbug.com/130738 and |
| 466 // http://lists.apple.com/archives/apple-cdsa/2006/Jan/msg00025.html . |
| 467 switch (old_attributes_and_data.item_class()) { |
| 468 case kSecInternetPasswordItemClass: |
| 469 case kSecGenericPasswordItemClass: |
| 470 break; |
| 471 default: |
| 472 return; |
| 473 } |
| 474 |
458 // SecKeychainItemCreateFromContent fails if any attribute is zero-length, | 475 // SecKeychainItemCreateFromContent fails if any attribute is zero-length, |
459 // but old_attributes_and_data can contain zero-length attributes. Create | 476 // but old_attributes_and_data can contain zero-length attributes. Create |
460 // a new attribute list devoid of zero-length attributes. | 477 // a new attribute list devoid of zero-length attributes. |
461 // | 478 // |
462 // This is awkward: only the logic to build the | 479 // This is awkward: only the logic to build the |
463 // std::vector<SecKeychainAttribute> is in KCAttributesWithoutZeroLength | 480 // std::vector<SecKeychainAttribute> is in KCAttributesWithoutZeroLength |
464 // because the storage used for the new attribute list (the vector) needs to | 481 // because the storage used for the new attribute list (the vector) needs to |
465 // persist through the lifetime of this function. | 482 // persist through the lifetime of this function. |
466 // KCAttributesWithoutZeroLength doesn't return a | 483 // KCAttributesWithoutZeroLength doesn't return a |
467 // CrSKeychainItemAttributesAndData (which could be held here in a | 484 // CrSKeychainItemAttributesAndData (which could be held here in a |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 525 } |
509 | 526 |
510 return new_attributes; | 527 return new_attributes; |
511 } | 528 } |
512 | 529 |
513 } // namespace | 530 } // namespace |
514 | 531 |
515 } // namespace mac | 532 } // namespace mac |
516 } // namespace browser | 533 } // namespace browser |
517 } // namespace chrome | 534 } // namespace chrome |
OLD | NEW |