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

enigma: How to sign and verify tokens or let's use HMAC-SHA256 #11

Closed
aeneasr opened this issue Jan 8, 2016 · 10 comments
Closed

enigma: How to sign and verify tokens or let's use HMAC-SHA256 #11

aeneasr opened this issue Jan 8, 2016 · 10 comments
Assignees
Labels
help wanted We are looking for help on this one. rfc A request for comments to discuss and share ideas.
Milestone

Comments

@aeneasr
Copy link
Member

aeneasr commented Jan 8, 2016

Right now, tokens are going to be saved as a hashed version. I think there should be one more step.

Issuance:

  1. Create random > 128bit key
  2. Create signature by hashing the key with a secret encryption key using HMAC-256)
  3. Use the signature as primary key for the request session end persist it in the store
  4. Issue {base64_encode(key)}.{base64_encode(signature)} to client

Validation:

  1. Decode base64 values
  2. Validate that key matches signature the key and the secret encryption key
  3. Look up key claims (e.g. expiration date or response types) in the store using the signature
  4. Finish request

The secret encryption key should in fact be {global-secret}-{app-secret} making client validation easier and automaticall revoking tokens when secrets are changed.

This has upsides:

  • We could preemptively discgard any tokens that have an invalid signature (and thus remove database workload).
  • Resource servers could validate the tokens if they know the secret key without establishing a network connection.
  • An attacker knowing the secret encryption key would still not be able to restore a token's key from it's signature.
  • An attacker would require the secret encryption key and have somehow gain write permissions on the database to forge and inject a valid token or authorize code.
  • If the secret encryption key is believed to be compromised, changing it will invalidate all tokens including those who are possibliy forged
  • If the mechanism for generating the secret key is believed to be weak, it can be replaced with a new one making all old and insecure tokens invalid
  • If the client secret is changed, all of it's tokens bekome invalid giving the power to handle and invalidate lost client credentials in a timely fashion.

It should be noted that the secret encryption key is replaceable. Clients are expected to handle revoked tokens if they implement OAuth2. Replacing the current secret encryption key with a new one would render all previously generated tokens to become invalid. Clients should handle this by re-authorizing.

The more I think about this, the more I like this idea.

@aeneasr aeneasr added help wanted We are looking for help on this one. rfc A request for comments to discuss and share ideas. labels Jan 8, 2016
@aeneasr aeneasr self-assigned this Jan 8, 2016
@aeneasr aeneasr added this to the v0 milestone Jan 8, 2016
@aeneasr aeneasr changed the title enigma: How to sign and verify tokens enigma: How to sign and verify tokens or let's use HMAC-SHA256 Jan 8, 2016
@aeneasr aeneasr closed this as completed in 01f9ede Jan 8, 2016
aeneasr pushed a commit that referenced this issue Jan 8, 2016
Closes #8 and introduces shift to new token logic proposed in #11
@danielchatfield
Copy link

I know you've closed this but thought I'd add my 2¢.

Could you not support the use of an asymmetric signature scheme? You could have systems that need to check the validity of a token but shouldn't be trusted with the key that can sign them.

@danielchatfield
Copy link

Example use case: you might want a high performance proxy to drop all requests with invalid tokens to mitigate a DDoS attack but would not want the secret to be on an internet facing box.

@danielchatfield
Copy link

Just to be clear, I think HMAC-256 is perfectly fine but would like the interface to be provided in a way such that it would be easy to swap it for an asymmetric DSA.

@aeneasr aeneasr reopened this Jan 9, 2016
@aeneasr
Copy link
Member Author

aeneasr commented Jan 9, 2016

Definitely appreciate the cents :)

Yes, I think it is a good idea to support different token generation strategies. This is already possible, because Enigma is an interface and the authorize code plugin uses that interface, not a concrete implementation of it. You can switch the code generation strategy (and later access token / refresh token) easily by replacing the dependency in your fosite factory method.

It should however be noted that cryptographic token validation on the resource provider side does not equal token validation by lookup. OAuth2 was designed with revokable tokens in mind, which always requires a database lookup. It fits however very nicely in to your use case:

Example use case: you might want a high performance proxy to drop all requests with invalid tokens to mitigate a DDoS attack but would not want the secret to be on an internet facing box.

Thanks for your input, I really appreciate it!

@aeneasr
Copy link
Member Author

aeneasr commented Jan 9, 2016

Check out the factory method of the authorize endpoint in the tests. I think this is what you asked for, isn't it? :)

@danielchatfield
Copy link

Looks good to me :)

@aeneasr
Copy link
Member Author

aeneasr commented Jan 9, 2016

Awesome, closing this then :)

@aeneasr aeneasr closed this as completed Jan 9, 2016
@aeneasr
Copy link
Member Author

aeneasr commented Jan 10, 2016

I just stumbled upon https://tools.ietf.org/html/rfc6819#section-5.1.4.1.5

5.1.4.1.5. Use of Asymmetric Cryptography
Usage of asymmetric cryptography will free the authorization server
of the obligation to manage credentials.

@aeneasr
Copy link
Member Author

aeneasr commented Jan 13, 2016

JWT are encoded as a JSON object that is used as the payload of a JSON Web Signature (JWS) structure or ...
Source

And JWS support assymetric algorithms like RS256.

@danielchatfield what do you think of using JWT instead of DSA for your use case?

Also take a look at #16

@danielchatfield
Copy link

👍

@aeneasr aeneasr mentioned this issue Jan 20, 2016
budougumi0617 added a commit to budougumi0617/fosite that referenced this issue May 10, 2019
budougumi0617 added a commit to budougumi0617/fosite that referenced this issue May 10, 2019
Closes ory#8 and introduces shift to new token logic proposed in ory#11
juguhan pushed a commit to juguhan/fosite that referenced this issue Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We are looking for help on this one. rfc A request for comments to discuss and share ideas.
Projects
None yet
Development

No branches or pull requests

2 participants