1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gdata.tlslite.integration.TLSSocketServerMixIn</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="gdata.html"><font color="#ffffff">gdata</font></a>.<a href="gdata.tlslite.html"><font color="#ffffff">tlslite</font></a>.<a href="gdata.tlslite.integration.html"><font color="#ffffff">integration</font></a>.TLSSocketServerMixIn</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/afshar/wrk/gdata-python-client/src/gdata/tlslite/integration/TLSSocketServerMixIn.py">/home/afshar/wrk/gdata-python-client/src/gdata/tlslite/integration/TLSSocketServerMixIn.py</a></font></td></tr></table>
<p><tt>TLS Lite + SocketServer.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="gdata.tlslite.integration.TLSSocketServerMixIn.html#TLSSocketServerMixIn">TLSSocketServerMixIn</a>
</font></dt></dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="TLSSocketServerMixIn">class <strong>TLSSocketServerMixIn</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>This class can be mixed in with any L{SocketServer.TCPServer} to<br>
add TLS support.<br>
<br>
To use this class, define a new class that inherits from it and<br>
some L{SocketServer.TCPServer} (with the mix-in first). Then<br>
implement the <a href="#TLSSocketServerMixIn-handshake">handshake</a>() method, doing some sort of server<br>
handshake on the connection argument. If the handshake method<br>
returns True, the RequestHandler will be triggered. Below is a<br>
complete example of a threaded HTTPS server::<br>
<br>
from SocketServer import *<br>
from BaseHTTPServer import *<br>
from SimpleHTTPServer import *<br>
from tlslite.api import *<br>
<br>
s = open("./serverX509Cert.pem").read()<br>
x509 = X509()<br>
x509.parse(s)<br>
certChain = X509CertChain([x509])<br>
<br>
s = open("./serverX509Key.pem").read()<br>
privateKey = parsePEMKey(s, private=True)<br>
<br>
sessionCache = SessionCache()<br>
<br>
class MyHTTPServer(ThreadingMixIn, <a href="#TLSSocketServerMixIn">TLSSocketServerMixIn</a>,<br>
HTTPServer):<br>
def <a href="#TLSSocketServerMixIn-handshake">handshake</a>(self, tlsConnection):<br>
try:<br>
tlsConnection.handshakeServer(certChain=certChain,<br>
privateKey=privateKey,<br>
sessionCache=sessionCache)<br>
tlsConnection.ignoreAbruptClose = True<br>
return True<br>
except TLSError, error:<br>
print "Handshake failure:", str(error)<br>
return False<br>
<br>
httpd = MyHTTPServer(('localhost', 443), SimpleHTTPRequestHandler)<br>
httpd.serve_forever()<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="TLSSocketServerMixIn-finish_request"><strong>finish_request</strong></a>(self, sock, client_address)</dt></dl>
<dl><dt><a name="TLSSocketServerMixIn-handshake"><strong>handshake</strong></a>(self, tlsConnection)</dt><dd><tt>#Implement this method to do some form of handshaking. Return True<br>
#if the handshake finishes properly and the request is authorized.</tt></dd></dl>
</td></tr></table></td></tr></table>
</body></html>
|