Skip to content

Commit 31fa9b1

Browse files
authored
Merge pull request #420 from GeneralLibrary/cleanup/blacklist-httpclient-ipc
Cleanup: remove deprecated BlackListManager, unify HttpClient via IHttpClientFactory, deduplicate IPC encryption
2 parents 7c3d702 + f6f2e8d commit 31fa9b1

17 files changed

Lines changed: 116 additions & 280 deletions

src/c#/GeneralUpdate.Core/Configuration/ConfiginfoBuilder-Example.cs

Lines changed: 0 additions & 118 deletions
This file was deleted.

src/c#/GeneralUpdate.Core/Configuration/Environments.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
using System.IO;
33
using System.Security.Cryptography;
44
using System.Text;
5+
using GeneralUpdate.Core.Ipc;
56

67
namespace GeneralUpdate.Core.Configuration;
78

89
/// <summary>
910
/// Secure IPC environment variable provider.
1011
/// AES-encrypted temp files in a dedicated subdirectory, auto-deleted after read.
12+
/// Encryption is delegated to <see cref="IpcEncryption"/>.
1113
/// </summary>
1214
public static class Environments
1315
{
14-
// Fixed key/IV derived from a constant — not crypto-grade, but sufficient for
15-
// ephemeral IPC where the file lives < 1 second and is in a per-user directory.
1616
private static readonly byte[] _aesKey = SHA256.Create()
1717
.ComputeHash(Encoding.UTF8.GetBytes("GeneralUpdate.IPC.EnvironmentProvider.v1"));
1818
private static readonly byte[] _aesIV = new byte[16] { 0x47, 0x55, 0x50, 0x44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -31,33 +31,13 @@ public static void SetEnvironmentVariable(string key, string value)
3131
{
3232
var filePath = Path.Combine(IpcDir, $"{key}.enc");
3333
var plainBytes = Encoding.UTF8.GetBytes(value);
34-
using var aes = Aes.Create();
35-
aes.Key = _aesKey;
36-
aes.IV = _aesIV;
37-
using var encryptor = aes.CreateEncryptor();
38-
var encrypted = encryptor.TransformFinalBlock(plainBytes, 0, plainBytes.Length);
39-
File.WriteAllBytes(filePath, encrypted);
34+
IpcEncryption.EncryptToFile(plainBytes, filePath, _aesKey, _aesIV);
4035
}
4136

4237
public static string GetEnvironmentVariable(string key)
4338
{
4439
var filePath = Path.Combine(Path.GetTempPath(), "GeneralUpdate", "ipc", $"{key}.enc");
45-
if (!File.Exists(filePath))
46-
return string.Empty;
47-
48-
try
49-
{
50-
var encrypted = File.ReadAllBytes(filePath);
51-
using var aes = Aes.Create();
52-
aes.Key = _aesKey;
53-
aes.IV = _aesIV;
54-
using var decryptor = aes.CreateDecryptor();
55-
var plainBytes = decryptor.TransformFinalBlock(encrypted, 0, encrypted.Length);
56-
return Encoding.UTF8.GetString(plainBytes);
57-
}
58-
finally
59-
{
60-
try { File.Delete(filePath); } catch { /* best-effort cleanup */ }
61-
}
40+
var plainBytes = IpcEncryption.DecryptFromFile(filePath, _aesKey, _aesIV);
41+
return plainBytes != null ? Encoding.UTF8.GetString(plainBytes) : string.Empty;
6242
}
6343
}

src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MutiAllDownloadCompletedEventArgs.cs renamed to src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MultiAllDownloadCompletedEventArgs.cs

File renamed without changes.

src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MutiDownloadCompletedEventArgs.cs renamed to src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MultiDownloadCompletedEventArgs.cs

File renamed without changes.

src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MutiDownloadErrorEventArgs.cs renamed to src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MultiDownloadErrorEventArgs.cs

File renamed without changes.

src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MutiDownloadStatisticsEventArgs.cs renamed to src/c#/GeneralUpdate.Core/Download/MultiEventArgs/MultiDownloadStatisticsEventArgs.cs

File renamed without changes.

src/c#/GeneralUpdate.Core/FileSystem/BlackListDefaults.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace GeneralUpdate.Core.FileSystem;
44

5-
/// <summary>Built-in default blacklist items — previously hardcoded in BlackListManager.</summary>
5+
/// <summary>Built-in default blacklist items.</summary>
66
public static class BlackListDefaults
77
{
88
/// <summary>Default blacklisted files (system DLLs that ship with the runtime).</summary>

src/c#/GeneralUpdate.Core/FileSystem/BlackListManager.cs

Lines changed: 0 additions & 88 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace GeneralUpdate.Core.FileSystem;
4+
5+
/// <summary>Matches files/directories against a blacklist configuration.</summary>
6+
public interface IBlackListMatcher
7+
{
8+
bool IsBlacklisted(string relativeFilePath);
9+
bool IsBlacklistedFormat(string extension);
10+
bool ShouldSkipDirectory(string directoryName);
11+
}

src/c#/GeneralUpdate.Core/FileSystem/StorageManager.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public sealed class StorageManager
1414
private long _fileCount = 0;
1515
public const string DirectoryName = "app-";
1616

17-
/// <summary>Optional blacklist matcher. When set, takes precedence over BlackListManager.</summary>
17+
/// <summary>Optional blacklist matcher. Must be set before any file operation.</summary>
1818
public static IBlackListMatcher? BlackListMatcher { get; set; }
1919

2020
private ComparisonResult ComparisonResult { get; set; }
@@ -267,9 +267,7 @@ private IEnumerable<FileNode> ReadFileNode(string path, string rootPath = null)
267267

268268
foreach (var subPath in Directory.EnumerateFiles(path))
269269
{
270-
#pragma warning disable CS0618 // Obsolete fallback
271-
if ((BlackListMatcher ?? BlackListManager.Instance).IsBlacklisted(subPath)) continue;
272-
#pragma warning restore CS0618
270+
if (BlackListMatcher != null && BlackListMatcher.IsBlacklisted(subPath)) continue;
273271

274272
var hashAlgorithm = new Sha256HashAlgorithm();
275273
var hash = hashAlgorithm.ComputeHash(subPath);
@@ -288,9 +286,7 @@ private IEnumerable<FileNode> ReadFileNode(string path, string rootPath = null)
288286

289287
foreach (var subPath in Directory.EnumerateDirectories(path))
290288
{
291-
#pragma warning disable CS0618 // Obsolete fallback
292-
if ((BlackListMatcher ?? BlackListManager.Instance).ShouldSkipDirectory(subPath)) continue;
293-
#pragma warning restore CS0618
289+
if (BlackListMatcher != null && BlackListMatcher.ShouldSkipDirectory(subPath)) continue;
294290
resultFiles.AddRange(ReadFileNode(subPath, rootPath));
295291
}
296292

0 commit comments

Comments
 (0)