fixed overwriting key in keychain

This commit is contained in:
Jeena Paradies 2012-11-24 08:27:12 +01:00
parent b07088f15b
commit 75442db9e0
8 changed files with 57 additions and 65 deletions

View file

@ -46,20 +46,37 @@
- (void)setSecret:(NSString *)_secret
{
UInt32 _passwordLength = 0;
char *_password = nil;
SecKeychainItemRef item = nil;
SecKeychainFindGenericPassword(NULL, 6, "Tentia", 17, "TentiaUserAccount", &_passwordLength, (void **)&_password, &item);
OSStatus status;
void * passwordData = (void*)[_secret cStringUsingEncoding:NSUTF8StringEncoding];
UInt32 passwordLength = strlen((char*)passwordData);
status = SecKeychainAddGenericPassword (
NULL, // default keychain
6, // length of service name
"Tentia", // service name
17, // length of account name
"TentiaUserAccount", // account name
passwordLength, // length of password
passwordData, // pointer to password data
NULL // the item reference
);
//NSLog(@"%@",(NSString *)SecCopyErrorMessageString (status,NULL));
if (!item)
{
status = SecKeychainAddGenericPassword(
NULL, // default keychain
6, // length of service name
"Tentia", // service name
17, // length of account name
"TentiaUserAccount", // account name
passwordLength, // length of password
passwordData, // pointer to password data
NULL // the item reference
);
}
else
{
status = SecKeychainItemModifyContent(
item,
NULL,
passwordLength,
passwordData
);
}
NSLog(@"%@",(NSString *)SecCopyErrorMessageString (status,NULL));
}
- (NSString *)secret
@ -68,6 +85,11 @@
char *password = nil;
SecKeychainItemRef item = nil;
SecKeychainFindGenericPassword(NULL, 6, "Tentia", 17, "TentiaUserAccount", &passwordLength, (void **)&password, &item);
if (!item) {
return nil;
}
//Get password
NSString *passwordString = [[[NSString alloc] initWithData:[NSData dataWithBytes:password length:passwordLength] encoding:NSUTF8StringEncoding] autorelease];
SecKeychainItemFreeContent(NULL, password);

View file

@ -71,7 +71,7 @@
[accessToken setString:nil forKey:@"user_mac_key"];
}
}
if (![accessToken stringForKey:@"user_access_token"]) {
if (![accessToken stringForKey:@"user_access_token"] || ![accessToken secret]) {
[timelineViewWindow performClose:self];
[mentionsViewWindow performClose:self];
[self.loginViewWindow makeKeyAndOrderFront:self];

View file

@ -195,7 +195,7 @@
</object>
<object class="NSMenuItem" id="502380341">
<reference key="NSMenu" ref="723763594"/>
<string key="NSTitle">Add image</string>
<string key="NSTitle">Add photo</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="400068421"/>

View file

@ -253,7 +253,7 @@
if (!self.imageFilePath)
{
[menuItem setTitle:@"Remove image"];
[menuItem setTitle:@"Remove photo"];
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setPrompt:@"Select"];
@ -283,7 +283,7 @@
else
{
self.imageFilePath = nil;
[menuItem setTitle:@"Add image"];
[menuItem setTitle:@"Add photo"];
}
}

View file

@ -6,15 +6,15 @@
<description>Most recent changes with links to updates.</description>
<language>en</language>
<item>
<title>Version 0.3.1</title>
<title>Version 0.4.0</title>
<sparkle:minimumSystemVersion>10.5.0</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>http://jabs.nu/Tentia/download/ReleaseNotes.html</sparkle:releaseNotesLink>
<pubDate>Sat, 24 Nov 2012 00:48:42 +0100</pubDate>
<pubDate>Sat, 24 Nov 2012 05:03:37 +0100</pubDate>
<enclosure url="http://jabs.nu/Tentia/download/Tentia.app.zip"
sparkle:version="0.3.1"
length="1032871"
sparkle:version="0.4.0"
length="1039378"
type="application/octet-stream"
sparkle:dsaSignature="MCwCFFpH1VFUwJj251WwYbO1El8Ra742AhRHvFroDTIjqBVsqOJt+7L/rcZaDA==" />
sparkle:dsaSignature="MCwCFDFeNCx4UYAuH9tSCP3pKZqka5JqAhRcXwhxaOsyVNLfBBTwI0tEpz3W5w==" />
</item>
</channel>
</rss>