Ejemplo n.º 1
0
  def validate(self):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    # TODO: Edit cannot change username!
    # TODO: Verify validation of User Object
    if not (self.password or self.username):
      return False
    ObjectValidator.validateAlNum(self,
                                  'username',
                                  minLength=3,
                                  maxLength=254)
    # Don't update if the password is already a hash
    if not (self.password == 'EXTERNALAUTH') and re.match('^[0-9a-f]{40}$',
                                                          self.password) is None:
      ObjectValidator.validateRegex(self,
                                    'password',
                                    r'(?=^.{8,}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[\W_])(?=^.*[^\s].*$).*$',
                                    'Password has to be set and contain Upper and Lower cases, symbols and numbers and have at least a length of 8'
                                    )

    ObjectValidator.validateEmailAddress(self, 'email')
    ObjectValidator.validateAlNum(self, 'name', minLength=3, withSymbols=True)
    ObjectValidator.validateAlNum(self, 'sirname', minLength=3, withSymbols=True)

    # if self.gpg_key:
    #  ObjectValidator.validateRegex(self,
    #                                'gpg_key',
    #                                '-----BEGIN PGP PUBLIC KEY BLOCK-----(.*?)-----END PGP PUBLIC KEY BLOCK-----',
    #                                'GPG Key not under the right format')
    if self.last_login is not None:
      ObjectValidator.validateDateTime(self, 'last_login')
    return ObjectValidator.isObjectValid(self)
Ejemplo n.º 2
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        # TODO: Verify validation of AttributeDefinition Object
        ObjectValidator.validateAlNum(self,
                                      'name',
                                      withSpaces=True,
                                      withSymbols=True,
                                      minLength=3)
        ObjectValidator.validateAlNum(self,
                                      'description',
                                      withNonPrintableCharacters=True,
                                      withSpaces=True,
                                      minLength=3,
                                      withSymbols=True)
        ObjectValidator.validateRegularExpression(self, 'regex')

        # check if handler is compatible with the class_index
        allowed_tables = self.handler.get_allowed_types()
        if not (self.table_id in allowed_tables):
            self.class_index = FailedValidation(
                self.table_id,
                ('Class is not compatible "{0}".\n'
                 'Supported classes are {1}').format(
                     self.attribute_handler.classname,
                     self.__class_numbers_to_text(allowed_tables)))
        return ObjectValidator.isObjectValid(self)
Ejemplo n.º 3
0
  def validate(self, full=True):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    ObjectValidator.validateDigits(self, 'def_attribute_id')
    # validate attribute value
    value_obj = self.__get_value_obj()
    # TODO: encoding error
    ObjectValidator.validateRegex(value_obj,
                                  'value',
                                  getattr(self.definition, 'regex'),
                                  u'The value "{0}" does not match {1} for definition {2}'.format(value_obj.value,
                                                                                                  getattr(self.definition, 'regex'),
                                                                                                  getattr(self.definition, 'name')).encode('utf-8'),
                                  True)
    errors = not getattr(value_obj, 'validate')()
    if errors:
      return False

    if full:
      ObjectValidator.validateDigits(self, 'object_id')
      ObjectValidator.validateDigits(self, 'creator_id')
      ObjectValidator.validateDigits(self, 'modifier_id')
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDateTime(self, 'modified')
    return ObjectValidator.isObjectValid(self)
Ejemplo n.º 4
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        # TODO: Verify validation of Group Object
        ObjectValidator.validateAlNum(self,
                                      'name',
                                      withSymbols=True,
                                      minLength=3)
        # TODO: validate
        return ObjectValidator.isObjectValid(self)
Ejemplo n.º 5
0
  def validate(self):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    ObjectValidator.validateAlNum(self, 'title', withSpaces=True, minLength=3,
                                  withSymbols=True)
    ObjectValidator.validateAlNum(self,
                                  'description',
                                  withNonPrintableCharacters=True,
                                  withSpaces=True,
                                  minLength=3,
                                  withSymbols=True)
    ObjectValidator.validateDigits(self, 'tlp_level_id', minimal=0, maximal=3)
    ObjectValidator.validateDigits(self, 'status_id', minimal=0, maximal=3)
    ObjectValidator.validateDigits(self, 'published', minimal=0, maximal=1)
    ObjectValidator.validateDigits(self, 'risk_id', minimal=0, maximal=4)
    ObjectValidator.validateDigits(self, 'analysis_status_id', minimal=0, maximal=4)
    ObjectValidator.validateDigits(self, 'creator_id')
    ObjectValidator.validateDigits(self, 'modifier_id')
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDateTime(self, 'modified')
    if self.first_seen is not None:
      ObjectValidator.validateDateTime(self, 'first_seen')
    if self.last_seen is not None:
      ObjectValidator.validateDateTime(self, 'last_seen')
    if ((self.first_seen is not None and self.last_seen is not None) and not isinstance(self.first_seen, FailedValidation) and not isinstance(self.last_seen, FailedValidation)):
      # check if date is time zone avare
      if not self.first_seen.tzinfo:
        self.first_seen = self.__create_tzaware_datetime(self.first_seen)
      if not self.last_seen.tzinfo:
        self.last_seen = self.__create_tzaware_datetime(self.last_seen)

      if self.first_seen > self.last_seen:
        setattr(self, 'first_seen',
                FailedValidation(self.first_seen,
                                 'First seen is after last seen.'))
        setattr(self, 'last_seen',
                FailedValidation(self.last_seen,
                                 'Last seen is before last seen.'))
    if self.first_seen is None and self.last_seen is not None:
      setattr(self, 'first_seen',
              FailedValidation(self.first_seen,
                               'First seen cannot be empty when last seen is'
                               + ' set.'))
      setattr(self, 'last_seen',
              FailedValidation(self.last_seen,
                               'Last seen cannot be set when first seen is'
                               + ' empty.'))
    return ObjectValidator.isObjectValid(self)
Ejemplo n.º 6
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        ObjectValidator.validateAlNum(self,
                                      'name',
                                      withSymbols=True,
                                      minLength=3)
        ObjectValidator.validateAlNum(self,
                                      'description',
                                      minLength=5,
                                      withSpaces=True,
                                      withNonPrintableCharacters=True,
                                      withSymbols=True)
        return ObjectValidator.isObjectValid(self)
Ejemplo n.º 7
0
  def validate(self):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDigits(self, 'creator_id')
    ObjectValidator.validateDigits(self, 'modifier_id')
    ObjectValidator.validateDigits(self, 'event_id')
    ObjectValidator.validateAlNum(self,
                                  'comment',
                                  minLength=5,
                                  withSpaces=True,
                                  withNonPrintableCharacters=True,
                                  withSymbols=True)
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDateTime(self, 'modified')
    return ObjectValidator.isObjectValid(self)
Ejemplo n.º 8
0
 def validate(self):
     """Validates the mail template object"""
     ObjectValidator.validateAlNum(self,
                                   'name',
                                   withSpaces=True,
                                   minLength=3,
                                   withSymbols=True)
     ObjectValidator.validateAlNum(self,
                                   'body',
                                   withNonPrintableCharacters=True,
                                   withSpaces=True,
                                   minLength=3,
                                   withSymbols=True)
     ObjectValidator.validateAlNum(self,
                                   'subject',
                                   withSpaces=True,
                                   minLength=3,
                                   withSymbols=True)
     return ObjectValidator.isObjectValid(self)
Ejemplo n.º 9
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        # validate attribute value
        value_instance = self.__get_value_instance()
        # TODO: encoding error
        ObjectValidator.validateRegex(
            value_instance, 'value', getattr(self.definition, 'regex'),
            u'The value "{0}" does not match {1} for definition {2}'.format(
                value_instance.value, getattr(self.definition, 'regex'),
                getattr(self.definition, 'name')).encode('utf-8'), True)
        if not isinstance(value_instance, FailedValidation):
            errors = not getattr(value_instance, 'validate')()
            if errors:
                return False
        return ObjectValidator.isObjectValid(self)
Ejemplo n.º 10
0
  def validate(self, ignore_attribtues=False):
    """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
    if not ignore_attribtues:
      for attribute in self.attributes:
        result = attribute.validate()
        if not result:
          return False
    function = getattr(self.definition, 'validate')
    if not function():
      return False
    ObjectValidator.validateDigits(self, 'creator_id')
    ObjectValidator.validateDateTime(self, 'created')
    ObjectValidator.validateDigits(self, 'def_object_id')
    if self.parent_object_id is not None:
      ObjectValidator.validateDigits(self, 'parent_object_id')
    ObjectValidator.validateDateTime(self, 'created')
    return ObjectValidator.isObjectValid(self)
Ejemplo n.º 11
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        ObjectValidator.validateAlNum(self,
                                      'name',
                                      withSymbols=True,
                                      minLength=3)
        ObjectValidator.validateAlNum(self,
                                      'description',
                                      minLength=5,
                                      withSpaces=True,
                                      withNonPrintableCharacters=True,
                                      withSymbols=True)
        ObjectValidator.validateDigits(self,
                                       'can_download',
                                       minimal=0,
                                       maximal=1)
        ObjectValidator.validateDigits(self, 'usermails', minimal=0, maximal=1)
        if self.usermails == 0:
            ObjectValidator.validateEmailAddress(self, 'email')
        return ObjectValidator.isObjectValid(self)