---
koji/ssl/SSLCommon.py | 58 --------------
koji/ssl/XMLRPCServerProxy.py | 177 ------------------------------------------
2 files changed, 235 deletions(-)
delete mode 100644 koji/ssl/XMLRPCServerProxy.py
diff --git a/koji/ssl/SSLCommon.py b/koji/ssl/SSLCommon.py
index 5a9a5e4..56efc05 100644
--- a/koji/ssl/SSLCommon.py
+++ b/koji/ssl/SSLCommon.py
@@ -47,46 +47,6 @@ def CreateSSLContext(certs):
return ctx
-
-class PlgBaseServer(SocketServer.ThreadingTCPServer):
- allow_reuse_address = 1
-
- def __init__(self, server_addr, req_handler):
- self._quit = False
- self.allow_reuse_address = 1
- SocketServer.ThreadingTCPServer.__init__(self, server_addr, req_handler)
-
- def stop(self):
- self._quit = True
-
- def serve_forever(self):
- while not self._quit:
- self.handle_request()
- self.server_close()
-
-
-class PlgBaseSSLServer(PlgBaseServer):
- """ SSL-enabled variant """
-
- def __init__(self, server_address, req_handler, certs, timeout=None):
- self._timeout = timeout
- self.ssl_ctx = CreateSSLContext(certs)
-
- PlgBaseServer.__init__(self, server_address, req_handler)
-
- sock = socket.socket(self.address_family, self.socket_type)
- con = SSL.Connection(self.ssl_ctx, sock)
- self.socket = SSLConnection.SSLConnection(con)
- if sys.version_info[:3] >= (2, 3, 0):
- self.socket.settimeout(self._timeout)
- self.server_bind()
- self.server_activate()
-
- host, port = self.socket.getsockname()[:2]
- self.server_name = socket.getfqdn(host)
- self.server_port = port
-
-
class PlgHTTPSConnection(httplib.HTTPConnection):
"This class allows communication via SSL."
@@ -119,21 +79,3 @@ class PlgHTTPSConnection(httplib.HTTPConnection):
break
else:
raise socket.error, "failed to connect"
-
-
-
-class PlgHTTPS(httplib.HTTP):
- """Compatibility with 1.5 httplib interface
-
- Python 1.5.2 did not have an HTTPS class, but it defined an
- interface for sending http requests that is also useful for
- https.
- """
-
- _http_vsn = 11
- _http_vsn_str = 'HTTP/1.1'
-
- _connection_class = PlgHTTPSConnection
-
- def __init__(self, host='', port=None, ssl_context=None, strict=None,
timeout=None):
- self._setup(self._connection_class(host, port, ssl_context, strict, timeout))
diff --git a/koji/ssl/XMLRPCServerProxy.py b/koji/ssl/XMLRPCServerProxy.py
deleted file mode 100644
index 78273c8..0000000
--- a/koji/ssl/XMLRPCServerProxy.py
+++ /dev/null
@@ -1,177 +0,0 @@
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Modified by Dan Williams <dcbw(a)redhat.com>
-# Further modified by Mike Bonnet <mikeb(a)redhat.com>
-
-import os, sys
-import SSLCommon
-import urllib
-import xmlrpclib
-
-__version__='0.12'
-
-class PlgSSL_Transport(xmlrpclib.Transport):
-
- user_agent = "pyOpenSSL_XMLRPC/%s - %s" % (__version__,
xmlrpclib.Transport.user_agent)
-
- def __init__(self, ssl_context, timeout=None, use_datetime=0):
- if sys.version_info[:3] >= (2, 5, 0):
- xmlrpclib.Transport.__init__(self, use_datetime)
- self.ssl_ctx=ssl_context
- self._timeout = timeout
- self._https = None
-
- def make_connection(self, host):
- # Handle username and password.
- try:
- host, extra_headers, x509 = self.get_host_info(host)
- except AttributeError:
- # Yay for Python 2.2
- pass
- _host, _port = urllib.splitport(host)
- if hasattr(xmlrpclib.Transport, 'single_request'):
- cnx_class = SSLCommon.PlgHTTPSConnection
- else:
- cnx_class = SSLCommon.PlgHTTPS
- self._https = cnx_class(_host, (_port and int(_port) or 443),
ssl_context=self.ssl_ctx, timeout=self._timeout)
- return self._https
-
- def close(self):
- if self._https:
- self._https.close()
- self._https = None
-
-
-class Plg_ClosableTransport(xmlrpclib.Transport):
- """Override make_connection so we can close it."""
- def __init__(self):
- self._http = None
-
- def make_connection(self, host):
- # create a HTTP connection object from a host descriptor
- import httplib
- host, extra_headers, x509 = self.get_host_info(host)
- self._http = httplib.HTTP(host)
- return self._http
-
- def close(self):
- if self._http:
- self._http.close()
- self._http = None
-
-
-class PlgXMLRPCServerProxy(xmlrpclib.ServerProxy):
- def __init__(self, uri, certs, timeout=None, verbose=0, allow_none=0):
- if certs and len(certs) > 0:
- self.ctx = SSLCommon.CreateSSLContext(certs)
- self._transport = PlgSSL_Transport(ssl_context=self.ctx, timeout=timeout)
- else:
- self._transport = Plg_ClosableTransport()
- xmlrpclib.ServerProxy.__init__(self, uri, transport=self._transport,
- verbose=verbose, allow_none=allow_none)
-
- def cancel(self):
- self._transport.close()
-
-
-###########################################################
-# Testing stuff
-###########################################################
-
-
-import threading
-import time
-import random
-import OpenSSL
-import socket
-
-client_start = False
-
-threadlist_lock = threading.Lock()
-threadlist = {}
-
-class TestClient(threading.Thread):
- def __init__(self, certs, num, tm):
- self.server = PlgXMLRPCServerProxy("https://127.0.0.1:8886", certs,
timeout=20)
- self.num = i
- self.tm = tm
- threading.Thread.__init__(self)
-
- def run(self):
- while not client_start:
- time.sleep(0.05)
- i = 0
- while i < 5:
- reply = None
- try:
- reply = self.server.ping(self.num, i)
- except OpenSSL.SSL.Error, e:
- reply = "OpenSSL Error (%s)" % e
- except socket.timeout, e:
- reply = "Socket timeout (%s)" % e
- threadlist_lock.acquire()
- self.tm.inc()
- threadlist_lock.release()
- print "TRY(%d / %d): %s" % (self.num, i, reply)
- time.sleep(0.05)
- i = i + 1
- threadlist_lock.acquire()
- del threadlist[self]
- threadlist_lock.release()
-
-class TimeoutCounter:
- def __init__(self):
- self._timedout = 0
- self._lock = threading.Lock();
-
- def inc(self):
- self._lock.acquire()
- self._timedout = self._timedout + 1
- self._lock.release()
-
- def get(self):
- return self._timedout
-
-if __name__ == '__main__':
- if len(sys.argv) < 4:
- print "Usage: python XMLRPCServerProxy.py key_and_cert peer_ca_cert"
- sys.exit(1)
-
- certs = {}
- certs['key_and_cert'] = sys.argv[1]
- certs['peer_ca_cert'] = sys.argv[3]
-
- tm = TimeoutCounter()
- i = 100
- while i > 0:
- t = TestClient(certs, i, tm)
- threadlist[t] = None
- print "Created thread %d." % i
- t.start()
- i = i - 1
-
- time.sleep(3)
- print "Unleashing threads."
- client_start = True
- while True:
- try:
- time.sleep(0.25)
- threadlist_lock.acquire()
- if len(threadlist) == 0:
- break
- threadlist_lock.release()
- except KeyboardInterrupt:
- os._exit(0)
- print "All done. (%d timed out)" % tm.get()
--
2.4.3