From 3a27cf4bac9eb23a6bfc7cdab1ded88d1812b3cb Mon Sep 17 00:00:00 2001 From: "stuart.morgan%alumni.case.edu" Date: Mon, 26 Feb 2007 16:08:16 +0000 Subject: [PATCH] Camino only - Bug 371272: Upgrade old Camino keychain items even when changing username. r=josh sr=pink git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@220928 18797224-902f-48f8-a5cc-f745e15eee43 --- .../camino/src/formfill/KeychainService.mm | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/mozilla/camino/src/formfill/KeychainService.mm b/mozilla/camino/src/formfill/KeychainService.mm index 10a880f1653..780e567fc34 100644 --- a/mozilla/camino/src/formfill/KeychainService.mm +++ b/mozilla/camino/src/formfill/KeychainService.mm @@ -96,6 +96,9 @@ GetNSWindow(nsIDOMWindow* inWindow); @interface KeychainService(Private) - (KeychainItem*)findLegacyKeychainEntryForHost:(NSString*)host port:(PRInt32)port; +- (void)upgradeLegacyKeychainEntry:(KeychainItem*)keychainItem + withScheme:(NSString*)scheme + isForm:(BOOL)isFrom; @end @implementation KeychainService @@ -294,18 +297,16 @@ int KeychainPrefChangedCallback(const char* inPref, void* unused) scheme:(NSString*)scheme isForm:(BOOL)isForm { + // If this is one of our old items, upgrade it to the new format. We do this here instead of when + // we first find the item so that users trying out 1.1 previews won't be missing the passwords of + // all the sites they visit if/when they go back to 1.0.x, as well as to prevent passwords from accidentally + // being associated with the wrong type (e.g., if a user has a password stored for a site's web form, + // but hits the http auth dialog first). + if ([keychainItem authenticationType] == kSecAuthenticationTypeHTTPDigest) + [self upgradeLegacyKeychainEntry:keychainItem withScheme:scheme isForm:isForm]; + if ([username isEqualToString:[keychainItem username]] || [keychainItem creator] == kCaminoKeychainCreatorCode) { [keychainItem setUsername:username password:password]; - // If this is one of our old items, upgrade it to the new format. We do this here instead of when - // we first find the item so that users trying out 1.1 previews won't be missing the passwords of - // all the sites they visit if/when they go back to 1.0.x, as well as to prevent passwords from accidentally - // being associated with the wrong type (e.g., if a user has a password stored for a site's web form, - // but hits the http auth dialog first). - if ([keychainItem authenticationType] == kSecAuthenticationTypeHTTPDigest) { - [keychainItem setProtocol:([scheme isEqualToString:@"https"] ? kSecProtocolTypeHTTPS : kSecProtocolTypeHTTP)]; - [keychainItem setAuthenticationType:(isForm ? kSecAuthenticationTypeHTMLForm : kSecAuthenticationTypeDefault)]; - [keychainItem setCreator:kCaminoKeychainCreatorCode]; - } } else { KeychainItem* newItem = [KeychainItem addKeychainItemForHost:[keychainItem host] @@ -318,6 +319,17 @@ int KeychainPrefChangedCallback(const char* inPref, void* unused) } } +- (void)upgradeLegacyKeychainEntry:(KeychainItem*)keychainItem + withScheme:(NSString*)scheme + isForm:(BOOL)isForm +{ + [keychainItem setProtocol:([scheme isEqualToString:@"https"] ? kSecProtocolTypeHTTPS + : kSecProtocolTypeHTTP)]; + [keychainItem setAuthenticationType:(isForm ? kSecAuthenticationTypeHTMLForm + : kSecAuthenticationTypeDefault)]; + [keychainItem setCreator:kCaminoKeychainCreatorCode]; +} + // Removes all Camino-created keychain entries. This will only remove new-style entries, // because it's not safe to assume that all passwords that match the old format were // necessarily created by us.