I am making Https connection with NSURLConnection so I wanted to know default What version of Protocol(TLS) used.
How can I differentiate SSL/TLS and HTTP Protocol while making request.
Related
I am trying to implement an HTTP server inside an iOS app. I could see similar apps in the app store. But in my case, embedded HTTP server has to communicate with external HTTPS Server. So now,
is the communication secured? Or do I need to implement HTTPS server, instead?
Is it possible to implement an HTTPS server in iOS app?
Will Apple reject this approach?
Thanks in Advance
I'm assuming that you use the internal HTTP server to provide interceped content for a WKWebView. I this case you web view connects to the HTTP server over HTTP and this connection is insecure. But generally this shouldn't be an issue because nobody can intercept the connection. You HTTP server connects to the internet over HTTPS, and this should be done because this connection could be compromised.
Don't be confused about the different protocols. If you call a HTTPS-URL NSURLSession will use HTTPS and use a secured connection. There is no pitfall or issue. You needn't to support HTTPS for the web view to server connection. This will give you not more notable security.
I use a similar setup in my application and it works perfectly.
BTW: In iOS 11 you may use WKURLSchemeHandler to intercept web view requests. This should be much easier than a local HTTP server. The disadvantage is, that you have to define a custom protocol (e.g. xhttp instead of http), and rewrite the URLs in the web content. But this should be much easier to achieve than a local HTTP server.
I have developed an iOS app using Xamarin and I am unsure about how encryption would work when calling a service that uses HTTPS.
On my end I do nothing particularly special: I utilize a RestClient and add the credentials to the body of a json serialized request. I then post it to the HTTPS service.
Is this safe or should I be doing more? I am not sure if iOS handles the rest for me in terms of encryption.
Answer
Yes, by using HTTPS, you are most-likely safe. However, there are a couple things to verify to ensure that there are no security leaks.
More Info on TLS
Communication with secure HTTPS enpoints encrypt the header and body of the message by default using TLS.
HTTPS consists of communication over Hypertext Transfer Protocol (HTTP) within a connection encrypted by Transport Layer Security. Source
Things To Verify
Do Not Use Sensitve Data in the URL
The Url of the HTTPS endpoint is not encrypted. It is important to never put any sensitive data into the Url of the HTTPS enpoint. To ensure sensitive data is encrpyted, put the data in the message body.
For example, if you are validating a user's login (username: user1234, password: password1234), do not send the username/password as a url parameter. Instead, serialize the username and password data, and set it as the HttpContent of the HttpClient.
Bad: https://myApiEndpoint.com/getIsUserValid/user123/password1234
iOS HttpClient Implementation
Ensure that you are using NSUrlSession for the iOS HttpClient Implementation.
NSUrlSession will use TLS by default when communicating with secure HTTPS endpoints. As of iOS 10, NSAppTransportSecurity will not allow communication to non-secure HTTP endpoints by default; communication with non-secure HTTP enpoints can be enabled by updating NSAppTransportSecurity in Info.plist, Apple Documentation.
You can verify NSUrlSession is being used in the iOS Build Settings (screenshot below).
When using HTTPS everything except the server address is encrypted during transit. The encryption is totally transparent to the client and server.
Example: for the URL https://myApiEndpoint.com/getIsUserValid/user123/password1234 only myApiEndpoint.com is not encrypted, the rest of the URL is encrypted.
In order to protect against MITM attacks pin the server certificate, that is verify that the certificate received on the request belongs to the correct server.
If you control the server use TLS 1.2 and Perfect Forward Secrecy.
According to Apple:
If your application implements a TLS client using the CFStream APIs or the SecureTransport APIs, it will now default to using a TLS 1.2 handshake when connecting to a TLS server.
Reference:
https://developer.apple.com/library/ios/technotes/tn2287/_index.html
However, in my application, I am not using CFStream API. I am using an NSURLConnection. For NSURLConnection, is the default TLS 1.2 also?
Currently the app I'm working on uses NSURLConnection to connect to the server using HTTPS. The requirement is to enforce the prevention of connections using SSL 2.0 and to use only SSL 3.0 or TLS for connections.
What should be done to disable SSL 2.0 support in the app? As far as i see lower level CFNetwork or Secure Transport API provide some control over SSL protocol, but should all the current NSURL* networking code be changed in order to do this?
As far as I know, you cannot achieve this with NSURLConnection.
However, NSURLSession provides APIs to configure a session via a NSULRSessionConfiguration and TLSMaximumSupportedProtocol and TLSMinimumSupportedProtocol.
Switching from NSURLConnection to NSULRSession/NSURLSessionTask should be straight forward.
I am thinking of writing an Apple Push Notification server using Dart. Does Dart support client side SSL/TLS certificates?
Yes! Dart VM now supports SSL/TLS, and HTTPS.
See http://code.google.com/p/dart/issues/detail?id=3950 and http://code.google.com/p/dart/issues/detail?id=3593 which are now closed. :)
Dart supports SSL/TLS client connections using SecureSocket. It also supports secure server sockets using SecureServerSocket to (use this if you need to listen on a secure port on the VM).
Note that the ordinary HttpClient will automatically handle HTTPS for your browser connections so no extra code is needed in these cases.