Repository navigation
Only change ssl_renegotiation setting if the connection is on SSL. - #453
franciscojunior wants to merge 2 commits into
Conversation
|
Maybe we should also poke the mono people to fix this bug about ssl renegotiation? |
|
Yes. I think so. Albe Laurenz told me in the past about this configuration setting added by the postgresql guys to handle problems with broken ssl libraries and client which couldn't handle ssl renegotiations and so we added this configuration to Npgsql. I talked about that here: http://fxjr.blogspot.com.br/2010/03/ssl-renegotiation-patch.html Another improvement to this PR which we can make is to only send this setting if we are in a secure connection AND running under mono. SSLStream on windows (ms.net) doesn't have this problem. When I was working with the sslstream, I made this test to confirm it. |
|
Nothing has happened since 2011 :/ |
|
Looks good to me, but one thought... I think we mentioned dropping mono.security entirely for v3.0. I'm not sure if there are postgresql SSL settings that aren't supported by the Microsoft .NET implementation, if not we can just kill it? |
|
Yes, we did. I think we can remove it with no problem. The issue is that when running under mono on osx and gnu/linux, |
|
Yes :-( After the existence of the postgresql setting , I decided to simply use it
|
|
Ahh, I understand. So it seem that what we need is to drop the dependency on Mono.Security, but include a runtime check whether we're on mono, and if so, send the ssl_renegotiation=0 setting... This way when running on Windows we do ssl_renegotiation. Does that sound like a good way to go? |
|
If running mono, we should probably use Mono's own SslClientStream and not Check out 2015-01-11 17:34 GMT+01:00 Shay Rojansky [email protected]:
|
Yes. That's the idea. +1 |
Hmmmm, my bet is that they changed everything to use the Begin/End idiom and used this to implement the sync operations. I think this was the way to go when the Begin/End idiom appeared. |
b892f8a to
0e71556
Compare
|
Probably, but it turned out to be a bad idea. HttpWebRequest, used 2015-01-11 20:20 GMT+01:00 Francisco Figueiredo Jr. <
|
Yes. I remember this discussion about threadpool and deadlocks. Well, I think removing the dependency on Mono.Security would be a good thing as it would be one less dependency we would need to carry. On the other side, your observation is totally valid and this mean a possible deadlock problem for people using ssl connections under mono. We could document about that and they would be aware of it. We could give a heads up to Mono guys talking to them about that. Another approach would be to use reflection to get SslClientStream instance and use it instead. We would document that and explain users how to use it if they find problems using sslstream. What do you think? |
Seems like a good idea. Just check if current environment is mono, and if it is, use SslClientStream. |
Whooops, that's true. :) I was still thinking about the situation where we would need to use it when running under ms.net :) |
I'll work on this and will push commits when done. |
|
When do we need to use it when running under ms.net? 2015-01-11 21:34 GMT+01:00 Francisco Figueiredo Jr. <
|
|
Nevermind. :-)
|
|
Just a question, is it possible to set this renegotiation setting as a 2015-01-11 21:44 GMT+01:00 Francisco Figueiredo Jr. <
|
That was the initial idea. We even have some parameters which are passed like that. Unfortunately, at the time we were using ssl_renegotiation, it isn't supported as startup parameter. |
|
I found another thing disappointing with Mono's ssl stream: http://forums.xamarin.com/discussion/9098/weak-ciphers-with-ssl-tls It does not provide any cipher suite with Perfect Forward Secrecy. That means if an attacker has recorded a communication and some time later happen to get a copy of the server's private key, he can decrypt the recorded communication. They also do not support TLS 1.1 or TLS 1.2; only TLS 1.0 which is 16 years old and have some security flaws... Maybe we should just drop Mono's ssl stream and find/use a better one? However, support for TLS 1.2 might be on its way: https://trello.com/c/PvUaV89u/16-tls-stack One problem with Microsoft's SslStream though is that it does not provide a "DataAvailable" property, which means we can't get (a)synchronous notifications to work reliably. |
|
I'm sorry I have too much going on to participate seriously on this important issue... One thought though: it would be good to get a clear list of exactly what the PostgreSQL backend supports - which cyphers etc. This way we can compare against what mono's SSL implementation provides and see exactly if/what is missing... |
|
It uses OpenSSL, so it supports almost everything. The problem is however that the client should support secure cipher suites, so even if it only supported the best and nothing else, that would be enough (maybe a "backup" that is also secure in case the first one gets cracked, then if the server is the first to be upgraded, there is no harm). |
|
One more thought about this... In a way, the fact that mono's SslStream implementation doesn't have the most secure ciphers it could isn't really our problem with Npgsql. I mean that users who are unhappy with the cipher being used to communicate with Npgsql should really address (or contribute to) mono itself, which implements SSL - we're just using a standard .NET class/service here. Of course, I understand this can be viewed another way - that we want to provide the best service for Npgsql users and if mono doesn't do so we should find a workaround - but I'm not sure in this case it's worth the trouble of an additional dependency, etc. After all, SSL is implemented, even if it isn't the best it could be... All this is regardless of the DataAvailable problem, which we indeed have to study/work around for async notifications if we keep SslStream... Mentioning this on #270 to remember. |
Before that Npgsql was sending the ssl renegotiation statement regardless if the connection was secured or not.
0e71556 to
42faed0
Compare
1236d1f to
e8ae2e0
Compare
2fc8944 to
3eb6fa4
Compare
|
In 3.0 ssl_renegotiation_limit is only sent when SSL is enabled. Note that the whole feature has been deprecated in PostgreSQL (and removed in version 9.5). |
|
Will this work even for redshift? |
|
Yeah, for Redshift you need to specify "Server Compatibility Mode=Redshift" in the connection string, this disables sending of |
|
But doesn't that mean renegotiation still occurs, and the callbacks must remain? |
|
Ah shit you're probably right :( I missed this... I'll try to find out what the exact status of Redshift's SSL renegotiation is. If we're very lucky maybe they don't do it or something... Otherwise I'll have to revert f021c11... |
|
@Emill, take a look at the gitter, I set up a test to checking SSL renegotiation but I can't get it to work |
|
@Emill, I wanted to play around with SSL renegotiation a little bit (for #453, Redshift) So I set up a branch with ssl_renegotiation_limit enabled and set to 1MB, along with a test that sends enough data to trigger it When I tried it locally (before switching to Redshift) it seems to bomb - with both your TlsClientStream and .NET SSLStream. I'm sure I'm doing something wrong, but can you please take a look? The branch is https://github.com/roji/npgsql/tree/ssl-renegotiation. (the idea is that maybe if we test this against Redshift, we find out that they've ripped out SSL renegotiation anyway) |
|
I've fixed a bug in TlsClientStream that occurred if "directBuf" was larger than 16 kb (which is the maximum allowed size of a TLS record). I also added async to TlsClientStream. I've tested your branch against PostgreSQL 9.4.1 with a Linux backend and it works well with TlsClientStream but times out during renegotiation with SslStream. What behaviour did you get? I also tested against a Windows build of PostgreSQL 9.3 which doesn't work that well. The test (both TlsClientStream and SslStream) works each other time and fails each other time. When you send large amounts of data the backend requests renegotiation, but since the frontend doesn't reply to that in a short amount of time (or because it keeps sending data without renegotiation), the backend terminates the connection. Of course this is hard to fix and would require another thread or something that reads data at the same time a send happens. I think the server behaviour depends both on PostgreSQL version and OpenSSL version. |
|
Ah, OK - I was testing on a Windows build of PostgreSQL 9.4.1. I will try to look at this again on Linux. My idea was to confirm that renegotiation actually happens on Redshift, by running this test on it. Who knows, maybe it simply doesn't happen and then we can just forget about it forever. If you have some time you can also test against Redshift. Even if Redshift require us to keep renegotiation, don't forget that we never need to support renegotiation for a Windows server (I assume it's not Windows). |
|
You can create an aws account and test redshift for free for two months I think. My free time is up however... |
|
Yeah, mine too but I'll create a new AWS account. Will let you know about the results. |
Before that Npgsql was sending the ssl renegotiation statement regardless if
the connection was secured or not.