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. | |
Nico
2012/06/01 19:09:14
nit: Add a http://crbug.com/ link to the comment
| |
466 switch (old_attributes_and_data.item_class()) { | |
467 case kSecInternetPasswordItemClass: | |
468 case kSecGenericPasswordItemClass: | |
469 break; | |
470 default: | |
471 return; | |
472 } | |
473 | |
458 // SecKeychainItemCreateFromContent fails if any attribute is zero-length, | 474 // SecKeychainItemCreateFromContent fails if any attribute is zero-length, |
459 // but old_attributes_and_data can contain zero-length attributes. Create | 475 // but old_attributes_and_data can contain zero-length attributes. Create |
460 // a new attribute list devoid of zero-length attributes. | 476 // a new attribute list devoid of zero-length attributes. |
461 // | 477 // |
462 // This is awkward: only the logic to build the | 478 // This is awkward: only the logic to build the |
463 // std::vector<SecKeychainAttribute> is in KCAttributesWithoutZeroLength | 479 // std::vector<SecKeychainAttribute> is in KCAttributesWithoutZeroLength |
464 // because the storage used for the new attribute list (the vector) needs to | 480 // because the storage used for the new attribute list (the vector) needs to |
465 // persist through the lifetime of this function. | 481 // persist through the lifetime of this function. |
466 // KCAttributesWithoutZeroLength doesn't return a | 482 // KCAttributesWithoutZeroLength doesn't return a |
467 // CrSKeychainItemAttributesAndData (which could be held here in a | 483 // CrSKeychainItemAttributesAndData (which could be held here in a |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 } | 524 } |
509 | 525 |
510 return new_attributes; | 526 return new_attributes; |
511 } | 527 } |
512 | 528 |
513 } // namespace | 529 } // namespace |
514 | 530 |
515 } // namespace mac | 531 } // namespace mac |
516 } // namespace browser | 532 } // namespace browser |
517 } // namespace chrome | 533 } // namespace chrome |
OLD | NEW |