Skip to content

Commit 573bd08

Browse files
committed
Move EDH support to common files
The EDH support is not really specific to the OpenSSL implementation, so move the support and documentation comments to common files.
1 parent 7404e77 commit 573bd08

File tree

3 files changed

+42
-57
lines changed

3 files changed

+42
-57
lines changed

src/backend/libpq/README.SSL

+22
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ SSL
5858
Fail with unknown
5959

6060
---------------------------------------------------------------------------
61+
62+
Ephemeral DH
63+
============
64+
65+
Since the server static private key ($DataDir/server.key) will
66+
normally be stored unencrypted so that the database backend can
67+
restart automatically, it is important that we select an algorithm
68+
that continues to provide confidentiality even if the attacker has the
69+
server's private key. Ephemeral DH (EDH) keys provide this and more
70+
(Perfect Forward Secrecy aka PFS).
71+
72+
N.B., the static private key should still be protected to the largest
73+
extent possible, to minimize the risk of impersonations.
74+
75+
Another benefit of EDH is that it allows the backend and clients to
76+
use DSA keys. DSA keys can only provide digital signatures, not
77+
encryption, and are often acceptable in jurisdictions where RSA keys
78+
are unacceptable.
79+
80+
The downside to EDH is that it makes it impossible to use ssldump(1)
81+
if there's a problem establishing an SSL session. In this case you'll
82+
need to temporarily disable EDH (see initialize_dh()).

src/backend/libpq/be-secure-openssl.c

+1-57
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,6 @@
1111
* IDENTIFICATION
1212
* src/backend/libpq/be-secure-openssl.c
1313
*
14-
* Since the server static private key ($DataDir/server.key)
15-
* will normally be stored unencrypted so that the database
16-
* backend can restart automatically, it is important that
17-
* we select an algorithm that continues to provide confidentiality
18-
* even if the attacker has the server's private key. Ephemeral
19-
* DH (EDH) keys provide this and more (Perfect Forward Secrecy
20-
* aka PFS).
21-
*
22-
* N.B., the static private key should still be protected to
23-
* the largest extent possible, to minimize the risk of
24-
* impersonations.
25-
*
26-
* Another benefit of EDH is that it allows the backend and
27-
* clients to use DSA keys. DSA keys can only provide digital
28-
* signatures, not encryption, and are often acceptable in
29-
* jurisdictions where RSA keys are unacceptable.
30-
*
31-
* The downside to EDH is that it makes it impossible to
32-
* use ssldump(1) if there's a problem establishing an SSL
33-
* session. In this case you'll need to temporarily disable
34-
* EDH (see initialize_dh()).
35-
*
3614
*-------------------------------------------------------------------------
3715
*/
3816

@@ -87,40 +65,6 @@ static SSL_CTX *SSL_context = NULL;
8765
static bool SSL_initialized = false;
8866
static bool ssl_passwd_cb_called = false;
8967

90-
/* ------------------------------------------------------------ */
91-
/* Hardcoded values */
92-
/* ------------------------------------------------------------ */
93-
94-
/*
95-
* Hardcoded DH parameters, used in ephemeral DH keying.
96-
* As discussed above, EDH protects the confidentiality of
97-
* sessions even if the static private key is compromised,
98-
* so we are *highly* motivated to ensure that we can use
99-
* EDH even if the DBA has not provided custom DH parameters.
100-
*
101-
* We could refuse SSL connections unless a good DH parameter
102-
* file exists, but some clients may quietly renegotiate an
103-
* unsecured connection without fully informing the user.
104-
* Very uncool. Alternatively, the system could refuse to start
105-
* if a DH parameters is not specified, but this would tend to
106-
* piss off DBAs.
107-
*
108-
* If you want to create your own hardcoded DH parameters
109-
* for fun and profit, review "Assigned Number for SKIP
110-
* Protocols" (http://www.skip-vpn.org/spec/numbers.html)
111-
* for suggestions.
112-
*/
113-
114-
static const char file_dh2048[] =
115-
"-----BEGIN DH PARAMETERS-----\n\
116-
MIIBCAKCAQEA9kJXtwh/CBdyorrWqULzBej5UxE5T7bxbrlLOCDaAadWoxTpj0BV\n\
117-
89AHxstDqZSt90xkhkn4DIO9ZekX1KHTUPj1WV/cdlJPPT2N286Z4VeSWc39uK50\n\
118-
T8X8dryDxUcwYc58yWb/Ffm7/ZFexwGq01uejaClcjrUGvC/RgBYK+X0iP1YTknb\n\
119-
zSC0neSRBzZrM2w4DUUdD3yIsxx8Wy2O9vPJI8BD8KVbGI2Ou1WMuF040zT9fBdX\n\
120-
Q6MdGGzeMyEstSr/POGxKUAYEY18hKcKctaGxAMZyAcpesqVDNmWn6vQClCbAkbT\n\
121-
CD1mpF1Bn5x8vYlLIhkmuquiXsNV6TILOwIBAg==\n\
122-
-----END DH PARAMETERS-----\n";
123-
12468

12569
/* ------------------------------------------------------------ */
12670
/* Public interface */
@@ -1080,7 +1024,7 @@ initialize_dh(SSL_CTX *context, bool isServerStart)
10801024
if (ssl_dh_params_file[0])
10811025
dh = load_dh_file(ssl_dh_params_file, isServerStart);
10821026
if (!dh)
1083-
dh = load_dh_buffer(file_dh2048, sizeof file_dh2048);
1027+
dh = load_dh_buffer(FILE_DH2048, sizeof(FILE_DH2048));
10841028
if (!dh)
10851029
{
10861030
ereport(isServerStart ? FATAL : LOG,

src/include/libpq/libpq-be.h

+19
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,25 @@ typedef struct Port
193193
} Port;
194194

195195
#ifdef USE_SSL
196+
/*
197+
* Hardcoded DH parameters, used in ephemeral DH keying. (See also
198+
* README.SSL for more details on EDH.)
199+
*
200+
* If you want to create your own hardcoded DH parameters
201+
* for fun and profit, review "Assigned Number for SKIP
202+
* Protocols" (http://www.skip-vpn.org/spec/numbers.html)
203+
* for suggestions.
204+
*/
205+
#define FILE_DH2048 \
206+
"-----BEGIN DH PARAMETERS-----\n\
207+
MIIBCAKCAQEA9kJXtwh/CBdyorrWqULzBej5UxE5T7bxbrlLOCDaAadWoxTpj0BV\n\
208+
89AHxstDqZSt90xkhkn4DIO9ZekX1KHTUPj1WV/cdlJPPT2N286Z4VeSWc39uK50\n\
209+
T8X8dryDxUcwYc58yWb/Ffm7/ZFexwGq01uejaClcjrUGvC/RgBYK+X0iP1YTknb\n\
210+
zSC0neSRBzZrM2w4DUUdD3yIsxx8Wy2O9vPJI8BD8KVbGI2Ou1WMuF040zT9fBdX\n\
211+
Q6MdGGzeMyEstSr/POGxKUAYEY18hKcKctaGxAMZyAcpesqVDNmWn6vQClCbAkbT\n\
212+
CD1mpF1Bn5x8vYlLIhkmuquiXsNV6TILOwIBAg==\n\
213+
-----END DH PARAMETERS-----\n"
214+
196215
/*
197216
* These functions are implemented by the glue code specific to each
198217
* SSL implementation (e.g. be-secure-openssl.c)

0 commit comments

Comments
 (0)