Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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 N0body, Feb 11, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator 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

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block