Skip to content

Update README.md to include HMAC key length recommendations#447

Closed
philsmart wants to merge 1 commit intoauth0:masterfrom
philsmart:master
Closed

Update README.md to include HMAC key length recommendations#447
philsmart wants to merge 1 commit intoauth0:masterfrom
philsmart:master

Conversation

@philsmart
Copy link
Copy Markdown

Added JWA HMAC secret key length requirement information

Changes

Please describe both what is changing and why this is important. Include:

  • Endpoints added, deleted, deprecated, or changed
  • Classes and methods added, deleted, deprecated, or changed
  • Screenshots of new or changed UI, if applicable
  • A summary of usage if this is a new feature or change to a public API (this should also be added to relevant documentation once released)
  • Any alternative designs or approaches considered

References

Please include relevant links supporting this change such as a:

  • support ticket
  • community post
  • StackOverflow post
  • support forum thread

Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

  • This change adds test coverage
  • This change has been tested on the latest version of Java or why not

Checklist

Added JWA HMAC secret key length requirement information
@philsmart philsmart requested a review from a team October 24, 2020 09:11

##### HMAC Key Length and Security

When using a Hash-based Message Authenticaton Code e.g. HS256 or HS512, in order to comply with the strict requirements of the JSON Web Algorithms (JWA) specification (RFC7518), you **must** use a secret key which has the same bit length as the size of the output hash - to avoid weakening the security strength of the authentication code (see NIST recomendations NIST SP 800-117). For example, when using HMAC256, the secret key length must be a minimum of 256 bits (larger key sizes do not increase the security strength further).
Copy link
Copy Markdown
Member

@panva panva Oct 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When using a Hash-based Message Authenticaton Code e.g. HS256 or HS512, in order to comply with the strict requirements of the JSON Web Algorithms (JWA) specification (RFC7518), you **must** use a secret key which has the same bit length as the size of the output hash - to avoid weakening the security strength of the authentication code (see NIST recomendations NIST SP 800-117). For example, when using HMAC256, the secret key length must be a minimum of 256 bits (larger key sizes do not increase the security strength further).
When using a Hash-based Message Authenticaton Code e.g. HS256 or HS512, in order to comply with the strict requirements of the JSON Web Algorithms (JWA) specification (RFC7518), you **must** use a secret key which has the same (or larger) bit length as the size of the output hash - to avoid weakening the security strength of the authentication code (see NIST recomendations NIST SP 800-117). For example, when using HMAC256, the secret key length must be a minimum of 256 bits.


When using a Hash-based Message Authenticaton Code e.g. HS256 or HS512, in order to comply with the strict requirements of the JSON Web Algorithms (JWA) specification (RFC7518), you **must** use a secret key which has the same bit length as the size of the output hash - to avoid weakening the security strength of the authentication code (see NIST recomendations NIST SP 800-117). For example, when using HMAC256, the secret key length must be a minimum of 256 bits (larger key sizes do not increase the security strength further).

Note, the secret key string is converted to bytes assuming a UTF-8 encoding, you must therefore gurantee the results of that conversion produce the required bit length. For example, if only ASCII characters where used in the secret key, each character would convert to a single byte (8 bits), which means for HS256 you would need a mimimum of a 32 character secret.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no affordance for passing non-utf8 secrets? As in - providing the byte array directly?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the API for the Algorithm class supports byte arrays directly, yes. You could perhaps remove the last paragraph if you wanted.

However, I still think it is probably wise to let people know what happens if they do use a String input to the Algorithm API. Because I can not see there is an option to tell it that the String is actually a binary to text representation e.g. base64.

@jimmyjames jimmyjames self-assigned this Nov 5, 2020
@stevehobbsdev stevehobbsdev requested a review from panva February 4, 2021 16:07
Copy link
Copy Markdown
Member

@panva panva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to make the changes previously suggested and remove the second paragraph.

@jimmyjames
Copy link
Copy Markdown
Contributor

Replaced with #477, which includes the changes here along with the changes @panga recommended.

@jimmyjames jimmyjames closed this Feb 24, 2021
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 this pull request may close these issues.

3 participants