Example #1
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     if not hasattr(self, "salt_fn"):
         raise RuntimeError("No salt function specified for DataZoomerSaltedHash")
     salt = callable(self.salt_fn) and self.salt_fn() or self.salt_fn
     return str_to_uascii(sha1(sha1(salt.encode("ascii") + secret).digest()).hexdigest()).upper()
Example #2
0
 def _calc_checksum(self, secret, digestmod=None):
     if isinstance(secret, unicode):
         secret = secret.encode('utf-8')
     if isinstance(self.salt, unicode):
         self.salt = self.salt.encode('utf-8')
     # return hmac.new(self.salt, secret, digestmod).hexdigest()
     return str_to_uascii(hmac.new(self.salt, secret, digestmod).hexdigest())
Example #3
0
 def _calc_checksum_bcryptor(self, secret, config):
     # bcryptor behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported
     hash = _bcryptor.engine.Engine(False).hash_key(secret, config)
     assert hash.startswith(config) and len(hash) == len(config)+31
     return str_to_uascii(hash[-31:])
Example #4
0
    def _calc_checksum(self, secret):
        """Calculate string.

        :param secret: The secret key.
        :returns: The checksum.
        """
        return str_to_uascii(
            hashlib.sha256(mysql_aes_encrypt(self.salt, secret)).hexdigest())
Example #5
0
 def _calc_checksum_pybcrypt(self, secret, config):
     # py-bcrypt behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: unicode secret encoded as utf-8 bytes,
     #        hash encoded as ascii bytes, returns ascii unicode.
     hash = _bcrypt.hashpw(secret, config)
     assert hash.startswith(config) and len(hash) == len(config)+31
     return str_to_uascii(hash[-31:])
Example #6
0
 def _calc_checksum(self, secret):
     # bcryptor behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported
     secret, ident = self._prepare_digest_args(secret)
     config = self._get_config(ident)
     hash = _bcryptor.engine.Engine(False).hash_key(secret, config)
     assert hash.startswith(config) and len(hash) == len(config)+31
     return str_to_uascii(hash[-31:])
Example #7
0
 def _calc_checksum(self, secret):
     # bcryptor behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported
     secret, ident = self._prepare_digest_args(secret)
     config = self._get_config(ident)
     hash = _bcryptor.engine.Engine(False).hash_key(secret, config)
     assert hash.startswith(config) and len(hash) == len(config) + 31
     return str_to_uascii(hash[-31:])
Example #8
0
 def _calc_checksum_raw(self, secret):
     # py-bcrypt behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: unicode secret encoded as utf-8 bytes,
     #        hash encoded as ascii bytes, returns ascii unicode.
     secret, ident = self._prepare_digest_args(secret)
     config = self._get_config(ident)
     hash = _pybcrypt.hashpw(secret, config)
     assert hash.startswith(config) and len(hash) == len(config)+31
     return str_to_uascii(hash[-31:])
Example #9
0
 def _calc_checksum_raw(self, secret):
     # py-bcrypt behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: unicode secret encoded as utf-8 bytes,
     #        hash encoded as ascii bytes, returns ascii unicode.
     secret, ident = self._prepare_digest_args(secret)
     config = self._get_config(ident)
     hash = _pybcrypt.hashpw(secret, config)
     assert hash.startswith(config) and len(hash) == len(config) + 31
     return str_to_uascii(hash[-31:])
Example #10
0
 def _calc_checksum_pybcrypt(self, secret):
     # py-bcrypt behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported (patch submitted)
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     if _BNULL in secret:
         raise uh.exc.NullPasswordError(self)
     config = self._get_config()
     hash = pybcrypt_hashpw(secret, config)
     assert hash.startswith(config) and len(hash) == len(config) + 31
     return str_to_uascii(hash[-31:])
Example #11
0
 def _calc_checksum_pybcrypt(self, secret):
     # py-bcrypt behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported (patch submitted)
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     if _BNULL in secret:
         raise uh.exc.NullPasswordError(self)
     config = self._get_config()
     hash = pybcrypt_hashpw(secret, config)
     assert hash.startswith(config) and len(hash) == len(config)+31
     return str_to_uascii(hash[-31:])
Example #12
0
    def _calc_checksum(self, secret):
        if isinstance(secret, unicode):
            secret = secret.encode("utf-8")
        if not hasattr(self, "salt_fn"):
            raise RuntimeError("No salt function specified for DataZoomerSaltedHash")
        weak_dz_salt = callable(self.salt_fn) and self.salt_fn() or self.salt_fn
        dz_hash = '*' + str_to_uascii(sha1(sha1(weak_dz_salt.encode("ascii") + secret).digest()).hexdigest()).upper()

        # NOTE: can't use digest directly, since bcrypt stops at first NULL.
        # NOTE: bcrypt doesn't fully mix entropy for bytes 55-72 of password
        #       (XXX: citation needed), so we don't want key to be > 55 bytes.
        #       thus, have to use base64 (44 bytes) rather than hex (64 bytes).
        key = b64encode(sha256(dz_hash).digest())
        return self._calc_checksum_backend(key)
Example #13
0
    def _calc_checksum(self, secret):
        # NOTE: this bypasses bcrypt's _calc_checksum,
        #       so has to take care of all it's issues, such as secret encoding.
        if isinstance(secret, unicode):
            secret = secret.encode("utf-8")

        # generate the mysql41 hash first (as it would be in the db
        mysql41_hash = '*' + str_to_uascii(sha1(sha1(secret).digest()).hexdigest()).upper()

        # NOTE: can't use digest directly, since bcrypt stops at first NULL.
        # NOTE: bcrypt doesn't fully mix entropy for bytes 55-72 of password
        #       (XXX: citation needed), so we don't want key to be > 55 bytes.
        #       thus, have to use base64 (44 bytes) rather than hex (64 bytes).
        key = b64encode(sha256(mysql41_hash).digest())
        return self._calc_checksum_backend(key)
Example #14
0
 def _calc_checksum_bcryptor(self, secret):
     # bcryptor behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported
     if self.ident == IDENT_2:
         # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior
         # using the $2a$ algorithm, by repeating the password until
         # it's at least 72 chars in length.
         if secret:
             secret = repeat_string(secret, 72)
         config = self._get_config(IDENT_2A)
     else:
         config = self._get_config()
     hash = _bcryptor_engine(False).hash_key(secret, config)
     assert hash.startswith(config) and len(hash) == len(config) + 31
     return str_to_uascii(hash[-31:])
Example #15
0
 def _calc_checksum_bcryptor(self, secret):
     # bcryptor behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported
     if self.ident == IDENT_2:
         # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior
         # using the $2a$ algorithm, by repeating the password until
         # it's at least 72 chars in length.
         if secret:
             secret = repeat_string(secret, 72)
         config = self._get_config(IDENT_2A)
     else:
         config = self._get_config()
     hash = _bcryptor_engine(False).hash_key(secret, config)
     assert hash.startswith(config) and len(hash) == len(config)+31
     return str_to_uascii(hash[-31:])
Example #16
0
 def _calc_checksum_bcryptor(self, secret):
     # bcryptor behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     if _BNULL in secret:
         # NOTE: especially important to forbid NULLs for bcryptor,
         # since it happily accepts them, and then silently truncates
         # the password at first one it encounters :(
         raise uh.exc.NullPasswordError(self)
     if self.ident == IDENT_2:
         # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior
         # using the $2a$ algorithm, by repeating the password until
         # it's at least 72 chars in length.
         if secret:
             secret = repeat_string(secret, 72)
         config = self._get_config(IDENT_2A)
     else:
         config = self._get_config()
     hash = bcryptor_engine(False).hash_key(secret, config)
     assert hash.startswith(config) and len(hash) == len(config) + 31
     return str_to_uascii(hash[-31:])
Example #17
0
 def _calc_checksum_bcryptor(self, secret):
     # bcryptor behavior:
     #   py2: unicode secret/hash encoded as ascii bytes before use,
     #        bytes taken as-is; returns ascii bytes.
     #   py3: not supported
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     if _BNULL in secret:
         # NOTE: especially important to forbid NULLs for bcryptor,
         # since it happily accepts them, and then silently truncates
         # the password at first one it encounters :(
         raise uh.exc.NullPasswordError(self)
     if self.ident == IDENT_2:
         # bcryptor doesn't support $2$ hashes; but we can fake $2$ behavior
         # using the $2a$ algorithm, by repeating the password until
         # it's at least 72 chars in length.
         if secret:
             secret = repeat_string(secret, 72)
         config = self._get_config(IDENT_2A)
     else:
         config = self._get_config()
     hash = bcryptor_engine(False).hash_key(secret, config)
     assert hash.startswith(config) and len(hash) == len(config)+31
     return str_to_uascii(hash[-31:])
Example #18
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     user = to_bytes(self.user, "utf-8", param="user")
     return str_to_uascii(md5(secret + user).hexdigest())
Example #19
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     return str_to_uascii(
         md5(self.salt.encode("ascii") + secret).hexdigest())
Example #20
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     return str_to_uascii(self._hash_func(secret).hexdigest())
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     data = self.salt.encode("ascii") + secret + self.salt.encode("ascii")
     return str_to_uascii(hashlib.sha1(data).hexdigest())
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     data = b"boblious" + secret
     return str_to_uascii(hashlib.sha1(data).hexdigest())
Example #23
0
 def _calc_checksum(self, secret):
     """Calculate string."""
     return str_to_uascii(
         hashlib.sha256(mysql_aes_encrypt(self.user, secret)).hexdigest()
     )
Example #24
0
 def _calc_checksum(self, secret):
     """Calculate string."""
     return str_to_uascii(
         hashlib.sha256(mysql_aes_encrypt(self.user, secret)).hexdigest())
Example #25
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     data = b"boblious" + secret
     return str_to_uascii(hashlib.sha1(data).hexdigest())
Example #26
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     data = self.salt.encode("ascii") + secret + self.salt.encode("ascii")
     return str_to_uascii(hashlib.sha1(data).hexdigest())
Example #27
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     chk = sha1(secret + unhexlify(self.salt.encode("ascii"))).hexdigest()
     return str_to_uascii(chk).upper()
Example #28
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     return str_to_uascii(self._hash_func(secret).hexdigest())
Example #29
0
 def _calc_checksum(self, secret):
     m_salt = b64decode(self.salt).decode('utf-8')
     m_hash = sha1(m_salt + sha1(secret.encode('utf-8')).digest())
     return str_to_uascii(m_hash.hexdigest())
Example #30
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     return str_to_uascii(md5(self.salt.encode("ascii") + secret).hexdigest())
Example #31
0
 def _calc_checksum(self, secret):
     # FIXME: no idea if mysql has a policy about handling unicode passwords
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     return str_to_uascii(sha1(sha1(secret).digest()).hexdigest()).upper()
Example #32
0
 def _calc_checksum(self, secret):
     # FIXME: no idea if mysql has a policy about handling unicode passwords
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     return str_to_uascii(sha1(sha1(secret).digest()).hexdigest()).upper()
Example #33
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     user = to_bytes(self.user, "utf-8", param="user")
     return str_to_uascii(md5(secret + user).hexdigest())
Example #34
0
 def _calc_checksum(self, secret):
     if isinstance(secret, unicode):
         secret = secret.encode("utf-8")
     chk = sha1(secret + unhexlify(self.salt.encode("ascii"))).hexdigest()
     return str_to_uascii(chk).upper()
Example #35
0
 def _calc_checksum(self, secret):
     m_str = secret + b64decode(self.salt).decode('utf-8')
     m_hash = sha256(m_str.encode('utf-8'))
     return str_to_uascii(m_hash.hexdigest())