| OLD | NEW |
| 1 # Authors: |
| 2 # Trevor Perrin |
| 3 # Martin von Loewis - python 3 port |
| 4 # |
| 5 # See the LICENSE file for legal information regarding use of this file. |
| 6 |
| 1 """TLS Lite + asyncore.""" | 7 """TLS Lite + asyncore.""" |
| 2 | 8 |
| 3 | 9 |
| 4 import asyncore | 10 import asyncore |
| 5 from tlslite.tlsconnection import TLSConnection | 11 from tlslite.tlsconnection import TLSConnection |
| 6 from asyncstatemachine import AsyncStateMachine | 12 from .asyncstatemachine import AsyncStateMachine |
| 7 | 13 |
| 8 | 14 |
| 9 class TLSAsyncDispatcherMixIn(AsyncStateMachine): | 15 class TLSAsyncDispatcherMixIn(AsyncStateMachine): |
| 10 """This class can be "mixed in" with an | 16 """This class can be "mixed in" with an |
| 11 L{asyncore.dispatcher} to add TLS support. | 17 L{asyncore.dispatcher} to add TLS support. |
| 12 | 18 |
| 13 This class essentially sits between the dispatcher and the select | 19 This class essentially sits between the dispatcher and the select |
| 14 loop, intercepting events and only calling the dispatcher when | 20 loop, intercepting events and only calling the dispatcher when |
| 15 applicable. | 21 applicable. |
| 16 | 22 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 dispatcher might not read all the bytes from the TLS layer, | 40 dispatcher might not read all the bytes from the TLS layer, |
| 35 leaving some bytes in limbo. | 41 leaving some bytes in limbo. |
| 36 | 42 |
| 37 3. IE seems to have a problem receiving a whole HTTP response in a | 43 3. IE seems to have a problem receiving a whole HTTP response in a |
| 38 single TLS record, so HTML pages containing '\\r\\n\\r\\n' won't | 44 single TLS record, so HTML pages containing '\\r\\n\\r\\n' won't |
| 39 be displayed on IE. | 45 be displayed on IE. |
| 40 | 46 |
| 41 Add the following text into 'start_medusa.py', in the 'HTTP Server' | 47 Add the following text into 'start_medusa.py', in the 'HTTP Server' |
| 42 section:: | 48 section:: |
| 43 | 49 |
| 44 from tlslite.api import * | 50 from tlslite import * |
| 45 s = open("./serverX509Cert.pem").read() | 51 s = open("./serverX509Cert.pem").read() |
| 46 x509 = X509() | 52 x509 = X509() |
| 47 x509.parse(s) | 53 x509.parse(s) |
| 48 certChain = X509CertChain([x509]) | 54 certChain = X509CertChain([x509]) |
| 49 | 55 |
| 50 s = open("./serverX509Key.pem").read() | 56 s = open("./serverX509Key.pem").read() |
| 51 privateKey = parsePEMKey(s, private=True) | 57 privateKey = parsePEMKey(s, private=True) |
| 52 | 58 |
| 53 class http_tls_channel(TLSAsyncDispatcherMixIn, | 59 class http_tls_channel(TLSAsyncDispatcherMixIn, |
| 54 http_server.http_channel): | 60 http_server.http_channel): |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 136 |
| 131 def send(self, writeBuffer): | 137 def send(self, writeBuffer): |
| 132 self.setWriteOp(writeBuffer) | 138 self.setWriteOp(writeBuffer) |
| 133 return len(writeBuffer) | 139 return len(writeBuffer) |
| 134 | 140 |
| 135 def close(self): | 141 def close(self): |
| 136 if hasattr(self, "tlsConnection"): | 142 if hasattr(self, "tlsConnection"): |
| 137 self.setCloseOp() | 143 self.setCloseOp() |
| 138 else: | 144 else: |
| 139 asyncore.dispatcher.close(self) | 145 asyncore.dispatcher.close(self) |
| OLD | NEW |