postgresql/src/backend/libpq
Tom Lane 7eaf654514 Don't assume GSSAPI result strings are null-terminated.
Our uses of gss_display_status() and gss_display_name() assumed
that the gss_buffer_desc strings returned by those functions are
null-terminated.  It appears that they generally are, given the
lack of field complaints up to now.  However, the available
documentation does not promise this, and some man pages
for gss_display_status() show examples that rely on the
gss_buffer_desc.length field instead of expecting null
termination.  Also, we now have a report that on some
implementations, clang's address sanitizer is of the opinion
that the byte after the specified length is undefined.

Hence, change the code to rely on the length field instead.

This might well be cosmetic rather than fixing any real bug, but
it's hard to be sure, so back-patch to all supported branches.
While here, also back-patch the v12 changes that made pg_GSS_error
deal honestly with multiple messages available from
gss_display_status.

Per report from Sudheer H R.

Discussion: https://postgr.es/m/5372B6D4-8276-42C0-B8FB-BD0918826FC3@tekenlight.com
2021-06-23 14:01:32 -04:00
..
auth-scram.c Fix buffer overflow when parsing SCRAM verifiers in backend 2019-06-17 21:48:17 +09:00
auth.c Don't assume GSSAPI result strings are null-terminated. 2021-06-23 14:01:32 -04:00
be-fsstubs.c Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
be-gssapi-common.c Don't assume GSSAPI result strings are null-terminated. 2021-06-23 14:01:32 -04:00
be-secure-common.c Fix failures to ignore \r when reading Windows-style newlines. 2019-07-25 12:11:18 -04:00
be-secure-gssapi.c Fix up usage of krb_server_keyfile GUC parameter. 2020-12-30 11:38:42 -05:00
be-secure-openssl.c Disallow SSL renegotiation 2021-05-25 10:11:17 +09:00
be-secure.c Fix assorted issues in backend's GSSAPI encryption support. 2020-12-28 17:44:17 -05:00
crypt.c Fix detection of passwords hashed with MD5 or SCRAM-SHA-256 2019-04-23 15:43:21 +09:00
hba.c Fix assorted issues in backend's GSSAPI encryption support. 2020-12-28 17:44:17 -05:00
ifaddr.c Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
Makefile GSSAPI encryption support 2019-04-03 15:02:33 -04:00
pg_hba.conf.sample gss: add missing references to hostgssenc and hostnogssenc 2020-05-25 20:19:28 -04:00
pg_ident.conf.sample Reformat the comments in pg_hba.conf and pg_ident.conf 2010-01-26 06:58:39 +00:00
pqcomm.c Fix assorted issues in backend's GSSAPI encryption support. 2020-12-28 17:44:17 -05:00
pqformat.c Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
pqmq.c Update copyright for 2019 2019-01-02 12:44:25 -05:00
pqsignal.c In the postmaster, rely on the signal infrastructure to block signals. 2020-10-15 12:50:57 -04:00
README.SSL Move EDH support to common files 2018-01-23 07:11:38 -05:00

src/backend/libpq/README.SSL

SSL
===

>From the servers perspective:


  Receives StartupPacket
           |
           |
 (Is SSL_NEGOTIATE_CODE?) -----------  Normal startup
           |                  No
           |
           | Yes
           |
           |
 (Server compiled with USE_SSL?) ------- Send 'N'
           |                       No        |
           |                                 |
           | Yes                         Normal startup
           |
           |
        Send 'S'
           |
           |
      Establish SSL
           |
           |
      Normal startup





>From the clients perspective (v6.6 client _with_ SSL):


      Connect
         |
         |
  Send packet with SSL_NEGOTIATE_CODE
         |
         |
  Receive single char  ------- 'S' -------- Establish SSL
         |                                       |
         | '<else>'                              |
         |                                  Normal startup
         |
         |
   Is it 'E' for error  ------------------- Retry connection
         |                  Yes             without SSL
         | No
         |
   Is it 'N' for normal ------------------- Normal startup
         |                  Yes
         |
   Fail with unknown

---------------------------------------------------------------------------

Ephemeral DH
============

Since the server static private key ($DataDir/server.key) will
normally be stored unencrypted so that the database backend can
restart automatically, it is important that we select an algorithm
that continues to provide confidentiality even if the attacker has the
server's private key.  Ephemeral DH (EDH) keys provide this and more
(Perfect Forward Secrecy aka PFS).

N.B., the static private key should still be protected to the largest
extent possible, to minimize the risk of impersonations.

Another benefit of EDH is that it allows the backend and clients to
use DSA keys.  DSA keys can only provide digital signatures, not
encryption, and are often acceptable in jurisdictions where RSA keys
are unacceptable.

The downside to EDH is that it makes it impossible to use ssldump(1)
if there's a problem establishing an SSL session.  In this case you'll
need to temporarily disable EDH (see initialize_dh()).