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

digest: algorithm is not supported #359

Closed
B190102B opened this issue May 31, 2024 · 2 comments
Closed

digest: algorithm is not supported #359

B190102B opened this issue May 31, 2024 · 2 comments

Comments

@B190102B
Copy link

代码:

	_, err := req.DevMode().R().SetDigestAuth("username", "password").Put(url)
	if err != nil {
		panic(err)
	}

Output:

HTTP/1.1 401 Unauthorized
Date: Thu, 30 May 2024 17:28:44 GMT
Server: web
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: default-src 'self' 'unsafe-inline' 'unsafe-eval'
X-XSS-Protection: 1
Strict-Transport-Security: max-age=31536000;includeSubDomains
X-Content-Type-Options: nosniff
Content-Length: 142
Content-Type: text/html
Connection: close
WWW-Authenticate: Digest realm="DS-TCG405-E", domain="::", qop="auth", nonce="4d6b493452444d335130553659324534597a41304f47493d", opaque="", algorithm="MD5", stale="FALSE"
X-Appweb-Seq: 193970

panic: digest: algorithm is not supported

req 无法识别 algorithm="MD5",
想请问为什么 c.algorithm 不使用 strings.Trim

digest.go:

func parseChallenge(input string) (*challenge, error) {
	const ws = " \n\r\t"
	const qs = `"`
	s := strings.Trim(input, ws)
	if !strings.HasPrefix(s, "Digest ") {
		return nil, errDigestBadChallenge
	}
	s = strings.Trim(s[7:], ws)
	sl := strings.Split(s, ",")
	c := &challenge{}
	var r []string
	for i := range sl {
		r = strings.SplitN(strings.TrimSpace(sl[i]), "=", 2)
		if len(r) != 2 {
			return nil, errDigestBadChallenge
		}
		switch r[0] {
		case "realm":
			c.realm = strings.Trim(r[1], qs)
		case "domain":
			c.domain = strings.Trim(r[1], qs)
		case "nonce":
			c.nonce = strings.Trim(r[1], qs)
		case "opaque":
			c.opaque = strings.Trim(r[1], qs)
		case "stale":
			c.stale = r[1]
		case "algorithm":
			// Here
			c.algorithm = r[1]
		case "qop":
			c.qop = strings.Trim(r[1], qs)
		case "charset":
			if strings.ToUpper(strings.Trim(r[1], qs)) != "UTF-8" {
				return nil, errDigestCharset
			}
		case "userhash":
			c.userhash = strings.Trim(r[1], qs)
		default:
			return nil, errDigestBadChallenge
		}
	}
	return c, nil
}
imroc added a commit that referenced this issue May 31, 2024
@imroc
Copy link
Owner

imroc commented May 31, 2024

应该是实现上的小失误,已修复,可升级到最新试试

@B190102B
Copy link
Author

Problem solved, thank for your response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants