TLS 1.2 - 提供给函数的令牌无效 [英] TLS 1.2 - The token supplied to the function is invalid
问题描述
我有一个奇怪的问题,SslStream.AuthenticateAsClient() 抛出以下异常:
I have this strange problem, SslStream.AuthenticateAsClient() throws following exception:
System.Security.Authentication.AuthenticationException : A call to SSPI failed, see inner exception.
----> System.ComponentModel.Win32Exception : The token supplied to the function is invalid
只有在客户端需要 Tls12 时才会发生:
It happens only when Tls12 is required by the client:
SslStream.AuthenticateAsClient(..., ..., SslProtocols.Tls12);
代码适用于 Ssl3、Tls11 和 Tls.
Code works properly for Ssl3, Tls11 and Tls.
服务器证书是自签名的并且是旧的".它使用 md5RSA 签名和 1024 位,最初我认为这是问题所在,因为重新生成证书会使异常消失(我厌倦了 SHA1 和 SHA512 - 都可以).
Server certificate is self-signed and 'old'. It uses md5RSA signature and 1024 bits, and innitially I thought that is the problem, as re-generating the certificate makes the exception go away (I tired both SHA1 and SHA512 - both ok).
然而,令我惊讶的是 FileZilla 客户端能够使用这个'旧'md5RSA 签名证书和TLS 1.2连接到该服务器:
However, to my surprise FileZilla client is able to connect to this server using this 'old' md5RSA-signed cert and using TLS 1.2:
这是证书:
-----BEGIN CERTIFICATE-----
MIICejCCAeOgAwIBAgIQzbvZdHHAV49D7R8OE2mEaDANBgkqhkiG9w0BAQQFADBA
MSswKQYJKoZIhvcNAQkBFhxlbWFpbEBpbi10aGUtY2VydGlmaWNhdGUuY29tMREw
DwYDVQQDEwhKb2huIERvZTAeFw0xMTAxMjAyMDAzNDFaFw0zOTEyMzEyMzU5NTla
MEAxKzApBgkqhkiG9w0BCQEWHGVtYWlsQGluLXRoZS1jZXJ0aWZpY2F0ZS5jb20x
ETAPBgNVBAMTCEpvaG4gRG9lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0
s5RAKYdw2AYk3t0oH5jDo6RQRRfabkOLfKvR8kOiYbqjtgblx7JhSZJHX/r6KLoc
hGgYkQPOSKnl8TdgEkzPxWHECV/iMdOxTsTv2P//ZM2INjb4H8JjDS16PYFwHP3w
/9RU6PjppK+mPdWP1pezBzebSM0QQwpmXlSmfe2ULQIDAQABo3UwczBxBgNVHQEE
ajBogBA4WNgTvhkmRD8DhHeRvAJcoUIwQDErMCkGCSqGSIb3DQEJARYcZW1haWxA
aW4tdGhlLWNlcnRpZmljYXRlLmNvbTERMA8GA1UEAxMISm9obiBEb2WCEM272XRx
wFePQ+0fDhNphGgwDQYJKoZIhvcNAQEEBQADgYEAFX6MM/E97hC6t1TAFBmM3tWr
fQ2cB0LFCe6J0I8phKQecpSYCkMdvaHdsT+sdzXNW4bgL064r731r8l/47VgfgIR
oRmsQYnwJ55nqZpEW2zL3vioedWiCVto8X9/dVC8jqPpcmMP5NWBHh88o7nkPBxe
C8iucrQvHnjYwaz1o/M=
-----END CERTIFICATE-----
我的问题是:
为什么
SslStream.AuthenticateAsClient
抛出,而 Filezilla 客户端能够连接?
Why
SslStream.AuthenticateAsClient
throws, whereas Filezilla client is able to connect?
使用 TLS 1.2 时是否有任何 .NET/Windows 10/CryptoAPI 证书限制?
Are there any .NET/Windows 10/CryptoAPI certificate restrictions when TLS 1.2 is used?
如果有限制,为什么 FileZilla 不强制执行?
If there are restrictions, why FileZilla is not enforcing them?
为什么会出现如此神秘的错误消息:提供给函数的令牌无效"?
Why so cryptic error message: 'The token supplied to the function is invalid'?
推荐答案
我终于想通了.提供给函数的令牌无效"在此上下文中表示链上的证书使用不受支持或禁用的算法签名."
I finally figured this out. "The token supplied to the function is invalid" in this context means a "Certificate on the chain is signed with an unsupported or disabled algorithm."
事实证明,这几乎总是意味着禁用.在HKEY_LOCAL_MACHINE
SYSTEM\CurrentControlSet\Control\Cryptography\Configuration\Local\SSL\00010003
Functions
中可以找到启用的算法列表.这是一个 REG_MULTI_SZ
,每个支持的算法有一个字符串.
It turns out in practice this almost always means disabled. The list of enabled algorithms is found in HKEY_LOCAL_MACHINE
SYSTEM\CurrentControlSet\Control\Cryptography\Configuration\Local\SSL\00010003
Functions
. This is a REG_MULTI_SZ
with one string per supported algorithm.
我在我的 Windows 10 机器上找到了这些值:
I found these values on my Windows 10 machine:
RSA/SHA256
RSA/SHA384
RSA/SHA1
ECDSA/SHA256
ECDSA/SHA384
ECDSA/SHA1
DSA/SHA1
我加了
RSA/SHA512
ECDSA/SHA512
如果您添加了 RSA/MD5
,您的密钥将开始工作,但是怎么强调都不为过,这是一个坏主意,并且会使您的系统接受伪造证书,因为MD5
已损坏.
Your key would start working if you added RSA/MD5
however it cannot be emphasized enough this is a bad idea and will open your system up to accepting forged certificates because MD5
has been broken.
Filezilla 正在运行,因为 Mozilla 不信任主机密码套件.
Filezilla is working because Mozilla distrusts the host cipher suite.
这篇关于TLS 1.2 - 提供给函数的令牌无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!