Exemplo n.º 1
0
 def extract_digest_info(cls, hash, alg):
     alg = norm_hash_name(alg, 'iana')
     self = cls.from_string(hash)
     chkmap = self.checksum
     if not chkmap:
         raise ValueError('scram hash contains no digests')
     return (self.salt, self.rounds, chkmap[alg])
Exemplo n.º 2
0
 def _norm_algs(cls, algs):
     if isinstance(algs, native_string_types):
         algs = splitcomma(algs)
     algs = sorted(norm_hash_name(alg, 'iana') for alg in algs)
     if any(len(alg) > 9 for alg in algs):
         raise ValueError('SCRAM limits alg names to max of 9 characters')
     if 'sha-1' not in algs:
         raise ValueError('sha-1 must be in algorithm list of scram hash')
     return algs
Exemplo n.º 3
0
    def test_norm_hash_name(self):
        from itertools import chain
        from otp.ai.passlib.crypto.digest import norm_hash_name, _known_hash_names
        ctx = warnings.catch_warnings()
        ctx.__enter__()
        self.addCleanup(ctx.__exit__)
        warnings.filterwarnings('ignore', '.*unknown hash')
        self.assertEqual(norm_hash_name(u('MD4')), 'md4')
        self.assertEqual(norm_hash_name('MD4'), 'md4')
        self.assertRaises(TypeError, norm_hash_name, None)
        for row in chain(_known_hash_names, self.norm_hash_samples):
            for idx, format in enumerate(self.norm_hash_formats):
                correct = row[idx]
                for value in row:
                    result = norm_hash_name(value, format)
                    self.assertEqual(result, correct,
                                     'name=%r, format=%r:' % (value, format))

        return
Exemplo n.º 4
0
    def _norm_checksum(self, checksum, relaxed=False):
        if not isinstance(checksum, dict):
            raise uh.exc.ExpectedTypeError(checksum, 'dict', 'checksum')
        for alg, digest in iteritems(checksum):
            if alg != norm_hash_name(alg, 'iana'):
                raise ValueError('malformed algorithm name in scram hash: %r' % (
                 alg,))
            if len(alg) > 9:
                raise ValueError('SCRAM limits algorithm names to 9 characters: %r' % (
                 alg,))
            if not isinstance(digest, bytes):
                raise uh.exc.ExpectedTypeError(digest, 'raw bytes', 'digests')

        if 'sha-1' not in checksum:
            raise ValueError('sha-1 must be in algorithm list of scram hash')
        return checksum
Exemplo n.º 5
0
 def extract_digest_algs(cls, hash, format='iana'):
     algs = cls.from_string(hash).algs
     if format == 'iana':
         return algs
     return [ norm_hash_name(alg, format) for alg in algs ]