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

[sd_jwt] possibly unsafe manipulation of secret bits #276

Open
Zicchio opened this issue Sep 30, 2024 · 0 comments
Open

[sd_jwt] possibly unsafe manipulation of secret bits #276

Zicchio opened this issue Sep 30, 2024 · 0 comments
Assignees
Labels
enhancement Something improving existing features security
Milestone

Comments

@Zicchio
Copy link
Collaborator

Zicchio commented Sep 30, 2024

These lines of code

pn = key.private_numbers()
params.update(
kty='RSA',
n=pk_encode_int(pn.public_numbers.n),
e=pk_encode_int(pn.public_numbers.e),
d=pk_encode_int(pn.d),
p=pk_encode_int(pn.p),
q=pk_encode_int(pn.q),
dp=pk_encode_int(pn.dmp1),
dq=pk_encode_int(pn.dmq1),
qi=pk_encode_int(pn.iqmp)
)

which use this function as primitive
def pk_encode_int(i: str, bit_size: int = None) -> str:
"""
Encode an integer as a base64url string with padding.
:param i: the integer to encode.
:type i: str
:param bit_size: the bit size of the integer.
:type bit_size: int
:returns: the encoded integer.
:rtype: str
"""
extend = 0
if bit_size is not None:
extend = ((bit_size + 7) // 8) * 2
hexi = hex(i).rstrip("L").lstrip("0x")
hexl = len(hexi)
if extend > hexl:
extend -= hexl
else:
extend = hexl % 2
return base64url_encode(unhexlify(extend * '0' + hexi))

possibly manipulate secret bits without using a constant time function.
This probably isn't a big problem, but there is a (very remote) possibility that this might lead to a time based side channel attack.

@Zicchio Zicchio self-assigned this Sep 30, 2024
@peppelinux peppelinux added enhancement Something improving existing features security labels Oct 23, 2024
@peppelinux peppelinux added this to the 0.9.1 milestone Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something improving existing features security
Projects
Status: No status
Development

No branches or pull requests

2 participants