def authorize(self, sec_buffer_in): if sec_buffer_in is not None and type( sec_buffer_in) != win32security.PySecBufferDescType: # User passed us the raw data - wrap it into a SecBufferDesc sec_buffer_new = win32security.PySecBufferDescType() tokenbuf = win32security.PySecBufferType(self.pkg_info['MaxToken'], sspicon.SECBUFFER_TOKEN) tokenbuf.Buffer = sec_buffer_in sec_buffer_new.append(tokenbuf) sec_buffer_in = sec_buffer_new sec_buffer_out = win32security.PySecBufferDescType() tokenbuf = win32security.PySecBufferType(self.pkg_info['MaxToken'], sspicon.SECBUFFER_TOKEN) sec_buffer_out.append(tokenbuf) ## input context handle is None initially, then handle returned from last call thereafter ctxtin = self.ctxt if self.ctxt is None: self.ctxt = win32security.PyCtxtHandleType() err, attr, exp = win32security.AcceptSecurityContext( self.credentials, ctxtin, sec_buffer_in, self.scflags, self.datarep, self.ctxt, sec_buffer_out) # Stash these away incase someone needs to know the state from the # final call. self.ctxt_attr = attr self.ctxt_expiry = exp if err in (sspicon.SEC_I_COMPLETE_NEEDED, sspicon.SEC_I_COMPLETE_AND_CONTINUE): self.ctxt.CompleteAuthToken(sec_buffer_out) self.authenticated = err == 0 return err, sec_buffer_out
def authorize(self, sec_buffer_in): """Perform *one* step of the client authentication process. Pass None for the first round""" if (sec_buffer_in is not None and type(sec_buffer_in) != win32security.PySecBufferDescType): # User passed us the raw data - wrap it into a SecBufferDesc sec_buffer_new = win32security.PySecBufferDescType() tokenbuf = win32security.PySecBufferType(self.pkg_info["MaxToken"], sspicon.SECBUFFER_TOKEN) tokenbuf.Buffer = sec_buffer_in sec_buffer_new.append(tokenbuf) sec_buffer_in = sec_buffer_new sec_buffer_out = win32security.PySecBufferDescType() tokenbuf = win32security.PySecBufferType(self.pkg_info["MaxToken"], sspicon.SECBUFFER_TOKEN) sec_buffer_out.append(tokenbuf) ## input context handle should be NULL on first call ctxtin = self.ctxt if self.ctxt is None: self.ctxt = win32security.PyCtxtHandleType() err, attr, exp = win32security.InitializeSecurityContext( self.credentials, ctxtin, self.targetspn, self.scflags, self.datarep, sec_buffer_in, self.ctxt, sec_buffer_out, ) # Stash these away incase someone needs to know the state from the # final call. self.ctxt_attr = attr self.ctxt_expiry = exp if err in (sspicon.SEC_I_COMPLETE_NEEDED, sspicon.SEC_I_COMPLETE_AND_CONTINUE): self.ctxt.CompleteAuthToken(sec_buffer_out) self.authenticated = err == 0 if self.authenticated: self._amend_ctx_name() return err, sec_buffer_out