Skip to content

Commit

Permalink
[fix] 强行指定 acl 签名时 ExtFields 的排序方式,防止部分接口 acl 认证出错。
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzebin committed Dec 17, 2024
1 parent 8b30292 commit 49c751b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions NewLife.RocketMQ/ClusterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,25 @@ private void SetSignature(Command cmd)
var sha = new HMACSHA1(secretKey.GetBytes());
var ms = new MemoryStream();

// AccessKey + OnsChannel
ms.Write(accessKey.GetBytes());
ms.Write(onsChannel.GetBytes());

// ExtFields
var dic = cmd.Header.GetExtFields();
//var extFieldsDic = dic.OrderBy(e => e.Key).ToDictionary(e => e.Key, e => e.Value);
foreach (var extFields in dic)
dic["AccessKey"] = accessKey;
dic["OnsChannel"] = onsChannel;

// 按照 asscii 排序已有 key
var comparer = Comparer<string>.Create(string.CompareOrdinal);
foreach (var item in dic.OrderBy(e => e.Key, comparer).ToDictionary(e => e.Key, e => e.Value))
{
if (extFields.Value != null) ms.Write(extFields.Value.GetBytes());
if (item.Value != null)
{
ms.Write(item.Value.GetBytes());
}
}

// Body
cmd.Payload?.CopyTo(ms);

var sign = sha.ComputeHash(ms.ToArray());
dic["Signature"] = sign.ToBase64();
dic["AccessKey"] = accessKey;
dic["OnsChannel"] = onsChannel;
}

/// <summary>发送指定类型的命令</summary>
Expand Down

0 comments on commit 49c751b

Please sign in to comment.