Search code examples
iossecuritydelphisslfiremonkey

How can we use Open SSL with Delphi iOS?


Apple has introduced a few changes with it's App Transport Security when working with Open SSL and I can't make it work on iOS.

“App Transport Security is a feature that improves the security of connections between an app and web services. The feature consists of default connection requirements that conform to best practices for secure connections. Apps can override this default behavior and turn off transport security. Transport security is available in iOS 9.0 or later, and in OS X v10.11 and later.”

When trying to connect to our server, I get the following response error:

"An SSL error has occurred and a secure connection to the server cannot be made."

Then, I found this tutorial and discovered that all we need to do is to include the unit IdSSLOpenSSLHeaders_Static in one of the uses statements of the project.

I did add the unit and both libcrypto.a and libssl.a. libraries to the project but so far I'm getting the same response error.

What could I possibly be doing wrong?


Solution

  • To disable ATS, you need to additionally follow this steps from this official embarcadero documentation:

    Open your Info.plist and add the following lines:

    <key> NSAppTransportSecurity</key>
    <dict>
         <key>NSAllowsArbitraryLoads</key>
         <true/>
    </dict>
    

    This will disable Apple’s App Transport Security feature for all HTTP communications used by the application, for example if you use the TWebBrowser or Project Indy's HTTP component.

    Your project’s Info.plist file is regenerated every time deployment is done. You need to save the file to a different location, like your project directory for example. (Note that the 32-bit and 64-bit versions are slightly different).

    Make your changes in the newly saved file and go to the Deployment Manager (Project -> Deployment). Make sure the configuration is set correctly and uncheck the default Info.plist.

    Add the new custom version and make sure you set the Remote Name to “Info.plist” (case-sensitive). Do this for both the 64-bit and 32-bit deployment.