I'm trying to connect with an SSL client key using DBI
and DBD::Pg
.
use strict;
use warnings 'all';
use DBI;
my $dsn = "dbi:Pg:db=mydb;sslmode=require;host=localhost;"
."sslcert=C:\\path with\\spaces.crt;"
."sslkey=C:\\path with\\spaces.key";
my $dbh = DBI->connect( $dsn, 'username', '' );
I get the following error:
Can't connect to database: missing "=" after "with\spaces.crt" in connection info string!
I have tried using single or double quotes around the values to no avail, and I can't find anything in the documentation.
Update
With single quotes as follows:
my $dsn = "dbi:Pg:db=mydb;sslmode=require;host=localhost;"
."sslcert='C:\\path with\\spaces.crt';"
."sslkey='C:\\path with\\spaces.key'";
I get the following error:
failed: FATAL: connection requires a valid client certificate
I know that this configuration works, as it works in Python.
It turns out that this works:
my $dsn = "dbi:Pg:db=mydb;sslmode=require;host=localhost;"
."sslcert='C:\\\\path with\\\\spaces.crt';"
."sslkey='C:\\\\path with\\\\spaces.key'";
Why do I need double escaped backslashes?
"sslcert='C:\\path with\\spaces.crt';"
etc.? As I suspect the OP means'sslcert=C:\path with\spaces.crt;'
– Electromyography"sslcert='C:\\path with\\spaces.crt';"
should work, but"'sslcert=C:\path with\spaces.crt;'"
or"sslcert='C:\\path with\\spaces.crt;'"
won't. But the OP didn't specify which one of those he used. – Depravity"sslcert='C:\\\\path with\\\\spaces.crt';"
to"sslcert='C:\\path with\\spaces.crt';"
. And the docs for libpq say, "Single quotes and backslashes within the value must be escaped with a backslash, i.e.,\'
and\\
." – Depravity