Skip to content

KeyBundle's do_keys ignores invalid keys #63

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

Closed
angelakis opened this issue Aug 28, 2020 · 7 comments · Fixed by #69
Closed

KeyBundle's do_keys ignores invalid keys #63

angelakis opened this issue Aug 28, 2020 · 7 comments · Fixed by #69
Assignees

Comments

@angelakis
Copy link
Contributor

KeyBundle's do_keys method tries to load keys from a JSON jwks file and if it finds a key that is considered invalid, it overwrites it in the existing file.

Not sure if this is considered a bug, but it seems counter-intuitive to me. Maybe we should instead raise an exception and let the user/app know that there's an error with their key?

@jschlyter jschlyter self-assigned this Aug 31, 2020
@jschlyter
Copy link
Collaborator

Can you provide an example? I tried to replicate, but failed.

@angelakis
Copy link
Contributor Author

angelakis commented Aug 31, 2020

You can replicate by loading a malformed RSA key from a json file given in the private_path of init_key_jar. Cryptojwt will issue a warning (e.g. While loading keys: private_exponent must be < modulus.) and then proceed in generating a new RSA key and overwriting the existing (malformed) RSA key in the file.

This happens only with read_only set to False. If it's True, a new key is generated but is not written to the file and a warning is written: Not allowed to write to disc! (sic). This also strikes me as non-intuitive, as the key will be lost when the app is restarted.

I would prefer that an exception is raised in cases of corrupted/malformed keys, instead of handling it and generating new keys, but I may well be wrong.

@jschlyter
Copy link
Collaborator

A challenge might be that sometimes you want to read all the keys you can and ignore the other, and sometimes you want to fail upon error. Perhaps a flag to KeyBundle (default False) to indicate whether to abort on invalid keys?

@rohe
Copy link
Contributor

rohe commented Sep 1, 2020

Yeah, I've never been able to decide on the correct behaviour (fail or best effort).
A flag deciding on what to do sounds good to me.

@jschlyter
Copy link
Collaborator

I'm thinking we could add a accept_invalid_keys(default True, current behavior) flag to KeyBundle. If False, raise exception when reading an invalid/unknown/unsupported key.

@jschlyter
Copy link
Collaborator

Code review needed by @angelakis

@rohe
Copy link
Contributor

rohe commented Oct 2, 2020

What I think is more of an ignore_invalid_keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants