Skip to content

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

Closed

Description

@greglearns

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?

Activity

  1. Keats commented on Dec 5, 2018

    @Keats
    Owner

    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.

  2. AaronFriel commented on Jan 2, 2019

    @AaronFriel

    @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.

  3. mikeumus commented on Dec 12, 2019

    @mikeumus

    @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");
  4. Keats commented on Dec 12, 2019

    @Keats
    Owner

    v7 alpha also does it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions