Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with pytest.raises(AlreadyFinalized):
h.finalize()
def test_unsupported_hash(self, backend):
with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_HASH):
hashes.Hash(DummyHashAlgorithm(), backend)
@pytest.mark.supported(
only_if=lambda backend: backend.hash_supported(hashes.SHA1()),
skip_message="Does not support SHA1",
)
@pytest.mark.requires_backend_interface(interface=HashBackend)
class TestSHA1(object):
test_sha1 = generate_base_hash_test(
hashes.SHA1(),
digest_size=20,
)
@pytest.mark.supported(
only_if=lambda backend: backend.hash_supported(hashes.SHA224()),
skip_message="Does not support SHA224",
)
@pytest.mark.requires_backend_interface(interface=HashBackend)
class TestSHA224(object):
test_sha224 = generate_base_hash_test(
hashes.SHA224(),
digest_size=28,
)
def test_valid_mgf1_parameters(self):
algorithm = hashes.SHA1()
mgf = padding.MGF1(algorithm)
assert mgf._algorithm == algorithm
def test_rsa_padding_unsupported_mgf(self):
assert backend.rsa_padding_supported(
padding.OAEP(
mgf=DummyMGF(),
algorithm=hashes.SHA1(),
label=None
),
) is False
assert backend.rsa_padding_supported(
padding.PSS(mgf=DummyMGF(), salt_length=0)
) is False
'SHA1': lambda m: doDSA(hashes.SHA1, m),
'SHA224': lambda m: doDSA(hashes.SHA224, m),
raise InvalidUsage("You are trying to add a personal password in a folder you can not",400)
ext = "/Personal/"+name+"/External"
if folder == ext:
raise InvalidUsage("You are trying to add a personal password in a folder you can not",400)
folderdb = dbController.get_folder(folder)
if len(folderdb) == 0:
raise InvalidUsage("This folder does not exist",400)
pub_key = crypto.get_pubkey(userdb)
try:
password = pub_key.encrypt(str(request.json["passwd"]),padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA1()),algorithm=hashes.SHA1(),label=None))
passwd_login = pub_key.encrypt(passwd_login,padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA1()),algorithm=hashes.SHA1(),label=None))
passwd_url = pub_key.encrypt(passwd_url,padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA1()),algorithm=hashes.SHA1(),label=None))
passwd_description = pub_key.encrypt(passwd_description,padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA1()),algorithm=hashes.SHA1(),label=None))
except Exception,e:
raise InvalidUsage("Failed to encrypt password",500)
dbController.add_personal_password(user.username,folder,password,passwd_name,passwd_login,passwd_url,passwd_description)
log_message = """action=|/add/password/personal| user=|%s| src=|%s| result=|success|"""%(user.username,src)
log.log_info(log_message)
return jsonify({"status":"success","message":"password successfully added"})
k = k.public_key()
args = (
common.getNS(signature)[0],
data,
padding.PKCS1v15(),
hashes.SHA1(),
)
elif keyType == 'DSA':
concatenatedSignature = common.getNS(signature)[0]
r = int_from_bytes(concatenatedSignature[:20], 'big')
s = int_from_bytes(concatenatedSignature[20:], 'big')
signature = encode_dss_signature(r, s)
k = self._keyObject
if not self.isPublic():
k = k.public_key()
args = (signature, data, hashes.SHA1())
elif keyType == 'EC': # Pragma: no branch
concatenatedSignature = common.getNS(signature)[0]
rstr, sstr, rest = common.getNS(concatenatedSignature, 2)
r = int_from_bytes(rstr, 'big')
s = int_from_bytes(sstr, 'big')
signature = encode_dss_signature(r, s)
k = self._keyObject
if not self.isPublic():
k = k.public_key()
keySize = self.size()
if keySize <= 256: # Hash size depends on key size
hashSize = hashes.SHA256()
elif keySize <= 384:
def _oaep_hash_supported(self, algorithm):
if self._lib.Cryptography_HAS_RSA_OAEP_MD:
return isinstance(
algorithm, (
hashes.SHA1,
hashes.SHA224,
hashes.SHA256,
hashes.SHA384,
hashes.SHA512,
)
)
else:
return isinstance(algorithm, hashes.SHA1)
def encrypt(self,content):
"""Encrypt a (small) message will can be decrypted with the public key"""
apadding = padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA1()),
algorithm=hashes.SHA1(),
label=None)
return self.rsa.encrypt(content,apadding)
fixed_iv_length = cipher_params['fixed_iv_length']
label = b'key expansion'
secret_md5 = secret[:len(secret)/2]
secret_sha = secret[-len(secret)/2:]
md5_material = b''
cur_hash = self.hmac(secret_md5, MD5(), b'%s%s%s' % (label, sr, cr))
for i in range(16):
md5_material += self.hmac(secret_md5, MD5(), b'%s%s%s%s' % (cur_hash, label, sr, cr))
cur_hash = self.hmac(secret_md5, MD5(), cur_hash)
sha_material = b''
cur_hash = self.hmac(secret_sha, SHA1(), b'%s%s%s' % (label, sr, cr))
for i in range(16):
sha_material += self.hmac(secret_sha, SHA1(), b'%s%s%s%s' % (cur_hash, label, sr, cr))
cur_hash = self.hmac(secret_sha, SHA1(), cur_hash)
output = b''
for i in range(min(len(md5_material),len(sha_material))):
output += chr(ord(md5_material[i]) ^ ord(sha_material[i]))
key_material_lengths = [cipher_params['mac_key_length']]*2 + \
[cipher_params['enc_key_length']]*2 + \
[fixed_iv_length]*2
offset = 0
key_material = []
for l in key_material_lengths:
key_material.append(output[offset:offset+l])
offset += l
# DNSSEC algorithm number -> name
ALG = {
5: "RSASHA1",
7: "NSEC3-RSASHA1",
8: "RSASHA256",
10: "RSASHA512",
12: "ECC-GOST",
13: "ECDSA-P256",
14: "ECDSA-P384",
15: "ED25519",
16: "ED448",
}
# DNSSEC algorithm -> hash function
HASHFUNC = {
5: hashes.SHA1,
7: hashes.SHA1,
8: hashes.SHA256,
10: hashes.SHA512,
13: hashes.SHA256,
14: hashes.SHA384,
15: None,
16: None,
}
# DS (Delegation Signer) Digest Algorithms
DS_ALG = {
1: hashes.SHA1,
2: hashes.SHA256,
4: hashes.SHA384,
}