mirror of
https://github.com/2dust/v2rayN.git
synced 2026-07-26 09:52:05 +03:00
Update cert (#9773)
This commit is contained in:
105
.github/scripts/UpdateCert.cs
vendored
105
.github/scripts/UpdateCert.cs
vendored
@@ -1,3 +1,49 @@
|
||||
/*
|
||||
==============================================================================
|
||||
THIRD-PARTY CA CERTIFICATE DATA ATTRIBUTION
|
||||
==============================================================================
|
||||
|
||||
This component includes CA certificate data obtained from third-party sources.
|
||||
|
||||
1. Common CA Database (CCADB)
|
||||
------------------------------------------------------------------------------
|
||||
Website:
|
||||
https://www.ccadb.org/
|
||||
|
||||
Data source:
|
||||
https://ccadb.my.salesforce-sites.com/mozilla/IncludedRootsPEMTxt?TrustBitsInclude=Websites
|
||||
|
||||
License:
|
||||
Community Data License Agreement – Permissive, Version 2.0 (CDLA-2.0 Permissive)
|
||||
|
||||
The names and trademarks of CCADB contributors may not be used to endorse or
|
||||
promote products derived from this data without prior written permission.
|
||||
|
||||
License text:
|
||||
https://cdla.dev/permissive-2-0/
|
||||
|
||||
|
||||
2. Chromium Root Store
|
||||
------------------------------------------------------------------------------
|
||||
Source:
|
||||
Chromium Project
|
||||
|
||||
Data source:
|
||||
https://chromium.googlesource.com/chromium/src/+/main/net/data/ssl/chrome_root_store/root_store.certs?format=TEXT
|
||||
|
||||
License:
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright:
|
||||
Copyright (c) The Chromium Authors
|
||||
|
||||
The Chromium Root Store data is distributed under the BSD 3-Clause License.
|
||||
|
||||
License text:
|
||||
https://opensource.org/licenses/BSD-3-Clause
|
||||
==============================================================================
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
@@ -27,68 +73,23 @@ Console.WriteLine("\nAll done!");
|
||||
|
||||
async Task ProcessMozillaAsync(string outputDir)
|
||||
{
|
||||
const string certdataUrl = "https://raw.githubusercontent.com/mozilla-firefox/firefox/refs/heads/release/security/nss/lib/ckfw/builtins/certdata.txt";
|
||||
const string certdataUrl = "https://ccadb.my.salesforce-sites.com/mozilla/IncludedRootsPEMTxt?TrustBitsInclude=Websites";
|
||||
var outputFile = Path.Combine(outputDir, "mozilla_roots_pem");
|
||||
|
||||
Console.WriteLine("Downloading Mozilla certdata.txt...");
|
||||
var content = await client.GetStringAsync(certdataUrl);
|
||||
|
||||
Console.WriteLine("Parsing MULTILINE_OCTAL to PEM...");
|
||||
var pems = ParseMozillaCertData(content);
|
||||
var pemMatches = Regex.Matches(content, @"(-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----)");
|
||||
var pems = new List<string>();
|
||||
foreach (Match m in pemMatches)
|
||||
{
|
||||
pems.Add(m.Groups[1].Value.Trim());
|
||||
}
|
||||
|
||||
await File.WriteAllTextAsync(outputFile, string.Join("\n\n", pems));
|
||||
Console.WriteLine($"Mozilla roots saved to: {outputFile} ({pems.Count} certificates)");
|
||||
}
|
||||
|
||||
List<string> ParseMozillaCertData(string text)
|
||||
{
|
||||
var pems = new List<string>();
|
||||
|
||||
var matches = Regex.Matches(text,
|
||||
@"CKA_VALUE MULTILINE_OCTAL\s*([\s\S]*?)\s*END",
|
||||
RegexOptions.Multiline);
|
||||
|
||||
foreach (Match m in matches)
|
||||
{
|
||||
var octalBlock = m.Groups[1].Value.Trim();
|
||||
var der = OctalToBytes(octalBlock);
|
||||
if (der.Length > 0)
|
||||
{
|
||||
var pem = ConvertToPem(der);
|
||||
pems.Add(pem);
|
||||
}
|
||||
}
|
||||
return pems;
|
||||
}
|
||||
|
||||
byte[] OctalToBytes(string octalBlock)
|
||||
{
|
||||
var bytes = new List<byte>();
|
||||
var matches = Regex.Matches(octalBlock, @"\\(\d{1,3})");
|
||||
foreach (Match m in matches)
|
||||
{
|
||||
bytes.Add((byte)Convert.ToInt32(m.Groups[1].Value, 8));
|
||||
}
|
||||
return bytes.ToArray();
|
||||
}
|
||||
|
||||
string ConvertToPem(byte[] der)
|
||||
{
|
||||
var base64 = Convert.ToBase64String(der);
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("-----BEGIN CERTIFICATE-----\n");
|
||||
|
||||
for (int i = 0; i < base64.Length; i += 64)
|
||||
{
|
||||
var length = Math.Min(64, base64.Length - i);
|
||||
sb.Append(base64.Substring(i, length));
|
||||
sb.Append("\n");
|
||||
}
|
||||
|
||||
sb.Append("-----END CERTIFICATE-----\n");
|
||||
return sb.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
async Task ProcessChromeAsync(string outputDir)
|
||||
{
|
||||
const string chromeCertsUrl = "https://chromium.googlesource.com/chromium/src/+/main/net/data/ssl/chrome_root_store/root_store.certs?format=TEXT";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user