def make_GSS_authentication(self):
    try:
        import kerberos
    except ImportError as e:
        raise errors.ConnectionError("{}\nCannot make a Kerberos authentication because no Kerberos package is installed. Get it with 'pip install kerberos'.".format(str(e)))
    gssflag = (((kerberos.GSS_C_DELEG_FLAG | kerberos.GSS_C_MUTUAL_FLAG) | kerberos.GSS_C_SEQUENCE_FLAG) | kerberos.GSS_C_REPLAY_FLAG)
    service_principal = '{}@{}'.format(self.options['kerberos_service_name'], self.options['kerberos_host_name'])
    self._logger.info('Initializing a context for GSSAPI client-side authentication with service principal {}'.format(service_principal))
    try:
        (result, context) = kerberos.authGSSClientInit(service_principal, gssflags=gssflag)
    except kerberos.GSSError as err:
        msg = 'GSSAPI initialization error: {}'.format(str(err))
        self._logger.error(msg)
        raise errors.KerberosError(msg)
    if (result != kerberos.AUTH_GSS_COMPLETE):
        msg = 'Failed to initialize a context for GSSAPI client-side authentication with service principal {}'.format(service_principal)
        self._logger.error(msg)
        raise errors.KerberosError(msg)
    try:
        challenge = b''
        while True:
            self._logger.info('Processing a single GSSAPI client-side step')
            challenge = base64.b64encode(challenge).decode('utf-8')
            result = kerberos.authGSSClientStep(context, challenge)
            if (result == kerberos.AUTH_GSS_COMPLETE):
                self._logger.info('Result: GSSAPI step complete')
                break
            elif (result == kerberos.AUTH_GSS_CONTINUE):
                self._logger.info('Result: GSSAPI step continuation')
                response = kerberos.authGSSClientResponse(context)
                challenge = self.send_GSS_response_and_receive_challenge(response)
            else:
                msg = 'GSSAPI client-side step error status {}'.format(result)
                self._logger.error(msg)
                raise errors.KerberosError(msg)
    except kerberos.GSSError as err:
        msg = 'GSSAPI client-side step error: {}'.format(str(err))
        self._logger.error(msg)
        raise errors.KerberosError(msg)
def make_GSS_authentication(self):
    try:
        import kerberos
    except ImportError as e:
        raise errors.ConnectionError("{}\nCannot make a Kerberos authentication because no Kerberos package is installed. Get it with 'pip install kerberos'.".format(str(e)))
    gssflag = (((kerberos.GSS_C_DELEG_FLAG | kerberos.GSS_C_MUTUAL_FLAG) | kerberos.GSS_C_SEQUENCE_FLAG) | kerberos.GSS_C_REPLAY_FLAG)
    service_principal = '{}@{}'.format(self.options['kerberos_service_name'], self.options['kerberos_host_name'])
    self._logger.info('Initializing a context for GSSAPI client-side authentication with service principal {}'.format(service_principal))
    try:
        (result, context) = kerberos.authGSSClientInit(service_principal, gssflags=gssflag)
    except kerberos.GSSError as err:
        msg = 'GSSAPI initialization error: {}'.format(str(err))
        self._logger.error(msg)
        raise errors.KerberosError(msg)
    if (result != kerberos.AUTH_GSS_COMPLETE):
        msg = 'Failed to initialize a context for GSSAPI client-side authentication with service principal {}'.format(service_principal)
        self._logger.error(msg)
        raise errors.KerberosError(msg)
    try:
        challenge = b
        while True:
            self._logger.info('Processing a single GSSAPI client-side step')
            challenge = base64.b64encode(challenge).decode('utf-8')
            result = kerberos.authGSSClientStep(context, challenge)
            if (result == kerberos.AUTH_GSS_COMPLETE):
                self._logger.info('Result: GSSAPI step complete')
                break
            elif (result == kerberos.AUTH_GSS_CONTINUE):
                self._logger.info('Result: GSSAPI step continuation')
                response = kerberos.authGSSClientResponse(context)
                challenge = self.send_GSS_response_and_receive_challenge(response)
            else:
                msg = 'GSSAPI client-side step error status {}'.format(result)
                self._logger.error(msg)
                raise errors.KerberosError(msg)
    except kerberos.GSSError as err:
        msg = 'GSSAPI client-side step error: {}'.format(str(err))
        self._logger.error(msg)
        raise errors.KerberosError(msg)