Beispiel #1
0
 def _calc_checksum(self, secret):
     secret, ident = self._prepare_digest_args(secret)
     config = self._get_config(ident)
     hash = safe_crypt(secret, config)
     if hash:
         return hash[-31:]
     raise uh.exc.MissingBackendError(
         "non-utf8 encoded passwords can't be handled by crypt.crypt() under python3, recommend running `pip install bcrypt`."
     )
Beispiel #2
0
    def test_crypt(self):
        from otp.ai.passlib.utils import has_crypt, safe_crypt, test_crypt
        if not has_crypt:
            self.assertEqual(safe_crypt('test', 'aa'), None)
            self.assertFalse(test_crypt('test', 'aaqPiZY5xR5l.'))
            raise self.skipTest('crypt.crypt() not available')
        self.assertIsInstance(safe_crypt(u('test'), u('aa')), unicode)
        h1 = u('aaqPiZY5xR5l.')
        self.assertEqual(safe_crypt(u('test'), u('aa')), h1)
        self.assertEqual(safe_crypt('test', 'aa'), h1)
        h2 = u('aahWwbrUsKZk.')
        self.assertEqual(safe_crypt(u('test\\u1234'), 'aa'), h2)
        self.assertEqual(safe_crypt('test\xe1\x88\xb4', 'aa'), h2)
        hash = safe_crypt('test\xff', 'aa')
        if PY3:
            self.assertEqual(hash, None)
        else:
            self.assertEqual(hash, u('aaOx.5nbTU/.M'))
        self.assertRaises(ValueError, safe_crypt, '\x00', 'aa')
        h1x = h1[:-1] + 'x'
        self.assertTrue(test_crypt('test', h1))
        self.assertFalse(test_crypt('test', h1x))
        import otp.ai.passlib.utils as mod
        orig = mod._crypt
        try:
            fake = None
            mod._crypt = lambda secret, hash: fake
            for fake in [None, '', ':', ':0', '*0']:
                self.assertEqual(safe_crypt('test', 'aa'), None)
                self.assertFalse(test_crypt('test', h1))

            fake = 'xxx'
            self.assertEqual(safe_crypt('test', 'aa'), 'xxx')
        finally:
            mod._crypt = orig

        return
Beispiel #3
0
 def _calc_checksum_os_crypt(self, secret):
     hash = safe_crypt(secret, self.salt)
     if hash:
         return hash[2:]
     return self._calc_checksum_builtin(secret)
Beispiel #4
0
 def _calc_checksum_os_crypt(self, secret):
     config = self.to_string()
     hash = safe_crypt(secret, config)
     if hash:
         return hash[-11:]
     return self._calc_checksum_builtin(secret)
Beispiel #5
0
 def crypt_supports_variant(self, hash):
     from otp.ai.passlib.handlers.bcrypt import bcrypt, IDENT_2X, IDENT_2Y
     from otp.ai.passlib.utils import safe_crypt
     ident = bcrypt.from_string(hash)
     return (safe_crypt('test', ident + '04$5BJqKfqMQvV7nS.yUguNcu')
             or '').startswith(ident)
Beispiel #6
0
 def _calc_checksum_os_crypt(self, secret):
     hash = safe_crypt(secret, self.to_string())
     if hash:
         cs = self.checksum_size
         return hash[-cs:]
     return self._calc_checksum_builtin(secret)
Beispiel #7
0
 def _calc_checksum_os_crypt(self, secret):
     config = self.ident + self.salt
     hash = safe_crypt(secret, config)
     if hash:
         return hash[-22:]
     return self._calc_checksum_builtin(secret)