Re: SSL renegotiation and other related woes

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SSL renegotiation and other related woes
Date: 2015-02-11 12:54:03
Message-ID: 54DB50EB.6000902@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 02/05/2015 11:03 PM, Heikki Linnakangas wrote:
> On 01/26/2015 12:14 PM, Andres Freund wrote:
> Can we work-around that easily? I believe we can. The crucial part is
> that we mustn't let SSL_write() to process any incoming application
> data. We can achieve that if we always call SSL_read() to drain such
> data, before calling SSL_write(). But that's not quite enough; if we're
> in renegotiation, SSL_write() might still try to read more data from the
> socket that has arrived after the SSL_read() call. Fortunately, we can
> easily prevent that by hacking pqsecure_raw_read() to always return
> EWOULDBLOCK, when it's called through SSL_write().
>
> The attached patch does that. I've been running your pg_receivexlog test
> case with this for about 15 minutes without any errors now, with
> ssl_renegotiation_limit=50kB, while before it errored out within seconds.

Here is a simplified version of this patch. It seems to be enough to not
let SSL_write() to read any data from the socket. No need to call
SSL_read() first, and the server-side changes I made were only needed
because of the other patch I had applied.

Thoughts? Can you reproduce any errors with this?

> In theory, I guess we should do similar hacks in the server, and always
> call SSL_read() before SSL_write(), but it seems to work without it. Or
> maybe not; OpenSSL server and client code is not symmetric, so perhaps
> it works in server mode without that.

Not included in this patch, but I believe we apply a similar patch to
the server-side too.

- Heikki

Attachment Content-Type Size
0001-Fix-sslv3-alert-unexpected-message-errors-in-SSL-ren.patch application/x-patch 4.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2015-02-11 13:02:03 Re: reducing our reliance on MD5
Previous Message Robert Haas 2015-02-11 12:49:45 Re: reducing our reliance on MD5