I am finding that when my iOS device automatically configures a proxy, all of my NSURLSessions are using it for downloads/uploads/requests. This becomes a problem when I'm trying to make those requests from other devices on the same local network. I need to disable the proxy that the device autodetects for NSURLSession.
Every post everywhere indicates how to set the proxy dictionary, however, I can't find anywhere how to make sure the NRURLSession doesn't use a proxy.
Any help would be appreciated!
If you provide an empty proxy dictionary when creating the session configuration, NSURLSession should ignore the system-provided proxies in all sessions created with that session configuration.
If you're trying to override it for something where you didn't create the session (e.g. third-party frameworks, web views, etc.), you can usually solve that by creating and registering (globally) an NSURLProtocol that takes the requests and reissues them in your own session (adding some custom header so that you don't keep reissuing the same request in an infinite loop). There are some basic examples of writing custom protocols on Apple's website.
Related
I just added SSL to my backend framework (Django REST API) and I want my iOS application to talk to it. Do I have to do anything differently on the iOS side of my project? How do I tell Alamofire to encrypt the data its sending? Or Does it happen automatically?
The only difference is using https instead of http. I have the same setup at work, and originally thought I was going to have to delve into certificates. I started heading in that direction and then realized all my requests worked as soon as I stuck the "s" on the end.
I will say, while using NSStream, you do have to setup the stream to handle the certificate. I am doing this in another application, but that is below the URLRequest class. I am unsure of how low level Alomofire actually delves, but it will definitely handle everything you desire without doing anything differently.
Just update URLs inside your app to use "https" and you are done.
It seems there are a couple choices within Xcode/iOS to communicate with my server, using simple HTTP requests or creating a full blown socket system. What vulnerabilities does each have? My main concern is that I can't allow someone to replicate a call that's not from my app, like you could spoof an AJAX call by examining a webpage's Javascript and getting the address for the call. Obv it wouldn't be so simple with a phone app, but I don't know what's possible for hackers.
Use HTTPS.
Override the TLS chain validation to fail if the public key doesn't match the one stored in your app.
In Apple's TLS validation doc below, start with "Listing 3 Overriding the trust object used by an NSURLConnection object", then add code so that if certificate evaluation succeeds, you check the key inside the challenge's protection space against a known-valid key (or keys) before allowing the connection to proceed.
I'm using a JavaFX webview in my application. Inside of it I load a local html file, which itself loads some javascript library from maps.google.com and then displays a google map with some markers inside the webview.
Now according to this question if I want to use a proxy I should just do:
System.setProperty("http.proxyHost","proxy.esrf.fr");
System.setProperty("http.proxyPort","3128");
But this has no effect. I can set whatever I want as the host and port. The google map tiles are still loaded, even if the settings are no valid proxy. So apparently it is not making use of the proxy settings.
How can I make sure, that all web traffic within the WebView is going via the proxy.
I also set the https.proxyHost and https.proxyPort by the way, just in case.
Thanks!
The problem was cause by a bugfix I did earlier.
When working with proxies in java this post is quite helpful. In the end it recommends setting
ProxySelector.setDefault(null);
to avoid issue with sockets and proxies.
However, this made setting the proxy via
System.setProperty("http.proxyHost","proxy.esrf.fr");
System.setProperty("http.proxyPort","3128");
impossible. Actually, it wasn't possible to set any proxy at all except by passing a Proxy object to URL.openConnection(Proxy p);
So instead of setting the default ProxySelector to null, I recommend setting
ProxySelector.setDefault(ProxySelector.getDefault());
I'm trying to make a UIWebView application, just like any other (with refresh, go forward, back, google search, etc). It is going to be very simple. One thing I want to do however, is make the data loaded into the UIWebView loaded through a proxy server (like hideMyAss) - so websites like at schools or workplaces become unblocked.
I have been looking for a proxy which enables me to input the website address at the end of a proxy's URL, but I have not found one.
E.g. Hidemyass.com?url=google.com
Does Apple have any documentation as to how I could achieve this. I have no idea where to start looking as I don't know the exact name of what if be looking for. Any suggestions would be really helpful. Thanks!
Create a subclass of NSURLProtocol class that will handle all web protocols such as HTTP, HTTPS, SSL etc. This is a abstract class that provides the basic structure for performing protocol-specific loading of URL data. Guide on NSURLProtocol
Once your created your custom url protocol handler, register it in your appDelegate so your protocol will have priority over any of the built-in protocols.
[NSURLProtocol registerClass:[MyURLProtocol class]];
In terms of proxy, create your own server and implement a ready made solution that will do all your tunneling of client data to outside world. Tinyproxy is a example of a free software that can do your proxy requirements, research others or even create your own solution if you got the time.
So I have the following scenario (it's a Grails 2.1 app):
I have a Controller that can be accessed via //localhost:8080/myController
This controller in turn executes a call to another URL opening a connection using new URL("https://my.other.url").openConnection()
I want to capture the request so I can log the information
I have a Filter present in my web.xml already which does the job well for controllers mapped in my app. But as soon as a request is fired to an external URL, I don't get anything.
I understand that my filter will only be invoked to URLs inside my app, and that depends on my filter mapping which is fine.
I'm struggling to see how a solution inside the app is actually viable. I'm thinking of using a mixed approach with the DevOps team to capture such outgoing calls from the container and then log them into a separate file.
I guess my questions are:
Is there a way to do it inside the app itself?
Is the approach I'm planning a sensible one?
Cheers!
Any reason why you don't want to use http-builder? There a Grails plugin for it, and it makes remote XML calls much easier than handling the plumbing yourself. At the bottom of the linked page they describe how you can enable request logging via log4j configuration.