Skip to content

Commit a80b8f1

Browse files
committed
QpChannel add property:AuthenticateQuestion
1 parent 80d62f3 commit a80b8f1

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Quick.Protocol/QpChannel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ protected set
8686
/// 通道名称
8787
/// </summary>
8888
public abstract string ChannelName { get; }
89+
/// <summary>
90+
/// 认证问题
91+
/// </summary>
92+
public string AuthenticateQuestion { get; protected set; }
8993

9094
//长整型数字的一半,统计大于这个数时,统计计数归零,防止溢出
9195
private long LONG_HALF_MAX_VALUE = long.MaxValue / 2;

Quick.Protocol/QpClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ public async Task ConnectAsync()
4646
{
4747
InstructionIds = Options.InstructionSet.Select(t => t.Id).ToArray()
4848
});
49+
AuthenticateQuestion = repConnect.Question;
4950

5051
//如果服务端使用的缓存大小与客户端不同,则设置缓存大小为与服务端同样的大小
5152
if (BufferSize != repConnect.BufferSize)
5253
ChangeBufferSize(repConnect.BufferSize);
53-
54+
5455
var repAuth = await SendCommand(new Commands.Authenticate.Request()
5556
{
56-
Answer = CryptographyUtils.ComputeMD5Hash(repConnect.Question + Options.Password)
57+
Answer = CryptographyUtils.ComputeMD5Hash(AuthenticateQuestion + Options.Password)
5758
});
5859

5960
var repHandShake = await SendCommand(new Commands.HandShake.Request()

Quick.Protocol/QpServerChannel.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public class QpServerChannel : QpChannel
1616
private CancellationTokenSource cts;
1717
private QpServerOptions options;
1818
private string channelName;
19-
private string question;
2019
//通过认证后,才允许使用的命令执行管理器列表
2120
private List<CommandExecuterManager> authedCommandExecuterManagerList = null;
2221
//通过认证后,才允许使用的通知处理器管理器列表
@@ -97,18 +96,17 @@ private Commands.Connect.Response connect(QpChannel handler, Commands.Connect.Re
9796
throw new CommandException(255, $"Unknown instruction: {id}");
9897
}
9998
}
100-
101-
question = Guid.NewGuid().ToString("N");
99+
AuthenticateQuestion = Guid.NewGuid().ToString("N");
102100
return new Commands.Connect.Response()
103101
{
104102
BufferSize = options.BufferSize,
105-
Question = question
103+
Question = AuthenticateQuestion
106104
};
107105
}
108106

109107
private Commands.Authenticate.Response authenticate(QpChannel handler, Commands.Authenticate.Request request)
110108
{
111-
if (Utils.CryptographyUtils.ComputeMD5Hash(question + options.Password) != request.Answer)
109+
if (Utils.CryptographyUtils.ComputeMD5Hash(AuthenticateQuestion + options.Password) != request.Answer)
112110
{
113111
Task.Delay(1000).ContinueWith(t =>
114112
{

0 commit comments

Comments
 (0)