aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2009-12-09 06:37:13 +0000
committerMagnus Hagander <magnus@hagander.net>2009-12-09 06:37:13 +0000
commite27495f3c9ac38b28a004177174039f0621980bf (patch)
treec7f8d53549c25f683b64a3ab286f80a6bc31023c
parent17d1e65972c25608eda7e9c801cfaf2e0b4ceb21 (diff)
downloadpostgresql-e27495f3c9ac38b28a004177174039f0621980bf.tar.gz
postgresql-e27495f3c9ac38b28a004177174039f0621980bf.zip
Reject certificates with embedded NULLs in the commonName field. This stops
attacks where an attacker would put <attack>\0<propername> in the field and trick the validation code that the certificate was for <attack>. This is a very low risk attack since it reuqires the attacker to trick the CA into issuing a certificate with an incorrect field, and the common PostgreSQL deployments are with private CAs, and not external ones. Also, default mode in 8.4 does not do any name validation, and is thus also not vulnerable - but the higher security modes are. Backpatch all the way. Even though versions 8.3.x and before didn't have certificate name validation support, they still exposed this field for the user to perform the validation in the application code, and there is no way to detect this problem through that API. Security: CVE-2009-4034
-rw-r--r--src/backend/libpq/be-secure.c24
-rw-r--r--src/interfaces/libpq/fe-secure.c25
2 files changed, 44 insertions, 5 deletions
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index 541ab91f39a..851163b8866 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.56.4.4 2009/01/28 15:06:50 mha Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.56.4.5 2009/12/09 06:37:13 mha Exp $
*
* Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database
@@ -894,9 +894,29 @@ aloop:
X509_NAME_oneline(X509_get_subject_name(port->peer),
port->peer_dn, sizeof(port->peer_dn));
port->peer_dn[sizeof(port->peer_dn) - 1] = '\0';
- X509_NAME_get_text_by_NID(X509_get_subject_name(port->peer),
+ r = X509_NAME_get_text_by_NID(X509_get_subject_name(port->peer),
NID_commonName, port->peer_cn, sizeof(port->peer_cn));
port->peer_cn[sizeof(port->peer_cn) - 1] = '\0';
+ if (r == -1)
+ {
+ /* Unable to get the CN, set it to blank so it can't be used */
+ port->peer_cn[0] = '\0';
+ }
+ else
+ {
+ /*
+ * Reject embedded NULLs in certificate common name to prevent attacks like
+ * CVE-2009-4034.
+ */
+ if (r != strlen(port->peer_cn))
+ {
+ ereport(COMMERROR,
+ (errcode(ERRCODE_PROTOCOL_VIOLATION),
+ errmsg("SSL certificate's common name contains embedded null")));
+ close_SSL(port);
+ return -1;
+ }
+ }
}
ereport(DEBUG2,
(errmsg("SSL connection from \"%s\"", port->peer_cn)));
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 0ca7de14c98..a463bca0d9a 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.67.4.1 2009/01/28 15:06:51 mha Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-secure.c,v 1.67.4.2 2009/12/09 06:37:13 mha Exp $
*
* NOTES
* [ Most of these notes are wrong/obsolete, but perhaps not all ]
@@ -1121,9 +1121,28 @@ open_client_SSL(PGconn *conn)
conn->peer_dn, sizeof(conn->peer_dn));
conn->peer_dn[sizeof(conn->peer_dn) - 1] = '\0';
- X509_NAME_get_text_by_NID(X509_get_subject_name(conn->peer),
+ r = X509_NAME_get_text_by_NID(X509_get_subject_name(conn->peer),
NID_commonName, conn->peer_cn, SM_USER);
- conn->peer_cn[SM_USER] = '\0';
+ conn->peer_cn[SM_USER] = '\0'; /* buffer is SM_USER+1 chars! */
+ if (r == -1)
+ {
+ /* Unable to get the CN, set it to blank so it can't be used */
+ conn->peer_cn[0] = '\0';
+ }
+ else
+ {
+ /*
+ * Reject embedded NULLs in certificate common name to prevent attacks like
+ * CVE-2009-4034.
+ */
+ if (r != strlen(conn->peer_cn))
+ {
+ printfPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("SSL certificate's common name contains embedded null\n"));
+ close_SSL(conn);
+ return PGRES_POLLING_FAILED;
+ }
+ }
/* verify that the common name resolves to peer */