This commit is contained in:
DHR60 2025-09-17 21:11:05 +08:00
parent 12b46e7c43
commit 942335db61
3 changed files with 11 additions and 7 deletions

View file

@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Principal; using System.Security.Principal;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using CliWrap; using CliWrap;
using CliWrap.Buffered; using CliWrap.Buffered;
@ -357,6 +358,14 @@ public class Utils
return userHostsMap; return userHostsMap;
} }
public static List<string> ParseCertSha256ToList(string certSha256Content)
{
return String2List(certSha256Content)
.Select(s => s.Replace(":", "").Replace(" ", ""))
.Where(s => s.Length == 64 && Regex.IsMatch(s, @"\A\b[0-9a-fA-F]+\b\Z"))
.ToList();
}
#endregion #endregion
#region #region

View file

@ -256,9 +256,7 @@ public partial class CoreConfigSingboxService
if (node.CertSha256.IsNotEmpty()) if (node.CertSha256.IsNotEmpty())
{ {
// hex to raw to base64 // hex to raw to base64
var certSha256List = Utils.String2List(node.CertSha256) var certSha256List = Utils.ParseCertSha256ToList(node.CertSha256)
.Select(s => s.Replace(":", "").Replace(" ", ""))
.Where(s => s.Length == 64 && Regex.IsMatch(s, @"\A[0-9a-fA-F]{64}\Z"))
.Select(s => Convert.ToBase64String( .Select(s => Convert.ToBase64String(
Enumerable.Range(0, 32) Enumerable.Range(0, 32)
.Select(i => Convert.ToByte(s.Substring(i * 2, 2), 16)) .Select(i => Convert.ToByte(s.Substring(i * 2, 2), 16))

View file

@ -281,10 +281,7 @@ public partial class CoreConfigV2rayService
} }
if (node.CertSha256.IsNotEmpty()) if (node.CertSha256.IsNotEmpty())
{ {
var certSha256List = Utils.String2List(node.CertSha256) var certSha256List = Utils.ParseCertSha256ToList(node.CertSha256);
.Select(s => s.Replace(":", "").Replace(" ", ""))
.Where(s => s.Length == 64 && Regex.IsMatch(s, @"\A\b[0-9a-fA-F]+\b\Z"))
.ToList();
if (certSha256List.Count > 0) if (certSha256List.Count > 0)
{ {
tlsSettings.pinnedPeerCertificateSha256 = certSha256List; tlsSettings.pinnedPeerCertificateSha256 = certSha256List;