Skip to content

Commit c770686

Browse files
committed
Apply 0002-Replace-PostmasterRandom-with-a-stronger-way-of-gene.patch
1 parent f858ca3 commit c770686

File tree

11 files changed

+249
-392
lines changed

11 files changed

+249
-392
lines changed

contrib/pgcrypto/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# contrib/pgcrypto/Makefile
22

33
INT_SRCS = md5.c sha1.c sha2.c internal.c internal-sha2.c blf.c rijndael.c \
4-
fortuna.c random.c pgp-mpi-internal.c imath.c
4+
fortuna.c pgp-mpi-internal.c imath.c
55
INT_TESTS = sha2
66

77
OSSL_SRCS = openssl.c pgp-mpi-openssl.c sha2_openssl.c

contrib/pgcrypto/internal.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,6 @@ static time_t check_time = 0;
626626
static void
627627
system_reseed(void)
628628
{
629-
uint8 buf[1024];
630-
int n;
631629
time_t t;
632630
int skip = 1;
633631

@@ -642,24 +640,34 @@ system_reseed(void)
642640
else if (check_time == 0 ||
643641
(t - check_time) > SYSTEM_RESEED_CHECK_TIME)
644642
{
643+
uint8 buf;
644+
645645
check_time = t;
646646

647647
/* roll dice */
648-
px_get_random_bytes(buf, 1);
649-
skip = buf[0] >= SYSTEM_RESEED_CHANCE;
650-
}
651-
/* clear 1 byte */
652-
px_memset(buf, 0, sizeof(buf));
653-
654-
if (skip)
655-
return;
656-
657-
n = px_acquire_system_randomness(buf);
658-
if (n > 0)
659-
fortuna_add_entropy(buf, n);
648+
px_get_random_bytes(&buf, 1);
649+
skip = (buf >= SYSTEM_RESEED_CHANCE);
660650

661-
seed_time = t;
662-
px_memset(buf, 0, sizeof(buf));
651+
/* clear 1 byte */
652+
px_memset(&buf, 0, sizeof(buf));
653+
}
654+
if (!skip)
655+
{
656+
/*
657+
* fortuna_add_entropy passes the input to SHA-256, so there's no
658+
* point in giving it more than 256 bits of input to begin with.
659+
*/
660+
uint8 buf[32];
661+
662+
if (!pg_strong_random(buf, sizeof(buf)))
663+
ereport(ERROR,
664+
(errcode(ERRCODE_INTERNAL_ERROR),
665+
errmsg("could not acquire random data")));
666+
fortuna_add_entropy(buf, sizeof(buf));
667+
668+
seed_time = t;
669+
px_memset(buf, 0, sizeof(buf));
670+
}
663671
}
664672

665673
int

contrib/pgcrypto/random.c

Lines changed: 0 additions & 247 deletions
This file was deleted.

src/backend/libpq/auth.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ static void auth_failed(Port *port, int status, char *logdetail);
4444
static char *recv_password_packet(Port *port);
4545
static int recv_and_check_password_packet(Port *port, char **logdetail);
4646

47+
/*----------------------------------------------------------------
48+
* MD5 authentication
49+
*----------------------------------------------------------------
50+
*/
51+
static int CheckMD5Auth(Port *port, char **logdetail);
52+
4753

4854
/*----------------------------------------------------------------
4955
* Ident authentication
@@ -534,8 +540,7 @@ ClientAuthentication(Port *port)
534540
ereport(FATAL,
535541
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
536542
errmsg("MD5 authentication is not supported when \"db_user_namespace\" is enabled")));
537-
sendAuthRequest(port, AUTH_REQ_MD5);
538-
status = recv_and_check_password_packet(port, &logdetail);
543+
status = CheckMD5Auth(port, &logdetail);
539544
break;
540545

541546
case uaPassword:
@@ -710,10 +715,25 @@ recv_password_packet(Port *port)
710715

711716

712717
/*----------------------------------------------------------------
713-
* MD5 authentication
718+
* MD5 and password authentication
714719
*----------------------------------------------------------------
715720
*/
716721

722+
static int
723+
CheckMD5Auth(Port *port, char **logdetail)
724+
{
725+
/* include the salt to use for computing the response */
726+
if (!pg_strong_random(port->md5Salt, sizeof(port->md5Salt)))
727+
{
728+
*logdetail = psprintf(_("Could not generate random salt"));
729+
return STATUS_ERROR;
730+
}
731+
732+
sendAuthRequest(port, AUTH_REQ_MD5);
733+
return recv_and_check_password_packet(port, logdetail);
734+
}
735+
736+
717737
/*
718738
* Called when we have sent an authorization request for a password.
719739
* Get the response and check it.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy