You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.5 KiB
60 lines
2.5 KiB
diff -urN M2Crypto/M2Crypto/httpslib.py M2Crypto-0.21.1/M2Crypto/httpslib.py |
|
--- M2Crypto/M2Crypto/httpslib.py 2011-01-15 20:10:05.000000000 +0100 |
|
+++ M2Crypto-0.21.1/M2Crypto/httpslib.py 2012-03-13 15:04:13.848836581 +0100 |
|
@@ -44,10 +44,33 @@ |
|
HTTPConnection.__init__(self, host, port, strict) |
|
|
|
def connect(self): |
|
- self.sock = SSL.Connection(self.ssl_ctx) |
|
- if self.session: |
|
- self.sock.set_session(self.session) |
|
- self.sock.connect((self.host, self.port)) |
|
+ error = None |
|
+ # We ignore the returned sockaddr because SSL.Connection.connect needs |
|
+ # a host name. |
|
+ for (family, _, _, _, _) in \ |
|
+ socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM): |
|
+ sock = None |
|
+ try: |
|
+ try: |
|
+ sock = SSL.Connection(self.ssl_ctx, family=family) |
|
+ if self.session is not None: |
|
+ sock.set_session(self.session) |
|
+ sock.connect((self.host, self.port)) |
|
+ |
|
+ self.sock = sock |
|
+ sock = None |
|
+ return |
|
+ except socket.error, e: |
|
+ # Other exception are probably SSL-related, in that case we |
|
+ # abort and the exception is forwarded to the caller. |
|
+ error = e |
|
+ finally: |
|
+ if sock is not None: |
|
+ sock.close() |
|
+ |
|
+ if error is None: |
|
+ raise AssertionError("Empty list returned by getaddrinfo") |
|
+ raise error |
|
|
|
def close(self): |
|
# This kludges around line 545 of httplib.py, |
|
diff -urN M2Crypto/M2Crypto/SSL/Connection.py M2Crypto-0.21.1/M2Crypto/SSL/Connection.py |
|
--- M2Crypto/M2Crypto/SSL/Connection.py 2012-03-13 15:00:25.058411492 +0100 |
|
+++ M2Crypto-0.21.1/M2Crypto/SSL/Connection.py 2012-03-13 15:04:13.849836578 +0100 |
|
@@ -38,13 +38,13 @@ |
|
m2_bio_free = m2.bio_free |
|
m2_ssl_free = m2.ssl_free |
|
|
|
- def __init__(self, ctx, sock=None): |
|
+ def __init__(self, ctx, sock=None, family=socket.AF_INET): |
|
self.ctx = ctx |
|
self.ssl = m2.ssl_new(self.ctx.ctx) |
|
if sock is not None: |
|
self.socket = sock |
|
else: |
|
- self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
+ self.socket = socket.socket(family, socket.SOCK_STREAM) |
|
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
self._fileno = self.socket.fileno() |
|
|
|
|