Skip to content

Commit

Permalink
Fixed verification key loading and hopefully signing as well
Browse files Browse the repository at this point in the history
with the new certificate loader interface (it turned out the hopeful commit from earlier did not work)
  • Loading branch information
hhyyrylainen committed Nov 29, 2024
1 parent 97ecf26 commit 689e9c9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions DevCenterCommunication/Utilities/SignedDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ public class SignedDataHandler
[UnsupportedOSPlatform("browser")]
public async Task<byte[]> CreateSignature(Stream data, string keyFile, string? keyPassword)
{
using var certificate = X509CertificateLoader.LoadPkcs12(await File.ReadAllBytesAsync(keyFile), keyPassword,
X509KeyStorageFlags.EphemeralKeySet);
var certificateData = await File.ReadAllBytesAsync(keyFile);

using var certificate = string.IsNullOrEmpty(keyPassword) ?
X509CertificateLoader.LoadCertificate(certificateData) :
X509CertificateLoader.LoadPkcs12(certificateData, keyPassword,
X509KeyStorageFlags.EphemeralKeySet);

var key = certificate.GetRSAPrivateKey();

Expand Down Expand Up @@ -47,8 +51,7 @@ public async Task<byte[]> CreateSignature(Stream data, string keyFile, string? k

foreach (var (potentialKeyDataRetriever, keyName) in allowedKeyData)
{
using var certificate = X509CertificateLoader.LoadPkcs12(await potentialKeyDataRetriever(),
null, X509KeyStorageFlags.EphemeralKeySet);
using var certificate = X509CertificateLoader.LoadCertificate(await potentialKeyDataRetriever());

// Ignore certificates that are expired or not valid yet
if (certificate.NotBefore > now || certificate.NotAfter < now)
Expand Down

0 comments on commit 689e9c9

Please sign in to comment.