def __get_token_gss(self): """ Sends a request to get an auth token from the server and stores it as a class attribute. Uses Kerberos authentication. :returns: True if the token was successfully received. False otherwise. """ if not EXTRA_MODULES['requests_kerberos']: raise MissingModuleException('The requests-kerberos module is not installed.') url = build_url(self.auth_host, path='auth/gss') result = self._send_request(url, get_token=True, auth=HTTPKerberosAuth()) if not result: self.logger.error('Cannot retrieve authentication token!') return False if result.status_code != codes.ok: # pylint: disable-msg=E1101 exc_cls, exc_msg = self._get_exception(headers=result.headers, status_code=result.status_code, data=result.content) raise exc_cls(exc_msg) self.auth_token = result.headers['x-rucio-auth-token'] return True
def __get_token_gss(self): """ Sends a request to get an auth token from the server and stores it as a class attribute. Uses Kerberos authentication. :returns: True if the token was successfully received. False otherwise. """ if not EXTRA_MODULES['requests_kerberos']: raise MissingModuleException('The requests-kerberos module is not installed.') headers = {'X-Rucio-Account': self.account, 'X-Rucio-VO': self.vo} url = build_url(self.auth_host, path='auth/gss') result = None for retry in range(self.AUTH_RETRIES + 1): try: result = self.session.get(url, headers=headers, verify=self.ca_cert, auth=HTTPKerberosAuth()) break except ConnectionError as error: LOG.error('ConnectionError: ' + str(error)) if retry > self.request_retries: raise if not result: LOG.error('Cannot retrieve authentication token!') return False if result.status_code != codes.ok: # pylint: disable-msg=E1101 exc_cls, exc_msg = self._get_exception(headers=result.headers, status_code=result.status_code, data=result.content) raise exc_cls(exc_msg) self.auth_token = result.headers['x-rucio-auth-token'] return True
def ssh_sign(private_key, message): """ Sign a string message using the private key. :param private_key: The SSH RSA private key as a string. :param message: The message to sign as a string. :return: Base64 encoded signature as a string. """ if not EXTRA_MODULES['paramiko']: raise MissingModuleException('The paramiko module is not installed or faulty.') sio_private_key = StringIO(private_key) priv_k = RSAKey.from_private_key(sio_private_key) sio_private_key.close() signature_stream = priv_k.sign_ssh_data(message) signature_stream.rewind() return base64.b64encode(signature_stream.get_remainder())