コード例 #1
0
 def _scrape(self, query):
     """ Make an HTTP GET request to the tracker
         Note: This runs in its own thread.
     """
     self.spath = "/scrape"
     if not self.https:
         log.warning("Warning: Will not connect to non HTTPS server")
         return
     try:
         if self.proxy_url:
             h = ProxyHTTPSConnection(self.proxy_url, \
                                      username=self.proxy_username, \
                                      password=self.proxy_password, \
                                      ssl_context=self.ssl_ctx)
             s = "https://%s:%d%s%s" % (self.url, self.remote_port, self.spath, query)
             h.putrequest('GET', s)
         else:
             #No proxy url, use normal connection
             h = HTTPSConnection(self.url, self.remote_port, ssl_context=self.ssl_ctx)
             h.putrequest('GET', self.spath+query)
         h.endheaders()
         resp = h.getresponse()
         data = resp.read()
         resp.close()
         h.close()
         h = None
     # urllib2 can raise various crap that doesn't have a common base
     # exception class especially when proxies are used, at least
     # ValueError and stuff from httplib
     except Exception, g:
         def f(r='Problem connecting to ' + self.url + ':  ' + str(g)):
             self._postrequest(errormsg=r)
コード例 #2
0
ファイル: m2crypto.py プロジェクト: chaosphere2112/ndg_saml
 def __init__(self, *args, **kw):
     '''Overload to enable setting of post connection check
     callback to SSL.Connection
     
     type *args: tuple
     param *args: args which apply to M2Crypto.httpslib.HTTPSConnection
     type **kw: dict
     param **kw: additional keywords
     :type postConnectionCheck: SSL.Checker.Checker derivative
     :keyword postConnectionCheck: set class for checking peer
     :type readTimeout: M2Crypto.SSL.timeout
     :keyword readTimeout: readTimeout - set timeout for read
     :type writeTimeout: M2Crypto.SSL.timeout
     :keyword writeTimeout: similar to read timeout'''
     
     self._postConnectionCheck = kw.pop('postConnectionCheck',
                                        SSL.Checker.Checker)
     
     if 'readTimeout' in kw:
         if not isinstance(kw['readTimeout'], SSL.timeout):
             raise AttributeError("readTimeout must be of type "
                                  "M2Crypto.SSL.timeout")
         self.readTimeout = kw.pop('readTimeout')
     else:
         self.readTimeout = HTTPSConnection.defReadTimeout
           
     if 'writeTimeout' in kw:
         if not isinstance(kw['writeTimeout'], SSL.timeout):
             raise AttributeError("writeTimeout must be of type "
                                  "M2Crypto.SSL.timeout") 
         self.writeTimeout = kw.pop('writeTimeout')
     else:
         self.writeTimeout = HTTPSConnection.defWriteTimeout
 
     self._clntCertFilePath = kw.pop('clntCertFilePath', None)
     self._clntPriKeyFilePath = kw.pop('clntPriKeyFilePath', None)
     
     _HTTPSConnection.__init__(self, *args, **kw)
     
     # load up certificate stuff
     if (self._clntCertFilePath is not None and 
         self._clntPriKeyFilePath is not None):
         self.ssl_ctx.load_cert(self._clntCertFilePath, 
                                self._clntPriKeyFilePath)
コード例 #3
0
 def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
     #putrequest is called before connect, so can interpret url and get
     #real host/port to be used to make CONNECT request to proxy
     log.warning("Using ProxyHTTPSConnection")
     proto, rest = urllib.splittype(url)
     if proto is None:
         raise ValueError, "unknown URL type: %s" % url
     #get host
     host, rest = urllib.splithost(rest)
     #try to get port
     host, port = urllib.splitport(host)
     #if port is not defined try to get from proto
     if port is None:
         try:
             port = self._ports[proto]
         except KeyError:
             raise ValueError, "unknown protocol for: %s" % url
     self._real_host = host
     self._real_port = int(port) #This whole class exists for this line :/
     HTTPSConnection.putrequest(self, method, url, skip_host, skip_accept_encoding)
コード例 #4
0
ファイル: wesabe.py プロジェクト: dsedivec/wesabe-downloader
    def request(self, path):
        # A little non-SSL test code commented out, for when you just
        # want to see what the request looks like (for example).
        #from httplib import HTTPConnection
        #conn = HTTPConnection("localhost", 4242)
        conn = HTTPSConnection("www.wesabe.com")

        headers = {'Authorization': "Basic " + self.encoded_credentials,
                   # Wesabe used to let you download OFX[2].  No
                   # longer since their site redesign.  Haven't seen
                   # movement from them on this.  The below fix was
                   # suggested, but had no effect.
                   #"Accept": "*/*; application/x-ofx; application/xml",
                   }
        conn.request("GET", path, headers=headers)
        response = conn.getresponse()
        if response.status != 200:
            print response.getheaders()
            print response.reason
            print response.msg
            raise Exception("request for %r returned status %r"
                            % (path, response.status))
        return response.read()
コード例 #5
0
 def _rerequest(self, query):
     """ Make an HTTP GET request to the tracker
         Note: This runs in its own thread.
     """
     log.info("Making announce to " + self.url + ":" + str(self.remote_port))
     if not self.https:
         log.warning("Warning: Will not connect to non HTTPS server")
         return
     try:
         if self.proxy_url:
             h = ProxyHTTPSConnection(self.proxy_url, \
                                      username=self.proxy_username, \
                                      password=self.proxy_password, \
                                      ssl_context=self.ssl_ctx)
             s = "https://%s:%d%s%s" % (self.url, self.remote_port, self.path, query)
             h.putrequest('GET', s)
             
             # I suggest that for now, until there is a better solution in python, 
             # that connections with socks proxies be done with:
             #  socat TCP4-LISTEN:5555,fork SOCKS4A:s,socksport=9050 
             #  or use Privoxy:
             #  127.0.0.1:8118
                                 
         else:
             #No proxy url, use normal connection
             h = HTTPSConnection(self.url, self.remote_port, ssl_context=self.ssl_ctx)
             h.putrequest('GET', self.path+query)
         h.endheaders()
         resp = h.getresponse()
         data = resp.read()
         resp.close()
         h.close()
         h = None
     # urllib2 can raise various crap that doesn't have a common base
     # exception class especially when proxies are used, at least
     # ValueError and stuff from httplib
     except Exception, g:
         def f(r='Problem connecting to ' + self.url + ':  ' + str(g)):
             self._postrequest(errormsg=r)
コード例 #6
0
        <samlp:AttributeQuery xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Version="2.0" IssueInstant="2010-10-22T10:32:07.585451Z" ID="bf152f2e-d00f-44a3-93ea-968445bbeb4a">
            <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Format="urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName">/O=STFC/OU=BADC/CN=Test</saml:Issuer>
            <saml:Subject xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
                <saml:NameID Format="urn:esg:openid">https://ceda.ac.uk/openid/Philip.Kershaw</saml:NameID>
            </saml:Subject>
            <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" FriendlyName="GroupRole" Name="urn:esg:group:role" NameFormat="groupRole"></saml:Attribute>
            <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" FriendlyName="LastName" Name="urn:esg:last:name" NameFormat="http://www.w3.org/2001/XMLSchema#string"></saml:Attribute>
            <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" FriendlyName="EmailAddress" Name="urn:esg:email:address" NameFormat="http://www.w3.org/2001/XMLSchema#string"></saml:Attribute>
            <saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" FriendlyName="FirstName" Name="urn:esg:first:name" NameFormat="http://www.w3.org/2001/XMLSchema#string"></saml:Attribute>
        </samlp:AttributeQuery>
    </soap11:Body>
</soap11:Envelope>
'''
ctx = SSL.Context()
ctx.load_verify_locations(capath=caDir)
ctx.set_verify(SSL.verify_peer, 9)
con = HTTPSConnection(hostname, ssl_context=ctx)
con.putrequest('POST', path)
con.putheader('Content-Type', 'text/xml')
con.putheader('Content-Length', str(len(body)))
con.endheaders()
con.send(body)
resp = con.getresponse()
print resp.read()

#con = HTTPSConnection(hostname)
#con.putrequest('GET', path)
#con.endheaders()
#resp = con.getresponse()
#print resp.read()
コード例 #7
0
ファイル: rpcproxy.py プロジェクト: pombreda/rmake-2
 def __init__(self, *args, **kwargs):
     self.ignoreCommonName = kwargs.pop('ignoreCommonName', False)
     HTTPSConnection.__init__(self, *args, **kwargs)
コード例 #8
0
ファイル: rpcproxy.py プロジェクト: pombreda/rmake3
 def __init__(self, *args, **kwargs):
     self.ignoreCommonName = kwargs.pop('ignoreCommonName', False)
     HTTPSConnection.__init__(self, *args, **kwargs)
コード例 #9
0
ファイル: m2crypto.py プロジェクト: chaosphere2112/ndg_saml
 def putrequest(self, method, url, **kw):
     '''Overload to work around bug with unicode type URL'''
     url = str(url)
     _HTTPSConnection.putrequest(self, method, url, **kw) 
コード例 #10
0
ファイル: m2helpers.py プロジェクト: dchang00/keekaa-back-end
 def factory(*args, **kwargs):
     return HTTPSConnection(ssl_context=secure_context(cafile=cafile,
                                                       capath=capath),
                            *args,
                            **kwargs)