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

Fix PKCE Oauth2 exchange #24858

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,16 @@ func (c *LoginCommand) proofKey() (key, challenge string, err error) {
// UUID spec, but our go-uuid just generates totally random number sequences
// formatted in the conventional UUID syntax, so that concern does not
// apply here: this is just a 128-bit crypto-random number.
key, err = uuid.GenerateUUID()
uu, err := uuid.GenerateUUID()
if err != nil {
return "", "", err
}

key = fmt.Sprintf("%s.%09d", uu, rand.Intn(999999999))

h := sha256.New()
h.Write([]byte(key))
challenge = base64.URLEncoding.EncodeToString(h.Sum(nil))
challenge = base64.RawURLEncoding.EncodeToString(h.Sum(nil))

return key, challenge, nil
}
Expand Down
2 changes: 1 addition & 1 deletion command/testdata/login-oauth-server/oauthserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (h handler) serveToken(resp http.ResponseWriter, req *http.Request) {
case "S256":
h := sha256.New()
h.Write([]byte(codeVerifier))
encVerifier := base64.URLEncoding.EncodeToString(h.Sum(nil))
encVerifier := base64.RawURLEncoding.EncodeToString(h.Sum(nil))
if codeParts[1] != encVerifier {
log.Printf("/token: incorrect code verifier %q; want %q", codeParts[1], encVerifier)
resp.Header().Set("Content-Type", "application/json")
Expand Down