Changeset 6197


Ignore:
Timestamp:
Jun 15, 2008, 8:47:24 PM (14 years ago)
Author:
livings124
Message:

drop EMKeychain and just do the Keychain manipulations ourselves

Location:
trunk
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Transmission.xcodeproj/project.pbxproj

    r6196 r6197  
    8383                A215760B0C0D449A0057A26A /* NSBezierPathAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A21576090C0D449A0057A26A /* NSBezierPathAdditions.m */; };
    8484                A219798B0D07B78400438EA7 /* GroupToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A219798A0D07B78400438EA7 /* GroupToolbarItem.m */; };
    85                 A21A23740E00B7FF00D424F8 /* EMKeychainProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = A21A23700E00B7FF00D424F8 /* EMKeychainProxy.m */; };
    86                 A21A23750E00B7FF00D424F8 /* EMKeychainItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A21A23720E00B7FF00D424F8 /* EMKeychainItem.m */; };
    8785                A21DFF100A292B2B007C5F76 /* Transfers.png in Resources */ = {isa = PBXBuildFile; fileRef = A21DFF0F0A292B2B007C5F76 /* Transfers.png */; };
    8886                A22180980D148A71007D09ED /* GroupsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = A22180970D148A71007D09ED /* GroupsWindowController.m */; };
     
    488486                A21979890D07B78400438EA7 /* GroupToolbarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GroupToolbarItem.h; path = macosx/GroupToolbarItem.h; sourceTree = "<group>"; };
    489487                A219798A0D07B78400438EA7 /* GroupToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GroupToolbarItem.m; path = macosx/GroupToolbarItem.m; sourceTree = "<group>"; };
    490                 A21A23700E00B7FF00D424F8 /* EMKeychainProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EMKeychainProxy.m; path = macosx/EMKeychain/EMKeychainProxy.m; sourceTree = "<group>"; };
    491                 A21A23710E00B7FF00D424F8 /* EMKeychainItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EMKeychainItem.h; path = macosx/EMKeychain/EMKeychainItem.h; sourceTree = "<group>"; };
    492                 A21A23720E00B7FF00D424F8 /* EMKeychainItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EMKeychainItem.m; path = macosx/EMKeychain/EMKeychainItem.m; sourceTree = "<group>"; };
    493                 A21A23730E00B7FF00D424F8 /* EMKeychainProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EMKeychainProxy.h; path = macosx/EMKeychain/EMKeychainProxy.h; sourceTree = "<group>"; };
    494488                A21DFF0F0A292B2B007C5F76 /* Transfers.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Transfers.png; path = macosx/Images/Transfers.png; sourceTree = "<group>"; };
    495489                A22180960D148A71007D09ED /* GroupsWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GroupsWindowController.h; path = macosx/GroupsWindowController.h; sourceTree = "<group>"; };
     
    935929                                E138A9720C04D88F00C5426C /* CTGradient */,
    936930                                E1B6FBEB0C0D70AC0015FE4D /* UKKQueue */,
    937                                 A21A236F0E00B7DC00D424F8 /* EMKeychain */,
    938931                                A21282A50CA6C66800EAEE0F /* StatusBarView.h */,
    939932                                A21282A60CA6C66800EAEE0F /* StatusBarView.m */,
     
    12361229                        sourceTree = "<group>";
    12371230                };
    1238                 A21A236F0E00B7DC00D424F8 /* EMKeychain */ = {
    1239                         isa = PBXGroup;
    1240                         children = (
    1241                                 A21A23700E00B7FF00D424F8 /* EMKeychainProxy.m */,
    1242                                 A21A23710E00B7FF00D424F8 /* EMKeychainItem.h */,
    1243                                 A21A23720E00B7FF00D424F8 /* EMKeychainItem.m */,
    1244                                 A21A23730E00B7FF00D424F8 /* EMKeychainProxy.h */,
    1245                         );
    1246                         name = EMKeychain;
    1247                         sourceTree = "<group>";
    1248                 };
    12491231                A234D0D40C79FB6000A82373 /* Additions */ = {
    12501232                        isa = PBXGroup;
     
    20272009                                A2725B6E0DE5C4F5003445E7 /* FileListNode.m in Sources */,
    20282010                                A2725D5D0DE7507C003445E7 /* TrackerTableView.m in Sources */,
    2029                                 A21A23740E00B7FF00D424F8 /* EMKeychainProxy.m in Sources */,
    2030                                 A21A23750E00B7FF00D424F8 /* EMKeychainItem.m in Sources */,
    20312011                        );
    20322012                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/macosx/Controller.m

    r6178 r6197  
    229229                                [fDefaults boolForKey: @"ProxyAuthorize"],
    230230                                [[fDefaults stringForKey: @"ProxyUsername"] UTF8String],
    231                                 NULL); /* reset in prefs - from Keychain */
     231                                ""); /* reset in prefs - from Keychain */
    232232       
    233233        [NSApp setDelegate: self];
  • trunk/macosx/PrefsController.m

    r6195 r6197  
    5252#define TOOLBAR_REMOTE      @"TOOLBAR_REMOTE"
    5353
    54 #define PROXY_KEYCHAIN_SERVICE  @"Transmission:Proxy"
    55 #define PROXY_KEYCHAIN_NAME     @"Proxy"
    56 
    57 #define RPC_KEYCHAIN_SERVICE    @"Transmission:Remote"
    58 #define RPC_KEYCHAIN_NAME       @"Remote"
     54#define PROXY_KEYCHAIN_SERVICE  "Transmission:Proxy"
     55#define PROXY_KEYCHAIN_NAME     "Proxy"
     56
     57#define RPC_KEYCHAIN_SERVICE    "Transmission:Remote"
     58#define RPC_KEYCHAIN_NAME       "Remote"
    5959
    6060@interface PrefsController (Private)
     
    6666- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
    6767
    68 - (void) setKeychainPassword: (NSString *) password forService: (NSString *) service username: (NSString *) username;
     68- (void) setKeychainPassword: (NSString *) password forService: (const char *) service username: (const char *) username;
    6969
    7070@end
     
    769769- (void) setProxyPassword: (id) sender
    770770{
    771     NSString * password = [[sender stringValue] retain];
     771    NSString * password = [sender stringValue];
    772772    [self setKeychainPassword: password forService: PROXY_KEYCHAIN_SERVICE username: PROXY_KEYCHAIN_NAME];
    773773   
     
    777777- (void) updateProxyPassword
    778778{
    779     EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: PROXY_KEYCHAIN_SERVICE
    780                                             withUsername: PROXY_KEYCHAIN_NAME];
    781    
    782     NSString * password;
    783     if (!(password = [keychainItem password]))
    784         password = @"";
    785    
    786     tr_sessionSetProxyPassword(fHandle, [password UTF8String]);
    787    
    788     [fProxyPasswordField setStringValue: password];
     779    UInt32 passwordLength;
     780        const char * password = nil;
     781    SecKeychainFindGenericPassword(NULL, strlen(PROXY_KEYCHAIN_SERVICE), PROXY_KEYCHAIN_SERVICE,
     782        strlen(PROXY_KEYCHAIN_NAME), PROXY_KEYCHAIN_NAME, &passwordLength, (void **)&password, NULL);
     783   
     784    if (password != NULL)
     785    {
     786        char fullPassword[passwordLength+1];
     787        strncpy(fullPassword, password, passwordLength);
     788        fullPassword[passwordLength] = '\0';
     789        SecKeychainItemFreeContent(NULL, (void *)password);
     790       
     791        tr_sessionSetProxyPassword(fHandle, fullPassword);
     792        [fProxyPasswordField setStringValue: [NSString stringWithUTF8String: fullPassword]];
     793    }
    789794}
    790795
     
    806811- (void) setRPCPassword: (id) sender
    807812{
    808     NSString * password = [[sender stringValue] retain];
     813    NSString * password = [sender stringValue];
    809814    [self setKeychainPassword: password forService: RPC_KEYCHAIN_SERVICE username: RPC_KEYCHAIN_NAME];
    810815   
     
    814819- (void) updateRPCPassword
    815820{
    816     EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: RPC_KEYCHAIN_SERVICE
    817                                             withUsername: RPC_KEYCHAIN_NAME];
    818    
    819     NSString * password;
    820     if (!(password = [keychainItem password]))
    821         password = @"";
    822    
    823     tr_sessionSetRPCPassword(fHandle, [password UTF8String]);
    824    
    825     [fRPCPasswordField setStringValue: password];
     821    UInt32 passwordLength;
     822        const char * password = nil;
     823    SecKeychainFindGenericPassword(NULL, strlen(RPC_KEYCHAIN_SERVICE), RPC_KEYCHAIN_SERVICE,
     824        strlen(RPC_KEYCHAIN_NAME), RPC_KEYCHAIN_NAME, &passwordLength, (void **)&password, NULL);
     825   
     826    if (password != NULL)
     827    {
     828        char fullPassword[passwordLength+1];
     829        strncpy(fullPassword, password, passwordLength);
     830        fullPassword[passwordLength] = '\0';
     831        SecKeychainItemFreeContent(NULL, (void *)password);
     832       
     833        tr_sessionSetRPCPassword(fHandle, fullPassword);
     834        [fRPCPasswordField setStringValue: [NSString stringWithUTF8String: fullPassword]];
     835    }
    826836}
    827837
     
    11501160}
    11511161
    1152 - (void) setKeychainPassword: (NSString *) password forService: (NSString *) service username: (NSString *) username
    1153 {
     1162- (void) setKeychainPassword: (NSString *) password forService: (const char *) service username: (const char *) username
     1163{
     1164    SecKeychainItemRef item = NULL;
    11541165    BOOL shouldAdd = password && ![password isEqualToString: @""];
    11551166   
    1156     EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: service withUsername: username];
    1157     if (keychainItem)
     1167    OSStatus result = SecKeychainFindGenericPassword(NULL, strlen(service), service, strlen(username), username, NULL, NULL, &item);
     1168    if (result == noErr && item)
     1169    {
     1170        if (shouldAdd) //found, so update
     1171        {
     1172            result = SecKeychainItemModifyAttributesAndData(item, NULL, [password length], (const void *)[password UTF8String]);
     1173            if (result != noErr)
     1174                NSLog(@"Problem updating Keychain item: %s", GetMacOSStatusErrorString(result));
     1175        }
     1176        else //remove the item
     1177        {
     1178            result = SecKeychainItemDelete(item);
     1179            if (result != noErr)
     1180                NSLog(@"Problem removing Keychain item: %s", GetMacOSStatusErrorString(result));
     1181        }
     1182    }
     1183    else if (result == errSecItemNotFound) //not found, so add
    11581184    {
    11591185        if (shouldAdd)
    1160             [keychainItem setPassword: password];
    1161         else
    1162             [keychainItem removeFromKeychain];
     1186        {
     1187            result = SecKeychainAddGenericPassword(NULL, strlen(service), service, strlen(username), username,
     1188                        [password length], (const void *)[password UTF8String], NULL);
     1189            if (result != noErr)
     1190                NSLog(@"Problem adding Keychain item: %s", GetMacOSStatusErrorString(result));
     1191        }
    11631192    }
    11641193    else
    1165     {
    1166         if (shouldAdd)
    1167             [[EMKeychainProxy sharedProxy] addGenericKeychainItemForService: service withUsername: username password: password];
    1168     }
     1194        NSLog(@"Problem accessing Keychain: %s", GetMacOSStatusErrorString(result));
    11691195}
    11701196
Note: See TracChangeset for help on using the changeset viewer.