Kestel (.NET Core 3.1) 是否支持 md5RSA 证书?
Does Kestel (.NET Core 3.1) support md5RSA certificates?
我一直在尝试获得一个简单的 HTTPS 安全 Kestrel 服务 运行ning,它使用已安装的自签名根证书(来自第 3 方)验证客户端。我正在努力寻找客户端证书的具体问题以及服务退回连接的原因。有人可以明确地回答 .NET Core 3.1 中的 Kestrel on a linux box 运行ning OpenSSL 1.0.2k-fips 26 Jan 2017 不再接受具有 md5RSA 签名算法的根证书吗?
我一直无法找到任何方法从 Kestrel 中找到更具体的内容。
我在 program.cs 中添加了以下内容以尝试提供帮助:
private static bool ClientCertificateValidation(X509Certificate2 clientCertificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
StringBuilder sb = new StringBuilder();
int certNumber = 0;
foreach (X509ChainElement element in chain.ChainElements)
{
certNumber++;
var errors = element.ChainElementStatus;
List<string> errorList = new List<string>();
foreach(var cError in errors)
{
errorList.Add(cError.StatusInformation);
}
sb.AppendLine("Certificate #" + certNumber + ": (" + string.Join(",", errorList.ToArray()) + ")");
sb.AppendLine(" Subject: " + element.Certificate.Subject);
sb.AppendLine(" Issuer: " + element.Certificate.Issuer);
sb.AppendLine(" Serial #: " + element.Certificate.SerialNumber);
sb.AppendLine(" Thumbprint: " + element.Certificate.Thumbprint);
sb.AppendLine(" Valid Dates: " + element.Certificate.NotBefore.ToString() + " to " + element.Certificate.NotAfter.ToString());
sb.AppendLine(" Signature Algorithm: " + element.Certificate.SignatureAlgorithm.FriendlyName);
sb.AppendLine(" Version: " + element.Certificate.Version);
sb.AppendLine(" Encoded Certificate: " + Convert.ToBase64String(element.Certificate.Export(X509ContentType.Cert)));
}
Console.WriteLine(sb.ToString());
if (sslPolicyErrors.HasFlag(SslPolicyErrors.None))
{
Console.WriteLine($"***************** NO POLICY ERRORS! **********************");
return true;
}
return false;
}
通过以下方式调用它:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureKestrel(options =>
{
options.ConfigureHttpsDefaults(
httpsOptions =>
{
httpsOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
httpsOptions.SslProtocols = SslProtocols.Tls12;
httpsOptions.ClientCertificateValidation =ClientCertificateValidation;
});
});
});
但真正的“证书签名失败”让我无法继续下去。 运行 openssl 验证 - 结果正常....那么 Kestrel 在做什么?
提前致谢
更新:
服务器上安装了自签名(第 3 方)证书以验证第 3 方的客户端。提到的命令确实 return 出错,但由于证书是由第 3 方提供的,我不确定它的问题是什么?
好的,dotnet 和 openssl 都同意签名无效。虽然我没有看到重现这一点的实用方法,但 'unknown digest'(而不是 'bad padding' 或 'out of range')表明签名实际上是由发行者创建的(即没有损坏的数据或签名, 或错误的密钥)但签名者做错了。尝试以下过程(我使用了我自己的证书,因为你的证书太私密了,任何人都看不到):
$ openssl req -newkey rsa:1024 -keyout 70348834.key -nodes -x509 -md5 -subj /CN=70348834 -out 70348834.crt
Generating a RSA private key
.....+++++
....+++++
writing new private key to '70348834.key'
-----
# RSA-1024 no longer meets standards but this is just for testing
$ openssl verify -check_ss_sig -CAfile 70348834.crt 70348834.crt
70348834.crt: OK
$ openssl asn1parse -i <70348834.crt
0:d=0 hl=4 l= 514 cons: SEQUENCE
4:d=1 hl=4 l= 363 cons: SEQUENCE
8:d=2 hl=2 l= 3 cons: cont [ 0 ]
10:d=3 hl=2 l= 1 prim: INTEGER :02
13:d=2 hl=2 l= 20 prim: INTEGER :39163AA0A0B6898D0DF0304F4F8D5649507B4877
35:d=2 hl=2 l= 13 cons: SEQUENCE
37:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
48:d=3 hl=2 l= 0 prim: NULL
50:d=2 hl=2 l= 19 cons: SEQUENCE
52:d=3 hl=2 l= 17 cons: SET
54:d=4 hl=2 l= 15 cons: SEQUENCE
56:d=5 hl=2 l= 3 prim: OBJECT :commonName
61:d=5 hl=2 l= 8 prim: UTF8STRING :70348834
71:d=2 hl=2 l= 30 cons: SEQUENCE
73:d=3 hl=2 l= 13 prim: UTCTIME :211217042113Z
88:d=3 hl=2 l= 13 prim: UTCTIME :220116042113Z
103:d=2 hl=2 l= 19 cons: SEQUENCE
105:d=3 hl=2 l= 17 cons: SET
107:d=4 hl=2 l= 15 cons: SEQUENCE
109:d=5 hl=2 l= 3 prim: OBJECT :commonName
114:d=5 hl=2 l= 8 prim: UTF8STRING :70348834
124:d=2 hl=3 l= 159 cons: SEQUENCE
127:d=3 hl=2 l= 13 cons: SEQUENCE
129:d=4 hl=2 l= 9 prim: OBJECT :rsaEncryption
140:d=4 hl=2 l= 0 prim: NULL
142:d=3 hl=3 l= 141 prim: BIT STRING
286:d=2 hl=2 l= 83 cons: cont [ 3 ]
288:d=3 hl=2 l= 81 cons: SEQUENCE
290:d=4 hl=2 l= 29 cons: SEQUENCE
292:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Subject Key Identifier
297:d=5 hl=2 l= 22 prim: OCTET STRING [HEX DUMP]:041438C135B9D18DF0668B0AA31933FE0F947FBEDF84
321:d=4 hl=2 l= 31 cons: SEQUENCE
323:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Authority Key Identifier
328:d=5 hl=2 l= 24 prim: OCTET STRING [HEX DUMP]:3016801438C135B9D18DF0668B0AA31933FE0F947FBEDF84
354:d=4 hl=2 l= 15 cons: SEQUENCE
356:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Basic Constraints
361:d=5 hl=2 l= 1 prim: BOOLEAN :255
364:d=5 hl=2 l= 5 prim: OCTET STRING [HEX DUMP]:30030101FF
371:d=1 hl=2 l= 13 cons: SEQUENCE
373:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
384:d=2 hl=2 l= 0 prim: NULL
386:d=1 hl=3 l= 129 prim: BIT STRING
# the number before the colon on the last line is the offset of the raw signature
$ openssl asn1parse <70348834.crt -strparse 386 -out 70348834.sig
Error in encoding
139775850254976:error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long:../crypto/asn1/asn1_lib.c:101:
# ignore that error; RSA signature isn't ASN.1, but -strparse still extracts it, see:
$ ls -l 70348834.sig
-rwxrwxrwx 1 dthomps dthomps 128 Dec 16 23:27 70348834.sig
$ openssl rsautl -verify -certin -inkey 70348834.crt -in 70348834.sig -asn1parse
0:d=0 hl=2 l= 32 cons: SEQUENCE
2:d=1 hl=2 l= 12 cons: SEQUENCE
4:d=2 hl=2 l= 8 prim: OBJECT :md5
14:d=2 hl=2 l= 0 prim: NULL
16:d=1 hl=2 l= 16 prim: OCTET STRING
0000 - 2b 7c cf 6d c8 0f 53 82-0b 57 64 4d 5a e0 d6 9a +|.m..S..WdMZ...
# FYI rsautl -verify isn't properly a verify operation in cryptographic terms,
# technically it's only the 'recover' part of verify-with-recovery (only for RSA)
你的 'recovered' 签名应该看起来像我上面的最后一个块,除了 OCTET STRING 中的数据(但它应该仍然是相同的长度,l=16);如果不向证书颁发者或提供者投诉他们给你的证书无效。
我一直在尝试获得一个简单的 HTTPS 安全 Kestrel 服务 运行ning,它使用已安装的自签名根证书(来自第 3 方)验证客户端。我正在努力寻找客户端证书的具体问题以及服务退回连接的原因。有人可以明确地回答 .NET Core 3.1 中的 Kestrel on a linux box 运行ning OpenSSL 1.0.2k-fips 26 Jan 2017 不再接受具有 md5RSA 签名算法的根证书吗?
我一直无法找到任何方法从 Kestrel 中找到更具体的内容。
我在 program.cs 中添加了以下内容以尝试提供帮助:
private static bool ClientCertificateValidation(X509Certificate2 clientCertificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
StringBuilder sb = new StringBuilder();
int certNumber = 0;
foreach (X509ChainElement element in chain.ChainElements)
{
certNumber++;
var errors = element.ChainElementStatus;
List<string> errorList = new List<string>();
foreach(var cError in errors)
{
errorList.Add(cError.StatusInformation);
}
sb.AppendLine("Certificate #" + certNumber + ": (" + string.Join(",", errorList.ToArray()) + ")");
sb.AppendLine(" Subject: " + element.Certificate.Subject);
sb.AppendLine(" Issuer: " + element.Certificate.Issuer);
sb.AppendLine(" Serial #: " + element.Certificate.SerialNumber);
sb.AppendLine(" Thumbprint: " + element.Certificate.Thumbprint);
sb.AppendLine(" Valid Dates: " + element.Certificate.NotBefore.ToString() + " to " + element.Certificate.NotAfter.ToString());
sb.AppendLine(" Signature Algorithm: " + element.Certificate.SignatureAlgorithm.FriendlyName);
sb.AppendLine(" Version: " + element.Certificate.Version);
sb.AppendLine(" Encoded Certificate: " + Convert.ToBase64String(element.Certificate.Export(X509ContentType.Cert)));
}
Console.WriteLine(sb.ToString());
if (sslPolicyErrors.HasFlag(SslPolicyErrors.None))
{
Console.WriteLine($"***************** NO POLICY ERRORS! **********************");
return true;
}
return false;
}
通过以下方式调用它:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureKestrel(options =>
{
options.ConfigureHttpsDefaults(
httpsOptions =>
{
httpsOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
httpsOptions.SslProtocols = SslProtocols.Tls12;
httpsOptions.ClientCertificateValidation =ClientCertificateValidation;
});
});
});
但真正的“证书签名失败”让我无法继续下去。 运行 openssl 验证 - 结果正常....那么 Kestrel 在做什么?
提前致谢
更新:
服务器上安装了自签名(第 3 方)证书以验证第 3 方的客户端。提到的命令确实 return 出错,但由于证书是由第 3 方提供的,我不确定它的问题是什么?
好的,dotnet 和 openssl 都同意签名无效。虽然我没有看到重现这一点的实用方法,但 'unknown digest'(而不是 'bad padding' 或 'out of range')表明签名实际上是由发行者创建的(即没有损坏的数据或签名, 或错误的密钥)但签名者做错了。尝试以下过程(我使用了我自己的证书,因为你的证书太私密了,任何人都看不到):
$ openssl req -newkey rsa:1024 -keyout 70348834.key -nodes -x509 -md5 -subj /CN=70348834 -out 70348834.crt
Generating a RSA private key
.....+++++
....+++++
writing new private key to '70348834.key'
-----
# RSA-1024 no longer meets standards but this is just for testing
$ openssl verify -check_ss_sig -CAfile 70348834.crt 70348834.crt
70348834.crt: OK
$ openssl asn1parse -i <70348834.crt
0:d=0 hl=4 l= 514 cons: SEQUENCE
4:d=1 hl=4 l= 363 cons: SEQUENCE
8:d=2 hl=2 l= 3 cons: cont [ 0 ]
10:d=3 hl=2 l= 1 prim: INTEGER :02
13:d=2 hl=2 l= 20 prim: INTEGER :39163AA0A0B6898D0DF0304F4F8D5649507B4877
35:d=2 hl=2 l= 13 cons: SEQUENCE
37:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
48:d=3 hl=2 l= 0 prim: NULL
50:d=2 hl=2 l= 19 cons: SEQUENCE
52:d=3 hl=2 l= 17 cons: SET
54:d=4 hl=2 l= 15 cons: SEQUENCE
56:d=5 hl=2 l= 3 prim: OBJECT :commonName
61:d=5 hl=2 l= 8 prim: UTF8STRING :70348834
71:d=2 hl=2 l= 30 cons: SEQUENCE
73:d=3 hl=2 l= 13 prim: UTCTIME :211217042113Z
88:d=3 hl=2 l= 13 prim: UTCTIME :220116042113Z
103:d=2 hl=2 l= 19 cons: SEQUENCE
105:d=3 hl=2 l= 17 cons: SET
107:d=4 hl=2 l= 15 cons: SEQUENCE
109:d=5 hl=2 l= 3 prim: OBJECT :commonName
114:d=5 hl=2 l= 8 prim: UTF8STRING :70348834
124:d=2 hl=3 l= 159 cons: SEQUENCE
127:d=3 hl=2 l= 13 cons: SEQUENCE
129:d=4 hl=2 l= 9 prim: OBJECT :rsaEncryption
140:d=4 hl=2 l= 0 prim: NULL
142:d=3 hl=3 l= 141 prim: BIT STRING
286:d=2 hl=2 l= 83 cons: cont [ 3 ]
288:d=3 hl=2 l= 81 cons: SEQUENCE
290:d=4 hl=2 l= 29 cons: SEQUENCE
292:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Subject Key Identifier
297:d=5 hl=2 l= 22 prim: OCTET STRING [HEX DUMP]:041438C135B9D18DF0668B0AA31933FE0F947FBEDF84
321:d=4 hl=2 l= 31 cons: SEQUENCE
323:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Authority Key Identifier
328:d=5 hl=2 l= 24 prim: OCTET STRING [HEX DUMP]:3016801438C135B9D18DF0668B0AA31933FE0F947FBEDF84
354:d=4 hl=2 l= 15 cons: SEQUENCE
356:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Basic Constraints
361:d=5 hl=2 l= 1 prim: BOOLEAN :255
364:d=5 hl=2 l= 5 prim: OCTET STRING [HEX DUMP]:30030101FF
371:d=1 hl=2 l= 13 cons: SEQUENCE
373:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption
384:d=2 hl=2 l= 0 prim: NULL
386:d=1 hl=3 l= 129 prim: BIT STRING
# the number before the colon on the last line is the offset of the raw signature
$ openssl asn1parse <70348834.crt -strparse 386 -out 70348834.sig
Error in encoding
139775850254976:error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long:../crypto/asn1/asn1_lib.c:101:
# ignore that error; RSA signature isn't ASN.1, but -strparse still extracts it, see:
$ ls -l 70348834.sig
-rwxrwxrwx 1 dthomps dthomps 128 Dec 16 23:27 70348834.sig
$ openssl rsautl -verify -certin -inkey 70348834.crt -in 70348834.sig -asn1parse
0:d=0 hl=2 l= 32 cons: SEQUENCE
2:d=1 hl=2 l= 12 cons: SEQUENCE
4:d=2 hl=2 l= 8 prim: OBJECT :md5
14:d=2 hl=2 l= 0 prim: NULL
16:d=1 hl=2 l= 16 prim: OCTET STRING
0000 - 2b 7c cf 6d c8 0f 53 82-0b 57 64 4d 5a e0 d6 9a +|.m..S..WdMZ...
# FYI rsautl -verify isn't properly a verify operation in cryptographic terms,
# technically it's only the 'recover' part of verify-with-recovery (only for RSA)
你的 'recovered' 签名应该看起来像我上面的最后一个块,除了 OCTET STRING 中的数据(但它应该仍然是相同的长度,l=16);如果不向证书颁发者或提供者投诉他们给你的证书无效。