Skip to content

Commit e7c8360

Browse files
committed
Protect added certificates
1 parent c487d29 commit e7c8360

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/EasySign/Bundle.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Bundle
5353
/// The entries with these names are only resolved with <see cref="ReadSource.Bundle"/>.
5454
/// This feature is only designed to prevent accidental modification of important files.
5555
/// </remarks>
56-
protected List<string> ProtectedEntryNames { get; private set; } =
56+
protected HashSet<string> ProtectedEntryNames { get; private set; } =
5757
[
5858
".manifest.ec",
5959
".signatures.ec",
@@ -330,7 +330,7 @@ protected virtual void Parse(ZipArchive zip)
330330
Logger.LogDebug("Parsing manifest");
331331
Manifest = JsonSerializer.Deserialize(entry.Open(), typeof(Manifest), SourceGenerationManifestContext.Default) as Manifest ?? new Manifest();
332332

333-
List<string> protectedEntries = ProtectedEntryNames.Union(Manifest.ProtectedEntryNames).ToList();
333+
HashSet<string> protectedEntries = ProtectedEntryNames.Union(Manifest.ProtectedEntryNames).ToHashSet();
334334
ProtectedEntryNames = protectedEntries;
335335
Manifest.ProtectedEntryNames = protectedEntries;
336336
}
@@ -447,6 +447,9 @@ public void Sign(X509Certificate2 certificate, RSA privateKey)
447447
byte[] certData = certificate.Export(X509ContentType.Cert);
448448
string name = certificate.GetCertHashString();
449449

450+
Logger.LogDebug("Adding entry name: {name} to protected entry names", name);
451+
ProtectedEntryNames.Add(name);
452+
450453
Logger.LogDebug("Signing manifest");
451454
byte[] manifestData = GetManifestData();
452455
byte[] signature = privateKey.SignData(manifestData, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1);
@@ -785,6 +788,7 @@ private void ProcessPendingFiles(ZipArchive zip)
785788
protected virtual byte[] GetManifestData()
786789
{
787790
Manifest.UpdatedBy = GetType().FullName;
791+
Manifest.ProtectedEntryNames = ProtectedEntryNames.Union(Manifest.ProtectedEntryNames).ToHashSet();
788792

789793
return Export(Manifest, SourceGenerationManifestContext.Default);
790794
}

src/EasySign/Manifest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public SortedDictionary<string, byte[]> Entries
3636
/// <summary>
3737
/// Gets or sets the list of entry names that should be protected by the bundle from accidental modifications.
3838
/// </summary>
39-
public List<string> ProtectedEntryNames { get; set; } = [];
39+
public HashSet<string> ProtectedEntryNames { get; set; } = [];
4040

4141
/// <summary>
4242
/// Gets the entries as a thread-safe concurrent dictionary.

0 commit comments

Comments
 (0)