mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-01 13:20:30 +00:00
A key agreement cannot be chained with PSA_ALG_TLS12_ECJPAKE_TO_PMS
Test accordingly. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
2566679eb8
commit
f6c6b64be2
@ -246,6 +246,8 @@ class KeyType:
|
|||||||
# So a public key object with a key agreement algorithm is not
|
# So a public key object with a key agreement algorithm is not
|
||||||
# a valid combination.
|
# a valid combination.
|
||||||
return False
|
return False
|
||||||
|
if alg.is_invalid_key_agreement_with_derivation():
|
||||||
|
return False
|
||||||
if self.head == 'ECC':
|
if self.head == 'ECC':
|
||||||
assert self.params is not None
|
assert self.params is not None
|
||||||
eccc = EllipticCurveCategory.from_family(self.params[0])
|
eccc = EllipticCurveCategory.from_family(self.params[0])
|
||||||
@ -412,17 +414,38 @@ class Algorithm:
|
|||||||
self.category = self.determine_category(self.base_expression, self.head)
|
self.category = self.determine_category(self.base_expression, self.head)
|
||||||
self.is_wildcard = self.determine_wildcard(self.expression)
|
self.is_wildcard = self.determine_wildcard(self.expression)
|
||||||
|
|
||||||
def is_key_agreement_with_derivation(self) -> bool:
|
def get_key_agreement_derivation(self) -> Optional[str]:
|
||||||
"""Whether this is a combined key agreement and key derivation algorithm."""
|
"""For a combined key agreement and key derivation algorithm, get the derivation part.
|
||||||
|
|
||||||
|
For anything else, return None.
|
||||||
|
"""
|
||||||
if self.category != AlgorithmCategory.KEY_AGREEMENT:
|
if self.category != AlgorithmCategory.KEY_AGREEMENT:
|
||||||
return False
|
return None
|
||||||
m = re.match(r'PSA_ALG_KEY_AGREEMENT\(\w+,\s*(.*)\)\Z', self.expression)
|
m = re.match(r'PSA_ALG_KEY_AGREEMENT\(\w+,\s*(.*)\)\Z', self.expression)
|
||||||
if not m:
|
if not m:
|
||||||
return False
|
return None
|
||||||
kdf_alg = m.group(1)
|
kdf_alg = m.group(1)
|
||||||
# Assume kdf_alg is either a valid KDF or 0.
|
# Assume kdf_alg is either a valid KDF or 0.
|
||||||
return not re.match(r'(?:0[Xx])?0+\s*\Z', kdf_alg)
|
if re.match(r'(?:0[Xx])?0+\s*\Z', kdf_alg):
|
||||||
|
return None
|
||||||
|
return kdf_alg
|
||||||
|
|
||||||
|
KEY_DERIVATIONS_INCOMPATIBLE_WITH_AGREEMENT = frozenset([
|
||||||
|
'PSA_ALG_TLS12_ECJPAKE_TO_PMS', # secret input in specific format
|
||||||
|
])
|
||||||
|
def is_valid_key_agreement_with_derivation(self) -> bool:
|
||||||
|
"""Whether this is a valid combined key agreement and key derivation algorithm."""
|
||||||
|
kdf_alg = self.get_key_agreement_derivation()
|
||||||
|
if kdf_alg is None:
|
||||||
|
return False
|
||||||
|
return kdf_alg not in self.KEY_DERIVATIONS_INCOMPATIBLE_WITH_AGREEMENT
|
||||||
|
|
||||||
|
def is_invalid_key_agreement_with_derivation(self) -> bool:
|
||||||
|
"""Whether this is an invalid combined key agreement and key derivation algorithm."""
|
||||||
|
kdf_alg = self.get_key_agreement_derivation()
|
||||||
|
if kdf_alg is None:
|
||||||
|
return False
|
||||||
|
return kdf_alg in self.KEY_DERIVATIONS_INCOMPATIBLE_WITH_AGREEMENT
|
||||||
|
|
||||||
def short_expression(self, level: int = 0) -> str:
|
def short_expression(self, level: int = 0) -> str:
|
||||||
"""Abbreviate the expression, keeping it human-readable.
|
"""Abbreviate the expression, keeping it human-readable.
|
||||||
@ -515,7 +538,7 @@ class Algorithm:
|
|||||||
if category == self.category:
|
if category == self.category:
|
||||||
return True
|
return True
|
||||||
if category == AlgorithmCategory.KEY_DERIVATION and \
|
if category == AlgorithmCategory.KEY_DERIVATION and \
|
||||||
self.is_key_agreement_with_derivation():
|
self.is_valid_key_agreement_with_derivation():
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user