-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Bug
Current EVE SSO implementation of /v2/oauth/token endpoint for PKCE uses unnecessary BASE64URL-ENCODING for code_verifier parameter.
According to RFC 7636 Proof Key for Code Exchange by OAuth Public Clients code_verifier and code_challenge parameters are created in following manner:
STRING code_verifier = random STRING of characters [A-Z]/[a-z]/[0-9]/-/./_/~
STRING code_challenge = BASE64URL-ENCODE( SHA256( ASCII(code_verifier) ) )
No additional encoding is required for the parameters sent to the server. RFC 7636, Appendix B provides an example:
code_verifier = random_string => "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
d = SHA256(code_verifier) => 0x13d31e961a1ad8ec2f16b10c4c982e0876a878ad6df144566ee1894acb70f9c3
code_challenge = BASE64URL-ENCODE(d) => "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"
In the example, the authorization request includes
code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256
and the request to the token_endpoint includes
code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
There is no additional encoding for the parameters.
This procedure doesn't work for EVE SSO and results in status 500 for POST request to /v2/oauth/token enpoint.
Actual Behaviour
Actual EVE SSO Authorization Code with PKCE behaviour can be reconstructed by python example available here. The example does work with EVE SSO server!
According to the example code_verifier and code_challenge parameters are created in following manner:
random = BASE64URL-ENCODE( <32 random bytes> )
d = SHA256( random )
code_challenge = BASE64URL-ENCODE(d)
code_verifier = BASE64URL-ENCODE(random)
First three lines follow RFC 7636 procedure for code_challenge creation.
To follow the RFC, code_verifier value should be equal to value of random string. But in fourth line the example makes additional BASE64URL-ENCODE to calc code_verifier value and this violates RFC 7636.
Expected Behaviour
No additional BASE64URL-ENCODE for code_verifier parameter required on /v2/oauth/token endpoint.
Workaround
One can't use standard OAuth 2.0 RFC 7636 compatible libraries to work with EVE SSO because of the bug. To make them work one can intercept POST request to /v2/oauth/token enpoint and replace code_verifier body parameter with BASE64URL-ENCODE(code_verifier) value.