mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-26 08:02:59 +08:00
Expose binary password to MqttConnectionValidatorContext.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using IronPython.Runtime;
|
using IronPython.Runtime;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -23,12 +22,6 @@ namespace MQTTnet.Server.Mqtt
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string passwordString = null;
|
|
||||||
if (context.Password != null)
|
|
||||||
{
|
|
||||||
passwordString = Encoding.UTF8.GetString(context.Password);
|
|
||||||
}
|
|
||||||
|
|
||||||
var pythonContext = new PythonDictionary
|
var pythonContext = new PythonDictionary
|
||||||
{
|
{
|
||||||
{ "client_id", context.ClientId },
|
{ "client_id", context.ClientId },
|
||||||
@@ -36,7 +29,7 @@ namespace MQTTnet.Server.Mqtt
|
|||||||
{ "is_secure_connection", context.IsSecureConnection },
|
{ "is_secure_connection", context.IsSecureConnection },
|
||||||
{ "username", context.Username },
|
{ "username", context.Username },
|
||||||
{ "password", context.Password },
|
{ "password", context.Password },
|
||||||
{ "password_string", passwordString },
|
{ "raw_password", context.RawPassword },
|
||||||
{ "result", PythonConvert.Pythonfy(context.ReturnCode) }
|
{ "result", PythonConvert.Pythonfy(context.ReturnCode) }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,17 @@ namespace MQTTnet.Server
|
|||||||
{
|
{
|
||||||
public class MqttConnectionValidatorContext
|
public class MqttConnectionValidatorContext
|
||||||
{
|
{
|
||||||
public MqttConnectionValidatorContext(string clientId, string username, byte[] password, MqttApplicationMessage willMessage, string endpoint, bool isSecureConnection)
|
public MqttConnectionValidatorContext(
|
||||||
|
string clientId,
|
||||||
|
string username,
|
||||||
|
byte[] password,
|
||||||
|
MqttApplicationMessage willMessage,
|
||||||
|
string endpoint,
|
||||||
|
bool isSecureConnection)
|
||||||
{
|
{
|
||||||
ClientId = clientId;
|
ClientId = clientId;
|
||||||
Username = username;
|
Username = username;
|
||||||
Password = password;
|
RawPassword = password;
|
||||||
WillMessage = willMessage;
|
WillMessage = willMessage;
|
||||||
Endpoint = endpoint;
|
Endpoint = endpoint;
|
||||||
IsSecureConnection = isSecureConnection;
|
IsSecureConnection = isSecureConnection;
|
||||||
@@ -19,7 +25,9 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public string Username { get; }
|
public string Username { get; }
|
||||||
|
|
||||||
public byte[] Password { get; }
|
public string Password => Encoding.UTF8.GetString(RawPassword ?? new byte[0]);
|
||||||
|
|
||||||
|
public byte[] RawPassword { get; }
|
||||||
|
|
||||||
public MqttApplicationMessage WillMessage { get; }
|
public MqttApplicationMessage WillMessage { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ namespace MQTTnet.TestApp.NetCore
|
|||||||
{
|
{
|
||||||
if (p.ClientId == "SpecialClient")
|
if (p.ClientId == "SpecialClient")
|
||||||
{
|
{
|
||||||
var password = Encoding.UTF8.GetString(p.Password);
|
if (p.Username != "USER" || p.Password != "PASS")
|
||||||
if (p.Username != "USER" || password != "PASS")
|
|
||||||
{
|
{
|
||||||
p.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
p.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -633,9 +633,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var password = Encoding.UTF8.GetString(c.Password);
|
if (c.Password != "mySecretPassword")
|
||||||
|
|
||||||
if (password != "mySecretPassword")
|
|
||||||
{
|
{
|
||||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||||
return;
|
return;
|
||||||
@@ -719,8 +717,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var password = Encoding.UTF8.GetString(c.Password);
|
if (c.Password != "mySecretPassword")
|
||||||
if (password != "mySecretPassword")
|
|
||||||
{
|
{
|
||||||
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
c.ReturnCode = MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user