FHIR Chat · Java RS384 JWT Implementation · Security and Privacy

Stream: Security and Privacy

Topic: Java RS384 JWT Implementation


view this post on Zulip Benjamin Langley (Oct 21 2020 at 16:32):

I'm looking at implementing server to server OAuth as defined in Bulk Data (https://hl7.org/fhir/uv/bulkdata/authorization/index.html). The client assertion is a signed JWT using RS384. I have a Java server which wishes to verify this signature using the public key from the jwks.

I'm using the auth0 jwt library to verify the signature. To do this an algorithm is required which takes as an input the java security RSAPublicKey. However I am having difficulty creating the RSAPublicKey object from the jwk set. The parameters n and e in jwks are Base64 URL Encoded by the RSAPublicKey uses BigIntegers. The following seems to work:
BigInteger e = new BigInteger(Base64.getUrlDecoder().decode(rawExponent));
But for the modulus it appears to overflow; the result is -310301627147497527848975101822928448285430943117086804.......

Has anyone else successfully created an RSAPublicKey object from a jwk set?

view this post on Zulip Benjamin Langley (Oct 21 2020 at 16:33):

For reference here is the public key I am using to verify the JWT

{
  "keys": [
    {
      "kty": "RSA",
      "alg": "RS384",
      "n": "52tcPrGJgzyGqjcUiHsbSk_PxQ7Uovz4saGxva3iyBoidsekonigJJ3LnFlHYb3vBa2NA-0GpX2E1KhNNcYWAWQFcu069zi0YZ_wWGn6PWZURuonUoKH4dGHggym3xxVUxuA8OPubGe5ji56eic4RPINg0z-TtPlS-H9dnDIVznRUTXf3fy2dqWMuTY4D2e4fXGII6OpFAsEyrOqIoR8pLWGu7AiQkothunopp9q_Gu2xqB6l8BNulsbiwsQMeRE-9SGfeFpyblHiizHDwSqeZ3iv49Ellk4yjmrf6wOaFA2IXRqL1cCLj86B6KIDrjdzOL4lOSiES-PclNpioG2rQ",
      "e": "AQAB",
      "key_ops": ["verify"],
      "ext": true,
      "kid": "3ab8b05b64d799e289e10a201786b38c"
    }
  ]
}

view this post on Zulip Benjamin Langley (Oct 21 2020 at 17:47):

If anyone runs into this problem again the issue was with number representations. The jwks is Base64Url encoded big endian but the BigInteger byte array constructor expects two's complement. The solution is to use BigInteger e = new BigInteger(1, Base64.getUrlDecoder().decode(rawExponent));

view this post on Zulip John Moehrke (Oct 21 2020 at 19:37):

:+1:


Last updated: Apr 12 2022 at 19:14 UTC