Skip to content

Commit 814b93b

Browse files
committed
fix: verifier with multiple certificate.
1 parent 68f001d commit 814b93b

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
.idea/

pymdoccbor/mso/verifier.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pycose.keys import CoseKey, EC2Key
66
from pycose.messages import Sign1Message
77

8-
from typing import Union
8+
from typing import Union, Any
99

1010
from pymdoccbor.exceptions import (
1111
MsoX509ChainNotFound,
@@ -75,15 +75,31 @@ def payload_as_dict(self):
7575
)
7676

7777
@property
78-
def raw_public_keys(self) -> bytes:
78+
def raw_public_keys(self) -> list[Any]:
7979
"""
8080
it returns the public key extract from x509 certificates
8181
looking to both phdr and uhdr
8282
"""
83-
_mixed_heads = self.object.phdr.items() | self.object.uhdr.items()
83+
# _mixed_heads = self.object.phdr.items() | self.object.uhdr.items()
84+
85+
merged = self.object.phdr.copy()
86+
merged.update(self.object.uhdr)
87+
_mixed_heads = merged.items()
8488
for h, v in _mixed_heads:
8589
if h.identifier == 33:
86-
return list(self.object.uhdr.values())
90+
# return list(self.object.uhdr.values())
91+
if isinstance(v, bytes):
92+
return [v]
93+
elif isinstance(v, list):
94+
return v
95+
elif isinstance(v, dict):
96+
return [v]
97+
else:
98+
logger.warning(
99+
f"Unexpected type for public key: {type(v)}. "
100+
"Expected bytes, list or dict."
101+
)
102+
continue
87103

88104
raise MsoX509ChainNotFound(
89105
"I can't find any valid X509certs, identified by label number 33, "

0 commit comments

Comments
 (0)