[英]NetworkCredentials exposes password in plain text
I'm about to create an authentication module in my C#/WPF application. 我即将在我的C#/ WPF应用程序中创建一个身份验证模块。 To authenticate the user, I would like to use NetworkCredential
to store the credentials. 要对用户进行身份验证,我想使用NetworkCredential
来存储凭据。
Credential = new NetworkCredential(credential.UserName, credential.Password);
Where the credential.UserName
is a string
and credential.Password
is of the type SecureString
. 其中credential.UserName
是string
, credential.Password
的类型为SecureString
。 When debugging the application I can see the password in plain text as well as in secure string 调试应用程序时,我可以在纯文本和安全字符串中看到密码
Why is the password exposed as plain text? 为什么密码是以纯文本形式公开的? Isn't this a possible security threat? 这不是一个可能的安全威胁吗?
Thanks for answering. 谢谢回答。
EDIT: 编辑:
For the record, the NetworkCredential
object shall be used on the WCF client, like this: 对于记录,应在WCF客户端上使用NetworkCredential
对象,如下所示:
client.ClientCredentials.Windows.ClientCredential = Credentials
The NetworkCredential
class internally always stores the password as a SecureString
: NetworkCredential
类在内部始终将密码存储为SecureString
:
public string Password {
get {
ExceptionHelper.UnmanagedPermission.Demand();
return InternalGetPassword();
}
set {
m_password = UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString(value);
}
}
When someone needs to retrieve the password as plain text (which at some point will be needed, either from this class or somewhere further down the chain), it retrieves it from the secure string : 当有人需要以纯文本的形式检索密码时(无论是从某个类还是从该类中的某个地方开始),它都会从安全字符串中检索密码 :
internal string InternalGetPassword() {
string decryptedString = UnsafeNclNativeMethods.SecureStringHelper.CreateString(m_password);
return decryptedString;
}
When using the debugger, it shows the properties, so the value is retrieved from the SecureString
使用调试器时,它显示属性,因此从SecureString
检索值
SecureString
has nothing to do with encryption! SecureString
与加密无关! (a gross oversimplification - it's possible it's also encrypted, but that's not all that important here; if you create a SecureString
from a normal string
, you've already negated plenty of gain of SecureString
- short-term) (一个粗略的过度简化 - 它可能也加密了,但这里并不重要;如果你从普通string
创建一个SecureString
,你已经否定了SecureString
大量收益 - 短期)
It's simply a string that can be deterministically deallocated. 它只是一个可以确定性地解除分配的字符串。 This is important for security reasons, since .NET strings may be very long lived (for interned strings, the whole life of the application). 出于安全原因,这很重要,因为.NET字符串可能非常长寿(对于实习字符串,应用程序的整个生命周期)。
NetworkCredential
is not used for storing credentials - it's just a simple wagon to get them where they are going - a common API, basically. NetworkCredential
不用于存储凭证 - 它只是一个简单的马车,可以让它们到达目的地 - 基本上是一个常见的API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.