X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/95de13bdab14eb803a4c9e2243df50e1eb0df69a..ba1114ac181b6648a798385058e6c18d92ec56ef:/sdk/go/auth/salt.go diff --git a/sdk/go/auth/salt.go b/sdk/go/auth/salt.go index f669eb2760..2140215986 100644 --- a/sdk/go/auth/salt.go +++ b/sdk/go/auth/salt.go @@ -9,6 +9,7 @@ import ( "crypto/sha1" "errors" "fmt" + "io" "regexp" "strings" ) @@ -25,15 +26,16 @@ func SaltToken(token, remote string) (string, error) { if len(parts) < 3 || parts[0] != "v2" { if reObsoleteToken.MatchString(token) { return "", ErrObsoleteToken - } else { - return "", ErrTokenFormat } + return "", ErrTokenFormat } uuid := parts[1] secret := parts[2] if len(secret) != 40 { // not already salted - secret = fmt.Sprintf("%x", hmac.New(sha1.New, []byte(secret)).Sum([]byte(remote))) + hmac := hmac.New(sha1.New, []byte(secret)) + io.WriteString(hmac, remote) + secret = fmt.Sprintf("%x", hmac.Sum(nil)) return "v2/" + uuid + "/" + secret, nil } else if strings.HasPrefix(uuid, remote) { // already salted for the desired remote