Skip to content

Commit 77aabc8

Browse files
committed
A2 hash should use the request's method (closes #13)
According to RFC2617 3.2.2.3 A2, 'If the "qop" directive's value is "auth" or is unspecified, then A2 is': A2 = Method ":" digest-uri-value Before this commit 'Method' was always GET even if the request was a POST, PUT, etc. For some reason, this bug has only posed a problem for SetReview. In other cases Gerrit seems to accept the request rather than returning 401 Unauthorized.
1 parent 8534915 commit 77aabc8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

authentication.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (s *AuthenticationService) SetDigestAuth(username, password string) {
5151
// returns 401 Unauthorized and authType was set to authTypeDigest. The
5252
// resulting string is used to set the Authorization header before retrying
5353
// the request.
54-
func (s *AuthenticationService) digestAuthHeader(response *http.Response) (string, error) {
54+
func (s *AuthenticationService) digestAuthHeader(method string, response *http.Response) (string, error) {
5555
authenticateHeader := response.Header.Get("WWW-Authenticate")
5656
if authenticateHeader == "" {
5757
return "", fmt.Errorf("WWW-Authenticate header is missing")
@@ -112,7 +112,7 @@ func (s *AuthenticationService) digestAuthHeader(response *http.Response) (strin
112112

113113
// A2
114114
h = md5.New()
115-
A2 := fmt.Sprintf("GET:%s", uriHeader)
115+
A2 := fmt.Sprintf("%s:%s", method, uriHeader)
116116
io.WriteString(h, A2)
117117
HA2 := fmt.Sprintf("%x", h.Sum(nil))
118118

gerrit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (c *Client) addAuthentication(req *http.Request) error {
277277
defer response.Body.Close()
278278

279279
if response.StatusCode == http.StatusUnauthorized {
280-
authorization, err := c.Authentication.digestAuthHeader(response)
280+
authorization, err := c.Authentication.digestAuthHeader(req.Method, response)
281281

282282
if err != nil {
283283
return err

0 commit comments

Comments
 (0)