mirror of
https://github.com/transmission/transmission
synced 2024-12-24 16:52:39 +00:00
drop EMKeychain and just do the Keychain manipulations ourselves
This commit is contained in:
parent
2bde997b18
commit
df22774126
7 changed files with 62 additions and 563 deletions
|
@ -82,8 +82,6 @@
|
|||
A21282A80CA6C66800EAEE0F /* StatusBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = A21282A60CA6C66800EAEE0F /* StatusBarView.m */; };
|
||||
A215760B0C0D449A0057A26A /* NSBezierPathAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A21576090C0D449A0057A26A /* NSBezierPathAdditions.m */; };
|
||||
A219798B0D07B78400438EA7 /* GroupToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A219798A0D07B78400438EA7 /* GroupToolbarItem.m */; };
|
||||
A21A23740E00B7FF00D424F8 /* EMKeychainProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = A21A23700E00B7FF00D424F8 /* EMKeychainProxy.m */; };
|
||||
A21A23750E00B7FF00D424F8 /* EMKeychainItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A21A23720E00B7FF00D424F8 /* EMKeychainItem.m */; };
|
||||
A21DFF100A292B2B007C5F76 /* Transfers.png in Resources */ = {isa = PBXBuildFile; fileRef = A21DFF0F0A292B2B007C5F76 /* Transfers.png */; };
|
||||
A22180980D148A71007D09ED /* GroupsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = A22180970D148A71007D09ED /* GroupsWindowController.m */; };
|
||||
A22180B60D148F0F007D09ED /* GroupsWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A22180B50D148F0F007D09ED /* GroupsWindow.xib */; };
|
||||
|
@ -487,10 +485,6 @@
|
|||
A215760A0C0D449A0057A26A /* NSBezierPathAdditions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = NSBezierPathAdditions.h; path = macosx/NSBezierPathAdditions.h; sourceTree = "<group>"; };
|
||||
A21979890D07B78400438EA7 /* GroupToolbarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GroupToolbarItem.h; path = macosx/GroupToolbarItem.h; sourceTree = "<group>"; };
|
||||
A219798A0D07B78400438EA7 /* GroupToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GroupToolbarItem.m; path = macosx/GroupToolbarItem.m; sourceTree = "<group>"; };
|
||||
A21A23700E00B7FF00D424F8 /* EMKeychainProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EMKeychainProxy.m; path = macosx/EMKeychain/EMKeychainProxy.m; sourceTree = "<group>"; };
|
||||
A21A23710E00B7FF00D424F8 /* EMKeychainItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EMKeychainItem.h; path = macosx/EMKeychain/EMKeychainItem.h; sourceTree = "<group>"; };
|
||||
A21A23720E00B7FF00D424F8 /* EMKeychainItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EMKeychainItem.m; path = macosx/EMKeychain/EMKeychainItem.m; sourceTree = "<group>"; };
|
||||
A21A23730E00B7FF00D424F8 /* EMKeychainProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EMKeychainProxy.h; path = macosx/EMKeychain/EMKeychainProxy.h; sourceTree = "<group>"; };
|
||||
A21DFF0F0A292B2B007C5F76 /* Transfers.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Transfers.png; path = macosx/Images/Transfers.png; sourceTree = "<group>"; };
|
||||
A22180960D148A71007D09ED /* GroupsWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GroupsWindowController.h; path = macosx/GroupsWindowController.h; sourceTree = "<group>"; };
|
||||
A22180970D148A71007D09ED /* GroupsWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GroupsWindowController.m; path = macosx/GroupsWindowController.m; sourceTree = "<group>"; };
|
||||
|
@ -934,7 +928,6 @@
|
|||
E1B6FC000C0D72A00015FE4D /* Overlay Window */,
|
||||
E138A9720C04D88F00C5426C /* CTGradient */,
|
||||
E1B6FBEB0C0D70AC0015FE4D /* UKKQueue */,
|
||||
A21A236F0E00B7DC00D424F8 /* EMKeychain */,
|
||||
A21282A50CA6C66800EAEE0F /* StatusBarView.h */,
|
||||
A21282A60CA6C66800EAEE0F /* StatusBarView.m */,
|
||||
A2ED7D8D0CEF431B00970975 /* FilterButton.h */,
|
||||
|
@ -1235,17 +1228,6 @@
|
|||
name = CLI;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A21A236F0E00B7DC00D424F8 /* EMKeychain */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A21A23700E00B7FF00D424F8 /* EMKeychainProxy.m */,
|
||||
A21A23710E00B7FF00D424F8 /* EMKeychainItem.h */,
|
||||
A21A23720E00B7FF00D424F8 /* EMKeychainItem.m */,
|
||||
A21A23730E00B7FF00D424F8 /* EMKeychainProxy.h */,
|
||||
);
|
||||
name = EMKeychain;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A234D0D40C79FB6000A82373 /* Additions */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -2026,8 +2008,6 @@
|
|||
A2DF57740DE46A6A000795D5 /* QuickLookController.m in Sources */,
|
||||
A2725B6E0DE5C4F5003445E7 /* FileListNode.m in Sources */,
|
||||
A2725D5D0DE7507C003445E7 /* TrackerTableView.m in Sources */,
|
||||
A21A23740E00B7FF00D424F8 /* EMKeychainProxy.m in Sources */,
|
||||
A21A23750E00B7FF00D424F8 /* EMKeychainItem.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -228,7 +228,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
TR_DEFAULT_PROXY_TYPE, /* reset in prefs */
|
||||
[fDefaults boolForKey: @"ProxyAuthorize"],
|
||||
[[fDefaults stringForKey: @"ProxyUsername"] UTF8String],
|
||||
NULL); /* reset in prefs - from Keychain */
|
||||
""); /* reset in prefs - from Keychain */
|
||||
|
||||
[NSApp setDelegate: self];
|
||||
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Carbon/Carbon.h>
|
||||
#import <Security/Security.h>
|
||||
|
||||
@interface EMKeychainItem : NSObject
|
||||
{
|
||||
NSString *myPassword;
|
||||
NSString *myUsername;
|
||||
NSString *myLabel;
|
||||
SecKeychainItemRef coreKeychainItem;
|
||||
}
|
||||
- (NSString *)password;
|
||||
- (NSString *)username;
|
||||
- (NSString *)label;
|
||||
- (BOOL)setPassword:(NSString *)newPassword;
|
||||
- (BOOL)setUsername:(NSString *)newUsername;
|
||||
- (BOOL)setLabel:(NSString *)newLabel;
|
||||
|
||||
//added by ML
|
||||
- (void)removeFromKeychain;
|
||||
@end
|
||||
|
||||
@interface EMKeychainItem (Private)
|
||||
- (BOOL)modifyAttributeWithTag:(SecItemAttr)attributeTag toBeString:(NSString *)newStringValue;
|
||||
@end
|
||||
|
||||
@interface EMGenericKeychainItem : EMKeychainItem
|
||||
{
|
||||
NSString *myServiceName;
|
||||
}
|
||||
+ (id)genericKeychainItem:(SecKeychainItemRef)item forServiceName:(NSString *)serviceName username:(NSString *)username password:(NSString *)password;
|
||||
- (NSString *)serviceName;
|
||||
- (BOOL)setServiceName:(NSString *)newServiceName;
|
||||
@end
|
||||
|
||||
@interface EMInternetKeychainItem : EMKeychainItem
|
||||
{
|
||||
NSString *myServer;
|
||||
NSString *myPath;
|
||||
int myPort;
|
||||
SecProtocolType myProtocol;
|
||||
}
|
||||
+ (id)internetKeychainItem:(SecKeychainItemRef)item forServer:(NSString *)server username:(NSString *)username password:(NSString *)password path:(NSString *)path port:(int)port protocol:(SecProtocolType)protocol;
|
||||
- (NSString *)server;
|
||||
- (NSString *)path;
|
||||
- (int)port;
|
||||
- (SecProtocolType)protocol;
|
||||
- (BOOL)setServer:(NSString *)newServer;
|
||||
- (BOOL)setPath:(NSString *)newPath;
|
||||
- (BOOL)setPort:(int)newPort;
|
||||
- (BOOL)setProtocol:(SecProtocolType)newProtocol;
|
||||
@end
|
|
@ -1,219 +0,0 @@
|
|||
/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import "EMKeychainItem.h"
|
||||
|
||||
@implementation EMKeychainItem
|
||||
- (id)initWithCoreKeychainItem:(SecKeychainItemRef)item username:(NSString *)username password:(NSString *)password
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
coreKeychainItem = item;
|
||||
[self setValue:username forKey:@"myUsername"];
|
||||
[self setValue:password forKey:@"myPassword"];
|
||||
return self;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
- (NSString *)password
|
||||
{
|
||||
return myPassword;
|
||||
}
|
||||
- (NSString *)username
|
||||
{
|
||||
return myUsername;
|
||||
}
|
||||
- (NSString *)label
|
||||
{
|
||||
return myLabel;
|
||||
}
|
||||
|
||||
- (BOOL)setPassword:(NSString *)newPasswordString
|
||||
{
|
||||
if (!newPasswordString)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
[self willChangeValueForKey:@"password"];
|
||||
[myPassword autorelease];
|
||||
myPassword = [newPasswordString copy];
|
||||
[self didChangeValueForKey:@"password"];
|
||||
|
||||
const char *newPassword = [newPasswordString UTF8String];
|
||||
OSStatus returnStatus = SecKeychainItemModifyAttributesAndData(coreKeychainItem, NULL, strlen(newPassword), (void *)newPassword);
|
||||
return (returnStatus == noErr);
|
||||
}
|
||||
- (BOOL)setUsername:(NSString *)newUsername
|
||||
{
|
||||
[self willChangeValueForKey:@"username"];
|
||||
[myUsername autorelease];
|
||||
myUsername = [newUsername copy];
|
||||
[self didChangeValueForKey:@"username"];
|
||||
|
||||
return [self modifyAttributeWithTag:kSecAccountItemAttr toBeString:newUsername];
|
||||
}
|
||||
- (BOOL)setLabel:(NSString *)newLabel
|
||||
{
|
||||
[self willChangeValueForKey:@"label"];
|
||||
[myLabel autorelease];
|
||||
myLabel = [newLabel copy];
|
||||
[self didChangeValueForKey:@"label"];
|
||||
|
||||
return [self modifyAttributeWithTag:kSecLabelItemAttr toBeString:newLabel];
|
||||
}
|
||||
|
||||
- (void)removeFromKeychain
|
||||
{
|
||||
SecKeychainItemDelete(coreKeychainItem);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation EMKeychainItem (Private)
|
||||
- (BOOL)modifyAttributeWithTag:(SecItemAttr)attributeTag toBeString:(NSString *)newStringValue
|
||||
{
|
||||
const char *newValue = [newStringValue UTF8String];
|
||||
SecKeychainAttribute attributes[1];
|
||||
attributes[0].tag = attributeTag;
|
||||
attributes[0].length = strlen(newValue);
|
||||
attributes[0].data = (void *)newValue;
|
||||
|
||||
SecKeychainAttributeList list;
|
||||
list.count = 1;
|
||||
list.attr = attributes;
|
||||
|
||||
OSStatus returnStatus = SecKeychainItemModifyAttributesAndData(coreKeychainItem, &list, 0, NULL);
|
||||
return (returnStatus == noErr);
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation EMGenericKeychainItem
|
||||
- (id)initWithCoreKeychainItem:(SecKeychainItemRef)item serviceName:(NSString *)serviceName username:(NSString *)username password:(NSString *)password
|
||||
{
|
||||
if ((self = [super initWithCoreKeychainItem:item username:username password:password]))
|
||||
{
|
||||
[self setValue:serviceName forKey:@"myServiceName"];
|
||||
return self;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
+ (id)genericKeychainItem:(SecKeychainItemRef)item forServiceName:(NSString *)serviceName username:(NSString *)username password:(NSString *)password
|
||||
{
|
||||
return [[[EMGenericKeychainItem alloc] initWithCoreKeychainItem:item serviceName:serviceName username:username password:password] autorelease];
|
||||
}
|
||||
- (NSString *)serviceName
|
||||
{
|
||||
return myServiceName;
|
||||
}
|
||||
|
||||
- (BOOL)setServiceName:(NSString *)newServiceName
|
||||
{
|
||||
[self willChangeValueForKey:@"serviceName"];
|
||||
[myServiceName autorelease];
|
||||
myServiceName = [newServiceName copy];
|
||||
[self didChangeValueForKey:@"serviceName"];
|
||||
|
||||
return [self modifyAttributeWithTag:kSecServiceItemAttr toBeString:newServiceName];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation EMInternetKeychainItem
|
||||
- (id)initWithCoreKeychainItem:(SecKeychainItemRef)item server:(NSString *)server username:(NSString *)username password:(NSString *)password path:(NSString *)path port:(int)port protocol:(SecProtocolType)protocol
|
||||
{
|
||||
if ((self = [super initWithCoreKeychainItem:item username:username password:password]))
|
||||
{
|
||||
[self setValue:server forKey:@"myServer"];
|
||||
[self setValue:path forKey:@"myPath"];
|
||||
[self setValue:[NSNumber numberWithInt:port] forKey:@"myPort"];
|
||||
[self setValue:[NSNumber numberWithInt:protocol] forKey:@"myProtocol"];
|
||||
return self;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
+ (id)internetKeychainItem:(SecKeychainItemRef)item forServer:(NSString *)server username:(NSString *)username password:(NSString *)password path:(NSString *)path port:(int)port protocol:(SecProtocolType)protocol
|
||||
{
|
||||
return [[[EMInternetKeychainItem alloc] initWithCoreKeychainItem:item server:server username:username password:password path:path port:port protocol:protocol] autorelease];
|
||||
}
|
||||
- (NSString *)server
|
||||
{
|
||||
return myServer;
|
||||
}
|
||||
- (NSString *)path
|
||||
{
|
||||
return myPath;
|
||||
}
|
||||
- (int)port
|
||||
{
|
||||
return myPort;
|
||||
}
|
||||
- (SecProtocolType)protocol
|
||||
{
|
||||
return myProtocol;
|
||||
}
|
||||
|
||||
- (BOOL)setServer:(NSString *)newServer
|
||||
{
|
||||
[self willChangeValueForKey:@"server"];
|
||||
[myServer autorelease];
|
||||
myServer = [newServer copy];
|
||||
[self didChangeValueForKey:@"server"];
|
||||
|
||||
return [self modifyAttributeWithTag:kSecServerItemAttr toBeString:newServer];
|
||||
}
|
||||
- (BOOL)setPath:(NSString *)newPath
|
||||
{
|
||||
[self willChangeValueForKey:@"path"];
|
||||
[myPath autorelease];
|
||||
myPath = [newPath copy];
|
||||
[self didChangeValueForKey:@"path"];
|
||||
|
||||
return [self modifyAttributeWithTag:kSecPathItemAttr toBeString:newPath];
|
||||
}
|
||||
- (BOOL)setPort:(int)newPort
|
||||
{
|
||||
[self willChangeValueForKey:@"port"];
|
||||
myPort = newPort;
|
||||
[self didChangeValueForKey:@"port"];
|
||||
|
||||
return [self modifyAttributeWithTag:kSecPortItemAttr toBeString:[NSString stringWithFormat:@"%i", newPort]];
|
||||
}
|
||||
- (BOOL)setProtocol:(SecProtocolType)newProtocol
|
||||
{
|
||||
[self willChangeValueForKey:@"protocol"];
|
||||
myProtocol = newProtocol;
|
||||
[self didChangeValueForKey:@"protocol"];
|
||||
|
||||
SecKeychainAttribute attributes[1];
|
||||
attributes[0].tag = kSecProtocolItemAttr;
|
||||
attributes[0].length = sizeof(newProtocol);
|
||||
attributes[0].data = (void *)newProtocol;
|
||||
|
||||
SecKeychainAttributeList list;
|
||||
list.count = 1;
|
||||
list.attr = attributes;
|
||||
|
||||
OSStatus returnStatus = SecKeychainItemModifyAttributesAndData(coreKeychainItem, &list, 0, NULL);
|
||||
return (returnStatus == noErr);
|
||||
}
|
||||
@end
|
|
@ -1,48 +0,0 @@
|
|||
/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//Last Changed on 2/07/08. Version 0.14
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Carbon/Carbon.h>
|
||||
#import <Security/Security.h>
|
||||
|
||||
#import "EMKeychainItem.h"
|
||||
|
||||
@interface EMKeychainProxy : NSObject
|
||||
{
|
||||
BOOL _logErrors;
|
||||
}
|
||||
+ (id)sharedProxy;
|
||||
- (void)lockKeychain;
|
||||
- (void)unlockKeychain;
|
||||
- (void)setLogsErrors:(BOOL)flag;
|
||||
|
||||
- (EMGenericKeychainItem *)genericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString;
|
||||
- (EMInternetKeychainItem *)internetKeychainItemForServer:(NSString *)serverString withUsername:(NSString *)usernameString path:(NSString *)pathString port:(int)port protocol:(SecProtocolType)protocol;
|
||||
|
||||
- (EMGenericKeychainItem *)addGenericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString password:(NSString *)passwordString;
|
||||
- (EMInternetKeychainItem *)addInternetKeychainItemForServer:(NSString *)serverString withUsername:(NSString *)usernameString password:(NSString *)passwordString path:(NSString *)pathString port:(int)port protocol:(SecProtocolType)protocol;
|
||||
|
||||
@end
|
|
@ -1,163 +0,0 @@
|
|||
/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import "EMKeychainProxy.h"
|
||||
|
||||
@implementation EMKeychainProxy
|
||||
|
||||
static EMKeychainProxy* sharedProxy;
|
||||
|
||||
+ (id)sharedProxy
|
||||
{
|
||||
if (!sharedProxy)
|
||||
{
|
||||
sharedProxy = [[EMKeychainProxy alloc] init];
|
||||
}
|
||||
return sharedProxy;
|
||||
}
|
||||
- (void)lockKeychain
|
||||
{
|
||||
SecKeychainLock(NULL);
|
||||
}
|
||||
- (void)unlockKeychain
|
||||
{
|
||||
SecKeychainUnlock(NULL, 0, NULL, NO);
|
||||
}
|
||||
- (void)setLogsErrors:(BOOL)flag
|
||||
{
|
||||
_logErrors = flag;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Getting Keychain Items
|
||||
- (EMGenericKeychainItem *)genericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString
|
||||
{
|
||||
if (!usernameString || [usernameString length] == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
const char *serviceName = [serviceNameString UTF8String];
|
||||
const char *username = [usernameString UTF8String];
|
||||
|
||||
UInt32 passwordLength = 0;
|
||||
char *password = nil;
|
||||
|
||||
SecKeychainItemRef item = nil;
|
||||
OSStatus returnStatus = SecKeychainFindGenericPassword(NULL, strlen(serviceName), serviceName, strlen(username), username, &passwordLength, (void **)&password, &item);
|
||||
if (returnStatus != noErr || !item)
|
||||
{
|
||||
if (_logErrors)
|
||||
{
|
||||
NSLog(@"Error (%@) - %s", NSStringFromSelector(_cmd), GetMacOSStatusErrorString(returnStatus));
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
NSString *passwordString = [NSString stringWithCString:password length:passwordLength];
|
||||
|
||||
return [EMGenericKeychainItem genericKeychainItem:item forServiceName:serviceNameString username:usernameString password:passwordString];
|
||||
}
|
||||
- (EMInternetKeychainItem *)internetKeychainItemForServer:(NSString *)serverString withUsername:(NSString *)usernameString path:(NSString *)pathString port:(int)port protocol:(SecProtocolType)protocol
|
||||
{
|
||||
if (!usernameString || [usernameString length] == 0 || !serverString || [serverString length] == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
const char *server = [serverString UTF8String];
|
||||
const char *username = [usernameString UTF8String];
|
||||
const char *path = [pathString UTF8String];
|
||||
|
||||
if (!pathString || [pathString length] == 0)
|
||||
{
|
||||
path = "";
|
||||
}
|
||||
|
||||
UInt32 passwordLength = 0;
|
||||
char *password = nil;
|
||||
|
||||
SecKeychainItemRef item = nil;
|
||||
OSStatus returnStatus = SecKeychainFindInternetPassword(NULL, strlen(server), server, 0, NULL, strlen(username), username, strlen(path), path, port, protocol, kSecAuthenticationTypeDefault, &passwordLength, (void **)&password, &item);
|
||||
|
||||
if (returnStatus != noErr || !item)
|
||||
{
|
||||
if (_logErrors)
|
||||
{
|
||||
NSLog(@"Error (%@) - %s", NSStringFromSelector(_cmd), GetMacOSStatusErrorString(returnStatus));
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
NSString *passwordString = [NSString stringWithCString:password length:passwordLength];
|
||||
|
||||
return [EMInternetKeychainItem internetKeychainItem:item forServer:serverString username:usernameString password:passwordString path:pathString port:port protocol:protocol];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Saving Passwords
|
||||
- (EMGenericKeychainItem *)addGenericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString password:(NSString *)passwordString
|
||||
{
|
||||
if (!usernameString || [usernameString length] == 0 || !serviceNameString || [serviceNameString length] == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
const char *serviceName = [serviceNameString UTF8String];
|
||||
const char *username = [usernameString UTF8String];
|
||||
const char *password = [passwordString UTF8String];
|
||||
|
||||
SecKeychainItemRef item = nil;
|
||||
OSStatus returnStatus = SecKeychainAddGenericPassword(NULL, strlen(serviceName), serviceName, strlen(username), username, strlen(password), (void *)password, &item);
|
||||
|
||||
if (returnStatus != noErr || !item)
|
||||
{
|
||||
NSLog(@"Error (%@) - %s", NSStringFromSelector(_cmd), GetMacOSStatusErrorString(returnStatus));
|
||||
return nil;
|
||||
}
|
||||
return [EMGenericKeychainItem genericKeychainItem:item forServiceName:serviceNameString username:usernameString password:passwordString];
|
||||
}
|
||||
- (EMInternetKeychainItem *)addInternetKeychainItemForServer:(NSString *)serverString withUsername:(NSString *)usernameString password:(NSString *)passwordString path:(NSString *)pathString port:(int)port protocol:(SecProtocolType)protocol
|
||||
{
|
||||
if (!usernameString || [usernameString length] == 0 || !serverString || [serverString length] == 0 || !passwordString || [passwordString length] == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
const char *server = [serverString UTF8String];
|
||||
const char *username = [usernameString UTF8String];
|
||||
const char *password = [passwordString UTF8String];
|
||||
const char *path = [pathString UTF8String];
|
||||
|
||||
if (!pathString || [pathString length] == 0)
|
||||
{
|
||||
path = "";
|
||||
}
|
||||
|
||||
SecKeychainItemRef item = nil;
|
||||
OSStatus returnStatus = SecKeychainAddInternetPassword(NULL, strlen(server), server, 0, NULL, strlen(username), username, strlen(path), path, port, protocol, kSecAuthenticationTypeDefault, strlen(password), (void *)password, &item);
|
||||
|
||||
if (returnStatus != noErr || !item)
|
||||
{
|
||||
NSLog(@"Error (%@) - %s", NSStringFromSelector(_cmd), GetMacOSStatusErrorString(returnStatus));
|
||||
return nil;
|
||||
}
|
||||
return [EMInternetKeychainItem internetKeychainItem:item forServer:serverString username:usernameString password:passwordString path:pathString port:port protocol:protocol];
|
||||
}
|
||||
@end
|
|
@ -51,11 +51,11 @@
|
|||
#define TOOLBAR_NETWORK @"TOOLBAR_NETWORK"
|
||||
#define TOOLBAR_REMOTE @"TOOLBAR_REMOTE"
|
||||
|
||||
#define PROXY_KEYCHAIN_SERVICE @"Transmission:Proxy"
|
||||
#define PROXY_KEYCHAIN_NAME @"Proxy"
|
||||
#define PROXY_KEYCHAIN_SERVICE "Transmission:Proxy"
|
||||
#define PROXY_KEYCHAIN_NAME "Proxy"
|
||||
|
||||
#define RPC_KEYCHAIN_SERVICE @"Transmission:Remote"
|
||||
#define RPC_KEYCHAIN_NAME @"Remote"
|
||||
#define RPC_KEYCHAIN_SERVICE "Transmission:Remote"
|
||||
#define RPC_KEYCHAIN_NAME "Remote"
|
||||
|
||||
@interface PrefsController (Private)
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
|||
- (void) incompleteFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
||||
- (void) importFolderSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info;
|
||||
|
||||
- (void) setKeychainPassword: (NSString *) password forService: (NSString *) service username: (NSString *) username;
|
||||
- (void) setKeychainPassword: (NSString *) password forService: (const char *) service username: (const char *) username;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -768,7 +768,7 @@
|
|||
|
||||
- (void) setProxyPassword: (id) sender
|
||||
{
|
||||
NSString * password = [[sender stringValue] retain];
|
||||
NSString * password = [sender stringValue];
|
||||
[self setKeychainPassword: password forService: PROXY_KEYCHAIN_SERVICE username: PROXY_KEYCHAIN_NAME];
|
||||
|
||||
tr_sessionSetProxyPassword(fHandle, [password UTF8String]);
|
||||
|
@ -776,16 +776,21 @@
|
|||
|
||||
- (void) updateProxyPassword
|
||||
{
|
||||
EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: PROXY_KEYCHAIN_SERVICE
|
||||
withUsername: PROXY_KEYCHAIN_NAME];
|
||||
UInt32 passwordLength;
|
||||
const char * password = nil;
|
||||
SecKeychainFindGenericPassword(NULL, strlen(PROXY_KEYCHAIN_SERVICE), PROXY_KEYCHAIN_SERVICE,
|
||||
strlen(PROXY_KEYCHAIN_NAME), PROXY_KEYCHAIN_NAME, &passwordLength, (void **)&password, NULL);
|
||||
|
||||
NSString * password;
|
||||
if (!(password = [keychainItem password]))
|
||||
password = @"";
|
||||
|
||||
tr_sessionSetProxyPassword(fHandle, [password UTF8String]);
|
||||
|
||||
[fProxyPasswordField setStringValue: password];
|
||||
if (password != NULL)
|
||||
{
|
||||
char fullPassword[passwordLength+1];
|
||||
strncpy(fullPassword, password, passwordLength);
|
||||
fullPassword[passwordLength] = '\0';
|
||||
SecKeychainItemFreeContent(NULL, (void *)password);
|
||||
|
||||
tr_sessionSetProxyPassword(fHandle, fullPassword);
|
||||
[fProxyPasswordField setStringValue: [NSString stringWithUTF8String: fullPassword]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setRPCEnabled: (id) sender
|
||||
|
@ -805,7 +810,7 @@
|
|||
|
||||
- (void) setRPCPassword: (id) sender
|
||||
{
|
||||
NSString * password = [[sender stringValue] retain];
|
||||
NSString * password = [sender stringValue];
|
||||
[self setKeychainPassword: password forService: RPC_KEYCHAIN_SERVICE username: RPC_KEYCHAIN_NAME];
|
||||
|
||||
tr_sessionSetRPCPassword(fHandle, [password UTF8String]);
|
||||
|
@ -813,16 +818,21 @@
|
|||
|
||||
- (void) updateRPCPassword
|
||||
{
|
||||
EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: RPC_KEYCHAIN_SERVICE
|
||||
withUsername: RPC_KEYCHAIN_NAME];
|
||||
UInt32 passwordLength;
|
||||
const char * password = nil;
|
||||
SecKeychainFindGenericPassword(NULL, strlen(RPC_KEYCHAIN_SERVICE), RPC_KEYCHAIN_SERVICE,
|
||||
strlen(RPC_KEYCHAIN_NAME), RPC_KEYCHAIN_NAME, &passwordLength, (void **)&password, NULL);
|
||||
|
||||
NSString * password;
|
||||
if (!(password = [keychainItem password]))
|
||||
password = @"";
|
||||
|
||||
tr_sessionSetRPCPassword(fHandle, [password UTF8String]);
|
||||
|
||||
[fRPCPasswordField setStringValue: password];
|
||||
if (password != NULL)
|
||||
{
|
||||
char fullPassword[passwordLength+1];
|
||||
strncpy(fullPassword, password, passwordLength);
|
||||
fullPassword[passwordLength] = '\0';
|
||||
SecKeychainItemFreeContent(NULL, (void *)password);
|
||||
|
||||
tr_sessionSetRPCPassword(fHandle, fullPassword);
|
||||
[fRPCPasswordField setStringValue: [NSString stringWithUTF8String: fullPassword]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setRPCPort: (id) sender
|
||||
|
@ -1149,23 +1159,39 @@
|
|||
[fImportFolderPopUp selectItemAtIndex: 0];
|
||||
}
|
||||
|
||||
- (void) setKeychainPassword: (NSString *) password forService: (NSString *) service username: (NSString *) username
|
||||
- (void) setKeychainPassword: (NSString *) password forService: (const char *) service username: (const char *) username
|
||||
{
|
||||
SecKeychainItemRef item = NULL;
|
||||
BOOL shouldAdd = password && ![password isEqualToString: @""];
|
||||
|
||||
EMGenericKeychainItem * keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService: service withUsername: username];
|
||||
if (keychainItem)
|
||||
OSStatus result = SecKeychainFindGenericPassword(NULL, strlen(service), service, strlen(username), username, NULL, NULL, &item);
|
||||
if (result == noErr && item)
|
||||
{
|
||||
if (shouldAdd) //found, so update
|
||||
{
|
||||
result = SecKeychainItemModifyAttributesAndData(item, NULL, [password length], (const void *)[password UTF8String]);
|
||||
if (result != noErr)
|
||||
NSLog(@"Problem updating Keychain item: %s", GetMacOSStatusErrorString(result));
|
||||
}
|
||||
else //remove the item
|
||||
{
|
||||
result = SecKeychainItemDelete(item);
|
||||
if (result != noErr)
|
||||
NSLog(@"Problem removing Keychain item: %s", GetMacOSStatusErrorString(result));
|
||||
}
|
||||
}
|
||||
else if (result == errSecItemNotFound) //not found, so add
|
||||
{
|
||||
if (shouldAdd)
|
||||
[keychainItem setPassword: password];
|
||||
else
|
||||
[keychainItem removeFromKeychain];
|
||||
{
|
||||
result = SecKeychainAddGenericPassword(NULL, strlen(service), service, strlen(username), username,
|
||||
[password length], (const void *)[password UTF8String], NULL);
|
||||
if (result != noErr)
|
||||
NSLog(@"Problem adding Keychain item: %s", GetMacOSStatusErrorString(result));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (shouldAdd)
|
||||
[[EMKeychainProxy sharedProxy] addGenericKeychainItemForService: service withUsername: username password: password];
|
||||
}
|
||||
NSLog(@"Problem accessing Keychain: %s", GetMacOSStatusErrorString(result));
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue