Esempio n. 1
0
def validate_ds_digest(digest_alg, digest, dnskey_msg):
    if not digest_alg_is_supported(digest_alg):
        return None

    if digest_alg == 1:
        md = EVP.MessageDigest("sha1")
        md.update(dnskey_msg)
        return md.final() == digest
    elif digest_alg == 2:
        md = EVP.MessageDigest("sha256")
        md.update(dnskey_msg)
        return md.final() == digest
    elif digest_alg == 3:
        _gost_init()
        try:
            mdgost = m2.get_digestbyname(GOST_DIGEST_NAME)
            md = GostMessageDigest(mdgost)
            md.update(dnskey_msg)
            return md.final() == digest
        finally:
            _gost_cleanup()
    elif digest_alg == 4:
        md = EVP.MessageDigest("sha384")
        md.update(dnskey_msg)
        return md.final() == digest
Esempio n. 2
0
 def __init__(self, algo):
     # type: (str) -> None
     md = getattr(m2, algo, None)  # type: Optional[Callable]
     if md is None:
         # if the digest algorithm isn't found as an attribute of the m2
         # module, try to look up the digest using get_digestbyname()
         self.md = m2.get_digestbyname(algo)
     else:
         self.md = md()
     self.ctx = m2.md_ctx_new()
     m2.digest_init(self.ctx, self.md)
Esempio n. 3
0
 def __init__(self, algo):
     # type: (str) -> None
     md = getattr(m2, algo, None)  # type: Optional[Callable]
     if md is None:
         # if the digest algorithm isn't found as an attribute of the m2
         # module, try to look up the digest using get_digestbyname()
         self.md = m2.get_digestbyname(algo)
     else:
         self.md = md()
     self.ctx = m2.md_ctx_new()
     m2.digest_init(self.ctx, self.md)
Esempio n. 4
0
 def __init__(self, algo):
     md = getattr(m2, algo, None)
     if md is None:
         # if the digest algorithm isn't found as an attribute of the m2
         # module, try to look up the digest using get_digestbyname()
         self.md = m2.get_digestbyname(algo)
         if self.md is None:
             raise ValueError('unknown algorithm', algo)
     else:
         self.md = md()
     self.ctx = m2.md_ctx_new()
     m2.digest_init(self.ctx, self.md)
Esempio n. 5
0
def _validate_rrsig_gost(alg, sig, msg, key):
    _gost_init()

    try:
        pubkey = _dnskey_to_gost(key)

        pubkey.md = m2.get_digestbyname(GOST_DIGEST_NAME)
        pubkey.verify_init()
        pubkey.verify_update(msg)

        return pubkey.verify_final(sig) == 1

    finally:
        _gost_cleanup()
Esempio n. 6
0
def _validate_rrsig_gost(alg, sig, msg, key):
    _gost_init()

    try:
        pubkey = _dnskey_to_gost(key)

        pubkey.md = m2.get_digestbyname(GOST_DIGEST_NAME)
        pubkey.verify_init()
        pubkey.verify_update(msg)

        return pubkey.verify_final(sig) == 1

    finally:
        _gost_cleanup()
Esempio n. 7
0
def _validate_rrsig_gost(alg, sig, msg, key):
    _gost_init()

    try:
        pubkey = _dnskey_to_gost(key)

        # if the key is invalid, then the signature is also invalid
        if pubkey is None:
            return False

        pubkey.md = m2.get_digestbyname(GOST_DIGEST_NAME)
        pubkey.verify_init()
        pubkey.verify_update(msg)

        return pubkey.verify_final(sig) == 1

    finally:
        _gost_cleanup()
Esempio n. 8
0
 def test_get_digestbyname(self):
     with self.assertRaises(EVP.EVPError):
         m2.get_digestbyname('sha513')
     self.assertNotEqual(m2.get_digestbyname('sha1'), None)
Esempio n. 9
0
 def test_get_digestbyname(self):
     self.assertEqual(m2.get_digestbyname('sha513'), None)
     self.assertNotEqual(m2.get_digestbyname('sha1'), None)
Esempio n. 10
0
 def test_get_digestbyname(self):
     self.assertEqual(m2.get_digestbyname('sha513'), None)
     self.assertNotEqual(m2.get_digestbyname('sha1'), None)
Esempio n. 11
0
 def test_get_digestbyname(self):
     with self.assertRaises(EVP.EVPError):
         m2.get_digestbyname('sha513')
     self.assertNotEqual(m2.get_digestbyname('sha1'), None)