Skip to content

Commit

Permalink
Fix for bug 2381168: Keychain issues with https.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnson1234 authored and johnson1234 committed Jan 21, 2009
1 parent 94fa969 commit 5955bad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Thanks!

2.3.2.2303
----------
-
- Fix for bug 2381168: Keychain issues with https.

2.3.1.2302
----------
Expand Down
20 changes: 11 additions & 9 deletions KeyChain.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ @implementation KeyChain
+(NSString *)getPasswordFromKeychain:(NSString *)username url:(NSString *)url
{
NSURL * secureUrl = [NSURL URLWithString:url];
const char * cServiceName = [[secureUrl host] cString];
const char * cUsername = [username cString];
const char * cServiceName = [[secureUrl host] UTF8String];
const char * cUsername = [username UTF8String];
int portNumber = [secureUrl port] ? [[secureUrl port] intValue] : 80;
SecProtocolType protocolType = ([[secureUrl scheme] caseInsensitiveCompare:@"https"] == NSOrderedSame) ? kSecProtocolTypeHTTPS : kSecProtocolTypeHTTP;
NSString * thePassword;

if (!cServiceName || !cUsername)
Expand All @@ -54,7 +55,7 @@ +(NSString *)getPasswordFromKeychain:(NSString *)username url:(NSString *)url
strlen(cPath),
cPath,
portNumber,
kSecProtocolTypeHTTP,
protocolType,
kSecAuthenticationTypeDefault,
&passwordLength,
&passwordPtr,
Expand All @@ -63,7 +64,7 @@ +(NSString *)getPasswordFromKeychain:(NSString *)username url:(NSString *)url
thePassword = @"";
else
{
thePassword = [NSString stringWithCString:passwordPtr length:passwordLength];
thePassword = [[[NSString alloc] initWithBytes:passwordPtr length:passwordLength encoding:NSUTF8StringEncoding] autorelease];
SecKeychainItemFreeContent(NULL, passwordPtr);
}
}
Expand All @@ -76,11 +77,12 @@ +(NSString *)getPasswordFromKeychain:(NSString *)username url:(NSString *)url
+(void)setPasswordInKeychain:(NSString *)password username:(NSString *)username url:(NSString *)url
{
NSURL * secureUrl = [NSURL URLWithString:url];
const char * cServiceName = [[secureUrl host] cString];
const char * cUsername = [username cString];
const char * cServiceName = [[secureUrl host] UTF8String];
const char * cUsername = [username UTF8String];
const char * cPath = "";
int portNumber = [secureUrl port] ? [[secureUrl port] intValue] : 80;
const char * cPassword = [password cString];
SecProtocolType protocolType = ([[secureUrl scheme] caseInsensitiveCompare:@"https"] == NSOrderedSame) ? kSecProtocolTypeHTTPS : kSecProtocolTypeHTTP;
const char * cPassword = [password UTF8String];
SecKeychainItemRef itemRef;
OSStatus status;

Expand All @@ -96,7 +98,7 @@ +(void)setPasswordInKeychain:(NSString *)password username:(NSString *)username
strlen(cPath),
cPath,
portNumber,
kSecProtocolTypeHTTP,
protocolType,
kSecAuthenticationTypeDefault,
NULL,
NULL,
Expand All @@ -113,7 +115,7 @@ +(void)setPasswordInKeychain:(NSString *)password username:(NSString *)username
strlen(cPath),
cPath,
portNumber,
kSecProtocolTypeHTTP,
protocolType,
kSecAuthenticationTypeDefault,
strlen(cPassword),
cPassword,
Expand Down
2 changes: 1 addition & 1 deletion notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</head>
<body>
<ul>
<li></li>
<li>Fix for bug 2381168: Keychain issues with https.</li>
</ul>
</body>
</html>

0 comments on commit 5955bad

Please sign in to comment.