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

How to use JsonWebToken when I don't have a DER and can't use command line tools #68

Closed
greglearns opened this issue Dec 4, 2018 · 4 comments

Comments

@greglearns
Copy link

I have a rust service that needs to verify JWTs from 3rd-party services that I do not control. The 3rd party service (Portier, in this case) supplies the RSA public components (n modulus, and e exponent). Given that jsonwebtoken can only read DER encoded keys and that I cannot manually run the recommended command-line options for OpenSSL, what is the recommended way of being able to decode a JWT using JsonWebToken in a rust service?

Currently, I have been able to get an ssh public key from the rsa components (n, e) https://github.com/coreos/openssh-keys/blob/master/src/lib.rs#L363 but that seems like a dead end since a public ssh key doesn't seem to be easily converted to DER.

Any ideas?

@Keats
Copy link
Owner

Keats commented Dec 5, 2018

I don't think there is currently an easy way to do that. It would be nice to have a function in jsonwebtoken that does the DER conversion but haven't looked into that yet.

@AaronFriel
Copy link

AaronFriel commented Jan 2, 2019

@Keats there appears to be a function in Ring that will do this: https://briansmith.org/rustdoc/ring/signature/primitive/fn.verify_rsa.html

Would you consider a PR that would add a function with a signature like the following?

pub fn decode_rsa<T: DeserializeOwned>(
    token: &str,
    n: &[u8],
    e: &[u8],
    validation: &Validation,
) -> Result<TokenData<T>>

Edit: Added the missing key parameter to the signature of the method.

@mikeumus
Copy link

@greglearns there's these methods from azure-jwt (rust) repo in GitHub that can convert a KEY to a DER format:

        // jwt library expects a `*.der` key wich is a byte encoded file so
        // we need to convert the key from base64 to their byte value to use them.
        let private_key = from_base64_to_bytearray_non_url(PRIVATE_KEY_TEST).expect("priv_key");

@Keats
Copy link
Owner

Keats commented Dec 12, 2019

v7 alpha also does it

@Keats Keats closed this as completed Jan 29, 2020
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

No branches or pull requests

4 participants