def get(self, environ, url): """Makes a HTTP request to the specified URL using the certificate obtained from the WSGI environ. @type environ: dict @param environ: WSGI environ @type url: basestring @param url: URL of resource to request @rtype: basestring @return: response from HTTP request """ current_token = environ.get(self.token_env_key) if current_token: log.debug("Token ID: %s", current_token) else: log.debug("No token found with environ key: %s", self.token_env_key) if self.token != current_token or not self.user_ssl_context: log.debug("Certificate request needed") if current_token: self.token = current_token # Get credential. log.debug("Making certificate request") (private_key, certificate) = certificate_request.request_certificate( self.token, self.resource_server_url, self.client_ssl_config, self.certificate_request_parameter) # Create SSL context using the resource owner's delegated # credential. self.user_ssl_context = ssl_context_util.make_ssl_context( None, None, self.ca_cert_file, self.ca_dir, True) clientKey = crypto.load_privatekey(crypto.FILETYPE_PEM, private_key) clientCert = crypto.load_certificate(crypto.FILETYPE_PEM, certificate) self.user_ssl_context.use_privatekey(clientKey) self.user_ssl_context.use_certificate(clientCert) log.debug("Created new SSL context") else: log.warn("Certificate needed but no token available") config = httpsclientutils.Configuration(self.user_ssl_context, True) log.debug("Making request to URL: %s", url) response = httpsclientutils.fetch_from_url(url, config) return response
def get(self, environ, url): """Makes a HTTP request to the specified URL using the certificate obtained from the WSGI environ. @type environ: dict @param environ: WSGI environ @type url: basestring @param url: URL of resource to request @rtype: basestring @return: response from HTTP request """ current_token = environ.get(self.token_env_key) if current_token: log.debug("Token ID: %s", current_token) else: log.debug("No token found with environ key: %s", self.token_env_key) if self.token != current_token or not self.user_ssl_context: log.debug("Certificate request needed") if current_token: self.token = current_token # Get credential. log.debug("Making certificate request") (private_key, certificate) = certificate_request.request_certificate( self.token, self.resource_server_url, self.client_ssl_config, self.certificate_request_parameter ) # Create SSL context using the resource owner's delegated # credential. self.user_ssl_context = ssl_context_util.make_ssl_context( None, None, self.ca_cert_file, self.ca_dir, True ) clientKey = crypto.load_privatekey(crypto.FILETYPE_PEM, private_key) clientCert = crypto.load_certificate(crypto.FILETYPE_PEM, certificate) self.user_ssl_context.use_privatekey(clientKey) self.user_ssl_context.use_certificate(clientCert) log.debug("Created new SSL context") else: log.warn("Certificate needed but no token available") config = httpsclientutils.Configuration(self.user_ssl_context, True) log.debug("Making request to URL: %s", url) response = httpsclientutils.fetch_from_url(url, config) return response
def _getAttributeService(self, subject): """ @type subject: basestring @param subject: subject for which the query is to be made @rtype: basestring @return: URL of attribute service """ if not self._isHttpUrl(subject): log.debug( "Subject is not a HTTP URL - not making Yadis request to" " obtain attribute service: %s", subject) return None try: log.debug( "Making Yadis request to obtain attribute service for" " subject %s", subject) xrdsStr = httpsclient_utils.fetch_from_url(subject, self._httpsClientConfig) except Exception, exc: log.error( "Unable to determine attribute service for subject %s: %s", subject, exc.__str__()) return None
def test02_fetch_from_url(self): config = Configuration(SSL.Context(SSL.TLSv1_METHOD), True) res = fetch_from_url(Constants.TEST_URI, config) self.assertTrue(res)