fixed overwriting key in keychain
This commit is contained in:
parent
b07088f15b
commit
75442db9e0
8 changed files with 57 additions and 65 deletions
|
@ -46,20 +46,37 @@
|
||||||
|
|
||||||
- (void)setSecret:(NSString *)_secret
|
- (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;
|
OSStatus status;
|
||||||
void * passwordData = (void*)[_secret cStringUsingEncoding:NSUTF8StringEncoding];
|
void * passwordData = (void*)[_secret cStringUsingEncoding:NSUTF8StringEncoding];
|
||||||
UInt32 passwordLength = strlen((char*)passwordData);
|
UInt32 passwordLength = strlen((char*)passwordData);
|
||||||
status = SecKeychainAddGenericPassword (
|
if (!item)
|
||||||
NULL, // default keychain
|
{
|
||||||
6, // length of service name
|
status = SecKeychainAddGenericPassword(
|
||||||
"Tentia", // service name
|
NULL, // default keychain
|
||||||
17, // length of account name
|
6, // length of service name
|
||||||
"TentiaUserAccount", // account name
|
"Tentia", // service name
|
||||||
passwordLength, // length of password
|
17, // length of account name
|
||||||
passwordData, // pointer to password data
|
"TentiaUserAccount", // account name
|
||||||
NULL // the item reference
|
passwordLength, // length of password
|
||||||
);
|
passwordData, // pointer to password data
|
||||||
//NSLog(@"%@",(NSString *)SecCopyErrorMessageString (status,NULL));
|
NULL // the item reference
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = SecKeychainItemModifyContent(
|
||||||
|
item,
|
||||||
|
NULL,
|
||||||
|
passwordLength,
|
||||||
|
passwordData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
NSLog(@"%@",(NSString *)SecCopyErrorMessageString (status,NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)secret
|
- (NSString *)secret
|
||||||
|
@ -68,6 +85,11 @@
|
||||||
char *password = nil;
|
char *password = nil;
|
||||||
SecKeychainItemRef item = nil;
|
SecKeychainItemRef item = nil;
|
||||||
SecKeychainFindGenericPassword(NULL, 6, "Tentia", 17, "TentiaUserAccount", &passwordLength, (void **)&password, &item);
|
SecKeychainFindGenericPassword(NULL, 6, "Tentia", 17, "TentiaUserAccount", &passwordLength, (void **)&password, &item);
|
||||||
|
|
||||||
|
if (!item) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
//Get password
|
//Get password
|
||||||
NSString *passwordString = [[[NSString alloc] initWithData:[NSData dataWithBytes:password length:passwordLength] encoding:NSUTF8StringEncoding] autorelease];
|
NSString *passwordString = [[[NSString alloc] initWithData:[NSData dataWithBytes:password length:passwordLength] encoding:NSUTF8StringEncoding] autorelease];
|
||||||
SecKeychainItemFreeContent(NULL, password);
|
SecKeychainItemFreeContent(NULL, password);
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
[accessToken setString:nil forKey:@"user_mac_key"];
|
[accessToken setString:nil forKey:@"user_mac_key"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (![accessToken stringForKey:@"user_access_token"]) {
|
if (![accessToken stringForKey:@"user_access_token"] || ![accessToken secret]) {
|
||||||
[timelineViewWindow performClose:self];
|
[timelineViewWindow performClose:self];
|
||||||
[mentionsViewWindow performClose:self];
|
[mentionsViewWindow performClose:self];
|
||||||
[self.loginViewWindow makeKeyAndOrderFront:self];
|
[self.loginViewWindow makeKeyAndOrderFront:self];
|
||||||
|
|
|
@ -195,7 +195,7 @@
|
||||||
</object>
|
</object>
|
||||||
<object class="NSMenuItem" id="502380341">
|
<object class="NSMenuItem" id="502380341">
|
||||||
<reference key="NSMenu" ref="723763594"/>
|
<reference key="NSMenu" ref="723763594"/>
|
||||||
<string key="NSTitle">Add image</string>
|
<string key="NSTitle">Add photo</string>
|
||||||
<string key="NSKeyEquiv"/>
|
<string key="NSKeyEquiv"/>
|
||||||
<int key="NSMnemonicLoc">2147483647</int>
|
<int key="NSMnemonicLoc">2147483647</int>
|
||||||
<reference key="NSOnImage" ref="400068421"/>
|
<reference key="NSOnImage" ref="400068421"/>
|
||||||
|
|
|
@ -253,7 +253,7 @@
|
||||||
|
|
||||||
if (!self.imageFilePath)
|
if (!self.imageFilePath)
|
||||||
{
|
{
|
||||||
[menuItem setTitle:@"Remove image"];
|
[menuItem setTitle:@"Remove photo"];
|
||||||
|
|
||||||
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
|
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
|
||||||
[openDlg setPrompt:@"Select"];
|
[openDlg setPrompt:@"Select"];
|
||||||
|
@ -283,7 +283,7 @@
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
self.imageFilePath = nil;
|
self.imageFilePath = nil;
|
||||||
[menuItem setTitle:@"Add image"];
|
[menuItem setTitle:@"Add photo"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,15 +6,15 @@
|
||||||
<description>Most recent changes with links to updates.</description>
|
<description>Most recent changes with links to updates.</description>
|
||||||
<language>en</language>
|
<language>en</language>
|
||||||
<item>
|
<item>
|
||||||
<title>Version 0.3.1</title>
|
<title>Version 0.4.0</title>
|
||||||
<sparkle:minimumSystemVersion>10.5.0</sparkle:minimumSystemVersion>
|
<sparkle:minimumSystemVersion>10.5.0</sparkle:minimumSystemVersion>
|
||||||
<sparkle:releaseNotesLink>http://jabs.nu/Tentia/download/ReleaseNotes.html</sparkle:releaseNotesLink>
|
<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"
|
<enclosure url="http://jabs.nu/Tentia/download/Tentia.app.zip"
|
||||||
sparkle:version="0.3.1"
|
sparkle:version="0.4.0"
|
||||||
length="1032871"
|
length="1039378"
|
||||||
type="application/octet-stream"
|
type="application/octet-stream"
|
||||||
sparkle:dsaSignature="MCwCFFpH1VFUwJj251WwYbO1El8Ra742AhRHvFroDTIjqBVsqOJt+7L/rcZaDA==" />
|
sparkle:dsaSignature="MCwCFDFeNCx4UYAuH9tSCP3pKZqka5JqAhRcXwhxaOsyVNLfBBTwI0tEpz3W5w==" />
|
||||||
</item>
|
</item>
|
||||||
</channel>
|
</channel>
|
||||||
</rss>
|
</rss>
|
||||||
|
|
|
@ -52,7 +52,6 @@ function(HostApp, Paths, Hmac) {
|
||||||
var those = this;
|
var those = this;
|
||||||
Paths.findProfileURL(entity,
|
Paths.findProfileURL(entity,
|
||||||
function(profile_url) {
|
function(profile_url) {
|
||||||
|
|
||||||
if (profile_url && (profile_url.startsWith("http://") || profile_url.startsWith("https://"))) {
|
if (profile_url && (profile_url.startsWith("http://") || profile_url.startsWith("https://"))) {
|
||||||
those.register(profile_url);
|
those.register(profile_url);
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,6 +66,7 @@ function(HostApp, Paths, Hmac) {
|
||||||
|
|
||||||
Oauth.prototype.register = function (url) {
|
Oauth.prototype.register = function (url) {
|
||||||
var those = this;
|
var those = this;
|
||||||
|
|
||||||
Paths.getURL(url, "GET", function(resp) {
|
Paths.getURL(url, "GET", function(resp) {
|
||||||
|
|
||||||
those.profile = JSON.parse(resp.responseText);
|
those.profile = JSON.parse(resp.responseText);
|
||||||
|
@ -78,7 +78,6 @@ function(HostApp, Paths, Hmac) {
|
||||||
var data = JSON.parse(resp.responseText);
|
var data = JSON.parse(resp.responseText);
|
||||||
those.authRequest(data);
|
those.authRequest(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
Paths.getURL(Paths.mkApiRootPath("/apps"), "POST", callback, JSON.stringify(those.app_info));
|
Paths.getURL(Paths.mkApiRootPath("/apps"), "POST", callback, JSON.stringify(those.app_info));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -144,7 +143,7 @@ function(HostApp, Paths, Hmac) {
|
||||||
Oauth.prototype.requestAccessTokenTicketFinished = function(responseBody) {
|
Oauth.prototype.requestAccessTokenTicketFinished = function(responseBody) {
|
||||||
|
|
||||||
var access = JSON.parse(responseBody);
|
var access = JSON.parse(responseBody);
|
||||||
|
|
||||||
HostApp.setStringForKey(access["access_token"], "user_access_token");
|
HostApp.setStringForKey(access["access_token"], "user_access_token");
|
||||||
HostApp.setSecret(access["mac_key"]);
|
HostApp.setSecret(access["mac_key"]);
|
||||||
HostApp.setStringForKey(access["mac_algorithm"], "user_mac_algorithm");
|
HostApp.setStringForKey(access["mac_algorithm"], "user_mac_algorithm");
|
||||||
|
|
|
@ -358,29 +358,24 @@ function(jQuery, Paths, URI, HostApp, Followings) {
|
||||||
|
|
||||||
post += "\r\n--" + boundary + "\r\n";
|
post += "\r\n--" + boundary + "\r\n";
|
||||||
|
|
||||||
var binary_data = this.dataURItoBlob(image_data_uri);
|
var blob_string = image_data_uri.split(',')[1];
|
||||||
|
var mime_type = image_data_uri.split(',')[0].split(':')[1].split(';')[0];
|
||||||
var ext = "png";
|
var ext = "png";
|
||||||
if (binary_data.mime_type == "image/jpeg") {
|
if (mime_type == "image/jpeg") {
|
||||||
ext = "jpeg";
|
ext = "jpeg";
|
||||||
} else if (binary_data.mime_type == "image/gif") {
|
} else if (mime_type == "image/gif") {
|
||||||
ext = "gif";
|
ext = "gif";
|
||||||
}
|
}
|
||||||
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.onload = function(e) {
|
|
||||||
|
|
||||||
var blob_string = e.target.result;
|
post += 'Content-Disposition: form-data; name="photos[0]"; filename="photo.' + ext + '"\r\n';
|
||||||
post += 'Content-Disposition: form-data; name="photos[0]"; filename="photo.' + ext + '"\r\n';
|
post += 'Content-Length: ' + blob_string.length + "\r\n";
|
||||||
post += 'Content-Length: ' + blob_string.length + "\r\n";
|
post += 'Content-Type: ' + mime_type + "\r\n";
|
||||||
post += 'Content-Type: ' + binary_data.mime_type + "\r\n";
|
post += 'Content-Transfer-Encoding: base64\r\n\r\n';
|
||||||
post += 'Content-Transfer-Encoding: base64\r\n\r\n';
|
post += blob_string;
|
||||||
post += image_data_uri.split(',')[1];
|
post += "\r\n--" + boundary + "--\r\n";
|
||||||
post += "\r\n--" + boundary + "--\r\n";
|
|
||||||
|
|
||||||
Paths.postMultipart(url.toString(), callback, post, boundary);
|
Paths.postMultipart(url.toString(), callback, post, boundary);
|
||||||
}
|
|
||||||
|
|
||||||
reader.readAsBinaryString(binary_data.blob)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Core.prototype.remove = function(id, callback) {
|
Core.prototype.remove = function(id, callback) {
|
||||||
|
@ -570,30 +565,6 @@ function(jQuery, Paths, URI, HostApp, Followings) {
|
||||||
HostApp.openNewMessageWidow(entity, status_id, string);
|
HostApp.openNewMessageWidow(entity, status_id, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core.prototype.dataURItoBlob = function(dataURI) {
|
|
||||||
// convert base64 to raw binary data held in a string
|
|
||||||
// doesn't handle URLEncoded DataURIs
|
|
||||||
var byteString = atob(dataURI.split(',')[1]);
|
|
||||||
|
|
||||||
// separate out the mime component
|
|
||||||
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
|
|
||||||
|
|
||||||
// write the bytes of the string to an ArrayBuffer
|
|
||||||
var ab = new ArrayBuffer(byteString.length);
|
|
||||||
var ia = new Uint8Array(ab);
|
|
||||||
for (var i = 0; i < byteString.length; i++) {
|
|
||||||
ia[i] = byteString.charCodeAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write the ArrayBuffer to a blob, and you're done
|
|
||||||
var blob = new Blob([ab], {type: mimeString});
|
|
||||||
return {
|
|
||||||
mime_type: mimeString,
|
|
||||||
blob: blob,
|
|
||||||
base64: byteString
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Core;
|
return Core;
|
||||||
|
|
||||||
});
|
});
|
|
@ -40,7 +40,7 @@ function(jQuery, HostApp, Hmac) {
|
||||||
|
|
||||||
var user_access_token = HostApp.stringForKey("user_access_token");
|
var user_access_token = HostApp.stringForKey("user_access_token");
|
||||||
|
|
||||||
if (auth_header !== false && user_access_token) {
|
if (auth_header !== false && typeof user_access_token != "undefined") {
|
||||||
|
|
||||||
auth_header = Hmac.makeAuthHeader(
|
auth_header = Hmac.makeAuthHeader(
|
||||||
url,
|
url,
|
||||||
|
@ -59,7 +59,7 @@ function(jQuery, HostApp, Hmac) {
|
||||||
data: data,
|
data: data,
|
||||||
processData: false,
|
processData: false,
|
||||||
error: function(xhr, ajaxOptions, thrownError) {
|
error: function(xhr, ajaxOptions, thrownError) {
|
||||||
console.error("getURL " + xhr.statusText + " " + http_method + " (" + url + "): '" + xhr.responseText + "'");
|
console.error("getURL (" + xhr.status + ")" + xhr.statusText + " " + http_method + " (" + url + "): '" + xhr.responseText + "'");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue