1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

SSL / HTTPS on different platforms with TIdHTTP and TRESTClient

Discussion in 'Delphi Programming' started by AdminDF, Feb 11, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    Using SSL/HTTPS with Indy’s TIdHttp (or through TRESTClient – which is effectively based on TIdHttp) requires external OpenSSL libraries, which is something most of us probably learned in the past.

    With Delphi XE5 now supporting different platforms, such as Windows, Mac, iOS devices, iOS Simulator and Android devices, there are now a couple of different libraries and approaches to follow.

    Btw, if you are using TRESTClient, then you can just assign a URL like https://www.example.com/api to TRESTClient.BaseURL – you don’t have to worry about assigning an SSL IO handler, as you would have to, if working with TIdHttp directly. TRESTClient detects that situation automatically.

    In one of Marco Cantú’s recent posts you will find some very useful information about how to build your own OpenSSL binaries iOS – which is a good idea from a security standpoint.

    Marco’s post is basically for iOS only, so I thought I should share an overview that covers all platforms and make this an easy to follow SSL with Delphi recipe.

    As mentioned above building your own SSL libraries from source is a good idea, but many people would just like to download ready-to-use binaries. For us Delphi users there is a trustful mirror site which has recent builds available since many years:

    http://indy.fulgan.com/SSL

    There are dynamic libraries (a.k.a “DLLs”) and static libraries (a.k.a “.a files”)

    Recent dynamic libraries (32-bit): openssl-1.0.1e-i386-win32.zip
    Recent static libraries: OpenSSLStaticLibs.7z

    Windows

    Download dynamic libraries and put them into the same directory as your exe. You may also put them into your system’s windows\system32 directory.

    Files (32 Bit)

    libeay32.dll
    ssleay32.dll

    Mac OSX

    No download required, recent versions of Mac OSX come with OpenSSL pre-installed, you only need to tell your app where the required dynamic libraries (a.k.a dylibs) can be found. On typical Mac installations they are in “/usr/lib/”



    Code:
    uses
    IdSSLOpenSSLHeaders;
    ...
    IdOpenSSLSetLibPath('/usr/lib');
    

    You could also deploy these files with your app by adding them to your apps deployment files list (and enable it for Mac OSX and iOS Simulator only)

    Files

    libcrypto.dylib
    libssl.dylib
    (Both files are usually symbolic links to actual binaries like /usr/lib/libssl.0.9.7.dylib)

    iOS Simulator

    No download required, recent versions of Mac OSX come with OpenSSL pre-installed (and which is used by the iOS Simulator as well), you only need to tell your app where the required dynamic libraries (a.k.a dylibs) can be found. On typical Mac installations they are in “/usr/lib/”


    Code:
    IdOpenSSLSetLibPath('/usr/lib');

    Files

    libcrypto.dylib
    libssl.dylib
    (Both files are usually symbolic links to actual binaries like /usr/lib/libssl.0.9.7.dylib)

    iOS Device

    iOS does not allow to load any dynamic code, thus you need to download the static OpenSSL libraries and put them into the main source directory of your application, so that Delphi can find them while compiling/linking your app.

    Files

    libcrypto.a
    libssl.a
    Android Device

    Info follows soon!

    Making your project multi platform

    As you can actually have one project compiling to all the mentioned platforms you probably want some ifdefs to handle all platforms and their units automatically. Below is a sample DPR file that works fine for me:


    Code:
    program SSLTest;
     
    uses
      System.StartUpCopy,
    {$IF Defined(IOS) and Defined(CPUARM)}
      IdSSLOpenSSLHeaders_Static,
    {$ELSE}
      IdSSLOpenSSLHeaders,
    {$ENDIF}
      FMX.Forms,
      Unit5 in 'Unit5.pas' {Form5};
     
    {$R *.res}
     
    begin
    {$IF Defined(IOS) and not Defined(CPUARM)}
      IdOpenSSLSetLibPath('/usr/lib/');
    {$ENDIF}
      Application.Initialize;
      Application.CreateForm(TForm5, Form5);
      Application.Run;
    end.
    
    
     

Share This Page