Security is very important when sending messages from the server to the client and vice versa. There are many data protection methods, including the use of SSL encryption to connect to a remote PostgreSQL server from a Delphi application. PostgreSQL supports data transfer via the TCP/IP protocol stack both using SSL encryption or without it.
Devart offers a solution called SecureBridge, which allows you to embed an SSL client into a Delphi or C++ Builder application to establish a secure connection to PostgreSQL server. This tutorial demonstrates how to create a sample Delphi application that connects to PostgreSQL using SSL as the encryption method.
Before connecting to PostgreSQL via SSL, create SSL certificates as explained in the PostgreSQL documentation and configure SSL parameters in postgresql.conf and pg.hba.conf files.
To create an SSL connection to PostgreSQL, PgDAC provides several values for the SSLOptions property. For this tutorial, the Mode property is set to smRequire , since it forces the application to only connect via SSL connection - if a connection attempt fails, an exeption is raised.
Example of SSLOptions property set to smRequire:
PgConnection.SSLOptions.Mode := smRequire;
After installing PgDAC and SecureBridge software on your machine, install the TCRSSLIOHandler component in RAD Studio to bind PgDAC with SecureBridge. The installation instructions are provided in the Readme.html, which is located by default in "My Documents\Devart\PgDAC for RAD Studio\Demos\TechnologySpecific\SecureBridge\DelphiXX".
Another way to embed SSL client functionality into your Delphi app, which uses PgDAC components to access PostgreSQL, is by using the OpenSSL library that implements the SSL protocol and enables servers to securely communicate with their clients. The description of the SSL connection features without the SecureBridge IOHandler usage:
The following options must be set for SSL connection:
Note:The ssleay32.dll and libeay32.dll files are required to use the SSL protocol with the OpenSSL library.