Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify location of alg and crit header parameters #94

Open
letmaik opened this issue Nov 6, 2022 · 0 comments
Open

Verify location of alg and crit header parameters #94

letmaik opened this issue Nov 6, 2022 · 0 comments
Labels
bug Something isn't working cose attributes Issue related to COSE attributes

Comments

@letmaik
Copy link
Collaborator

letmaik commented Nov 6, 2022

COSE requires that alg must be authenticated (external_aad or protected header) and crit must be in the protected header. pycose reads both parameters from the unprotected header if missing in the protected header.

def verify_signature(self, *args, **kwargs) -> bool:
"""
Verifies the signature of a received COSE message.
:returns: True for a valid signature or False for an invalid signature
"""
alg = self.get_attr(headers.Algorithm)
self._key_verification(alg, VerifyOp)
return alg.verify(key=self.key, data=self._sig_structure, signature=self.signature)

def get_attr(self, attribute: Type[CoseHeaderAttribute], default: Any = None) -> Optional[Any]:
"""
Fetches an header attribute from the COSE header buckets.
:param attribute: A header parameter to fetch from the buckets.
:param default: A default return value in case the attribute was not found
:raise CoseException: When the same attribute is found in both the protected and unprotected header.
:returns: If found returns a header attribute else 'None' or the default value
"""
p_attr = self._phdr.get(attribute, default)
u_attr = self._uhdr.get(attribute, default)
if p_attr is not None and u_attr is not None:
raise CoseException("MALFORMED: different values for the same header parameters in the header buckets")
if p_attr is not None:
return p_attr
else:
return u_attr

The get_attr method should be extended to check whether a parameter is required to be in the protected bucket. This requires another field in the attribute class.

@letmaik letmaik added bug Something isn't working cose attributes Issue related to COSE attributes labels Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cose attributes Issue related to COSE attributes
Projects
None yet
Development

No branches or pull requests

1 participant