diff --git a/Mac/AccessToken.m b/Mac/AccessToken.m index 02b181f..cb70213 100644 --- a/Mac/AccessToken.m +++ b/Mac/AccessToken.m @@ -7,6 +7,7 @@ // #import "AccessToken.h" +#include @implementation AccessToken @@ -45,13 +46,32 @@ - (void)setSecret:(NSString *)_secret { - [d setObject:_secret forKey:@"secret"]; - [d synchronize]; + 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)); } - (NSString *)secret { - return [d objectForKey:@"secret"]; + UInt32 passwordLength = 0; + char *password = nil; + SecKeychainItemRef item = nil; + SecKeychainFindGenericPassword(NULL, 6, "Tentia", 17, "TentiaUserAccount", &passwordLength, (void **)&password, &item); + //Get password + NSString *passwordString = [[[NSString alloc] initWithData:[NSData dataWithBytes:password length:passwordLength] encoding:NSUTF8StringEncoding] autorelease]; + SecKeychainItemFreeContent(NULL, password); + return passwordString; } - (void)setUserId:(NSString *)_userId diff --git a/Mac/Controller.h b/Mac/Controller.h index b422ea0..1fa902c 100644 --- a/Mac/Controller.h +++ b/Mac/Controller.h @@ -65,6 +65,8 @@ - (void)openURL:(NSString *)url; - (void)setString:(NSString *)string forKey:(NSString *)aKey; +- (void)setSecret:(NSString *)string; +- (NSString *)secret; - (NSString *)stringForKey:(NSString *)aKey; - (void)storeAccessToken:(NSString *)accessToken secret:(NSString *)secret userId:(NSString *)userId andScreenName:(NSString *)screenName; - (void)loggedIn; diff --git a/Mac/Controller.m b/Mac/Controller.m index 8ec834b..6041a71 100644 --- a/Mac/Controller.m +++ b/Mac/Controller.m @@ -64,7 +64,13 @@ [self logout:self]; [accessToken setString:@"yes" forKey:@"version-0.2.0-new-login"]; } - + if (![accessToken stringForKey:@"version-0.3.0-migrated"]) { + [accessToken setString:@"yes" forKey:@"version-0.3.0-migrated"]; + if ([accessToken stringForKey:@"user_mac_key"]){ + [accessToken setSecret:[accessToken stringForKey:@"user_mac_key"]]; + [accessToken setString:nil forKey:@"user_mac_key"]; + } + } if (![accessToken stringForKey:@"user_access_token"]) { [timelineViewWindow performClose:self]; [mentionsViewWindow performClose:self]; @@ -72,7 +78,7 @@ } else { [timelineViewWindow makeKeyAndOrderFront:self]; [self initWebViews]; - } + } } # pragma mark Init @@ -232,6 +238,15 @@ [self.accessToken setString:string forKey:aKey]; } +- (void)setSecret:(NSString *)string +{ + [self.accessToken setSecret:string]; +} +- (NSString *)secret +{ + return [self.accessToken secret]; +} + - (NSString *)stringForKey:(NSString *)aKey { return [self.accessToken stringForKey:aKey]; @@ -364,7 +379,6 @@ self.accessToken.secret = secret; self.accessToken.userId = userId; self.accessToken.screenName = screenName; - [timelineViewWindow makeKeyAndOrderFront:self]; [[NSNotificationCenter defaultCenter] postNotificationName:@"authentificationSucceded" object:nil]; diff --git a/Mac/Tentia-Info.plist b/Mac/Tentia-Info.plist index 661c9f4..98cfea2 100644 --- a/Mac/Tentia-Info.plist +++ b/Mac/Tentia-Info.plist @@ -42,7 +42,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.3.0 + 0.3.1 CFBundleSignature ???? CFBundleURLTypes @@ -57,7 +57,7 @@ CFBundleVersion - 0.3.0 + 0.3.1 LSApplicationCategoryType public.app-category.lifestyle LSMinimumSystemVersion diff --git a/Mac/Tentia.xcodeproj/project.pbxproj b/Mac/Tentia.xcodeproj/project.pbxproj index a4bd7c6..3561294 100644 --- a/Mac/Tentia.xcodeproj/project.pbxproj +++ b/Mac/Tentia.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ 1FFA36D71177D879006C8562 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FFA36D31177D879006C8562 /* Controller.m */; }; 1FFA36D81177D879006C8562 /* ViewDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1FFA36D51177D879006C8562 /* ViewDelegate.m */; }; 1FFA37071177DAF4006C8562 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FFA37061177DAF4006C8562 /* WebKit.framework */; }; + 6B68359B166015C4004F4732 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B68359A166015C4004F4732 /* Security.framework */; }; 8D15AC2C0486D014006FF6A4 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2A37F4B9FDCFA73011CA2CEA /* Credits.rtf */; }; 8D15AC2F0486D014006FF6A4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165FFE840EACC02AAC07 /* InfoPlist.strings */; }; 8D15AC310486D014006FF6A4 /* NewMessageWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 2A37F4ACFDCFA73011CA2CEA /* NewMessageWindow.m */; settings = {ATTRIBUTES = (); }; }; @@ -88,6 +89,7 @@ 2A37F4BAFDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = English; path = English.lproj/Credits.rtf; sourceTree = ""; }; 2A37F4C4FDCFA73011CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 2A37F4C5FDCFA73011CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; + 6B68359A166015C4004F4732 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = /System/Library/Frameworks/Security.framework; sourceTree = ""; }; 8D15AC360486D014006FF6A4 /* Tentia-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Tentia-Info.plist"; sourceTree = ""; }; 8D15AC370486D014006FF6A4 /* Tentia.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tentia.app; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -97,6 +99,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 6B68359B166015C4004F4732 /* Security.framework in Frameworks */, 1F2D79BD165E8C6B000E8428 /* CoreLocation.framework in Frameworks */, 1FDEF722164EFE9100F927F3 /* Growl.framework in Frameworks */, 1FA09847144602530079E258 /* libicucore.dylib in Frameworks */, @@ -114,6 +117,7 @@ 1058C7A6FEA54F5311CA2CBB /* Linked Frameworks */ = { isa = PBXGroup; children = ( + 6B68359A166015C4004F4732 /* Security.framework */, 1F2D79BC165E8C6B000E8428 /* CoreLocation.framework */, 1FDEF721164EFE9100F927F3 /* Growl.framework */, 1FE2FC92117A818D000504B0 /* Sparkle.framework */, diff --git a/WebKit/scripts/controller/Oauth.js b/WebKit/scripts/controller/Oauth.js index ef5b1f9..c790caa 100644 --- a/WebKit/scripts/controller/Oauth.js +++ b/WebKit/scripts/controller/Oauth.js @@ -146,7 +146,7 @@ function(HostApp, Paths, Hmac) { var access = JSON.parse(responseBody); HostApp.setStringForKey(access["access_token"], "user_access_token"); - HostApp.setStringForKey(access["mac_key"], "user_mac_key"); + HostApp.setSecret(access["mac_key"]); HostApp.setStringForKey(access["mac_algorithm"], "user_mac_algorithm"); HostApp.setStringForKey(access["token_type"], "user_token_type"); diff --git a/WebKit/scripts/helper/HostApp.js b/WebKit/scripts/helper/HostApp.js index ea6e76c..686f190 100644 --- a/WebKit/scripts/helper/HostApp.js +++ b/WebKit/scripts/helper/HostApp.js @@ -10,6 +10,23 @@ define(function() { controller.setStringForKey(string, key); } } + + HostApp.setSecret = function(string) { + + if (OS_TYPE == "mac") { + controller.setSecret_(string); + } else { + controller.setStringForKey(string, "user_mac_key"); + } + } + + HostApp.secret = function() { + if (OS_TYPE == "mac") { + return controller.secret(); + } else { + return controller.stringForKey("user_mac_key"); + } + } HostApp.stringForKey = function(key) { diff --git a/WebKit/scripts/helper/Paths.js b/WebKit/scripts/helper/Paths.js index 59d876f..1ce21c8 100644 --- a/WebKit/scripts/helper/Paths.js +++ b/WebKit/scripts/helper/Paths.js @@ -40,7 +40,8 @@ function(jQuery, HostApp, Hmac) { auth_header = Hmac.makeAuthHeader( url, http_method, - HostApp.stringForKey("user_mac_key"), + //HostApp.stringForKey("user_mac_key"), + HostApp.secret(), user_access_token ); xhr.setRequestHeader("Authorization", auth_header);