|
11 | 11 | *
|
12 | 12 | *
|
13 | 13 | * IDENTIFICATION
|
14 |
| - * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.2 2002/06/14 04:31:49 momjian Exp $ |
| 14 | + * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.3 2002/06/14 04:33:53 momjian Exp $ |
15 | 15 | *
|
16 | 16 | * Since the server static private key ($DataDir/server.key)
|
17 | 17 | * will normally be stored unencrypted so that the database
|
|
39 | 39 | * session. In this case you'll need to temporarily disable
|
40 | 40 | * EDH by commenting out the callback.
|
41 | 41 | *
|
| 42 | + * ... |
| 43 | + * |
| 44 | + * Because the risk of cryptanalysis increases as large |
| 45 | + * amounts of data are sent with the same session key, the |
| 46 | + * session keys are periodically renegotiated. |
| 47 | + * |
42 | 48 | * PATCH LEVEL
|
43 | 49 | * milestone 1: fix basic coding errors
|
44 | 50 | * [*] existing SSL code pulled out of existing files.
|
|
52 | 58 | * milestone 3: improve confidentially, support perfect forward secrecy
|
53 | 59 | * [ ] use 'random' file, read from '/dev/urandom?'
|
54 | 60 | * [*] emphermal DH keys, default values
|
55 |
| - * [ ] periodic renegotiation |
| 61 | + * [*] periodic renegotiation |
56 | 62 | * [ ] private key permissions
|
57 | 63 | *
|
58 | 64 | * milestone 4: provide endpoint authentication (client)
|
@@ -126,6 +132,12 @@ static const char *SSLerrmessage(void);
|
126 | 132 | #endif
|
127 | 133 |
|
128 | 134 | #ifdef USE_SSL
|
| 135 | +/* |
| 136 | + * How much data can be sent across a secure connection |
| 137 | + * (total in both directions) before we require renegotiation. |
| 138 | + */ |
| 139 | +#define RENEGOTIATION_LIMIT (64 * 1024) |
| 140 | + |
129 | 141 | static SSL_CTX *SSL_context = NULL;
|
130 | 142 | #endif
|
131 | 143 |
|
@@ -261,10 +273,17 @@ secure_read (Port *port, void *ptr, size_t len)
|
261 | 273 | #ifdef USE_SSL
|
262 | 274 | if (port->ssl)
|
263 | 275 | {
|
| 276 | + if (port->count > RENEGOTIATION_LIMIT) |
| 277 | + { |
| 278 | + SSL_renegotiate(port->ssl); |
| 279 | + port->count = 0; |
| 280 | + } |
| 281 | + |
264 | 282 | n = SSL_read(port->ssl, ptr, len);
|
265 | 283 | switch (SSL_get_error(port->ssl, n))
|
266 | 284 | {
|
267 | 285 | case SSL_ERROR_NONE:
|
| 286 | + port->count += n; |
268 | 287 | break;
|
269 | 288 | case SSL_ERROR_WANT_READ:
|
270 | 289 | break;
|
@@ -304,10 +323,17 @@ secure_write (Port *port, const void *ptr, size_t len)
|
304 | 323 | #ifdef USE_SSL
|
305 | 324 | if (port->ssl)
|
306 | 325 | {
|
| 326 | + if (port->count > RENEGOTIATION_LIMIT) |
| 327 | + { |
| 328 | + SSL_renegotiate(port->ssl); |
| 329 | + port->count = 0; |
| 330 | + } |
| 331 | + |
307 | 332 | n = SSL_write(port->ssl, ptr, len);
|
308 | 333 | switch (SSL_get_error(port->ssl, n))
|
309 | 334 | {
|
310 | 335 | case SSL_ERROR_NONE:
|
| 336 | + port->count += n; |
311 | 337 | break;
|
312 | 338 | case SSL_ERROR_WANT_WRITE:
|
313 | 339 | break;
|
@@ -574,6 +600,7 @@ open_server_SSL (Port *port)
|
574 | 600 | close_SSL(port);
|
575 | 601 | return -1;
|
576 | 602 | }
|
| 603 | + port->count = 0; |
577 | 604 |
|
578 | 605 | return 0;
|
579 | 606 | }
|
|
0 commit comments