[CalendarServer-changes] [5575] CalDAVTester/trunk/src

source_changes at macosforge.org source_changes at macosforge.org
Fri May 7 12:30:34 PDT 2010


Revision: 5575
          http://trac.macosforge.org/projects/calendarserver/changeset/5575
Author:   cdaboo at apple.com
Date:     2010-05-07 12:30:30 -0700 (Fri, 07 May 2010)
Log Message:
-----------
Handle ssl version smartly.

Modified Paths:
--------------
    CalDAVTester/trunk/src/caldavtest.py

Added Paths:
-----------
    CalDAVTester/trunk/src/httpshandler.py

Modified: CalDAVTester/trunk/src/caldavtest.py
===================================================================
--- CalDAVTester/trunk/src/caldavtest.py	2010-05-07 16:36:05 UTC (rev 5574)
+++ CalDAVTester/trunk/src/caldavtest.py	2010-05-07 19:30:30 UTC (rev 5575)
@@ -19,6 +19,7 @@
 """
 
 from cStringIO import StringIO
+from src.httpshandler import SmartHTTPConnection
 from src.manager import manager
 from src.request import data
 from src.request import request
@@ -29,7 +30,6 @@
 from xml.dom.minidom import Element
 from xml.dom.minidom import Node
 from xml.etree.ElementTree import ElementTree
-import httplib
 import rfc822
 import socket
 import src.xmlDefs
@@ -467,10 +467,7 @@
             stats.startTimer()
 
         # Do the http request
-        if self.manager.server_info.ssl:
-            http = httplib.HTTPSConnection( self.manager.server_info.host, self.manager.server_info.port )
-        else:
-            http = httplib.HTTPConnection( self.manager.server_info.host, self.manager.server_info.port )
+        http = SmartHTTPConnection( self.manager.server_info.host, self.manager.server_info.port, self.manager.server_info.ssl )
         try:
             #self.manager.log(manager.LOG_LOW, "Sending request")
             http.request( method, uri, data, headers )

Added: CalDAVTester/trunk/src/httpshandler.py
===================================================================
--- CalDAVTester/trunk/src/httpshandler.py	                        (rev 0)
+++ CalDAVTester/trunk/src/httpshandler.py	2010-05-07 19:30:30 UTC (rev 5575)
@@ -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
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100507/b7b23704/attachment-0001.html>


More information about the calendarserver-changes mailing list