[CalendarServer-changes] [5499] CalDAVClientLibrary/trunk/src/client

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 20 17:19:43 PDT 2010


Revision: 5499
          http://trac.macosforge.org/projects/calendarserver/changeset/5499
Author:   cdaboo at apple.com
Date:     2010-04-20 17:19:42 -0700 (Tue, 20 Apr 2010)
Log Message:
-----------
Better handling of SSLv23 vs SSLv3 (does auto-detect).

Modified Paths:
--------------
    CalDAVClientLibrary/trunk/src/client/clientsession.py
    CalDAVClientLibrary/trunk/src/client/simple.py

Added Paths:
-----------
    CalDAVClientLibrary/trunk/src/client/httpshandler.py

Modified: CalDAVClientLibrary/trunk/src/client/clientsession.py
===================================================================
--- CalDAVClientLibrary/trunk/src/client/clientsession.py	2010-04-21 00:19:11 UTC (rev 5498)
+++ CalDAVClientLibrary/trunk/src/client/clientsession.py	2010-04-21 00:19:42 UTC (rev 5499)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2009 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,6 +14,7 @@
 # limitations under the License.
 ##
 
+from client.httpshandler import SmartHTTPConnection
 from protocol.caldav.definitions import headers
 from protocol.caldav.makecalendar import MakeCalendar
 from protocol.http.authentication.basic import Basic
@@ -40,7 +41,6 @@
 from protocol.webdav.put import Put
 from protocol.webdav.session import Session
 from xml.etree.ElementTree import Element
-import httplib
 import types
 
 class CalDAVSession(Session):
@@ -532,11 +532,7 @@
 
     def openSession(self):
         # Create connection
-        if self.ssl:
-            self.connect = httplib.HTTPSConnection(self.server, self.port)
-        else:
-            self.connect = httplib.HTTPConnection(self.server, self.port)
-        self.connect.connect()
+        self.connect = SmartHTTPConnection(self.server, self.port, self.ssl)
         
         # Write to log file
         if self.loghttp and self.log:

Added: CalDAVClientLibrary/trunk/src/client/httpshandler.py
===================================================================
--- CalDAVClientLibrary/trunk/src/client/httpshandler.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/src/client/httpshandler.py	2010-04-21 00:19:42 UTC (rev 5499)
@@ -0,0 +1,69 @@
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import httplib
+import socket
+import ssl as sslmodule
+
+class HTTPSConnection_SSLv3(httplib.HTTPSConnection):
+    "This class allows communication via SSL."
+
+    def connect(self):
+        "Connect to a host on a given (SSL) port."
+
+        sock = socket.create_connection((self.host, self.port), self.timeout)
+        self.sock = sslmodule.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=sslmodule.PROTOCOL_SSLv3)
+
+https_v23_connects = set()
+https_v3_connects = set()
+
+def SmartHTTPConnection(host, port, ssl):
+    
+    def trySSL(cls, ):
+        connect = cls(host, port)
+        connect.connect()
+        return connect
+        
+    if ssl:
+        if (host, port) in https_v3_connects:
+            try:
+                return trySSL(HTTPSConnection_SSLv3)
+            except:
+                https_v3_connects.remove((host, port))
+        elif (host, port) in https_v23_connects:
+            try:
+                return trySSL(httplib.HTTPSConnection)
+            except:
+                https_v23_connects.remove((host, port))
+        
+        try:
+            https_v3_connects.add((host, port))
+            return trySSL(HTTPSConnection_SSLv3)
+        except:
+            https_v3_connects.remove((host, port))
+            
+        try:
+            https_v23_connects.add((host, port))
+            return trySSL(httplib.HTTPSConnection)
+        except:
+            https_v23_connects.remove((host, port))
+        
+        raise RuntimeError("Cannot connect via with SSLv23 or SSLv3")
+    else:
+        connect = httplib.HTTPConnection(host, port)
+        connect.connect()
+        return connect
+

Modified: CalDAVClientLibrary/trunk/src/client/simple.py
===================================================================
--- CalDAVClientLibrary/trunk/src/client/simple.py	2010-04-21 00:19:11 UTC (rev 5498)
+++ CalDAVClientLibrary/trunk/src/client/simple.py	2010-04-21 00:19:42 UTC (rev 5499)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2007 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2010 Apple Inc. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -14,17 +14,14 @@
 # limitations under the License.
 ##
 
+from client.httpshandler import SmartHTTPConnection
 from protocol.webdav.session import Session
 from protocol.webdav.options import Options
-import httplib
 
 def run(session, request):
     
     # Create connection
-    if session.ssl:
-        connect = httplib.HTTPSConnection(session.server, session.port)
-    else:
-        connect = httplib.HTTPConnection(session.server, session.port)
+    connect = SmartHTTPConnection(session.server, session.port, session.ssl)
     connect.set_debuglevel(1)
 
     # Do headers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100420/52ee9df3/attachment-0001.html>


More information about the calendarserver-changes mailing list