gpt4 book ai didi

ssl - Kestel (.NET Core 3.1) 是否支持 md5RSA 证书?

转载 作者:行者123 更新时间:2023-12-04 22:39:50 25 4
gpt4 key购买 nike

我一直在尝试运行一个简单的 HTTPS 安全 Kestrel 服务,该服务使用已安装的自签名根证书(来自第 3 方)验证客户端。我正在努力寻找客户端证书的具体问题以及服务反弹连接的原因。有人可以明确回答 .NET Core 3.1 中的 Kestrel 在运行 OpenSSL 1.0.2k-fips 2017 年 1 月 26 日的 Linux 机器上不再接受具有 md5RSA 签名算法的根证书吗?
enter image description here
我一直无法找到任何方法从 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 verify - 结果还可以……那么 Kestrel 在做什么?
提前致谢
更新:
自签名(第 3 方)证书安装在服务器上以验证第 3 方的客户端。提到的命令确实返回错误,但由于证书是由第 3 方提供的,我不确定它有什么问题?
check_ss_sig

最佳答案

好的,所以 dotnet 和 openssl 都同意签名无效。尽管我看不到重现此问题的实用方法,但“未知摘要”(而不是“错误填充”或“超出范围”)表明签名实际上是由发行人创建的(即没有损坏的数据或签名,或者错误的 key )但签名者做错了。尝试以下过程(我使用了自己的证书,因为您的证书太私密,任何人都看不到):

$ 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)
您的“恢复”签名应该看起来像我上面的最后一个 block ,除了 OCTET STRING 中的数据(但它应该仍然是相同的长度,l=16);如果不向证书颁发者或提供者提示他们给你的证书无效。

关于ssl - Kestel (.NET Core 3.1) 是否支持 md5RSA 证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70348834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com