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

[fix] 强行指定 acl 签名时 ExtFields 的排序方式,防止部分接口 acl 认证出错。 #90

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions NewLife.RocketMQ/ClusterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,26 @@ 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)
var extFieldsDic = cmd.Header.GetExtFields();
extFieldsDic["AccessKey"] = accessKey;
extFieldsDic["OnsChannel"] = onsChannel;

// 按照 asscii 排序已有 key
var comparer = Comparer<string>.Create(string.CompareOrdinal);
foreach (var item in extFieldsDic.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;
extFieldsDic["Signature"] = sign.ToBase64();
cmd.Header.ExtFields = extFieldsDic;
}

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