Search code examples
postgresqldelphisslfiremonkeyfiredac

SSLmode in FireDac for connection to Postgres


What I use: Delphi 12, FireDac, Postgres 11, Windows

My connection configuration in FireDac looks like this:

dm.DMForm.Connect.Params.Clear;
dm.DMForm.Connect.Params.Add('DriverID=PG');
dm.DMForm.Connect.Params.Add('Server=localhost');
dm.DMForm.Connect.Params.Add('Database=dbname');
dm.DMForm.Connect.Params.Add('User_Name=username');
dm.DMForm.Connect.Params.Add('Password=pass');
dm.DMForm.Connect.Params.Add('Port=5432');
dm.DMForm.Connect.Params.Add('UseSSL=True');
dm.DMForm.Connect.Params.Add('SSLMode=require')

In my opinion, this configuration is wrong, although, it is in accordance with the specification. SSLMODE does not force an SSL connection. When I connect to a server that does not have SSL configured, firedac makes the connection, while it should report an error.

When I do the same thing using UniDac components and try to connect to the same server, the component fails to connect and returns an error. That is, it behaves correctly.

Does anyone know how to force SSL connection correctly in firedac ?


Solution

  • Parameters not directly supported by FireDAC need to go in the PGAdvanced parameter and use the documented parameters and names in the PostgreSQL documentation.

    dm.DMForm.Connect.Params.Add('PGAdvanced=sslmode=require');
    

    Refs: Connect to PostgreSQL (FireDAC) - Connection Definition Parameters and Documentation → PostgreSQL 16, Database Connection Control Functions, sslmode