def _test_user_from_rfc2617_digest(self, name='test'):
     nonce = UUID()
     next_nonce = UUID()
     realm = 'digest test'
     algorithm = 'MD5'
     method = 'GET'
     uri = '/index.html'
     password = self.NAME_PASSWD_MAP[name]
     A1 = '%s:%s:%s' % (name,realm,password)
     A2 = '%s:%s' % (method,uri)
     digest = '%s:%s:%s' % (md5.new(A1).hexdigest(),nonce,
                            md5.new(A2).hexdigest())
     digest = md5.new(digest).hexdigest()
     none_user = self.user_manager.new_rfc2617_digest_user(nonce)
     assert none_user.name() == 'NoneUser','New digest returned wrong user'
     user = self.user_manager.user_from_rfc2617_digest(
         _file_=self.passwd_file,username=name,nonce=nonce,
         nextnonce=next_nonce,realm=realm,
         algorithm=algorithm,method=method,uri=uri,response=digest)
     nonce = next_nonce
     next_nonce = UUID()
     method = 'POST'
     uri = '/post.html'
     A2 = '%s:%s' % (method,uri)
     digest = '%s:%s:%s' % (md5.new(A1).hexdigest(),nonce,
                            md5.new(A2).hexdigest())
     digest = md5.new(digest).hexdigest()
     user = self.user_manager.user_from_rfc2617_digest(
         _file_=self.passwd_file,username=name,nonce=nonce,
         nextnonce=next_nonce,realm=realm,
         algorithm=algorithm,method=method,uri=uri,response=digest)
     assert user.name() == name,'Wrong user returned.'
Example #2
0
 def __new__(klass, context):
     adapter = super(UniquelyIdentified, klass).__new__(klass)
     meta_context = IMetaDataProvider(context)
     uuid = meta_context.setdefault_meta('identifier', UUID())
     identifier_registry.setdefault(uuid, context)
     adapter.initialize(meta_context)
     return adapter
Example #3
0
 def __new__(klass, callback, fast=True):
     guid = UUID()
     # Naming object that will be 'self' in instance methods, 'self'.
     self = super(CollectableCallback, klass).__new__(klass, callback, fast)
     CollectableCallback.instances[guid] = self
     self.initialize(callback, guid, fast)
     return self
Example #4
0
 def __init__(self, source, origin=None, guid=None):
     self.source = source
     if origin is None:
         origin = getattr(source, 'origin', self.LOCALORIGIN)
     self.origin = origin
     self.__GUID = UUID(guid)
     # setdefault is atomic...
     assigned = self.EVENTS.setdefault(self.GUID, self)
     if assigned is not self:
         raise ValueError('GUID %s already exists.' % self.GUID)
     super(Event, self).__init__(source, origin, guid)
Example #5
0
 def user_from_header(self):
     manager = self.server.user_manager
     authorization = self.get_header('Authorization')
     scheme, auth = string.split(authorization.lstrip(), ' ', 1)
     scheme = scheme.lower()
     if scheme == 'basic':
         user = manager.user_from_rfc2617_basic(auth)
     elif scheme == 'digest':
         params = {}
         while '=' in auth:
             name, rest = string.split(auth.lstrip(), '=', 1)
             rest = rest.lstrip()
             if rest[0] == '"':
                 begin = 1
                 end = rest.index('"', begin)
             else:
                 begin = 0
                 if ',' in rest:
                     end = rest.index(',')
                 else:
                     end = len(rest)
             params[name] = rest[begin:end]
             auth = rest[end + 2:]
         if params['uri'] != self.get_path():
             raise EAuthenticationFailed('Authorization URI does'
                                         ' not match request URI.')
         params['method'] = self.get_command()
         if not params.has_key('algorithm'):
             params['algorithm'] = 'MD5'
         if self.prevent_replay:
             params['nextnonce'] = UUID()
         validator = manager.validator_from_rfc2617_digest(**params)
         info = ''
         if params.has_key('cnonce'):
             A1 = validator.security_data()
             A2 = validator.message_data(uri='')
             digest = validator.digest(A1, A2)
             info += ('rspauth="%s", cnonce="%s"' %
                      (digest, params['cnonce']))
         if params.has_key('qop'):
             info += ', qop="%s"' % params['qop']
         if params.has_key('nc'):
             info += ', nc=%s' % params['nc']
         if params.has_key('nextnonce'):
             info += ', nextnonce="%s"' % params['nextnonce']
         if info:
             self['Authentication-Info'] = info
         user = validator.user
     else:
         raise EInvalidValue('scheme', scheme, 'Not supported yet')
     self._authentication_scheme = scheme
     return user
Example #6
0
 def digest_challenge(self, realm, stale='false'):
     nonce = UUID()
     manager = self.server.user_manager
     self._user_object = manager.new_rfc2617_digest_user(nonce)
     domain = self.get_path()
     if len(domain) > 1:
         domain = domain[0:domain.rfind('/')]
     params = {
         'nonce': '"%s"' % nonce,
         'qop': '"auth"',
         'domain': '"%s"' % domain,
         'stale': '%s' % stale
     }
     self.challenge(realm, 'digest', params)
Example #7
0
 def handle_request(self, request):
     output = StringIO()
     command = request.get_command()
     header = '-- %s request [%d] [%s] --      '
     header %= (command, id(request), time.ctime())
     output.write(header)
     output.write('\n' + '*' * len(header) + '\n')
     output.write('<<< Request >>>\n')
     output.write(' - headers - \n')
     output.write(string.join(request.get_headers(), '\n') + '\n\n')
     output.write(' - content - \n')
     data = '-- No incoming data --'
     delimlength = len(data)
     if command == 'POST':
         data = request.get_data().read_all()
     output.write(data + '\n' + '-' * delimlength + '\n\n')
     response = Response(request)
     output.write('<<< Response >>>\n')
     command_cookie = Cookie('command_id', str(UUID()))
     command_cookie.add_attribute('path', '/')
     command_cookie.add_attribute('domain', '.domain.com')
     test_cookie = Cookie('test_id', str(UUID()))
     test_cookie.add_attribute('path', '/')
     test_cookie.add_attribute('domain', '.domain.com')
     content = self.next_request()
     response.add_cookie(command_cookie)
     response.add_cookie(test_cookie)
     response.push(content)
     output.write(' - headers - \n')
     for name, value in request.response_headers.items():
         output.write("%s: %s\n" % (name, value))
     output.write(' - content - \n')
     output.write(content or '-- No outgoing data --')
     output.write('\n' + '*' * len(header) + '\n\n')
     response.done()
     self.debug_dumps(output.getvalue())
Example #8
0
 def __init__(self,
              name,
              password_file=PASSWD_FILE,
              group_file=GROUP_FILE,
              shadow_file=SHADOW_FILE):
     self.__lock = Lock()
     self.__password_file = password_file
     self.__group_file = group_file
     self.__shadow_file = shadow_file
     self.meta = {}
     self.USERS.load()
     if not self.USERS.has_key(self.name()):
         msglog.log('broadway', msglog.types.INFO,
                    ('No profile for user %s found, creating'
                     ' new profile' % name))
         self.USERS[self.name()] = str(UUID())
     PersistentDataObject.__init__(self, self.USERS[self.name()])
     PersistentDataObject.load(self)
Example #9
0
 def override(self, value, seconds=None, *clearing_value):
     if len(clearing_value):
         self.set_clearing_value(clearing_value[0])
     self.__state_lock.acquire()
     try:
         self.__override = override = UUID()
         self.__overridden_at = time.time()
         self.__clears_at = None
         self.node.set(value)
         self.active_overrides.setdefault(self.node.url, self)
         if seconds is not None:
             self.__clears_at = self.__overridden_at + seconds
             scheduler.at(self.__clears_at, self.clear_override,
                          (override, ))
     finally:
         self.__state_lock.release()
     self.__notify_if_changed()
     return override
Example #10
0
 def __init__(self, commands, operation='execute'):
     self.tid = UUID()
     self._commands = []
     for cmd in commands:
         if isinstance(cmd, CommandIface):
             self._commands.append(cmd)
     self._completed = 0
     self._num_commands = len(self._commands)
     self._errors = 0
     self._operation = operation
     value_map = {
         'completed': False,
         'success': False,
         'report_items': [],
         'transaction_id': self.tid,
         'percent_complete': 0
     }
     self._status = TransactionStatus(value_map)
     super(CommandSet, self).__init__()
Example #11
0
 def __init__(self,name=None,description=None,weekly=None, \
              effective=None,special_events=None,id=None):
     if name is None:
         name = ''
     self._name = name
     if description is None:
         description = ''
     self._description = description
     if not weekly:
         weekly = []
         for i in range(0, 7):
             weekly.append(datetime.DailySchedule())
     self._weekly = weekly
     if effective is None:
         effective = datetime.DateRange(None, None)
     self._effective = effective
     if not special_events:
         special_events = []
     self._special_events = special_events
     if id is None:
         id = UUID()
     self._id = id
 def test_new_DigestRFC2617Authenticator(self):
     nonce = UUID()
     none_user = self.user_manager.new_rfc2617_digest_user(nonce)
     assert none_user.name() == 'NoneUser','Returned wrong user'
Example #13
0
 def generate_oid(self):
     return str(UUID())
Example #14
0
 def create_query(self, iterator, **kw):
     qid = str(UUID())
     self.queries[qid] = Query(qid, iterator, **kw)
     return qid
Example #15
0
 def _random_id(self):
     return str(UUID())
 def data_id(self):
     return UUID()