votes up 2

invalid salt size

Package:
ansible
github stars 49704
Exception Class:
AnsibleError

Raise code

    def _salt(self, salt, salt_size):
        salt_size = salt_size or self.algo_data.salt_size
        ret = salt or random_salt(salt_size)
        if re.search(r'[^./0-9A-Za-z]', ret):
            raise AnsibleError("invalid characters in salt")
        if self.algo_data.salt_exact and len(ret) != self.algo_data.salt_size:
            raise AnsibleError("invalid salt size")
        elif not self.algo_data.salt_exact and len(ret) > self.algo_data.salt_size:
            raise AnsibleError("invalid salt size")
        return ret

    def _rounds(self, rounds):
        if rounds == self.algo_data.implicit_rounds:
            # Passlib does not include the rounds if it is the same as implicit_rounds.
😲 Agile task management is now easier than calling a taxi. #Tracklify

Ways to fix

votes up 3 votes down

Error to reproduce:

from ansible.utils import encrypt
crypt_hash = encrypt.CryptHash('bcrypt')
crypt_hash._salt('123456123456123456'7) <---- #Error 

 CryptHash function is a mathematical function used in cryptography. Typical hash functions take inputs of variable lengths to return outputs of a fixed length.

When we are writing :

print(crypt_hash.algo_data)

It returns information about the algorithm.

algo(crypt_id='2a', salt_size=22, implicit_rounds=None, salt_exact=True)

So within the documentation, we can easily see what is going on. salt_exact must be False or salt_size must be less than or equal our Hash salt_size.

if self.algo_data.salt_exact and len(ret) != self.algo_data.salt_size:
  raise AnsibleError("invalid salt size")
elif not self.algo_data.salt_exact and len(ret) > self.algo_data.salt_size:
  raise AnsibleError("invalid salt size")

Fix code:

from ansible.utils import encrypt
crypt_hash = encrypt.CryptHash('bcrypt')
crypt_hash._salt('1234561234561234561234'7)
Jun 26, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix