Add domain exception to App Transport Security ios9 [duplicate] - objective-c

This question already has answers here:
App Transport Security and IP addresses in iOS9
(4 answers)
Closed 7 years ago.
I am using following code in my plist to add my server exception to App Transport Security protocol.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>172.16.4.139</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSRequiresCertificateTransparency</key>
<false/>
</dict>
</dict>
</dict>
but it is giving message "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.".
What i am doing wrong?

Hard-coded IP address wont work in iOS 9.
Check this answer.

Related

My NSAppTransportSecurity settings in info.plist ins't working for all defined domanins and subdomains

in my info.plist under property NSAppTransportSecurity I added a set of domains with which my app communicates. But for some reasons my settings works only for some of added domains, not for all but I don't know why. I would be very helpful for any idea. Thanks in advance.
For example now it works for domain googleapis.com but not for imeteo.sk, imeteo.cz or any subdomain ( http://m.imeteo.cz )
Here is snippet of my info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowExceptionDomains</key>
<dict>
<key>imeteo.cz</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>imeteo.sk</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>googleapis.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
After trying to load some of this domains or subdomains in webview I'm getting this :
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
Try to replace NSExceptionAllowsInsecureHTTPLoads and NSExceptionMinimumTLSVersion with NSTemporaryExceptionAllowsInsecureHTTPLoads and NSTemporaryExceptionMinimumTLSVersion as is told in:
http://www.neglectedpotential.com/2015/06/working-with-apples-application-transport-security/
Also, I'm using NSExceptionDomains instead of NSAllowExceptionDomains.

No solution for Transport Security?

I have tried all the methods of here for solving the problem of: "Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file."
But if I try for example adding this in my plist file:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.myserver.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
I get an error:"Unsupported URL", where in this case my link, looks like this:
let url:NSURL = NSURL(string: "www.myserver.com/jsonsignup.php")
But if I would use:
let url:NSURL = NSURL(string: "http://www.myserver.com/jsonsignup.php")
I would get the same error of Transport Security as mentioned above.
Any help?
I had the same issue. I tried adding it to info.plist but it did not work for me either. So I tried this and it worked.
Click on your project name in the "Project Navigator" then click on info. And add it there. See highlighted.
Before I tried selecting the plist from my project navigator under supporting files and for some reason it did not work. The above should work for you.
Note: This will allow all connections.
Are you using http://request ? then add following code in your .plist file.
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
I hope it's work for you.

Cocoa finder menu item for folders only

I am trying to create a Finder context menu item using a service (as described here: Writing a Snow Leopard Service for Finder.app )
However, I wish to add a context menu entry for folders only.
Whenever I put the following code in my .plist file:
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Service Handling Demo</string>
</dict>
<key>NSMessage</key>
<string>handleServices</string> <!-- This specifies the selector -->
<key>NSPortName</key>
<string>Tmp</string> <!-- This is the name of the app -->
<key>NSSendTypes</key>
<array>
<string>NSFilenamesPboardType</string>
</array>
</dict>
</array>
Everything works fine, I can select my service in the Services tab (keyborad shourtcuts) and run it.
However, if I try to use the service for folders:
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Service Handling Demo</string>
</dict>
<key>NSMessage</key>
<string>handleServices</string> <!-- This specifies the selector -->
<key>NSPortName</key>
<string>Tmp</string> <!-- This is the name of the app -->
<key>NSSendFileTypes</key>
<array>
<string>public.directory</string>
</array>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>
</dict>
</array>
The service does not appear in the keyboard shortcuts' menu and of course is not visible in finder...
What am I missing?
Add the following code to the .plist:
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Folder Handling Demo</string>
</dict>
<key>NSMessage</key>
<string>handleServices</string> <!-- This specifies the selector -->
<key>NSPortName</key>
<string>Tmp</string> <!-- This is the name of the app -->
<!-- Here we're limiting where the service will appear. -->
<key>NSRequiredContext</key>
<dict>
<key>NSTextContent</key>
<string>FilePath</string>
</dict>
<!-- This service is only really useful from the Finder. So
we want the finder only to send us the URI "public.directory"
which *will* include packages (on the off-chance you want to
see the full package directory name) -->
<key>NSSendFileTypes</key>
<array>
<!-- Check out "System-Declared Uniform Type Identifiers"
in the Apple documentation for the various UTI types.
In this example, all we want is a directory, which is
a super-type to other types (e.g. public.folder) -->
<string>public.folder</string>
</array>
</dict>
And the service will appear under "Files and Folders" group in the services list (keyboard shortcuts tab).

My daemon is unregistered from launchd on logout/login

I create a plist that looks like this:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<!-- My version "1.2.3" -->
<plist version=\"1.0\">
<dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>MyPlistName</string>
<key>ProgramArguments</key>
<array>
<string>MyDaemonBinPath</string>
<string>-log</string>
<string>MyLogLevel</string>
<string>-launchd</string>
</array>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockFamily</key>
<string>Unix</string>
<key>SockPathMode</key>
<integer>438</integer>
<key>SockPathName</key>
<string>MySocketName</string>
</dict>
</dict>
<key>StandardErrorPath</key>
<string>MySTDERRLogPath</string>
<key>WaitForDebugger</key>
<false/>
<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>
</dict>
</plist>
I place it in /Library/LaunchDaemons
I then run the command:
/bin/launchctl unload /Library/LaunchDaemons/MyPlistName.plist
/bin/launchctl load /Library/LaunchDaemons/MyPlistName.plist
My daemon does launch when I connect to the socket specified in the plist and when I type:
launchctl list
The daemon is registered but when I log out and log back in and ask for the list again, it's no longer registered and I can't launch my daemon by connecting to the socket
Is there some special permissions I need to be setting on the plist or the daemon to get this to persist between sessions?
Did you check your /var/log/system.log for errors? Regular plists in /Library/LaunchDaemons/ are run as root on boot-up. You might want to check sudo launchctl list to see whether they run. If not, you might need to change the ownership / read+write attributes of the plists to match root. Finally, you could include the following to improve logging:
<key>StandardErrorPath</key>
<string>/logs/launchd_myprogram_stderr.log</string>
<key>StandardOutPath</key>
<string>/logs/launchd_myprogram_stdout.log</string>

register a custom file type in iOS

I'm working on iOS application in which i want XML file to be the main input for this application.I've started a search trip (mainly in stackoverflow)to find how can i receive XML files from the Email.
first I've found an alternative method which was registering URL format for my files and use it in the Email instead of the file attached and this method works good.
now I want to use the file itself (attached) I found that i need to register a custom file type in this application depend on this resources
apple reference
stackoverflow question
stackoverflow question 2
related to this I've edited the info.plist file with this code
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>XML File</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.IT.parseXML.XML</string>
</array>
</dict>
</array>
and this part also
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>XML Document</string>
<key>UTTypeIdentifier</key>
<string>public.xml</string>
<key>UTTypeReferenceURL</key>
<string>http://www.w3.org/TR/rec-xml</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>xml</string>
</array>
<key>public.mime-type</key>
<string>text/xml</string>
</dict>
</dict>
</array>
what I expect is to be able to handle XML files from emails... but this doesn't happen, what I'm missing ??
thanks in advance
I've figured out the problem in my configuration
it was on this line
<key>LSItemContentTypes</key>
<array>
<string>com.IT.parseXML.XML</string>
</array>
it should be
<key>LSItemContentTypes</key>
<array>
<string>public.XML</string>
</array>
as it is in the public identifier