补充阿里云DNS签名兼容说明
Some checks are pending
Security Checks / security (push) Waiting to run

This commit is contained in:
smail 2026-09-22 04:39:55 +08:00
parent 2489be5570
commit fd54ac9898

View File

@ -197,7 +197,9 @@ func (provider *aliDNSChallenge) call(action string, values url.Values, target a
values.Set("SignatureNonce", hex.EncodeToString(nonce))
values.Set("Timestamp", time.Now().UTC().Format("2006-01-02T15:04:05Z"))
canonical := strings.ReplaceAll(values.Encode(), "+", "%20")
mac := hmac.New(sha1.New, []byte(provider.secretKey+"&"))
// 阿里云 DNS RPC API 的当前签名协议固定使用 HMAC-SHA1;此处不能自行替换为 SHA-256,
// 否则服务商会拒绝请求。请求通过 HTTPS 发送,密钥只用于内存中的签名计算。
mac := hmac.New(sha1.New, []byte(provider.secretKey+"&")) // #nosec G505 -- 阿里云 DNS RPC API 要求 HMAC-SHA1
_, _ = mac.Write([]byte("POST&%2F&" + aliDNSPercentEncode(canonical)))
values.Set("Signature", base64.StdEncoding.EncodeToString(mac.Sum(nil)))
request, err := http.NewRequest(http.MethodPost, provider.endpoint, strings.NewReader(values.Encode()))