Commit Graph

19 Commits

Author SHA1 Message Date
Augie Fackler
006064bcd2 sslutil: make keyfile and certfile arguments consistent between 2.6+ and 2.5- 2013-09-20 09:15:43 -04:00
Augie Fackler
cb1c036518 sslutil: add a config knob to support TLS (default) or SSLv23 (bc) (issue4038)
Prior to this change, we default to SSLv23, which is insecure because
it allows use of SSLv2. Unfortunately, there's no constant for OpenSSL
to let us use SSLv3 or TLS - we have to pick one or the other. We
expose a knob to revert to pre-TLS SSL for the user that has an
ancient server that lacks proper TLS support.
2013-09-19 16:29:00 -04:00
Augie Fackler
fd194f3d5b sslutil: backed out changeset 2cb59fd7ebb6 (issue4038)
Python docs are a little unclear, but mpm reports reading the OpenSSL
source code shows that PROTOCOL_SSLv23 allows TLS whereas
PROTOCOL_SSLv3 does not.
2013-09-18 14:40:17 -04:00
Augie Fackler
9ec0b367aa sslutil: force SSLv3 on Python 2.6 and later (issue3905)
We can't (easily) force SSL version on older Pythons, but on 2.6 and
later we can force SSLv3, which is safer and widely supported. This
also appears to work around a bug in IIS detailed in issue 3905.
2013-07-24 14:51:13 -04:00
FUJIWARA Katsunori
36bc77eef3 sslutil: abort if peer certificate is not verified for secure use
Before this patch, "sslutil.validator" may returns successfully, even
if peer certificate is not verified because there is no information in
"[hostfingerprints]" and "[web] cacerts".

To prevent from sending authentication credential to untrustable SMTP
server, validation should be aborted if peer certificate is not
verified.

This patch introduces "strict" optional argument, and
"sslutil.validator" will abort if it is True and peer certificate is
not verified.
2013-03-26 02:28:10 +09:00
Matt Mackall
71c760e42b sslutil: try harder to avoid getpeercert problems
We wrap both calls to getpeercert in a try/except to make sure we
catch its bogus AttributeError.
2013-04-05 12:20:14 -05:00
Steven Stallion
af163e9811 ui: optionally quiesce ssl verification warnings on python 2.5
Some platforms, notably Plan 9 from Bell Labs are stuck on older
releases of Python. Due to restrictions in the platform, it is not
possible to backport the SSL library to the existing Python port.
This patch permits the UI to quiesce SSL verification warnings by
adding a configuration entry named reportoldssl to ui.
2012-04-09 14:36:16 -07:00
Matt Mackall
5a379a202e sslutil: more helpful fingerprint mismatch message
This will aid debugging for users of sites that renew certs.
2012-01-26 11:23:15 -06:00
Mads Kiilerich
53bbcb8a33 sslutil: abort properly if no certificate received for https connection
According to the documentation SSLSocket.getpeercert() can return None.
2012-01-09 14:56:05 +01:00
Mads Kiilerich
f23e3d95df sslutil: work around validator crash getting certificate on failed sockets
The previous workaround for correct handling of wrapping of failing connections
might be enough to prevent this from happening, but the check here makes this
function more robust.
2012-01-09 14:43:25 +01:00
Mads Kiilerich
78235f35f1 sslutil: reorder validator code to make it more readable 2012-01-09 14:43:24 +01:00
Mads Kiilerich
142d372dec sslutil: show fingerprint when cacerts validation fails 2012-01-09 14:43:24 +01:00
Mads Kiilerich
a41a6f6696 sslutil: handle setups without .getpeercert() early in the validator
This simplifies the code and makes the flow more obvious and reduces the
indentation level.
2012-01-09 14:43:23 +01:00
Mads Kiilerich
122292828b sslutil: verify that wrap_socket really wrapped the socket
This works around that ssl.wrap_socket silently skips ssl negotiation on
sockets that was connected but since then has been reset by the peer but not
yet closed at the Python level. That leaves the socket in a state where
.getpeercert() fails with an AttributeError on None. See
http://bugs.python.org/issue13721 .

A call to .cipher() is now used to verify that the wrapping really did succeed.
Otherwise it aborts with "ssl connection failed".
2012-01-09 14:43:15 +01:00
Mads Kiilerich
077bd711d0 sslutil: abort when ssl module is needed but not found
It is apparently possible to compile Python without SSL support or leave it out
when installing precompiled binaries.

Mercurial on such Pythons would crash if the user tried to use https. Now it
will be reported as "abort: Python SSL support not found" instead.
2011-09-27 18:51:10 +02:00
Mads Kiilerich
70902bb721 sslutil: make messages for Python without certificate handling more helpful
We now explain why there is no certificate to verify and do not give hints
about cacerts when they can't be used anyway.
2011-06-18 01:08:54 +02:00
Nicolas Bareil
db42995f2e sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Any entries in subjectAltName would prevent fallback to using commonName, but
RFC 2818 says:

    If a subjectAltName extension of type dNSName is present, that MUST
    be used as the identity. Otherwise, the (most specific) Common Name
    field in the Subject field of the certificate MUST be used.

We now only consider dNSNames in subjectAltName.

(dNSName is known as 'DNS' in OpenSSL/Python.)
2011-06-18 01:03:03 +02:00
Stephen Thorne
8176bbbdf9 sslutil: Restore missing imports of socket and httplib to sslutil
Two imports were omitted in the restructure of the code creating
sslutil.py, socket and httplib are required when the 'ssl' module
cannot be imported, restoring these imports allows mercurial to run
on python2.4+2.5.
2011-06-14 13:31:32 +10:00
Augie Fackler
71eea02c91 sslutil: extracted ssl methods from httpsconnection in url.py
This makes it easier to share ssl cert validation with other http
implementations.
2011-05-04 22:08:55 -05:00