fix: code challenge

This commit is contained in:
Livio Amstutz 2020-02-28 18:07:01 +01:00
parent 7f486a54c4
commit c3169868d8
3 changed files with 8 additions and 4 deletions

View file

@ -19,7 +19,7 @@ type CodeChallenge struct {
}
func NewSHACodeChallenge(code string) string {
return utils.HashString(sha256.New(), code)
return utils.HashString(sha256.New(), code.false)
}
func VerifyCodeChallenge(c *CodeChallenge, codeVerifier string) bool {

View file

@ -185,7 +185,7 @@ func ClaimHash(claim string, sigAlgorithm jose.SignatureAlgorithm) (string, erro
return "", err
}
return utils.HashString(hash, claim), nil
return utils.HashString(hash, claim, true), nil
}
func timeToJSON(t time.Time) int64 {

View file

@ -23,8 +23,12 @@ func GetHashAlgorithm(sigAlgorithm jose.SignatureAlgorithm) (hash.Hash, error) {
}
}
func HashString(hash hash.Hash, s string) string {
func HashString(hash hash.Hash, s string, firstHalf bool) string {
hash.Write([]byte(s)) // hash documents that Write will never return an error
sum := hash.Sum(nil)[:hash.Size()/2]
size = hash.Size()
if firstHalf {
size = size / 2
}
sum := hash.Sum(nil)[:size]
return base64.RawURLEncoding.EncodeToString(sum)
}