RDS PostgreSQL: General error: 7 SSL error: invalid key length RDS PostgreSQL: General error: 7 SSL error: invalid key length postgresql postgresql

RDS PostgreSQL: General error: 7 SSL error: invalid key length


Same issue here with Paypal, I turned off the sslmode in the PostgreSQL connection pool (internal network)

sslmode=disable

dsn = 'pgsql:host=host.com;port=5432;dbname=postgres;sslmode=disable'


TLDR;

If you are using OpenSSL or anything related to it and PHP < 7.1, turning off SSL for Postgres might solve your problem.

non-TLDR;

Had same issue with custom framework, Postgres 9.3 on AWS VM and a legacy PHP 5.3.

Worked for 3 years w/o any problems then all of a sudden a simple select started throwing this error without any relevant changes to code/configuration. It wasn't the longest query we have (char count) and it wasn't the query that took a long time to execute.

While SSL was off in Postgres pg_hba.conf, explicitly disabling it in DSN: sslmode=disable (see @Gergo Bacskai answer) did help and the error did not return.

So after a deeper investigation what seems to be the cause is this bug: https://bugs.php.net/bug.php?id=69524

We have started using phpseclib when integrating with 3rd party service and it probably uses openssl_pkey_get_public or some alternative to it and that's the moment we started receiving these errors.