3
votes

OpenSSL not working for iOS Simulator in Delphi DX Using info at: http://blog.marcocantu.com/blog/using_ssl_delphi_ios.html http://docwiki.embarcadero.com/RADStudio/Seattle/en/OpenSSL https://plus.google.com/100777187605111792758/posts/SPnHdXvTTNu

I can get it to work on devices, but not on the iOS simulator. Same URL works when I use a TWebbrowser.navigate, but not with INDY of course.. See below, and possibly offer suggestions on how to make HTTPS calls on the iOS simulator ! This worked before in earlier versions of Rad Studio ( XE4, XE5 ) but hasnt since XE7 if my memory has served me right.

I have these files in my usr/lib folder:

libcrypto.0.9.8.dylib
libssl.0.9.8.dylib

Here is my uses

uses
  IdSSLOpenSSL,
  {$IF Defined(IOS) and Defined(CPUARM)}
    IdSSLOpenSSLHeaders_Static,
  {$ELSE}
    IdSSLOpenSSLHeaders,
  {$ENDIF}
...

Here is my onCreate for the main form

procedure TmLoginForm.FormCreate(Sender: TObject);
var
  t:string;
begin
  IdOpenSSLSetLibPath('/usr/lib/');
...

Here is part of a function that I use, where on the last line an exception is thrown

function ParseGroups(OnlyUserCreated:boolean):integer;
var
  IdHTTP          :TIdHTTP;
  HTML            :String;
  JSON_Groups     :TJSONObject;
  Group           :uGroup;
begin
  result:=0;
  HTML:='';
  IdHTTP:=TIdHTTP.Create(nil);
  IdHTTP.HandleRedirects:=false;
  try
    HTML:=IdHTTP.Get(URL_Host+ACCESSTOKEN);

Error is: 'Could Not Load SSL Library'

ShowMessage(IdSSLOpenSSLHeaders.WhichFailedToLoad); shows a blank message

Update:

adding

 IdSSLOpenSSLHeaders.Load;

after setting the path now causes the whichFailedToLoad say: 'Failed to Load /usr/lib/libcrypto.'

2

2 Answers

4
votes

Use System.Net.HttpClient.THTTPClient instead of the Indy components.

var
  http : THTTPClient;
  html : string;

http := THTTPClient.Create;
try
  html := http.Get( url ).ContentAsString();
  ...
finally
  http.Free;
end;

It is a wrapper of the http function from the operating system. If the OS supports https, then this class will do also.

2
votes

You can also follow this nifty blogpost http://delphiworlds.com/2016/03/building-openssl-dylibs-for-ios-simulator/

It worked just fine for me. I needed it, because my Soap client needs to connect via https, and I did not want to rewrite the soap libs.