Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage
Highlighted

Error in querystring hash instructions for connect apps (JWT token creation) Edited

Hi

Following the instructions from: https://developer.atlassian.com/cloud/jira/platform/understanding-jwt/

I think there is a very misleading error in the description on how to create the query hash.

Step 7 states:

Hash the canonical request bytes using the SHA-256 algorithm

  • e.g. The SHA-256 hash of "foo" is "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"

This is not correct in all cases. The hash of foo in C# is a byte array, not a string. Only by applying hex encoding to the hash will the resulting UTF8 string become the string mentioned above. This step is omitted in the instructions. Also in other places Base64-encoding is used, but for the query hash, HEX encoding is used. Maybe this is some default in JAVA?

Since the query hash is a bit overworked anyway, clear instructions would help =).

For my C# aspnet core 2.2 implementation of a jwt token, I used the code below.
signingUrlString is the input in the format described in the instructions, ex:
GET&/path/to/api/method&....

using (SHA256 mySHA256 = SHA256.Create())
{
var signingBytes = Encoding.UTF8.GetBytes(signingUrlString);
var shaHashofSigning = mySHA256.ComputeHash(signingBytes);
queryHash = ToHex(shaHashofSigning, false);
}

 ToHex:

private static string ToHex(byte[] bytes, bool upperCase)
{
StringBuilder result = new StringBuilder(bytes.Length * 2);

for (int i = 0; i < bytes.Length; i++)
result.Append(bytes[i].ToString(upperCase ? "X2" : "x2"));

return result.ToString();
}

 I used a validation tool for the querystring hash during testing of the JWT implementation to check if the hash was correct: http://jwt-decoder.herokuapp.com/jwt/decode

I have no affiliation to the tool itself, so I cannot say if its safe or not, so use with caution, and do not expose any sensitive urls or queries.

I Hope this might help anyone who have issues with the querystring hash. Please comment if you have any input on this, or if you find errors in the code.

Best regards

Torbjörn

0 comments

Comment

Log in or Sign up to comment
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you