From 4dc63552109f65cebbe168203bd62c5e4c753162 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sat, 30 Nov 2019 15:27:13 -0500 Subject: libq support for sslpassword connection param, DER format keys This patch providies for support for password protected SSL client keys in libpq, and for DER format keys, both encrypted and unencrypted. There is a new connection parameter sslpassword, which is supplied to the OpenSSL libraries via a callback function. The callback function can also be set by an application by calling PQgetSSLKeyPassHook(). There is also a function to retreive the connection setting, PQsslpassword(). Craig Ringer and Andrew Dunstan Reviewed by: Greg Nancarrow Discussion: https://postgr.es/m/f7ee88ed-95c4-95c1-d4bf-7b415363ab62@2ndQuadrant.com --- src/interfaces/libpq/fe-connect.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/interfaces/libpq/fe-connect.c') diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index dcd86ee8043..5c786360a96 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -351,6 +351,10 @@ static const internalPQconninfoOption PQconninfoOptions[] = { "Target-Session-Attrs", "", 11, /* sizeof("read-write") = 11 */ offsetof(struct pg_conn, target_session_attrs)}, + {"sslpassword", NULL, NULL, NULL, + "SSL-Client-Key-Password", "*", 20, + offsetof(struct pg_conn, sslpassword)}, + /* Terminating entry --- MUST BE LAST */ {NULL, NULL, NULL, NULL, NULL, NULL, 0} @@ -4026,6 +4030,8 @@ freePGconn(PGconn *conn) free(conn->target_session_attrs); termPQExpBuffer(&conn->errorMessage); termPQExpBuffer(&conn->workBuffer); + if (conn->sslpassword) + free(conn->sslpassword); free(conn); @@ -6544,6 +6550,14 @@ PQport(const PGconn *conn) return ""; } +char * +PQsslpassword(const PGconn *conn) +{ + if (!conn) + return NULL; + return conn->sslpassword; +} + char * PQtty(const PGconn *conn) { -- cgit v1.2.3