[Twisted-Python] patch for TLS

jason-sage at creativetrax.com jason-sage at creativetrax.com
Thu Oct 7 14:53:54 EDT 2010


(cc to both twisted and sage-devel lists)

Hi all,

In the Sage project (http://sagemath.org), we apply a patch to the 
Twisted version we distribute.  I'd like to clean out our custom patches 
and push them upstream, if possible.  So I have a couple of questions 
(I'm not terribly familiar with Twisted):

1. Is the patch below generally useful?

2. Is there a better way to do this than to patch the file?

3. What do we need to do to incorporate it upstream in Twisted?


PATCH (against the Twisted git mirror, as of today):

diff --git a/twisted/application/internet.py 
b/twisted/application/internet.py
index 8437568..0397f08 100644
--- a/twisted/application/internet.py
+++ b/twisted/application/internet.py
@@ -193,7 +193,7 @@ on arguments to the reactor method.
  }

  import new
-for tran in 'TCP UNIX SSL UDP UNIXDatagram Multicast'.split():
+for tran in 'TCP UNIX SSL TLS UDP UNIXDatagram Multicast'.split():
      for side in 'Server Client'.split():
          if tran == "Multicast" and side == "Client":
              continue
diff --git a/twisted/application/strports.py 
b/twisted/application/strports.py
index 3654413..2b6ca08 100644
--- a/twisted/application/strports.py
+++ b/twisted/application/strports.py
@@ -79,9 +79,25 @@ def _parseSSL(factory, port, privateKey="server.pem", 
certKey=None,
      return ((int(port), factory, cf),
              {'interface': interface, 'backlog': int(backlog)})

+def _parseTLS(factory, port, privateKey='server.pem', certKey=None,
+              sslmethod=None, interface='', backlog=50):
+    from gnutls.interfaces.twisted import X509Credentials
+    from gnutls.crypto import X509Certificate, X509PrivateKey
+
+    if certKey is None:
+        certKey = privateKey
+
+    cert = X509Certificate(open(certKey).read())
+    key = X509PrivateKey(open(privateKey).read())
+    cf = X509Credentials(cert, key)
+
+    return ((int(port), factory, cf),
+            {'interface': interface, 'backlog': int(backlog)})
+
  _funcs = {"tcp": _parseTCP,
            "unix": _parseUNIX,
-          "ssl": _parseSSL}
+          "ssl": _parseSSL,
+          "tls": _parseTLS}

  _OP, _STRING = range(2)
  def _tokenize(description):



Thanks for the excellent software!

Jason

[1] http://sagemath.org



More information about the Twisted-Python mailing list