mirror of
https://github.com/2dust/v2rayN.git
synced 2026-09-13 18:02:07 +03:00
Fix hy2 fmt (#10044)
This commit is contained in:
@@ -223,6 +223,11 @@ public class Hysteria2Fmt : BaseFmt
|
||||
var sha = item.CertSha;
|
||||
dicQuery.Add("pinSHA256", Utils.UrlEncode(sha));
|
||||
}
|
||||
else if (!item.Cert.IsNullOrEmpty()
|
||||
&& CertPemManager.GetLeafCertSha256Thumbprint(item.Cert) is { Length: > 0 } thumbprint)
|
||||
{
|
||||
dicQuery.Add("pinSHA256", Utils.UrlEncode(thumbprint));
|
||||
}
|
||||
if (!item.EchConfigList.IsNullOrEmpty())
|
||||
{
|
||||
dicQuery.Add("ech", Utils.UrlEncode(item.EchConfigList));
|
||||
|
||||
@@ -281,6 +281,37 @@ public class CertPemManager
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetLeafCertSha256Thumbprint(string pemCertChain, bool includeColon = false)
|
||||
{
|
||||
var certs = ParsePemChain(pemCertChain);
|
||||
if (certs.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
foreach (var certStr in certs)
|
||||
{
|
||||
try
|
||||
{
|
||||
var cert = X509Certificate2.CreateFromPem(certStr);
|
||||
var extension = cert.Extensions
|
||||
.OfType<X509BasicConstraintsExtension>()
|
||||
.FirstOrDefault();
|
||||
var isCa = extension?.CertificateAuthority == true;
|
||||
if (isCa)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var thumbprint = cert.GetCertHashString(HashAlgorithmName.SHA256);
|
||||
return includeColon ? string.Join(":", thumbprint.Chunk(2).Select(c => new string(c))) : thumbprint;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private static readonly Lazy<X509Certificate2Collection> _chromeRootCerts = new(() =>
|
||||
{
|
||||
var pemText = EmbedUtils.GetEmbedText(Global.ChromeRootCertFileName);
|
||||
|
||||
Reference in New Issue
Block a user