示例#1
0
class SPNEGO_SSPI:
    def __init__(self, settings):
        self.mode = 'CLIENT'
        self.settings = settings
        self.sspi = None
        self.username = None
        self.password = None
        self.target = None

        self.setup()

    def setup(self):
        if 'mode' in self.settings:
            self.mode = self.settings['mode']

        if 'username' in self.settings:
            self.username = self.settings['username']
            if 'password' in self.settings:
                self.password = self.settings['password']

        if 'target' in self.settings:
            self.username = self.settings['target']

        self.sspi = NegotiateSSPI()
        self.sspi.authGSSClientInit(self.target, client_name=self.username)

    def get_session_key(self):
        return self.sspi.get_session_key()

    async def encrypt(self, data, message_no):
        return await self.sspi.encrypt(data, message_no)

    async def decrypt(self, data, message_no):
        return await self.sspi.decrypt(data, message_no)

    async def authenticate(self,
                           token,
                           flags=None,
                           seq_number=0,
                           is_rpc=False):
        try:
            if self.mode.upper() == 'CLIENT':
                res, data = self.sspi.authGSSClientStep(token)
                if res == SSPIResult.OK:
                    return data[0][1], True, None
                elif res == SSPIResult.CONTINUE:
                    return data[0][1], False, None
                else:
                    raise Exception('SSPI errors')

            else:
                raise Exception('SERVER is not supported now')
        except Exception as e:
            return None, None, e
            import traceback
            traceback.print_exc()
示例#2
0
    def setup(self):
        if 'mode' in self.settings:
            self.mode = self.settings['mode']

        if 'username' in self.settings:
            self.username = self.settings['username']
            if 'password' in self.settings:
                self.password = self.settings['password']

        if 'target' in self.settings:
            self.username = self.settings['target']

        self.sspi = NegotiateSSPI()
        self.sspi.authGSSClientInit(self.target, client_name=self.username)