<s> """<STR_LIT>""" <EOL> from SimpleXMLRPCServer import SimpleXMLRPCServer <EOL> from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler <EOL> import ssl <EOL> import base64 <EOL> import textwrap <EOL> class SecureXMLRPCRequestHandler ( SimpleXMLRPCRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def setup ( self ) : <EOL> SimpleXMLRPCRequestHandler . setup ( self ) <EOL> self . server . peercert = self . request . getpeercert ( ) <EOL> self . server . der_cert = self . request . getpeercert ( binary_form = True ) <EOL> self . server . pem_cert = self . der_to_pem ( self . server . der_cert ) <EOL> def finish ( self ) : <EOL> self . server . peercert = None <EOL> SimpleXMLRPCRequestHandler . finish ( self ) <EOL> def der_to_pem ( self , der_cert_bytes ) : <EOL> "<STR_LIT>" <EOL> f = base64 . standard_b64encode ( der_cert_bytes ) <EOL> return ( ssl . PEM_HEADER + '<STR_LIT:\n>' + <EOL> textwrap . fill ( f , <NUM_LIT:64> ) + <EOL> '<STR_LIT:\n>' + ssl . PEM_FOOTER + '<STR_LIT:\n>' ) <EOL> class SecureXMLRPCServer ( SimpleXMLRPCServer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , addr , requestHandler = SecureXMLRPCRequestHandler , <EOL> logRequests = False , allow_none = False , encoding = None , <EOL> bind_and_activate = True , keyfile = None , certfile = None , <EOL> ca_certs = None ) : <EOL> SimpleXMLRPCServer . __init__ ( self , addr , requestHandler , logRequests , <EOL> allow_none , encoding , False ) <EOL> if keyfile and certfile and ca_certs : <EOL> self . socket = ssl . wrap_socket ( self . socket , <EOL> keyfile = keyfile , <EOL> certfile = certfile , <EOL> server_side = True , <EOL> cert_reqs = ssl . CERT_REQUIRED , <EOL> ssl_version = ssl . PROTOCOL_SSLv23 , <EOL> ca_certs = ca_certs ) <EOL> if bind_and_activate : <EOL> self . server_bind ( ) <EOL> self . server_activate ( ) </s>
