ASIDownloadCache security - iphone

I am caching some data using ASIDownloadCache as shown below.
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];
[request setSecondsToCache:60*60*24*30]; // Cache for 30 days, this will change to a db version check.
[request setDelegate:self]; // this calls the delegate function requestFinished
[request startAsynchronous];
I was wondering how secure that data was? for instance I know that someone with a jailbroken phone can access coredata sotrage.. but what about ASIDownloadCache? what would someone need to do to get to it? how can I protect it?

You don't even have to jailbreak to access it, see:
http://www.macroplant.com/iexplorer/
If you want to protect it, you'll need to encrypt it, and you will have to do this yourself or modify ASIDownloadCache to do it.
Given the decryption key will need to be present in your application this would really just be obfuscation though.

Related

ASIHTTPRequest Integrate Twitter

I need your help. I have been switching from various libraries trying to find the suitable one to integrate Twitter in my application.
A while back i found out that i could use ASIHTTPRequest to send tweets from my app. I need to know if there's any tutorial or sample code available.
And i have already looked at share-kit and i prefer to integrate Twitter using ASIHTTPRequest
note: I have created my project using ARC, and it shoudl support both iOS4 and 5.
Twitter's documentation says that you have to make GET or POST HTTP requests with the appropriate form data (key-value pairs). For example, to post a status update, you can do:
NSURL *url = [NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addRequestHeader:#"Accept" value:#"*/*"];
[request addRequestHeader:#"onnection" value:#"close"];
[request addRequestHeader:#"Content-Type" value:#"application/x-www-form-urlencoded"];
[request addRequestHeader:#"Content-Length" value:#"17"];
[request addRequestHeader:#"Host" value:#"api.twitter.com"];
[request setPostValue:#"User's new status" forKey:#"status"];
// set here completion/error handlers
[request startAsynchronous];
More documentation on Twitter's REST/HTTP API: https://dev.twitter.com/docs
For authetication, you'll need some kind of OAuth library. Here's Karl Adam's MPOAuth, with few additions and corrections by me: https://github.com/H2CO3/MPOAuthiOS
On iOS 5.x, you can use Apple's default, and easy to use Twitter.framework: http://developer.apple.com/library/ios/#documentation/Twitter/Reference/TwitterFrameworkReference/_index.html

Posting data to http iPhone

I want to send an email address(will be getting from textfield) to http url by clicking a send button from an application which is already logged in at the same http server.
How can I do that programmatically?
u can do this with ASIHTTPRequest library. here is a sample code
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:#"Ben" forKey:#"first_name"];
[request setPostValue:#"Copsey" forKey:#"last_name"];
[request setFile:#"/Users/ben/Desktop/ben.jpg" forKey:#"photo"];

How to use post manner to transmit username and password in order to log in a website on iphone or ipad platform?

How to use post manner to transmit username and password in order to log in a website on iphone or ipad platform?
Some one has suggest me that use ASIHTTPRequest,but I don't know how to use it.
Can somebody help me ?Thank you ........
ASIHTTPRequest has one of the best how to use pages of any library I have ever encountered. It is located here: http://allseeing-i.com/ASIHTTPRequest/How-to-use
If you need to post to a web form you could do something like this:
#define kURLString #"https://yourwebsite.com"
NSURL *url = [NSURL urlWithString:kURLString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:#"myname" forKey:#"username"];
[request setPostValue:#"l33td00d" forKey:#"password"];
[request setDelegate:self];
[request startSynchronous];
Although in real life you may wish to run the request asynchronous. The details on how to do that are on the page I linked. It is defiantly worth reading.

API image file upload iPhone to Ruby on Rails

I am a backend Rails developer of an API that services several iPhone clients. I'm not an iPhone dev.
I have a need to accept binary data (several image files in this case) from the client via a POST request to the API.
To get the file content (file metadata other than image type is not relevant here), what tools might be used by the iPhone developer? I've found ObjectiveResource (used by iPhone on Rails) and ASIHTTPRequest. In the pages I found for those, there's no indication of what form the uploaded file will have when the controller action is executed. Will it be a Ruby File object or Tempfile object? I don't control the iPhone code development, there are some cross-cultural communication difficulties there, and they haven't used those suggestions so far. If I can submit better information to them, I might be getting better data back.
The backend app is currently running Rails 2.3.10, and will soon (in the next few weeks) likely be converted into Rails 3.
Thanks,
Craig
ObjectiveResource does not natively support file uploads. Try instead using ASIHTTPRequest with this snippet:
NSURL *url = [NSURL URLWithString:#"http://localhost:3000/file"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:#"Sample" forKey:#"name"];
[request setFile:... forKey:#"file"];
[request startSynchronous];
For more details, see the example page here (sending data).
The post will be encoded as a standard multipart form post (just like if it came from an HTML form). If you are using paperclip to store your uploads, the magic will just happen!
Use JSON over HTTP
NSMutableURLRequest *request =
[[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:urlStr]];
[request setHTTPMethod: #"POST"];
[request setValue:#"application/json; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
NSString* requestDataLengthString = [[NSString alloc] initWithFormat:#"%d", [jsonMessageStr length]];
[request setValue:requestDataLengthString forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setHTTPBody:jsonData];
NSURLConnection *theConnection =
[[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

iPhone and ASIHTTPRequest - Unable to start HTTP connection

I am using the ASIHTTPRequest class in order to communicate with a web service and get a response. This is how I send a request to the server
NSString *str = [NSString stringWithFormat:#"%#verifyLogin.json", serverUrl];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request addRequestHeader:#"Content-Type" value:#"text/x-gwt-rpc; charset=utf-8"];
NSDictionary* data = [NSDictionary dictionaryWithObjectsAndKeys:emailId, #"username", pwd, #"password", nil];
[request appendPostData: [[data JSONFragment] dataUsingEncoding: NSUTF8StringEncoding]];
[request setRequestMethod:#"POST"];
[request setDelegate:self];
[request setDidFinishSelector: #selector(gotLoginResponse:)];
[request setDidFailSelector: #selector(loginRequestFailed:)];
[networkQueue addOperation: request];
[networkQueue go];
The control immediately goes to the error routine and the error description and domain are
Unable to start HTTP connection and ASIHTTPRequestErrorDomain
I can get the same request to work via a desktop tool for checking HTTP requests so I know the settings are all correct.
Can someone please tell me what I am missing here while sending the request?
Thanks.
As I commented earlier;
in your first line it says
"%verifyLogin.json". Shouldn't that
be; "%#verifyLogin.json" ????
For me I forgot to add http:// as i was testing locally. But after adding http it ran successfully
Can you check the status code of the request when it fails? I recently dealt with a JSON user authentication issue with ASI-HTTP-Request where the first request would always fail with Status Code 0 and some sort of underlying network connection failure (as if it wasn't connected to the internet, but clearly was).
I was able to solve it by setting that particular request to not attempt to use a persistent connection.
So try that first!