Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
    def validateAlNum(string,
                      minLength=0,
                      maxLength=0,
                      withSpaces=False,
                      withNonPrintableCharacters=False,
                      withSymbols=False):
        """
      Validates if the string is of an alphanumeric kind.

      :param string: The string to be validated
      :type string: String
      :param minLength: The minimal length of the string
      :type minLength: Integer
      :param maxLength: The maximal length of the string
      :type maxLength: Integer
      :param withSpaces: If set the string can contain spaces
      :type withSpaces: Boolean
      :param withNonPrintableCharacters: If set the string can contain non
                                         printable characters as tab newlines
                                         etc.
      :type withNonPrintableCharacters: Boolean

      :return Boolean
    """

        obj = Container(string)
        return ObjectValidator.validateAlNum(
            obj,
            'value',
            minLength=minLength,
            maxLength=maxLength,
            withSpaces=withSpaces,
            withNonPrintableCharacters=withNonPrintableCharacters,
            withSymbols=withSymbols,
            changeAttribute=False)
Esempio n. 5
0
  def validateAlNum(string,
                    minLength=0,
                    maxLength=0,
                    withSpaces=False,
                    withNonPrintableCharacters=False,
                    withSymbols=False):
    """
      Validates if the string is of an alphanumeric kind.

      :param string: The string to be validated
      :type string: String
      :param minLength: The minimal length of the string
      :type minLength: Integer
      :param maxLength: The maximal length of the string
      :type maxLength: Integer
      :param withSpaces: If set the string can contain spaces
      :type withSpaces: Boolean
      :param withNonPrintableCharacters: If set the string can contain non
                                         printable characters as tab newlines
                                         etc.
      :type withNonPrintableCharacters: Boolean

      :return Boolean
    """

    obj = Container(string)
    return ObjectValidator.validateAlNum(obj,
                                         'value',
                                         minLength=minLength,
                                         maxLength=maxLength,
                                         withSpaces=withSpaces,
                                         withNonPrintableCharacters=withNonPrintableCharacters,
                                         withSymbols=withSymbols,
                                         changeAttribute=False)
Esempio 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)
Esempio 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)
Esempio n. 8
0
    def validate(self):
        """
    Checks if the attributes of the class are valid

    :returns: Boolean
    """
        return ObjectValidator.validateAlNum(self,
                                             'value',
                                             minLength=1,
                                             withSpaces=True,
                                             withSymbols=True)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)