Patch that checks ownership and permissions on server static
authorBruce Momjian
Fri, 14 Jun 2002 04:35:02 +0000 (04:35 +0000)
committerBruce Momjian
Fri, 14 Jun 2002 04:35:02 +0000 (04:35 +0000)
private key.  (You want it to be a regular file owned by the
database process, with 0400 or 0600 permissions.)

Bear Giles

src/backend/libpq/be-secure.c

index 51b7e85c4c136d8941d7eceab1e63d633f3e4ae2..4b2b3e852085740ce134e5487c8c39cc128c3898 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.3 2002/06/14 04:33:53 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.4 2002/06/14 04:35:02 momjian Exp $
  *
  *   Since the server static private key ($DataDir/server.key)
  *   will normally be stored unencrypted so that the database
@@ -59,7 +59,7 @@
  *   [ ] use 'random' file, read from '/dev/urandom?'
  *   [*] emphermal DH keys, default values
  *   [*] periodic renegotiation
- *   [ ] private key permissions
+ *   [*] private key permissions
  *
  *   milestone 4: provide endpoint authentication (client)
  *   [ ] server verifies client certificates
@@ -551,7 +551,20 @@ initialize_SSL (void)
                             fnbuf, SSLerrmessage());
            ExitPostmaster(1);
        }
+
        snprintf(fnbuf, sizeof(fnbuf), "%s/server.key", DataDir);
+       if (lstat(fnbuf, &buf) == -1)
+       {
+           postmaster_error("failed to stat private key file (%s): %s",
+                            fnbuf, strerror(errno));
+           ExitPostmaster(1);
+       }
+       if (!S_ISREG(buf.st_mode) || (buf.st_mode & 0077) ||
+           buf.st_uid != getuid())
+       {
+           postmaster_error("bad permissions on private key file (%s)", fnbuf);
+           ExitPostmaster(1);
+       }
        if (!SSL_CTX_use_PrivateKey_file(SSL_context, fnbuf, SSL_FILETYPE_PEM))
        {
            postmaster_error("failed to load private key file (%s): %s",