| OLD | NEW |
| 1 | 1 |
| 2 tlslite version 0.3.8 February 21, 2005 | 2 tlslite version 0.4.6 Mar 20 2013 |
| 3 Trevor Perrin <trevp at trevp.net> | 3 Trevor Perrin <tlslite at trevp.net> |
| 4 http://trevp.net/tlslite/ | 4 http://trevp.net/tlslite/ |
| 5 ============================================================================ | 5 ============================================================================ |
| 6 | 6 |
| 7 | 7 |
| 8 Table of Contents | 8 Table of Contents |
| 9 ================== | 9 ================== |
| 10 1 Introduction | 10 1 Introduction |
| 11 2 License/Acknowledgements | 11 2 License/Acknowledgements |
| 12 3 Installation | 12 3 Installation |
| 13 4 Getting Started with the Command-Line Tools | 13 4 Getting Started with the Command-Line Tools |
| 14 5 Getting Started with the Library | 14 5 Getting Started with the Library |
| 15 6 Using TLS Lite with httplib | 15 6 Using TLS Lite with httplib |
| 16 7 Using TLS Lite with xmlrpclib | 16 7 Using TLS Lite with poplib or imaplib |
| 17 8 Using TLS Lite with poplib or imaplib | 17 8 Using TLS Lite with smtplib |
| 18 9 Using TLS Lite with smtplib | 18 9 Using TLS Lite with SocketServer |
| 19 10 Using TLS Lite with SocketServer | 19 10 Using TLS Lite with asyncore |
| 20 11 Using TLS Lite with asyncore | 20 11 SECURITY CONSIDERATIONS |
| 21 12 Using TLS Lite with Twisted | 21 12 History |
| 22 13 SECURITY CONSIDERATIONS | |
| 23 14 History | |
| 24 15 References | |
| 25 | 22 |
| 26 | 23 |
| 27 1 Introduction | 24 1 Introduction |
| 28 =============== | 25 =============== |
| 29 TLS Lite is a free python library that implements SSL v3, TLS v1, and | 26 TLS Lite is an open source python library that implements SSL and TLS. TLS |
| 30 TLS v1.1 [0]. TLS Lite supports non-traditional authentication methods | 27 Lite supports RSA and SRP ciphersuites. TLS Lite is pure python, however it |
| 31 such as SRP [1], shared keys [2], and cryptoIDs [3], in addition to X.509 | 28 can use other libraries for faster crypto operations. TLS Lite integrates with |
| 32 certificates. TLS Lite is pure python, however it can access OpenSSL [4], | 29 several stdlib neworking libraries. |
| 33 cryptlib [5], pycrypto [9], and GMPY [10] for faster crypto operations. TLS | |
| 34 Lite integrates with httplib, xmlrpclib, poplib, imaplib, smtplib, | |
| 35 SocketServer, asyncore, and Twisted. | |
| 36 | 30 |
| 37 API documentation is available in the 'docs' directory. | 31 API documentation is available in the 'docs' directory. |
| 38 | 32 |
| 39 If you have questions or feedback, feel free to contact me. | 33 If you have questions or feedback, feel free to contact me. For discussing |
| 34 improvements to tlslite, also see 'tlslite-dev@googlegroups.com'. |
| 40 | 35 |
| 41 | 36 |
| 42 2 Licenses/Acknowledgements | 37 2 Licenses/Acknowledgements |
| 43 ============================ | 38 ============================ |
| 44 All code here is public domain. | 39 TLS Lite is written (mostly) by Trevor Perrin. It includes code from Bram |
| 40 Cohen, Google, Kees Bos, Sam Rushing, Dimitris Moraitis, Marcelo Fernandez, |
| 41 Martin von Loewis, and Dave Baggett. |
| 45 | 42 |
| 46 Thanks to Bram Cohen for his public domain Rijndael implementation. | 43 All code in TLS Lite has either been dedicated to the public domain by its |
| 44 authors, or placed under a BSD-style license. See the LICENSE file for |
| 45 details. |
| 47 | 46 |
| 48 Thanks to Edward Loper for Epydoc, which generated the API docs. | 47 Thanks to Edward Loper for Epydoc, which generated the API docs. |
| 49 | 48 |
| 50 | 49 |
| 51 3 Installation | 50 3 Installation |
| 52 =============== | 51 =============== |
| 53 Requirements: | 52 Requirements: |
| 54 Python 2.2 or greater is required. | 53 Python 2.6 or higher is required. Python 3 is supported. |
| 55 | 54 |
| 56 Options: | 55 Options: |
| 57 - If you have cryptoIDlib [8], you can use cryptoID certificate chains for | 56 - If you have the M2Crypto interface to OpenSSL, this will be used for fast |
| 58 authentication. CryptoIDlib is the sister library to TLS Lite; it was | 57 RSA operations and fast ciphers. |
| 59 written by the same author, and has a similar interface. | |
| 60 | 58 |
| 61 - If you have the M2Crypto [6] interface to OpenSSL, this will be used for | 59 - If you have pycrypto this will be used for fast RSA operations and fast |
| 62 fast RSA operations and fast ciphers. | 60 ciphers. |
| 63 | 61 |
| 64 - If you have the cryptlib_py [7] interface to cryptlib, this will be used | 62 - If you have the GMPY interface to GMP, this will be used for fast RSA and |
| 65 for random number generation and fast ciphers. If TLS Lite can't find an | 63 SRP operations. |
| 66 OS-level random-number generator (i.e. /dev/urandom on UNIX or CryptoAPI on | |
| 67 Windows), then you must MUST install cryptlib. | |
| 68 | |
| 69 - If you have pycrypto [9], this will be used for fast ciphers and fast RSA | |
| 70 operations. | |
| 71 | |
| 72 - If you have the GMPY [10] interface to GMP, this will be used for fast RSA | |
| 73 and SRP operations. | |
| 74 | 64 |
| 75 - These modules don't need to be present at installation - you can install | 65 - These modules don't need to be present at installation - you can install |
| 76 them any time. | 66 them any time. |
| 77 | 67 |
| 78 On Windows: | 68 Run 'python setup.py install' |
| 79 Run the installer in the 'installers' directory. | |
| 80 *OR* | |
| 81 Run 'setup.py install' (this only works if your system has a compiler | |
| 82 available). | |
| 83 | |
| 84 Anywhere else: | |
| 85 - Run 'python setup.py install' | |
| 86 | 69 |
| 87 Test the Installation: | 70 Test the Installation: |
| 88 - The 'tls.py' script should have been copied onto your path. If not, | 71 - From the distribution's ./tests subdirectory, run: |
| 89 you may have to copy it there manually. | 72 ./tlstest.py server localhost:4443 . |
| 90 - From the distribution's ./test subdirectory, run: | |
| 91 tls.py servertest localhost:4443 . | |
| 92 - While the test server is waiting, run: | 73 - While the test server is waiting, run: |
| 93 tls.py clienttest localhost:4443 . | 74 ./tlstest.py client localhost:4443 . |
| 94 | 75 |
| 95 If both say "Test succeeded" at the end, you're ready to go. | 76 If both say "Test succeeded" at the end, you're ready to go. |
| 96 | 77 |
| 97 (WARNING: Be careful running these (or any) scripts from the distribution's | |
| 98 root directory. Depending on your path, the scripts may load the local copy | |
| 99 of the library instead of the installed version, with unpredictable | |
| 100 results). | |
| 101 | |
| 102 | 78 |
| 103 4 Getting Started with the Command-Line Tools | 79 4 Getting Started with the Command-Line Tools |
| 104 ============================================== | 80 ============================================== |
| 105 tlslite comes with two command-line scripts: 'tlsdb.py' and 'tls.py'. They | 81 tlslite installs two command-line scripts: 'tlsdb.py' and 'tls.py'. |
| 106 can be run with no arguments to see a list of commands. | |
| 107 | 82 |
| 108 'tlsdb.py' lets you manage shared key or verifier databases. These databases | 83 'tls.py' lets you run test clients and servers. It can be used for testing |
| 109 store usernames associated with either shared keys, or SRP password verifiers. | 84 other TLS implementations, or as example code. Note that 'tls.py server' runs |
| 110 These databases are used by a TLS server when authenticating clients with | 85 an HTTPS server which will serve files rooted at the current directory by |
| 111 shared keys or SRP. | 86 default, so be careful. |
| 112 | 87 |
| 113 'tls.py' lets you run test clients and servers. It can be used for testing | 88 'tlsdb.py' lets you manage SRP verifier databases. These databases are used by |
| 114 other TLS implementations, or as example code for using tlslite. To run an | 89 a TLS server when authenticating clients with SRP. |
| 115 SRP server, try something like: | 90 |
| 91 X.509 |
| 92 ------ |
| 93 To run an X.509 server, go to the ./tests directory and do: |
| 94 |
| 95 tls.py server -k serverX509Key.pem -c serverX509Cert.pem localhost:4443 |
| 96 |
| 97 Try connecting to the server with a web browser, or with: |
| 98 |
| 99 tls.py client localhost:4443 |
| 100 |
| 101 X.509 with TACK |
| 102 ---------------- |
| 103 To run an X.509 server using a TACK, install TACKpy, then run the same server |
| 104 command as above with added arguments: |
| 105 |
| 106 ... -t TACK1.pem localhost:4443 |
| 107 |
| 108 SRP |
| 109 ---- |
| 110 To run an SRP server, try something like: |
| 116 | 111 |
| 117 tlsdb.py createsrp verifierDB | 112 tlsdb.py createsrp verifierDB |
| 118 tlsdb.py add verifierDB alice abra123cadabra 1024 | 113 tlsdb.py add verifierDB alice abra123cadabra 1024 |
| 119 tlsdb.py add verifierDB bob swordfish 2048 | 114 tlsdb.py add verifierDB bob swordfish 2048 |
| 120 | 115 |
| 121 tls.py serversrp localhost:443 verifierDB | 116 tls.py server -v verifierDB localhost:4443 |
| 122 | 117 |
| 123 Then you can try connecting to the server with: | 118 Then try connecting to the server with: |
| 124 | 119 |
| 125 tls.py clientsrp localhost:443 alice abra123cadabra | 120 tls.py client localhost:4443 alice abra123cadabra |
| 121 |
| 122 HTTPS |
| 123 ------ |
| 124 To run an HTTPS server with less typing, run ./tests/httpsserver.sh. |
| 125 |
| 126 To run an HTTPS client, run ./tests/httpsclient.py. |
| 126 | 127 |
| 127 | 128 |
| 128 5 Getting Started with the Library | 129 5 Getting Started with the Library |
| 129 =================================== | 130 =================================== |
| 130 Using the library is simple. Whether you're writing a client or server, there | 131 Whether you're writing a client or server, there are six steps: |
| 131 are six steps: | 132 |
| 132 1) Create a socket and connect it to the other party. | 133 1) Create a socket and connect it to the other party. |
| 133 2) Construct a TLSConnection instance with the socket. | 134 2) Construct a TLSConnection instance with the socket. |
| 134 3) Call a handshake function on TLSConnection to perform the TLS handshake. | 135 3) Call a handshake function on TLSConnection to perform the TLS handshake. |
| 135 4) Check the results to make sure you're talking to the right party. | 136 4) Check the results to make sure you're talking to the right party. |
| 136 5) Use the TLSConnection to exchange data. | 137 5) Use the TLSConnection to exchange data. |
| 137 6) Call close() on the TLSConnection when you're done. | 138 6) Call close() on the TLSConnection when you're done. |
| 138 | 139 |
| 139 TLS Lite also integrates with httplib, xmlrpclib, poplib, imaplib, smtplib, | 140 TLS Lite also integrates with several stdlib python libraries. See the |
| 140 SocketServer, asyncore, and Twisted. When used with these, some of the steps | 141 sections following this one for details. |
| 141 are performed for you. See the sections following this one for details. | |
| 142 | 142 |
| 143 5 Step 1 - create a socket | 143 5 Step 1 - create a socket |
| 144 --------------------------- | 144 --------------------------- |
| 145 Below demonstrates a socket connection to Amazon's secure site. It's a good | 145 Below demonstrates a socket connection to Amazon's secure site. |
| 146 idea to set the timeout value, so if the other side fails to respond you won't | |
| 147 end up waiting forever. | |
| 148 | 146 |
| 149 from socket import * | 147 from socket import * |
| 150 sock = socket(AF_INET, SOCK_STREAM) | 148 sock = socket(AF_INET, SOCK_STREAM) |
| 151 sock.connect( ("www.amazon.com", 443) ) | 149 sock.connect( ("www.amazon.com", 443) ) |
| 152 sock.settimeout(10) #Only on python 2.3 or greater | |
| 153 | 150 |
| 154 5 Step 2 - construct a TLSConnection | 151 5 Step 2 - construct a TLSConnection |
| 155 ------------------------------------- | 152 ------------------------------------- |
| 153 You can import tlslite objects individually, such as: |
| 154 from tlslite import TLSConnection |
| 155 |
| 156 Or import the most useful objects through: |
| 156 from tlslite.api import * | 157 from tlslite.api import * |
| 158 |
| 159 Then do: |
| 157 connection = TLSConnection(sock) | 160 connection = TLSConnection(sock) |
| 158 | 161 |
| 159 5 Step 3 - call a handshake function (client) | 162 5 Step 3 - call a handshake function (client) |
| 160 ---------------------------------------------- | 163 ---------------------------------------------- |
| 161 If you're a client, there's several different handshake functions you can | 164 If you're a client, there's two different handshake functions you can call, |
| 162 call, depending on how you want to authenticate: | 165 depending on how you want to authenticate: |
| 163 | 166 |
| 164 connection.handshakeClientCert() | 167 connection.handshakeClientCert() |
| 165 connection.handshakeClientCert(certChain, privateKey) | 168 connection.handshakeClientCert(certChain, privateKey) |
| 169 |
| 166 connection.handshakeClientSRP("alice", "abra123cadabra") | 170 connection.handshakeClientSRP("alice", "abra123cadabra") |
| 167 connection.handshakeClientSharedKey("alice", "PaVBVZkYqAjCQCu6UBL2xgsnZhw") | |
| 168 connection.handshakeClientUnknown(srpCallback, certCallback) | |
| 169 | 171 |
| 170 The ClientCert function without arguments is used when connecting to a site | 172 The ClientCert function without arguments is used when connecting to a site |
| 171 like Amazon, which doesn't require client authentication. The server will | 173 like Amazon, which doesn't require client authentication, but which will |
| 172 authenticate with a certificate chain. | 174 authenticate itself using an X.509 certificate chain. |
| 173 | 175 |
| 174 The ClientCert function can also be used to do client authentication with an | 176 The ClientCert function can also be used to do client authentication with an |
| 175 X.509 or cryptoID certificate chain. To use cryptoID chains, you'll need the | 177 X.509 certificate chain and corresponding private key. To use X.509 chains, |
| 176 cryptoIDlib library [8]. To use X.509 chains, you'll need some way of | 178 you'll need some way of creating these, such as OpenSSL (see |
| 177 creating these, such as OpenSSL (see http://www.openssl.org/docs/HOWTO/ for | 179 http://www.openssl.org/docs/HOWTO/ for details). |
| 178 details). | |
| 179 | 180 |
| 180 Below are examples of loading cryptoID and X.509 certificate chains: | 181 Below is an example of loading an X.509 chain and private key: |
| 181 | 182 |
| 182 #Load cryptoID certChain and privateKey. Requires cryptoIDlib. | 183 from tlslite import X509, X509CertChain, parsePEMKey |
| 183 from cryptoIDlib.CertChain import CertChain | |
| 184 s = open("./test/clientCryptoIDChain.xml").read() | |
| 185 certChain = CertChain() | |
| 186 certChain.parse(s) | |
| 187 s = open("./test/clientCryptoIDKey.xml").read() | |
| 188 privateKey = parseXMLKey(s, private=True) | |
| 189 | |
| 190 #Load X.509 certChain and privateKey. | |
| 191 s = open("./test/clientX509Cert.pem").read() | 184 s = open("./test/clientX509Cert.pem").read() |
| 192 x509 = X509() | 185 x509 = X509() |
| 193 x509.parse(s) | 186 x509.parse(s) |
| 194 certChain = X509CertChain([x509]) | 187 certChain = X509CertChain([x509]) |
| 195 s = open("./test/clientX509Key.pem").read() | 188 s = open("./test/clientX509Key.pem").read() |
| 196 privateKey = parsePEMKey(s, private=True) | 189 privateKey = parsePEMKey(s, private=True) |
| 197 | 190 |
| 198 The SRP and SharedKey functions both do mutual authentication with a username | 191 The SRP function does mutual authentication with a username and password - see |
| 199 and password. The difference is this: SRP is slow but safer when using low- | 192 RFC 5054 for details. |
| 200 entropy passwords, since the SRP protocol is not vulnerable to offline | |
| 201 dictionary attacks. Using shared keys is faster, but it's only safe when | |
| 202 used with high-entropy secrets. In general, you should prefer SRP for human- | |
| 203 memorable passwords, and use shared keys only when your performance needs | |
| 204 outweigh the inconvenience of handling large random strings. | |
| 205 | |
| 206 [WARNING: shared keys and SRP are internet-drafts; these protocols may change, | |
| 207 which means future versions of tlslite may not be compatible with this one. | |
| 208 This is less likely with SRP, more likely with shared-keys.] | |
| 209 | |
| 210 The Unknown function is used when you're not sure if the server requires | |
| 211 client authentication.» If the server requests SRP or certificate-based | |
| 212 authentication, the appropriate callback will be triggered, and you should | |
| 213 return a tuple containing either a (username, password) or (certChain, | |
| 214 privateKey), as appropriate. Alternatively, you can return None, which will | |
| 215 cancel the handshake from an SRP callback, or cause it to continue without | |
| 216 client authentication (if the server is willing) from a certificate callback. | |
| 217 | 193 |
| 218 If you want more control over the handshake, you can pass in a | 194 If you want more control over the handshake, you can pass in a |
| 219 HandshakeSettings instance. For example, if you're performing SRP, but you | 195 HandshakeSettings instance. For example, if you're performing SRP, but you |
| 220 only want to use SRP parameters of at least 2048 bits, and you only want to use | 196 only want to use SRP parameters of at least 2048 bits, and you only want to |
| 221 the AES-256 cipher, and you only want to allow TLS (version 3.1), not SSL | 197 use the AES-256 cipher, and you only want to allow TLS (version 3.1), not SSL |
| 222 (version 3.0), you can do: | 198 (version 3.0), you can do: |
| 223 | 199 |
| 224 settings = HandshakeSettings() | 200 settings = HandshakeSettings() |
| 225 settings.minKeySize = 2048 | 201 settings.minKeySize = 2048 |
| 226 settings.cipherNames = ["aes256"] | 202 settings.cipherNames = ["aes256"] |
| 227 settings.minVersion = (3,1) | 203 settings.minVersion = (3,1) |
| 204 settings.useExperimentalTACKExtension = True # Needed for TACK support |
| 205 |
| 228 connection.handshakeClientSRP("alice", "abra123cadabra", settings=settings) | 206 connection.handshakeClientSRP("alice", "abra123cadabra", settings=settings) |
| 229 | 207 |
| 230 Finally, every TLSConnection has a session object. You can try to resume a | 208 If you want to check the server's certificate using TACK, you should set the |
| 231 previous session by passing in the session object from the old session. If | 209 "useExperiementalTACKExtension" value in HandshakeSettings. (Eventually, TACK |
| 232 the server remembers this old session and supports resumption, the handshake | 210 support will be enabled by default, but for now it is an experimental feature |
| 233 will finish more quickly. Otherwise, the full handshake will be done. For | 211 which relies on a temporary TLS Extension number, and should not be used for |
| 234 example: | 212 production software.) This will cause the client to request the server to send |
| 213 you a TACK (and/or any TACK Break Signatures): |
| 214 |
| 215 Finally, every TLSConnection has a session object. You can try to resume a |
| 216 previous session by passing in the session object from the old session. If the |
| 217 server remembers this old session and supports resumption, the handshake will |
| 218 finish more quickly. Otherwise, the full handshake will be done. For example: |
| 235 | 219 |
| 236 connection.handshakeClientSRP("alice", "abra123cadabra") | 220 connection.handshakeClientSRP("alice", "abra123cadabra") |
| 237 . | 221 . |
| 238 . | 222 . |
| 239 oldSession = connection.session | 223 oldSession = connection.session |
| 240 connection2.handshakeClientSRP("alice", "abra123cadabra", session= | 224 connection2.handshakeClientSRP("alice", "abra123cadabra", session= |
| 241 oldSession) | 225 oldSession) |
| 242 | 226 |
| 243 5 Step 3 - call a handshake function (server) | 227 5 Step 3 - call a handshake function (server) |
| 244 ---------------------------------------------- | 228 ---------------------------------------------- |
| 245 If you're a server, there's only one handshake function, but you can pass it | 229 If you're a server, there's only one handshake function, but you can pass it |
| 246 several different parameters, depending on which types of authentication | 230 several different parameters, depending on which types of authentication |
| 247 you're willing to perform. | 231 you're willing to perform. |
| 248 | 232 |
| 249 To perform SRP authentication, you have to pass in a database of password | 233 To perform SRP authentication, you have to pass in a database of password |
| 250 verifiers. The VerifierDB class manages an in-memory or on-disk verifier | 234 verifiers. The VerifierDB class manages an in-memory or on-disk verifier |
| 251 database. | 235 database. |
| 252 | 236 |
| 253 #On-disk database (use no-arg constructor if you want an in-memory DB) | |
| 254 verifierDB = VerifierDB("./test/verifierDB") | 237 verifierDB = VerifierDB("./test/verifierDB") |
| 255 | |
| 256 #Open the pre-existing database (can also 'create()' a new one) | |
| 257 verifierDB.open() | 238 verifierDB.open() |
| 258 | |
| 259 #Add to the database | |
| 260 verifier = VerifierDB.makeVerifier("alice", "abra123cadabra", 2048) | |
| 261 verifierDB["alice"] = verifier | |
| 262 | |
| 263 #Perform a handshake using the database | |
| 264 connection.handshakeServer(verifierDB=verifierDB) | 239 connection.handshakeServer(verifierDB=verifierDB) |
| 265 | 240 |
| 266 To perform shared key authentication, you have to pass in a database of shared | |
| 267 keys. The SharedKeyDB class manages an in-memory or on-disk shared key | |
| 268 database. | |
| 269 | |
| 270 sharedKeyDB = SharedKeyDB("./test/sharedkeyDB") | |
| 271 sharedKeyDB.open() | |
| 272 sharedKeyDB["alice"] = "PaVBVZkYqAjCQCu6UBL2xgsnZhw" | |
| 273 connection.handshakeServer(sharedKeyDB=sharedKeyDB) | |
| 274 | |
| 275 To perform authentication with a certificate and private key, the server must | 241 To perform authentication with a certificate and private key, the server must |
| 276 load these as described in the previous section, then pass them in. If the | 242 load these as described in the previous section, then pass them in. If the |
| 277 server sets the reqCert boolean to True, a certificate chain will be requested | 243 server sets the reqCert boolean to True, a certificate chain will be requested |
| 278 from the client. | 244 from the client. |
| 279 | 245 |
| 280 connection.handshakeServer(certChain=certChain, privateKey=privateKey, | 246 connection.handshakeServer(certChain=certChain, privateKey=privateKey, |
| 281 reqCert=True) | 247 reqCert=True) |
| 282 | 248 |
| 283 You can pass in any combination of a verifier database, a shared key database, | 249 You can pass in a verifier database and/or a certificate chain+private key. |
| 284 and a certificate chain/private key. The client will use one of them to | 250 The client will use one or both to authenticate the server. |
| 285 authenticate. In the case of SRP and a certificate chain/private key, they | |
| 286 both may be used. | |
| 287 | 251 |
| 288 You can also pass in a HandshakeSettings object, as described in the last | 252 You can also pass in a HandshakeSettings object, as described in the last |
| 289 section, for finer control over handshaking details. Finally, the server can | 253 section, for finer control over handshaking details. |
| 290 maintain a SessionCache, which will allow clients to use session resumption: | 254 |
| 255 If you are passing in a certificate chain+private key, you may additionally |
| 256 provide a TACK to assist the client in authenticating your certificate chain. |
| 257 This requires the TACKpy library. Load a TACKpy.TACK object, then do: |
| 258 |
| 259 settings = HandshakeSettings() |
| 260 settings.useExperimentalTACKExtension = True # Needed for TACK support |
| 261 |
| 262 connection.handshakeServer(certChain=certChain, privateKey=privateKey, |
| 263 tack=tack, settings=settings) |
| 264 |
| 265 Finally, the server can maintain a SessionCache, which will allow clients to |
| 266 use session resumption: |
| 291 | 267 |
| 292 sessionCache = SessionCache() | 268 sessionCache = SessionCache() |
| 293 connection.handshakeServer(verifierDB=verifierDB, sessionCache=sessionCache) | 269 connection.handshakeServer(verifierDB=verifierDB, sessionCache=sessionCache) |
| 294 | 270 |
| 295 It should be noted that the session cache, and the verifier and shared key | 271 It should be noted that the session cache, and the verifier databases, are all |
| 296 databases, are all thread-safe. | 272 thread-safe. |
| 297 | 273 |
| 298 5 Step 4 - check the results | 274 5 Step 4 - check the results |
| 299 ----------------------------- | 275 ----------------------------- |
| 300 If the handshake completes without raising an exception, authentication | 276 If the handshake completes without raising an exception, authentication |
| 301 results will be stored in the connection's session object. The following | 277 results will be stored in the connection's session object. The following |
| 302 variables will be populated if applicable, or else set to None: | 278 variables will be populated if applicable, or else set to None: |
| 303 | 279 |
| 304 connection.session.srpUsername #string | 280 connection.session.srpUsername # string |
| 305 connection.session.sharedKeyUsername #string | 281 connection.session.clientCertChain # X509CertChain |
| 306 connection.session.clientCertChain #X509CertChain or | 282 connection.session.serverCertChain # X509CertChain |
| 307 #cryptoIDlib.CertChain.CertChain | 283 connection.session.tackExt # TACKpy.TACK_Extension |
| 308 connection.session.serverCertChain #X509CertChain or | |
| 309 #cryptoIDlib.CertChain.CertChain | |
| 310 | 284 |
| 311 Both types of certificate chain object support the getFingerprint() function, | 285 X.509 chain objects return the end-entity fingerprint via getFingerprint(), |
| 312 but with a difference. X.509 objects return the end-entity fingerprint, and | 286 and ignore the other certificates. |
| 313 ignore the other certificates. CryptoID fingerprints (aka "cryptoIDs") are | |
| 314 based on the root cryptoID certificate, so you have to call validate() on the | |
| 315 CertChain to be sure you're really talking to the cryptoID. | |
| 316 | 287 |
| 317 X.509 certificate chain objects may also be validated against a list of | 288 TACK objects return the (validated) TACK ID via getTACKID(). |
| 318 trusted root certificates. See the API documentation for details. | |
| 319 | 289 |
| 320 To save yourself the trouble of inspecting fingerprints after the handshake, | 290 To save yourself the trouble of inspecting certificates and/or TACKs after the |
| 321 you can pass a Checker object into the handshake function. The checker will be | 291 handshake, you can pass a Checker object into the handshake function. The |
| 322 called if the handshake completes successfully. If the other party's | 292 checker will be called if the handshake completes successfully. If the other |
| 323 certificate chain isn't approved by the checker, a subclass of | 293 party isn't approved by the checker, a subclass of TLSAuthenticationError will |
| 324 TLSAuthenticationError will be raised. For example, to perform a handshake | 294 be raised. |
| 325 with a server based on its X.509 fingerprint, do: | |
| 326 | 295 |
| 327 try: | 296 If the handshake fails for any reason, including a Checker error, an exception |
| 328 checker = Checker(\ | 297 will be raised and the socket will be closed. If the socket timed out or was |
| 329 x509Fingerprint='e049ff930af76d43ff4c658b268786f4df1296f2') | 298 unexpectedly closed, a socket.error or TLSAbruptCloseError will be raised. |
| 330 connection.handshakeClientCert(checker=checker) | |
| 331 except TLSAuthenticationError: | |
| 332 print "Authentication failure" | |
| 333 | 299 |
| 334 If the handshake fails for any reason, an exception will be raised. If the | 300 Otherwise, either a TLSLocalAlert or TLSRemoteAlert will be raised, depending |
| 335 socket timed out or was unexpectedly closed, a socket.error or | 301 on whether the local or remote implementation signalled the error. The |
| 336 TLSAbruptCloseError will be raised. Otherwise, either a TLSLocalAlert or | 302 exception object has a 'description' member which identifies the error based |
| 337 TLSRemoteAlert will be raised, depending on whether the local or remote | 303 on the codes in RFC 2246. A TLSLocalAlert also has a 'message' string that may |
| 338 implementation signalled the error. The exception object has a 'description' | 304 have more details. |
| 339 member which identifies the error based on the codes in RFC 2246. A | |
| 340 TLSLocalAlert also has a 'message' string that may have more details. | |
| 341 | 305 |
| 342 Example of handling a remote alert: | 306 Example of handling a remote alert: |
| 343 | 307 |
| 344 try: | 308 try: |
| 345 [...] | 309 [...] |
| 346 except TLSRemoteAlert, alert: | 310 except TLSRemoteAlert as alert: |
| 347 if alert.description == AlertDescription.unknown_srp_username: | 311 if alert.description == AlertDescription.unknown_psk_identity: |
| 348 print "Unknown user." | 312 print "Unknown user." |
| 349 [...] | 313 [...] |
| 350 | 314 |
| 351 Figuring out what went wrong based on the alert may require some | 315 Below are some common alerts and their probable causes, and whether they are |
| 352 interpretation, particularly with remote alerts where you don't have an error | 316 signalled by the client or server. |
| 353 string, and where the remote implementation may not be signalling alerts | |
| 354 properly. Many alerts signal an implementation error, and so should rarely be | |
| 355 seen in normal operation (unexpected_message, decode_error, illegal_parameter, | |
| 356 internal_error, etc.). | |
| 357 | 317 |
| 358 Others alerts are more likely to occur. Below are some common alerts and | 318 Client handshake_failure: |
| 359 their probable causes, and whether they are signalled by the client or server. | |
| 360 | |
| 361 Client bad_record_mac: | |
| 362 - bad shared key password | |
| 363 | |
| 364 Client handshake failure: | |
| 365 - SRP parameters are not recognized by client | 319 - SRP parameters are not recognized by client |
| 366 | 320 - Server's TACK was unrelated to its certificate chain |
| 367 Client user_canceled: | |
| 368 - The client might have returned None from an SRP callback. | |
| 369 | 321 |
| 370 Client insufficient_security: | 322 Client insufficient_security: |
| 371 - SRP parameters are too small | 323 - SRP parameters are too small |
| 372 | 324 |
| 373 Client protocol_version: | 325 Client protocol_version: |
| 374 - Client doesn't support the server's protocol version | 326 - Client doesn't support the server's protocol version |
| 375 | 327 |
| 376 Server protocol_version: | 328 Server protocol_version: |
| 377 - Server doesn't support the client's protocol version | 329 - Server doesn't support the client's protocol version |
| 378 | 330 |
| 379 Server bad_record_mac: | 331 Server bad_record_mac: |
| 380 - bad SRP username or password | 332 - bad SRP username or password |
| 381 | 333 |
| 382 Server unknown_srp_username | 334 Server unknown_psk_identity |
| 383 - bad SRP username (bad_record_mac could be used for the same thing) | 335 - bad SRP username (bad_record_mac could be used for the same thing) |
| 384 | 336 |
| 385 Server handshake_failure: | 337 Server handshake_failure: |
| 386 - bad shared key username | |
| 387 - no matching cipher suites | 338 - no matching cipher suites |
| 388 | 339 |
| 389 5 Step 5 - exchange data | 340 5 Step 5 - exchange data |
| 390 ------------------------- | 341 ------------------------- |
| 391 Now that you have a connection, you can call read() and write() as if it were | 342 Now that you have a connection, you can call read() and write() as if it were |
| 392 a socket.SSL object. You can also call send(), sendall(), recv(), and | 343 a socket.SSL object. You can also call send(), sendall(), recv(), and |
| 393 makefile() as if it were a socket. These calls may raise TLSLocalAlert, | 344 makefile() as if it were a socket. These calls may raise TLSLocalAlert, |
| 394 TLSRemoteAlert, socket.error, or TLSAbruptCloseError, just like the handshake | 345 TLSRemoteAlert, socket.error, or TLSAbruptCloseError, just like the handshake |
| 395 functions. | 346 functions. |
| 396 | 347 |
| 397 Once the TLS connection is closed by the other side, calls to read() or recv() | 348 Once the TLS connection is closed by the other side, calls to read() or recv() |
| 398 will return an empty string. If the socket is closed by the other side | 349 will return an empty string. If the socket is closed by the other side without |
| 399 without first closing the TLS connection, calls to read() or recv() will return | 350 first closing the TLS connection, calls to read() or recv() will return a |
| 400 a TLSAbruptCloseError, and calls to write() or send() will return a | 351 TLSAbruptCloseError, and calls to write() or send() will return a |
| 401 socket.error. | 352 socket.error. |
| 402 | 353 |
| 403 5 Step 6 - close the connection | 354 5 Step 6 - close the connection |
| 404 -------------------------------- | 355 -------------------------------- |
| 405 When you're finished sending data, you should call close() to close the | 356 When you're finished sending data, you should call close() to close the |
| 406 connection down. When the connection is closed properly, the socket stays | 357 connection and socket. When the connection is closed properly, the session |
| 407 open and can be used for exchanging non-secure data, the session object can be | 358 object can be used for session resumption. |
| 408 used for session resumption, and the connection object can be re-used by | |
| 409 calling another handshake function. | |
| 410 | 359 |
| 411 If an exception is raised, the connection will be automatically closed; you | 360 If an exception is raised the connection will be automatically closed; you |
| 412 don't need to call close(). Furthermore, you will probably not be able to re- | 361 don't need to call close(). Furthermore, you will probably not be able to |
| 413 use the socket, the connection object, or the session object, and you | 362 re-use the socket, the connection object, or the session object, and you |
| 414 shouldn't even try. | 363 shouldn't even try. |
| 415 | 364 |
| 416 By default, calling close() will leave the socket open. If you set the | 365 By default, calling close() will close the underlying socket. If you set the |
| 417 connection's closeSocket flag to True, the connection will take ownership of | 366 connection's closeSocket flag to False, the socket will remain open after |
| 418 the socket, and close it when the connection is closed. | 367 close. (NOTE: some TLS implementations will not respond properly to the |
| 368 close_notify alert that close() generates, so the connection will hang if |
| 369 closeSocket is set to True.) |
| 419 | 370 |
| 420 | 371 |
| 421 6 Using TLS Lite with httplib | 372 6 Using TLS Lite with httplib |
| 422 ============================== | 373 ============================== |
| 423 TLS Lite comes with an HTTPTLSConnection class that extends httplib to work | 374 TLS Lite comes with an HTTPTLSConnection class that extends httplib to work |
| 424 over SSL/TLS connections. Depending on how you construct it, it will do | 375 over SSL/TLS connections. Depending on how you construct it, it will do |
| 425 different types of authentication. | 376 different types of authentication. |
| 426 | 377 |
| 427 #No authentication whatsoever | 378 #No authentication whatsoever |
| 428 h = HTTPTLSConnection("www.amazon.com", 443) | 379 h = HTTPTLSConnection("www.amazon.com", 443) |
| 429 h.request("GET", "") | 380 h.request("GET", "") |
| 430 r = h.getresponse() | 381 r = h.getresponse() |
| 431 [...] | 382 [...] |
| 432 | 383 |
| 433 #Authenticate server based on its X.509 fingerprint | 384 #Authenticate server based on its TACK ID |
| 434 h = HTTPTLSConnection("www.amazon.com", 443, | 385 h = HTTPTLSConnection("localhost", 4443, |
| 435 x509Fingerprint="e049ff930af76d43ff4c658b268786f4df1296f2") | 386 tackID="B3ARS.EQ61B.F34EL.9KKLN.3WEW5", hardTack=False) |
| 436 [...] | |
| 437 | |
| 438 #Authenticate server based on its X.509 chain (requires cryptlib_py [7]) | |
| 439 h = HTTPTLSConnection("www.amazon.com", 443, | |
| 440 x509TrustList=[verisignCert], | |
| 441 x509CommonName="www.amazon.com") | |
| 442 [...] | |
| 443 | |
| 444 #Authenticate server based on its cryptoID | |
| 445 h = HTTPTLSConnection("localhost", 443, | |
| 446 cryptoID="dmqb6.fq345.cxk6g.5fha3") | |
| 447 [...] | 387 [...] |
| 448 | 388 |
| 449 #Mutually authenticate with SRP | 389 #Mutually authenticate with SRP |
| 450 h = HTTPTLSConnection("localhost", 443, | 390 h = HTTPTLSConnection("localhost", 443, |
| 451 username="alice", password="abra123cadabra") | 391 username="alice", password="abra123cadabra") |
| 452 [...] | 392 [...] |
| 453 | 393 |
| 454 #Mutually authenticate with a shared key | |
| 455 h = HTTPTLSConnection("localhost", 443, | |
| 456 username="alice", sharedKey="PaVBVZkYqAjCQCu6UBL2xgsnZhw") | |
| 457 [...] | |
| 458 | 394 |
| 459 #Mutually authenticate with SRP, *AND* authenticate the server based | 395 7 Using TLS Lite with poplib or imaplib |
| 460 #on its cryptoID | |
| 461 h = HTTPTLSConnection("localhost", 443, | |
| 462 username="alice", password="abra123cadabra", | |
| 463 cryptoID="dmqb6.fq345.cxk6g.5fha3") | |
| 464 [...] | |
| 465 | |
| 466 | |
| 467 7 Using TLS Lite with xmlrpclib | |
| 468 ================================ | |
| 469 TLS Lite comes with an XMLRPCTransport class that extends xmlrpclib to work | |
| 470 over SSL/TLS connections. This class accepts the same parameters as | |
| 471 HTTPTLSConnection (see previous section), and behaves similarly. Depending on | |
| 472 how you construct it, it will do different types of authentication. | |
| 473 | |
| 474 from tlslite.api import XMLRPCTransport | |
| 475 from xmlrpclib import ServerProxy | |
| 476 | |
| 477 #No authentication whatsoever | |
| 478 transport = XMLRPCTransport() | |
| 479 server = ServerProxy("https://localhost", transport) | |
| 480 server.someFunc(2, 3) | |
| 481 [...] | |
| 482 | |
| 483 #Authenticate server based on its X.509 fingerprint | |
| 484 transport = XMLRPCTransport(\ | |
| 485 x509Fingerprint="e049ff930af76d43ff4c658b268786f4df1296f2") | |
| 486 [...] | |
| 487 | |
| 488 | |
| 489 8 Using TLS Lite with poplib or imaplib | |
| 490 ======================================== | 396 ======================================== |
| 491 TLS Lite comes with POP3_TLS and IMAP4_TLS classes that extend poplib and | 397 TLS Lite comes with POP3_TLS and IMAP4_TLS classes that extend poplib and |
| 492 imaplib to work over SSL/TLS connections. These classes can be constructed | 398 imaplib to work over SSL/TLS connections. These classes can be constructed |
| 493 with the same parameters as HTTPTLSConnection (see previous section), and | 399 with the same parameters as HTTPTLSConnection (see previous section), and |
| 494 behave similarly. | 400 behave similarly. |
| 495 | 401 |
| 496 #To connect to a POP3 server over SSL and display its fingerprint: | 402 #To connect to a POP3 server over SSL and display its fingerprint: |
| 497 from tlslite.api import * | 403 from tlslite.api import * |
| 498 p = POP3_TLS("---------.net") | 404 p = POP3_TLS("---------.net", port=995) |
| 499 print p.sock.session.serverCertChain.getFingerprint() | 405 print p.sock.session.serverCertChain.getFingerprint() |
| 500 [...] | 406 [...] |
| 501 | 407 |
| 502 #To connect to an IMAP server once you know its fingerprint: | 408 #To connect to an IMAP server once you know its fingerprint: |
| 503 from tlslite.api import * | 409 from tlslite.api import * |
| 504 i = IMAP4_TLS("cyrus.andrew.cmu.edu", | 410 i = IMAP4_TLS("cyrus.andrew.cmu.edu", |
| 505 x509Fingerprint="00c14371227b3b677ddb9c4901e6f2aee18d3e45") | 411 x509Fingerprint="00c14371227b3b677ddb9c4901e6f2aee18d3e45") |
| 506 [...] | 412 [...] |
| 507 | 413 |
| 508 | 414 |
| 509 9 Using TLS Lite with smtplib | 415 8 Using TLS Lite with smtplib |
| 510 ============================== | 416 ============================== |
| 511 TLS Lite comes with an SMTP_TLS class that extends smtplib to work | 417 TLS Lite comes with an SMTP_TLS class that extends smtplib to work |
| 512 over SSL/TLS connections. This class accepts the same parameters as | 418 over SSL/TLS connections. This class accepts the same parameters as |
| 513 HTTPTLSConnection (see previous section), and behaves similarly. Depending | 419 HTTPTLSConnection (see previous section), and behaves similarly. Depending |
| 514 on how you call starttls(), it will do different types of authentication. | 420 on how you call starttls(), it will do different types of authentication. |
| 515 | 421 |
| 516 #To connect to an SMTP server once you know its fingerprint: | 422 #To connect to an SMTP server once you know its fingerprint: |
| 517 from tlslite.api import * | 423 from tlslite.api import * |
| 518 s = SMTP_TLS("----------.net") | 424 s = SMTP_TLS("----------.net", port=587) |
| 425 s.ehlo() |
| 519 s.starttls(x509Fingerprint="7e39be84a2e3a7ad071752e3001d931bf82c32dc") | 426 s.starttls(x509Fingerprint="7e39be84a2e3a7ad071752e3001d931bf82c32dc") |
| 520 [...] | 427 [...] |
| 521 | 428 |
| 522 | 429 |
| 523 10 Using TLS Lite with SocketServer | 430 9 Using TLS Lite with SocketServer |
| 524 ==================================== | 431 ==================================== |
| 525 You can use TLS Lite to implement servers using Python's SocketServer | 432 You can use TLS Lite to implement servers using Python's SocketServer |
| 526 framework. TLS Lite comes with a TLSSocketServerMixIn class. You can combine | 433 framework. TLS Lite comes with a TLSSocketServerMixIn class. You can combine |
| 527 this with a TCPServer such as HTTPServer. To combine them, define a new class | 434 this with a TCPServer such as HTTPServer. To combine them, define a new class |
| 528 that inherits from both of them (with the mix-in first). Then implement the | 435 that inherits from both of them (with the mix-in first). Then implement the |
| 529 handshake() method, doing some sort of server handshake on the connection | 436 handshake() method, doing some sort of server handshake on the connection |
| 530 argument. If the handshake method returns True, the RequestHandler will be | 437 argument. If the handshake method returns True, the RequestHandler will be |
| 531 triggered. Below is a complete example of a threaded HTTPS server. | 438 triggered. See the tests/httpsserver.py example. |
| 532 | |
| 533 from SocketServer import * | |
| 534 from BaseHTTPServer import * | |
| 535 from SimpleHTTPServer import * | |
| 536 from tlslite.api import * | |
| 537 | |
| 538 s = open("./serverX509Cert.pem").read() | |
| 539 x509 = X509() | |
| 540 x509.parse(s) | |
| 541 certChain = X509CertChain([x509]) | |
| 542 | |
| 543 s = open("./serverX509Key.pem").read() | |
| 544 privateKey = parsePEMKey(s, private=True) | |
| 545 | |
| 546 sessionCache = SessionCache() | |
| 547 | |
| 548 class MyHTTPServer(ThreadingMixIn, TLSSocketServerMixIn, HTTPServer): | |
| 549 def handshake(self, tlsConnection): | |
| 550 try: | |
| 551 tlsConnection.handshakeServer(certChain=certChain, | |
| 552 privateKey=privateKey, | |
| 553 sessionCache=sessionCache) | |
| 554 tlsConnection.ignoreAbruptClose = True | |
| 555 return True | |
| 556 except TLSError, error: | |
| 557 print "Handshake failure:", str(error) | |
| 558 return False | |
| 559 | |
| 560 httpd = MyHTTPServer(('localhost', 443), SimpleHTTPRequestHandler) | |
| 561 httpd.serve_forever() | |
| 562 | 439 |
| 563 | 440 |
| 564 11 Using TLS Lite with asyncore | 441 10 Using TLS Lite with asyncore |
| 565 ================================ | 442 ================================ |
| 566 TLS Lite can be used with subclasses of asyncore.dispatcher. See the comments | 443 TLS Lite can be used with subclasses of asyncore.dispatcher. See the comments |
| 567 in TLSAsyncDispatcherMixIn.py for details. This is still experimental, and | 444 in TLSAsyncDispatcherMixIn.py for details. This is still experimental, and |
| 568 may not work with all asyncore.dispatcher subclasses. | 445 may not work with all asyncore.dispatcher subclasses. |
| 569 | 446 |
| 570 Below is an example of combining Medusa's http_channel with | |
| 571 TLSAsyncDispatcherMixIn: | |
| 572 | 447 |
| 573 class http_tls_channel(TLSAsyncDispatcherMixIn, | 448 11 Security Considerations |
| 574 http_server.http_channel): | 449 =========================== |
| 575 ac_in_buffer_size = 16384 | 450 TLS Lite is beta-quality code. It hasn't received much security analysis. Use |
| 451 at your own risk. |
| 576 | 452 |
| 577 def __init__ (self, server, conn, addr): | 453 TLS Lite is probably vulnerable to the "Lucky 13" timing attack if AES or 3DES |
| 578 http_server.http_channel.__init__(self, server, conn, addr) | 454 are used. Thus, TLS Lite prefers the RC4 cipher. |
| 579 TLSAsyncDispatcherMixIn.__init__(self, conn) | |
| 580 self.tlsConnection.ignoreAbruptClose = True | |
| 581 self.setServerHandshakeOp(certChain=certChain, | |
| 582 privateKey=privateKey) | |
| 583 | 455 |
| 584 | 456 |
| 585 12 Using TLS Lite with Twisted | 457 12 History |
| 586 =============================== | 458 =========== |
| 587 TLS Lite can be used with Twisted protocols. Below is a complete example of | 459 0.4.6 - 3/20/2013 |
| 588 using TLS Lite with a Twisted echo server. | 460 - **API CHANGE**: TLSClosedConnectionError instead of ValueError when writing |
| 461 to a closed connection. This inherits from socket.error, so should |
| 462 interact better with SocketServer (see http://bugs.python.org/issue14574) |
| 463 and other things expecting a socket.error in this situation. |
| 464 - Added support for RC4-MD5 ciphersuite (if enabled in settings) |
| 465 - This is allegedly necessary to connect to some Internet servers. |
| 466 - Added TLSConnection.unread() function |
| 467 - Switched to New-style classes (inherit from 'object') |
| 468 - Minor cleanups |
| 469 |
| 470 0.4.5 - (release engineering problem, skipped!) |
| 589 | 471 |
| 590 There are two server implementations below. Echo is the original protocol, | 472 0.4.4 - 2/25/2013 |
| 591 which is oblivious to TLS. Echo1 subclasses Echo and negotiates TLS when the | 473 - Added Python 3 support (Martin von Loewis) |
| 592 client connects. Echo2 subclasses Echo and negotiates TLS when the client | 474 - Added NPN client support (Marcelo Fernandez) |
| 593 sends "STARTTLS". | 475 - Switched to RC4 as preferred cipher |
| 476 - faster in Python, avoids "Lucky 13" timing attacks |
| 477 - Fixed bug when specifying ciphers for anon ciphersuites |
| 478 - Made RSA hashAndVerify() tolerant of sigs w/o encoded NULL AlgorithmParam |
| 479 - (this function is not used for TLS currently, and this tolerance may |
| 480 not even be necessary) |
| 481 0.4.3 - 9/27/2012 |
| 482 - Minor bugfix (0.4.2 doesn't load tackpy) |
| 483 0.4.2 - 9/25/2012 |
| 484 - Updated TACK (compatible with tackpy 0.9.9) |
| 485 0.4.1 - 5/22/2012 |
| 486 - Fixed RSA padding bugs (w/help from John Randolph) |
| 487 - Updated TACK (compatible with tackpy 0.9.7) |
| 488 - Added SNI |
| 489 - Added NPN server support (Sam Rushing/Google) |
| 490 - Added AnonDH (Dimitris Moraitis) |
| 491 - Added X509CertChain.parsePemList |
| 492 - Improved XML-RPC (Kees Bos) |
| 594 | 493 |
| 595 from twisted.internet.protocol import Protocol, Factory | 494 0.4.0 - 2/11/2012 |
| 596 from twisted.internet import reactor | 495 - Fixed pycrypto support |
| 597 from twisted.protocols.policies import WrappingFactory | 496 - Fixed python 2.6 problems |
| 598 from twisted.protocols.basic import LineReceiver | 497 |
| 599 from twisted.python import log | 498 0.3.9.x - 2/7/2012 |
| 600 from twisted.python.failure import Failure | |
| 601 import sys | |
| 602 from tlslite.api import * | |
| 603 | 499 |
| 604 s = open("./serverX509Cert.pem").read() | 500 Much code cleanup, in particular decomposing the handshake functions so they |
| 605 x509 = X509() | 501 are readable. The main new feature is support for TACK, an experimental |
| 606 x509.parse(s) | 502 authentication method that provides a new way to pin server certificates (See |
| 607 certChain = X509CertChain([x509]) | 503 https://github.com/moxie0/Convergence/wiki/TACK ). |
| 608 | 504 |
| 609 s = open("./serverX509Key.pem").read() | 505 Also: |
| 610 privateKey = parsePEMKey(s, private=True) | |
| 611 | 506 |
| 612 verifierDB = VerifierDB("verifierDB") | 507 - Security Fixes |
| 613 verifierDB.open() | 508 - Sends SCSV ciphersuite as per RFC 5746, to signal non-renegotiated |
| 509 Client Hello. Does not support renegotiation (never has). |
| 510 - Change from e=3 to e=65537 for generated RSA keys, not strictly |
| 511 necessary but mitigates risk of sloppy verifier. |
| 512 - 1/(n-1) countermeasure for BEAST. |
| 614 | 513 |
| 615 class Echo(LineReceiver): | 514 - Behavior changes: |
| 616 def connectionMade(self): | 515 - Split cmdline into tls.py and tlstest.py, improved options. |
| 617 self.transport.write("Welcome to the echo server!\r\n") | 516 - Formalized LICENSE. |
| 517 - Defaults to closing socket after sending close_notify, fixes hanging. |
| 518 problem that would occur sometime when waiting for other party's |
| 519 close_notify. |
| 520 - Update SRP to RFC 5054 compliance. |
| 521 - Removed client handshake "callbacks", no longer support the SRP |
| 522 re-handshake idiom within a single handshake function. |
| 618 | 523 |
| 619 def lineReceived(self, line): | 524 - Bugfixes |
| 620 self.transport.write(line + "\r\n") | 525 - Added hashlib support, removes Deprecation Warning due to sha and md5. |
| 526 - Handled GeneratorExit exceptions that are a new Python feature, and |
| 527 interfere with the async code if not handled. |
| 528 |
| 529 - Removed: |
| 530 - Shared keys (it was based on an ancient I-D, not TLS-PSK). |
| 531 - cryptlib support, it wasn't used much, we have enough other options. |
| 532 - cryptoIDs (TACK is better). |
| 533 - win32prng extension module, as os.urandom is now available. |
| 534 - Twisted integration (unused?, slowed down loading). |
| 535 - Jython code (ancient, didn't work). |
| 536 - Compat support for python versions < 2.7. |
| 621 | 537 |
| 622 class Echo1(Echo): | 538 - Additions |
| 623 def connectionMade(self): | 539 - Support for TACK via TACKpy. |
| 624 if not self.transport.tlsStarted: | 540 - Support for CertificateRequest.certificate_authorities ("reqCAs") |
| 625 self.transport.setServerHandshakeOp(certChain=certChain, | 541 - Added TLSConnection.shutdown() to better mimic socket. |
| 626 privateKey=privateKey, | 542 - Enabled Session resumption for XMLRPCTransport. |
| 627 verifierDB=verifierDB) | |
| 628 else: | |
| 629 Echo.connectionMade(self) | |
| 630 | 543 |
| 631 def connectionLost(self, reason): | |
| 632 pass #Handle any TLS exceptions here | |
| 633 | |
| 634 class Echo2(Echo): | |
| 635 def lineReceived(self, data): | |
| 636 if data == "STARTTLS": | |
| 637 self.transport.setServerHandshakeOp(certChain=certChain, | |
| 638 privateKey=privateKey, | |
| 639 verifierDB=verifierDB) | |
| 640 else: | |
| 641 Echo.lineReceived(self, data) | |
| 642 | |
| 643 def connectionLost(self, reason): | |
| 644 pass #Handle any TLS exceptions here | |
| 645 | |
| 646 factory = Factory() | |
| 647 factory.protocol = Echo1 | |
| 648 #factory.protocol = Echo2 | |
| 649 | |
| 650 wrappingFactory = WrappingFactory(factory) | |
| 651 wrappingFactory.protocol = TLSTwistedProtocolWrapper | |
| 652 | |
| 653 log.startLogging(sys.stdout) | |
| 654 reactor.listenTCP(1079, wrappingFactory) | |
| 655 reactor.run() | |
| 656 | |
| 657 | |
| 658 13 Security Considerations | |
| 659 =========================== | |
| 660 TLS Lite is beta-quality code. It hasn't received much security analysis. | |
| 661 Use at your own risk. | |
| 662 | |
| 663 | |
| 664 14 History | |
| 665 =========== | |
| 666 0.3.8 - 2/21/2005 | 544 0.3.8 - 2/21/2005 |
| 667 - Added support for poplib, imaplib, and smtplib | 545 - Added support for poplib, imaplib, and smtplib |
| 668 - Added python 2.4 windows installer | 546 - Added python 2.4 windows installer |
| 669 - Fixed occassional timing problems with test suite | 547 - Fixed occassional timing problems with test suite |
| 670 0.3.7 - 10/05/2004 | 548 0.3.7 - 10/05/2004 |
| 671 - Added support for Python 2.2 | 549 - Added support for Python 2.2 |
| 672 - Cleaned up compatibility code, and docs, a bit | 550 - Cleaned up compatibility code, and docs, a bit |
| 673 0.3.6 - 9/28/2004 | 551 0.3.6 - 9/28/2004 |
| 674 - Fixed script installation on UNIX | 552 - Fixed script installation on UNIX |
| 675 - Give better error message on old Python versions | 553 - Give better error message on old Python versions |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 - fixed server when it has a key, but client selects plain SRP | 644 - fixed server when it has a key, but client selects plain SRP |
| 767 - fixed server to postpone errors until it has read client's messages | 645 - fixed server to postpone errors until it has read client's messages |
| 768 - fixed ServerHello to only include extension data if necessary | 646 - fixed ServerHello to only include extension data if necessary |
| 769 0.1.1 - 2/02/2004 | 647 0.1.1 - 2/02/2004 |
| 770 - fixed close_notify behavior | 648 - fixed close_notify behavior |
| 771 - fixed handling of empty application data packets | 649 - fixed handling of empty application data packets |
| 772 - fixed socket reads to not consume extra bytes | 650 - fixed socket reads to not consume extra bytes |
| 773 - added testing functions to tls.py | 651 - added testing functions to tls.py |
| 774 0.1.0 - 2/01/2004 | 652 0.1.0 - 2/01/2004 |
| 775 - first release | 653 - first release |
| 776 | |
| 777 | |
| 778 15 References | |
| 779 ============== | |
| 780 [0] http://www.ietf.org/html.charters/tls-charter.html | |
| 781 [1] http://www.trevp.net/tls_srp/draft-ietf-tls-srp-07.html | |
| 782 [2] http://www.ietf.org/internet-drafts/draft-ietf-tls-sharedkeys-02.txt | |
| 783 [3] http://www.trevp.net/cryptoID/ | |
| 784 [4] http://www.openssl.org/ | |
| 785 [5] http://www.cs.auckland.ac.nz/~pgut001/cryptlib/ | |
| 786 [6] http://sandbox.rulemaker.net/ngps/m2/ | |
| 787 [7] http://trevp.net/cryptlibConverter/ | |
| 788 [8] http://www.trevp.net/cryptoID/ | |
| 789 [9] http://www.amk.ca/python/code/crypto.html | |
| 790 [10] http://gmpy.sourceforge.net/ | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| OLD | NEW |