mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-14 12:29:13 +00:00
Refactor
This commit is contained in:
parent
12b46e7c43
commit
942335db61
3 changed files with 11 additions and 7 deletions
|
@ -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 数据检查
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue