Skip to content

Commit d00c7de

Browse files
authored
Merge pull request #148 from vcsjones/net6
Update to .NET 6.
2 parents 92cdca9 + 885be1a commit d00c7de

File tree

10 files changed

+41
-49
lines changed

10 files changed

+41
-49
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ jobs:
1111
name: Checkout
1212
- uses: actions/setup-dotnet@v1
1313
with:
14-
dotnet-version: '3.1.412'
14+
dotnet-version: '6.0'
1515
- run: dotnet test

src/AzureSign.Core/AuthenticodeKeyVaultSigner.cs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,20 @@ public class AuthenticodeKeyVaultSigner : IDisposable
3636
/// <param name="additionalCertificates">Any additional certificates to assist in building a certificate chain.</param>
3737
public AuthenticodeKeyVaultSigner(AsymmetricAlgorithm signingAlgorithm, X509Certificate2 signingCertificate,
3838
HashAlgorithmName fileDigestAlgorithm, TimeStampConfiguration timeStampConfiguration,
39-
X509Certificate2Collection additionalCertificates = null)
39+
X509Certificate2Collection? additionalCertificates = null)
4040
{
4141
_fileDigestAlgorithm = fileDigestAlgorithm;
4242
_signingCertificate = signingCertificate ?? throw new ArgumentNullException(nameof(signingCertificate));
4343
_timeStampConfiguration = timeStampConfiguration ?? throw new ArgumentNullException(nameof(timeStampConfiguration));
4444
_signingAlgorithm = signingAlgorithm ?? throw new ArgumentNullException(nameof(signingAlgorithm));
4545
_certificateStore = MemoryCertificateStore.Create();
4646
_chain = new X509Chain();
47-
if (additionalCertificates != null)
47+
48+
if (additionalCertificates is not null)
4849
{
4950
_chain.ChainPolicy.ExtraStore.AddRange(additionalCertificates);
5051
}
52+
5153
//We don't care about the trustworthiness of the cert. We just want a chain to sign with.
5254
_chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags;
5355

@@ -73,15 +75,18 @@ public AuthenticodeKeyVaultSigner(AsymmetricAlgorithm signingAlgorithm, X509Cert
7375
/// <param name="logger">An optional logger to capture signing operations.</param>
7476
/// <returns>A HRESULT indicating the result of the signing operation. S_OK, or zero, is returned if the signing
7577
/// operation completed successfully.</returns>
76-
public unsafe int SignFile(ReadOnlySpan<char> path, ReadOnlySpan<char> description, ReadOnlySpan<char> descriptionUrl, bool? pageHashing, ILogger logger = null)
78+
public unsafe int SignFile(ReadOnlySpan<char> path, ReadOnlySpan<char> description, ReadOnlySpan<char> descriptionUrl, bool? pageHashing, ILogger? logger = null)
7779
{
78-
static void CopyAndNullTerminate(ReadOnlySpan<char> str, Span<char> destination)
80+
static char[] NullTerminate(ReadOnlySpan<char> str)
7981
{
80-
str.CopyTo(destination);
81-
destination[destination.Length - 1] = '\0';
82+
char[] result = new char[str.Length + 1];
83+
str.CopyTo(result);
84+
result[result.Length - 1] = '\0';
85+
return result;
8286
}
8387

84-
var flags = SignerSignEx3Flags.SIGN_CALLBACK_UNDOCUMENTED;
88+
SignerSignEx3Flags flags = SignerSignEx3Flags.SIGN_CALLBACK_UNDOCUMENTED;
89+
8590
if (pageHashing == true)
8691
{
8792
flags |= SignerSignEx3Flags.SPC_INC_PE_PAGE_HASHES_FLAG;
@@ -93,7 +98,8 @@ static void CopyAndNullTerminate(ReadOnlySpan<char> str, Span<char> destination)
9398

9499
SignerSignTimeStampFlags timeStampFlags;
95100
ReadOnlySpan<byte> timestampAlgorithmOid;
96-
string timestampUrl;
101+
string? timestampUrl;
102+
97103
switch (_timeStampConfiguration.Type)
98104
{
99105
case TimeStampType.Authenticode:
@@ -107,32 +113,17 @@ static void CopyAndNullTerminate(ReadOnlySpan<char> str, Span<char> destination)
107113
timestampUrl = _timeStampConfiguration.Url;
108114
break;
109115
default:
110-
timeStampFlags = 0;
116+
timeStampFlags = default;
111117
timestampAlgorithmOid = default;
112118
timestampUrl = null;
113119
break;
114120
}
115121

116-
Span<char> pathWithNull = path.Length > 0x100 ? new char[path.Length + 1] : stackalloc char[path.Length + 1];
117-
Span<char> descriptionBuffer = description.Length > 0x100 ? new char[description.Length + 1] : stackalloc char[description.Length + 1];
118-
Span<char> descriptionUrlBuffer = descriptionUrl.Length > 0x100 ? new char[descriptionUrl.Length + 1] : stackalloc char[descriptionUrl.Length + 1];
119-
Span<char> timestampUrlBuffer = timestampUrl == null ?
120-
default : timestampUrl.Length > 0x100 ?
121-
new char[timestampUrl.Length + 1] : stackalloc char[timestampUrl.Length + 1];
122-
123-
CopyAndNullTerminate(path, pathWithNull);
124-
CopyAndNullTerminate(description, descriptionBuffer);
125-
CopyAndNullTerminate(descriptionUrl, descriptionUrlBuffer);
126-
if (timestampUrl != null)
127-
{
128-
CopyAndNullTerminate(timestampUrl.AsSpan(), timestampUrlBuffer);
129-
}
130-
131122
fixed (byte* pTimestampAlgorithm = timestampAlgorithmOid)
132-
fixed (char* pTimestampUrl = timestampUrlBuffer)
133-
fixed (char* pPath = pathWithNull)
134-
fixed (char* pDescription = descriptionBuffer)
135-
fixed (char* pDescriptionUrl = descriptionUrlBuffer)
123+
fixed (char* pTimestampUrl = timestampUrl)
124+
fixed (char* pPath = NullTerminate(path))
125+
fixed (char* pDescription = NullTerminate(description))
126+
fixed (char* pDescriptionUrl = NullTerminate(descriptionUrl))
136127
{
137128
var fileInfo = new SIGNER_FILE_INFO(pPath, default);
138129
var subjectIndex = 0u;

src/AzureSign.Core/AzureSign.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<RuntimeIdentifiers>win10-x64;win10-x86</RuntimeIdentifiers>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<MinVerTagPrefix>v</MinVerTagPrefix>
10+
<Nullable>enable</Nullable>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

src/AzureSign.Core/MemoryCertificateStore.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace AzureSign.Core
88
internal sealed class MemoryCertificateStore : IDisposable
99
{
1010
private IntPtr _handle;
11-
private X509Store _store;
11+
private readonly X509Store _store;
1212

1313
private MemoryCertificateStore(IntPtr handle)
1414
{
@@ -50,10 +50,12 @@ public static MemoryCertificateStore Create()
5050
private void Dispose(bool disposing)
5151
{
5252
GC.SuppressFinalize(this);
53+
5354
if (disposing)
5455
{
5556
_store.Dispose();
5657
}
58+
5759
FreeHandle();
5860
}
5961

src/AzureSign.Core/TimeStampConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class TimeStampConfiguration
1010
/// <summary>
1111
/// The URL to the timestamp authority.
1212
/// </summary>
13-
public string Url { get; }
13+
public string? Url { get; }
1414

1515
/// <summary>
1616
/// The digest algorithm the timestamp service authority should use on timestamp signatures.

src/AzureSignTool/AzureSignTool.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<PackAsTool>true</PackAsTool>
77
<ToolCommandName>azuresigntool</ToolCommandName>
8-
<Description>Azure Sign Tool is similar to signtool in the Windows SDK, with the major difference being that it uses Azure Key Vault for performing the signing process. The usage is like signtool, except with a limited set of options for signing and options for authenticating to Azure Key Vault.</Description>
9-
<RuntimeIdentifiers>win10-x64;win10-x86</RuntimeIdentifiers>
8+
<Description>Azure Sign Tool is similar to signtool in the Windows SDK, with the major difference being that it uses Azure Key Vault for performing the signing process. The usage is like signtool, except with a limited set of options for signing and options for authenticating to Azure Key Vault.</Description>
9+
<RuntimeIdentifiers>win10-x64;win10-x86;win10-arm;win10-arm64</RuntimeIdentifiers>
1010
<MinVerTagPrefix>v</MinVerTagPrefix>
1111
</PropertyGroup>
12-
12+
1313
<ItemGroup>
14-
<PackageReference Include="Azure.Identity" Version="1.4.1" />
14+
<PackageReference Include="Azure.Identity" Version="1.5.0" />
1515
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.2.0" />
1616
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
17-
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.18" />
18-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.18" />
17+
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
1919
<PackageReference Include="MinVer" Version="2.5.0">
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
<PrivateAssets>all</PrivateAssets>
2222
</PackageReference>
2323
<PackageReference Include="RSAKeyVaultProvider" Version="2.1.1" />
2424
</ItemGroup>
25-
25+
2626
<ItemGroup>
2727
<ProjectReference Include="..\AzureSign.Core\AzureSign.Core.csproj" />
2828
</ItemGroup>

src/AzureSignTool/SignCommand.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using McMaster.Extensions.CommandLineUtils;
33
using McMaster.Extensions.CommandLineUtils.Abstractions;
44
using Microsoft.Extensions.Logging;
5-
5+
using Microsoft.Extensions.Logging.Console;
66
using RSAKeyVaultProvider;
77

88
using System;
@@ -190,10 +190,11 @@ public int OnValidationError(ValidationResult result, CommandLineApplication<Sig
190190

191191
private void ConfigureLogging(ILoggingBuilder builder)
192192
{
193-
builder.AddConsole(console => {
193+
builder.AddSimpleConsole(console => {
194194
console.IncludeScopes = true;
195-
console.DisableColors = !Colors;
195+
console.ColorBehavior = Colors ? LoggerColorBehavior.Enabled : LoggerColorBehavior.Disabled;
196196
});
197+
197198
builder.SetMinimumLevel(LogLevel);
198199
}
199200

@@ -293,7 +294,7 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app, IConsole conso
293294
{
294295
return state;
295296
}
296-
using (var loopScope = logger.BeginScope("File: {Id}", filePath))
297+
using (logger.BeginScope("File: {Id}", filePath))
297298
{
298299
logger.LogInformation("Signing file.");
299300

src/AzureSignTool/runtimeconfig.template.json

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

test/AzureSign.Core.Tests/AzureSign.Core.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>

test/AzureSignTool.Tests/AzureSignTool.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
4+
<TargetFrameworks>net6.0</TargetFrameworks>
55

66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
1111
<PackageReference Include="xunit" Version="2.4.1" />
1212
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
1313
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)