'Symfony + mssql. Error tls_process_server_certificate:certificate verify failed:self signed certificate

I try to connect mssql to my symfony project, but get error SQLSTATE[08001]: [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:self signed certificate]" So I want to set "TrustServerCertificate=yes" on pdo conception but can't figure out how it does on symfony
I tried to write in .env

DATABASE_MSSQL_URL="mssql://user:password@ip:port/db_name?Trusted_Connection=yes&Encrypt=yes&TrustServerCertificate=yes"

in config/packages/doctrine.yaml:

   dbal:
     jtl:
        url: '%env(resolve:DATABASE_MSSQL_URL)%'
        driver: 'pdo_sqlsrv'
        server_version: '13'
        charset: utf8mb4

It did not help



Solution 1:[1]

There is a connection option you can add. However, in my project it only worked with a explicit "url" and with the "TrustServerCertificate" option added to both:

dbal:
  connections:
    ...
    my_ms_sql_db:
      url: "sqlsrv://my_user:[email protected]:1434/my_db?TrustServerCertificate=yes"
      driver: pdo_sqlsrv
      charset: UTF-8
      host: ...
      port: ...
      ...
      options:
        TrustServerCertificate: yes

Solution 2:[2]

In mssql connection url, properties can only be delimited by using the semicolon (';')

mssql://user:pass[serverName[\instanceName][:portNumber]];property=value[;property=value]]

Example:

DATABASE_URL=mssql://user:pass@serverName:port/db;**TrustServerCertificate=1**

Although it is jdbc, it also applies in this case.

Solution 3:[3]

You are missing the \0 (NUL) character at the end of your chars. At newKey[31] needs to be \0. Otherwise you print more than you wish.

In your example the \0 is within alphanum at the end, position 63. So the program reads all memory until it "sees" the \0.

Either you switch to use std::string which handles this for you, or you need to make sure that all your char arrays are null-terminated, by:

  • making them one larger than your expected output: char newKey[33];

AND

  • insert '\0' at the end: newKey[32] = '\0';.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 lemon
Solution 3 mistapink