home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / gdata / tlslite / integration / HTTPTLSConnection.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  7.3 KB  |  158 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''TLS Lite + httplib.'''
  5. import socket
  6. import httplib
  7. from gdata.tlslite.TLSConnection import TLSConnection
  8. from gdata.tlslite.integration.ClientHelper import ClientHelper
  9.  
  10. class HTTPBaseTLSConnection(httplib.HTTPConnection):
  11.     '''This abstract class provides a framework for adding TLS support
  12.     to httplib.'''
  13.     default_port = 443
  14.     
  15.     def __init__(self, host, port = None, strict = None):
  16.         if strict == None:
  17.             httplib.HTTPConnection.__init__(self, host, port)
  18.         else:
  19.             httplib.HTTPConnection.__init__(self, host, port, strict)
  20.  
  21.     
  22.     def connect(self):
  23.         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  24.         if hasattr(sock, 'settimeout'):
  25.             sock.settimeout(10)
  26.         
  27.         sock.connect((self.host, self.port))
  28.         self.sock = TLSConnection(sock)
  29.         self.sock.closeSocket = True
  30.         self._handshake(self.sock)
  31.  
  32.     
  33.     def _handshake(self, tlsConnection):
  34.         '''Called to perform some sort of handshake.
  35.  
  36.         This method must be overridden in a subclass to do some type of
  37.         handshake.  This method will be called after the socket has
  38.         been connected but before any data has been sent.  If this
  39.         method does not raise an exception, the TLS connection will be
  40.         considered valid.
  41.  
  42.         This method may (or may not) be called every time an HTTP
  43.         request is performed, depending on whether the underlying HTTP
  44.         connection is persistent.
  45.  
  46.         @type tlsConnection: L{tlslite.TLSConnection.TLSConnection}
  47.         @param tlsConnection: The connection to perform the handshake
  48.         on.
  49.         '''
  50.         raise NotImplementedError()
  51.  
  52.  
  53.  
  54. class HTTPTLSConnection(HTTPBaseTLSConnection, ClientHelper):
  55.     '''This class extends L{HTTPBaseTLSConnection} to support the
  56.     common types of handshaking.'''
  57.     
  58.     def __init__(self, host, port = None, username = None, password = None, sharedKey = None, certChain = None, privateKey = None, cryptoID = None, protocol = None, x509Fingerprint = None, x509TrustList = None, x509CommonName = None, settings = None):
  59.         """Create a new HTTPTLSConnection.
  60.  
  61.         For client authentication, use one of these argument
  62.         combinations:
  63.          - username, password (SRP)
  64.          - username, sharedKey (shared-key)
  65.          - certChain, privateKey (certificate)
  66.  
  67.         For server authentication, you can either rely on the
  68.         implicit mutual authentication performed by SRP or
  69.         shared-keys, or you can do certificate-based server
  70.         authentication with one of these argument combinations:
  71.          - cryptoID[, protocol] (requires cryptoIDlib)
  72.          - x509Fingerprint
  73.          - x509TrustList[, x509CommonName] (requires cryptlib_py)
  74.  
  75.         Certificate-based server authentication is compatible with
  76.         SRP or certificate-based client authentication.  It is
  77.         not compatible with shared-keys.
  78.  
  79.         The constructor does not perform the TLS handshake itself, but
  80.         simply stores these arguments for later.  The handshake is
  81.         performed only when this class needs to connect with the
  82.         server.  Thus you should be prepared to handle TLS-specific
  83.         exceptions when calling methods inherited from
  84.         L{httplib.HTTPConnection} such as request(), connect(), and
  85.         send().  See the client handshake functions in
  86.         L{tlslite.TLSConnection.TLSConnection} for details on which
  87.         exceptions might be raised.
  88.  
  89.         @type host: str
  90.         @param host: Server to connect to.
  91.  
  92.         @type port: int
  93.         @param port: Port to connect to.
  94.  
  95.         @type username: str
  96.         @param username: SRP or shared-key username.  Requires the
  97.         'password' or 'sharedKey' argument.
  98.  
  99.         @type password: str
  100.         @param password: SRP password for mutual authentication.
  101.         Requires the 'username' argument.
  102.  
  103.         @type sharedKey: str
  104.         @param sharedKey: Shared key for mutual authentication.
  105.         Requires the 'username' argument.
  106.  
  107.         @type certChain: L{tlslite.X509CertChain.X509CertChain} or
  108.         L{cryptoIDlib.CertChain.CertChain}
  109.         @param certChain: Certificate chain for client authentication.
  110.         Requires the 'privateKey' argument.  Excludes the SRP or
  111.         shared-key related arguments.
  112.  
  113.         @type privateKey: L{tlslite.utils.RSAKey.RSAKey}
  114.         @param privateKey: Private key for client authentication.
  115.         Requires the 'certChain' argument.  Excludes the SRP or
  116.         shared-key related arguments.
  117.  
  118.         @type cryptoID: str
  119.         @param cryptoID: cryptoID for server authentication.  Mutually
  120.         exclusive with the 'x509...' arguments.
  121.  
  122.         @type protocol: str
  123.         @param protocol: cryptoID protocol URI for server
  124.         authentication.  Requires the 'cryptoID' argument.
  125.  
  126.         @type x509Fingerprint: str
  127.         @param x509Fingerprint: Hex-encoded X.509 fingerprint for
  128.         server authentication.  Mutually exclusive with the 'cryptoID'
  129.         and 'x509TrustList' arguments.
  130.  
  131.         @type x509TrustList: list of L{tlslite.X509.X509}
  132.         @param x509TrustList: A list of trusted root certificates.  The
  133.         other party must present a certificate chain which extends to
  134.         one of these root certificates.  The cryptlib_py module must be
  135.         installed to use this parameter.  Mutually exclusive with the
  136.         'cryptoID' and 'x509Fingerprint' arguments.
  137.  
  138.         @type x509CommonName: str
  139.         @param x509CommonName: The end-entity certificate's 'CN' field
  140.         must match this value.  For a web server, this is typically a
  141.         server name such as 'www.amazon.com'.  Mutually exclusive with
  142.         the 'cryptoID' and 'x509Fingerprint' arguments.  Requires the
  143.         'x509TrustList' argument.
  144.  
  145.         @type settings: L{tlslite.HandshakeSettings.HandshakeSettings}
  146.         @param settings: Various settings which can be used to control
  147.         the ciphersuites, certificate types, and SSL/TLS versions
  148.         offered by the client.
  149.         """
  150.         HTTPBaseTLSConnection.__init__(self, host, port)
  151.         ClientHelper.__init__(self, username, password, sharedKey, certChain, privateKey, cryptoID, protocol, x509Fingerprint, x509TrustList, x509CommonName, settings)
  152.  
  153.     
  154.     def _handshake(self, tlsConnection):
  155.         ClientHelper._handshake(self, tlsConnection)
  156.  
  157.  
  158.