def _auth_OK(self, line): line = line.strip() if not line: raise DBusAuthenticationFailed('Missing guid in OK message') try: self.guid = binascii.unhexlify( line ) except: raise DBusAuthenticationFailed('Invalid guid in OK message') else: self.sendAuthMessage('BEGIN') self.authenticated = True
def _auth_OK(self, line): line = line.strip() if not line: raise DBusAuthenticationFailed('Missing guid in OK message') try: self.guid = binascii.unhexlify(line) except BaseException: raise DBusAuthenticationFailed('Invalid guid in OK message') else: if self.unixFDSupport: self.sendAuthMessage(b'NEGOTIATE_UNIX_FD') else: self.sendAuthMessage(b'BEGIN') self.authenticated = True
def _auth_BEGIN(self, line): if self.state == 'WaitingForBegin': self.authenticated = True self.guid = self.current_mech.getUserName() self.current_mech = None else: raise DBusAuthenticationFailed('Protocol violation')
def _auth_AGREE_UNIX_FD(self, line): if self.unixFDSupport: self.sendAuthMessage(b'BEGIN') self.authenticated = True else: raise DBusAuthenticationFailed( 'AGREE_UNIX_FD with no NEGOTIATE_UNIX_FD', )
def reject(self): if self.current_mech: self.current_mech.cancel() self.current_mech = None self.reject_count += 1 if self.reject_count > self.MAX_REJECTS_ALLOWED: raise DBusAuthenticationFailed('Client exceeded maximum failed authentication attempts') self.sendAuthMessage(self.reject_msg) self.state = 'WaitingForAuth'
def handleAuthMessage(self, line): if not ' ' in line: cmd = line args = '' else: cmd, args = line.split(' ',1) m = getattr(self, '_auth_' + cmd, None) if m: m( args ) else: raise DBusAuthenticationFailed('Invalid DBus authentcation protocol message: ' + line)
def handleAuthMessage(self, line): if b' ' not in line: cmd = line args = b'' else: cmd, args = line.split(b' ', 1) m = getattr(self, '_auth_' + cmd.decode(), None) if m: m(args) else: raise DBusAuthenticationFailed( 'Invalid DBus authentication protocol message: ' + line.decode("ascii", "replace"))
def authTryNextMethod(self): """ Tries the next authentication method or raises a failure if all mechanisms have been tried. """ if not self.authOrder: raise DBusAuthenticationFailed() self.authMech = self.authOrder.pop() if self.authMech == 'DBUS_COOKIE_SHA1': self.sendAuthMessage('AUTH ' + self.authMech + ' ' + binascii.hexlify(getpass.getuser())) else: self.sendAuthMessage('AUTH ' + self.authMech)