On 12/13/18 08:07, Andreas Karlsson wrote: > But I will attach my small patch for this, which I am now opposed to, anyway > so the code exists if a use case turns up in the future (or if it turns out > my reasoning above is incorrect).
Here's the same patch with one small copy-pasto fixed. -Chap
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index d2e5b08541e..528757f775d 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -1460,6 +1460,23 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname </listitem> </varlistentry> + <varlistentry id="libpq-connect-sslsni" xreflabel="sslsni"> + <term><literal>sslsni</literal></term> + <listitem> + <para> + If set to 1, the host name is sent to the server using SSL's + <acronym>SNI</acronym> (Server Name Indication) extension. If set + to 0, no <acronym>SNI</acronym> extension will be sent. The default is + 0. This parameter is ignored if a connection without SSL is made. + </para> + + <para> + The PostgreSQL server ignores the <acronym>SNI</acronym> extension, + but it can be used by SSL-aware proxy software. + </para> + </listitem> + </varlistentry> + <varlistentry id="libpq-connect-sslcert" xreflabel="sslcert"> <term><literal>sslcert</literal></term> <listitem> @@ -7373,6 +7390,16 @@ myEventProc(PGEventId evtId, void *evtInfo, void *passThrough) </para> </listitem> + <listitem> + <para> + <indexterm> + <primary><envar>PGSSLSNI</envar></primary> + </indexterm> + <envar>PGSSLSNI</envar> behaves the same as the <xref + linkend="libpq-connect-sslsni"/> connection parameter. + </para> + </listitem> + <listitem> <para> <indexterm> diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index bc456fec0c2..4587e5ebb5a 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -278,6 +278,10 @@ static const internalPQconninfoOption PQconninfoOptions[] = { "SSL-Compression", "", 1, offsetof(struct pg_conn, sslcompression)}, + {"sslsni", "PGSSLSNI", "0", NULL, + "SSL-SNI", "", 1, + offsetof(struct pg_conn, sslsni)}, + {"sslcert", "PGSSLCERT", NULL, NULL, "SSL-Client-Cert", "", 64, offsetof(struct pg_conn, sslcert)}, @@ -3690,6 +3694,8 @@ freePGconn(PGconn *conn) free(conn->sslcrl); if (conn->sslcompression) free(conn->sslcompression); + if (conn->sslsni) + free(conn->sslsni); if (conn->requirepeer) free(conn->requirepeer); if (conn->connip) diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index beca3492e8d..fdae2eac74f 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -781,6 +781,7 @@ initialize_SSL(PGconn *conn) char homedir[MAXPGPATH]; char fnbuf[MAXPGPATH]; char sebuf[PG_STRERROR_R_BUFLEN]; + char *host; bool have_homedir; bool have_cert; bool have_rootcert; @@ -1183,6 +1184,11 @@ initialize_SSL(PGconn *conn) #endif #endif + host = conn->connhost[conn->whichhost].host; + + if (conn->sslsni && conn->sslsni[0] == '1' && host) + SSL_set_tlsext_host_name(conn->ssl, host); + return 0; } diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index 66fd317b949..9f69fbdf5fc 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -353,6 +353,7 @@ struct pg_conn * retransmits */ char *sslmode; /* SSL mode (require,prefer,allow,disable) */ char *sslcompression; /* SSL compression (0 or 1) */ + char *sslsni; /* SSL SNI extension (0 or 1) */ char *sslkey; /* client key filename */ char *sslcert; /* client certificate filename */ char *sslrootcert; /* root certificate filename */