Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
MQTTnet
提交
ccfe67e6
MQTTnet
项目概览
dotNET Platform
/
MQTTnet
10 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MQTTnet
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ccfe67e6
编写于
5月 27, 2019
作者:
C
Christian Kratky
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix wrong password handling (string -> byte[])
上级
98e17903
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
52 addition
and
25 deletion
+52
-25
Source/MQTTnet.Server/Mqtt/MqttConnectionValidator.cs
Source/MQTTnet.Server/Mqtt/MqttConnectionValidator.cs
+8
-0
Source/MQTTnet.Server/Scripts/00_sample.py
Source/MQTTnet.Server/Scripts/00_sample.py
+1
-1
Source/MQTTnet/Client/Options/IMqttClientCredentials.cs
Source/MQTTnet/Client/Options/IMqttClientCredentials.cs
+1
-1
Source/MQTTnet/Client/Options/MqttClientCredentials.cs
Source/MQTTnet/Client/Options/MqttClientCredentials.cs
+1
-1
Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
+13
-0
Source/MQTTnet/Formatter/V3/MqttV310PacketFormatter.cs
Source/MQTTnet/Formatter/V3/MqttV310PacketFormatter.cs
+1
-1
Source/MQTTnet/Formatter/V5/MqttV500PacketDecoder.cs
Source/MQTTnet/Formatter/V5/MqttV500PacketDecoder.cs
+1
-1
Source/MQTTnet/Packets/MqttConnectPacket.cs
Source/MQTTnet/Packets/MqttConnectPacket.cs
+6
-5
Source/MQTTnet/Server/MqttConnectionValidatorContext.cs
Source/MQTTnet/Server/MqttConnectionValidatorContext.cs
+4
-3
Tests/MQTTnet.Core.Tests/MqttPacketSerializer_Tests.cs
Tests/MQTTnet.Core.Tests/MqttPacketSerializer_Tests.cs
+5
-5
Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs
Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs
+1
-1
Tests/MQTTnet.TestApp.NetCore/ServerTest.cs
Tests/MQTTnet.TestApp.NetCore/ServerTest.cs
+2
-1
Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs
Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs
+8
-5
未找到文件。
Source/MQTTnet.Server/Mqtt/MqttConnectionValidator.cs
浏览文件 @
ccfe67e6
using
System
;
using
System.Text
;
using
System.Threading.Tasks
;
using
IronPython.Runtime
;
using
Microsoft.Extensions.Logging
;
...
...
@@ -22,6 +23,12 @@ namespace MQTTnet.Server.Mqtt
{
try
{
string
passwordString
=
null
;
if
(
context
.
Password
!=
null
)
{
passwordString
=
Encoding
.
UTF8
.
GetString
(
context
.
Password
);
}
var
pythonContext
=
new
PythonDictionary
{
{
"client_id"
,
context
.
ClientId
},
...
...
@@ -29,6 +36,7 @@ namespace MQTTnet.Server.Mqtt
{
"is_secure_connection"
,
context
.
IsSecureConnection
},
{
"username"
,
context
.
Username
},
{
"password"
,
context
.
Password
},
{
"password_string"
,
passwordString
},
{
"result"
,
PythonConvert
.
Pythonfy
(
context
.
ReturnCode
)
}
};
...
...
Source/MQTTnet.Server/Scripts/00_sample.py
浏览文件 @
ccfe67e6
...
...
@@ -29,7 +29,7 @@ def on_validate_client_connection(context):
context
[
"result"
]
=
"connection_refused_not_authorized"
return
if
context
[
"password"
]
!=
"secret"
:
if
context
[
"password
_string
"
]
!=
"secret"
:
context
[
"result"
]
=
"connection_refused_not_authorized"
print
(
context
)
...
...
Source/MQTTnet/Client/Options/IMqttClientCredentials.cs
浏览文件 @
ccfe67e6
...
...
@@ -2,7 +2,7 @@
{
public
interface
IMqttClientCredentials
{
string
Password
{
get
;
}
string
Username
{
get
;
}
byte
[]
Password
{
get
;
}
}
}
\ No newline at end of file
Source/MQTTnet/Client/Options/MqttClientCredentials.cs
浏览文件 @
ccfe67e6
...
...
@@ -4,6 +4,6 @@
{
public
string
Username
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
byte
[]
Password
{
get
;
set
;
}
}
}
Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
浏览文件 @
ccfe67e6
using
System
;
using
System.Linq
;
using
System.Text
;
using
MQTTnet.Client.ExtendedAuthenticationExchange
;
using
MQTTnet.Formatter
;
...
...
@@ -116,6 +117,18 @@ namespace MQTTnet.Client.Options
}
public
MqttClientOptionsBuilder
WithCredentials
(
string
username
,
string
password
=
null
)
{
byte
[]
passwordBuffer
=
null
;
if
(
password
!=
null
)
{
passwordBuffer
=
Encoding
.
UTF8
.
GetBytes
(
password
);
}
return
WithCredentials
(
username
,
passwordBuffer
);
}
public
MqttClientOptionsBuilder
WithCredentials
(
string
username
,
byte
[]
password
=
null
)
{
_options
.
Credentials
=
new
MqttClientCredentials
{
...
...
Source/MQTTnet/Formatter/V3/MqttV310PacketFormatter.cs
浏览文件 @
ccfe67e6
...
...
@@ -293,7 +293,7 @@ namespace MQTTnet.Formatter.V3
if
(
passwordFlag
)
{
packet
.
Password
=
body
.
Read
String
WithLengthPrefix
();
packet
.
Password
=
body
.
ReadWithLengthPrefix
();
}
ValidateConnectPacket
(
packet
);
...
...
Source/MQTTnet/Formatter/V5/MqttV500PacketDecoder.cs
浏览文件 @
ccfe67e6
...
...
@@ -208,7 +208,7 @@ namespace MQTTnet.Formatter.V5
if
(
passwordFlag
)
{
packet
.
Password
=
body
.
Read
String
WithLengthPrefix
();
packet
.
Password
=
body
.
ReadWithLengthPrefix
();
}
return
packet
;
...
...
Source/MQTTnet/Packets/MqttConnectPacket.cs
浏览文件 @
ccfe67e6
...
...
@@ -6,7 +6,7 @@
public
string
Username
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
byte
[]
Password
{
get
;
set
;
}
public
ushort
KeepAlivePeriod
{
get
;
set
;
}
...
...
@@ -23,13 +23,14 @@
public
override
string
ToString
()
{
var
password
=
Password
;
if
(!
string
.
IsNullOrEmpty
(
password
))
var
passwordText
=
string
.
Empty
;
if
(
Password
!=
null
)
{
password
=
"****"
;
password
Text
=
"****"
;
}
return
string
.
Concat
(
"Connect: [ClientId="
,
ClientId
,
"] [Username="
,
Username
,
"] [Password="
,
password
,
"] [KeepAlivePeriod="
,
KeepAlivePeriod
,
"] [CleanSession="
,
CleanSession
,
"]"
);
return
string
.
Concat
(
"Connect: [ClientId="
,
ClientId
,
"] [Username="
,
Username
,
"] [Password="
,
password
Text
,
"] [KeepAlivePeriod="
,
KeepAlivePeriod
,
"] [CleanSession="
,
CleanSession
,
"]"
);
}
}
}
Source/MQTTnet/Server/MqttConnectionValidatorContext.cs
浏览文件 @
ccfe67e6
using
MQTTnet.Protocol
;
using
System.Text
;
using
MQTTnet.Protocol
;
namespace
MQTTnet.Server
{
public
class
MqttConnectionValidatorContext
{
public
MqttConnectionValidatorContext
(
string
clientId
,
string
username
,
string
password
,
MqttApplicationMessage
willMessage
,
string
endpoint
,
bool
isSecureConnection
)
public
MqttConnectionValidatorContext
(
string
clientId
,
string
username
,
byte
[]
password
,
MqttApplicationMessage
willMessage
,
string
endpoint
,
bool
isSecureConnection
)
{
ClientId
=
clientId
;
Username
=
username
;
...
...
@@ -18,7 +19,7 @@ namespace MQTTnet.Server
public
string
Username
{
get
;
}
public
string
Password
{
get
;
}
public
byte
[]
Password
{
get
;
}
public
MqttApplicationMessage
WillMessage
{
get
;
}
...
...
Tests/MQTTnet.Core.Tests/MqttPacketSerializer_Tests.cs
浏览文件 @
ccfe67e6
...
...
@@ -23,7 +23,7 @@ namespace MQTTnet.Tests
var
p
=
new
MqttConnectPacket
{
ClientId
=
"XYZ"
,
Password
=
"PASS"
,
Password
=
Encoding
.
UTF8
.
GetBytes
(
"PASS"
)
,
Username
=
"USER"
,
KeepAlivePeriod
=
123
,
CleanSession
=
true
...
...
@@ -38,7 +38,7 @@ namespace MQTTnet.Tests
var
p
=
new
MqttConnectPacket
{
ClientId
=
"XYZ"
,
Password
=
"PASS"
,
Password
=
Encoding
.
UTF8
.
GetBytes
(
"PASS"
)
,
Username
=
"USER"
,
KeepAlivePeriod
=
123
,
CleanSession
=
true
...
...
@@ -53,7 +53,7 @@ namespace MQTTnet.Tests
var
p
=
new
MqttConnectPacket
{
ClientId
=
"XYZ"
,
Password
=
"PASS"
,
Password
=
Encoding
.
UTF8
.
GetBytes
(
"PASS"
)
,
Username
=
"USER"
,
KeepAlivePeriod
=
123
,
CleanSession
=
true
,
...
...
@@ -75,7 +75,7 @@ namespace MQTTnet.Tests
var
p
=
new
MqttConnectPacket
{
ClientId
=
"XYZ"
,
Password
=
"PASS"
,
Password
=
Encoding
.
UTF8
.
GetBytes
(
"PASS"
)
,
Username
=
"USER"
,
KeepAlivePeriod
=
123
,
CleanSession
=
true
...
...
@@ -90,7 +90,7 @@ namespace MQTTnet.Tests
var
p
=
new
MqttConnectPacket
{
ClientId
=
"XYZ"
,
Password
=
"PASS"
,
Password
=
Encoding
.
UTF8
.
GetBytes
(
"PASS"
)
,
Username
=
"USER"
,
KeepAlivePeriod
=
123
,
CleanSession
=
true
,
...
...
Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs
浏览文件 @
ccfe67e6
...
...
@@ -62,7 +62,7 @@ namespace MQTTnet.TestApp.NetCore
public
class
RandomPassword
:
IMqttClientCredentials
{
public
string
Password
=>
Guid
.
NewGuid
().
ToString
();
public
byte
[]
Password
=>
Guid
.
NewGuid
().
ToByteArray
();
public
string
Username
=>
"the_static_user"
;
}
...
...
Tests/MQTTnet.TestApp.NetCore/ServerTest.cs
浏览文件 @
ccfe67e6
...
...
@@ -28,7 +28,8 @@ namespace MQTTnet.TestApp.NetCore
{
if
(
p
.
ClientId
==
"SpecialClient"
)
{
if
(
p
.
Username
!=
"USER"
||
p
.
Password
!=
"PASS"
)
var
password
=
Encoding
.
UTF8
.
GetString
(
p
.
Password
);
if
(
p
.
Username
!=
"USER"
||
password
!=
"PASS"
)
{
p
.
ReturnCode
=
MqttConnectReturnCode
.
ConnectionRefusedBadUsernameOrPassword
;
}
...
...
Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs
浏览文件 @
ccfe67e6
...
...
@@ -138,7 +138,7 @@ namespace MQTTnet.TestApp.UniversalWindows
options
.
Credentials
=
new
MqttClientCredentials
{
Username
=
User
.
Text
,
Password
=
Password
.
Text
Password
=
Encoding
.
UTF8
.
GetBytes
(
Password
.
Text
)
};
}
...
...
@@ -539,7 +539,7 @@ namespace MQTTnet.TestApp.UniversalWindows
//...
}
client
.
UseApplicationMessageReceivedHandler
(
Handler
);
client
.
UseApplicationMessageReceivedHandler
(
e
=>
Handler
(
e
)
);
// Subscribe after connect
...
...
@@ -601,7 +601,7 @@ namespace MQTTnet.TestApp.UniversalWindows
Credentials
=
new
MqttClientCredentials
{
Username
=
"bud"
,
Password
=
"%spencer%"
Password
=
Encoding
.
UTF8
.
GetBytes
(
"%spencer%"
)
},
ChannelOptions
=
new
MqttClientTcpOptions
{
...
...
@@ -633,7 +633,9 @@ namespace MQTTnet.TestApp.UniversalWindows
return
;
}
if
(
c
.
Password
!=
"mySecretPassword"
)
var
password
=
Encoding
.
UTF8
.
GetString
(
c
.
Password
);
if
(
password
!=
"mySecretPassword"
)
{
c
.
ReturnCode
=
MqttConnectReturnCode
.
ConnectionRefusedBadUsernameOrPassword
;
return
;
...
...
@@ -717,7 +719,8 @@ namespace MQTTnet.TestApp.UniversalWindows
return
;
}
if
(
c
.
Password
!=
"mySecretPassword"
)
var
password
=
Encoding
.
UTF8
.
GetString
(
c
.
Password
);
if
(
password
!=
"mySecretPassword"
)
{
c
.
ReturnCode
=
MqttConnectReturnCode
.
ConnectionRefusedBadUsernameOrPassword
;
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录