Skip to content

Commit 9d9773a

Browse files
committedAug 9, 2024··
Added specific support for .NET 8.0's time clock replacememt in constructors
Suppressed vuln checking in packages for older sample apps, as they're stuck on those unsupported versions.
1 parent e9d3daa commit 9d9773a

12 files changed

+87
-20
lines changed
 

‎idunno.Authentication.sln

+4-8
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,13 @@ Global
8787
{1F0D1711-6A93-4428-A404-8F1F13AD5D61}.Release|Any CPU.ActiveCfg = Release|Any CPU
8888
{1F0D1711-6A93-4428-A404-8F1F13AD5D61}.Release|Any CPU.Build.0 = Release|Any CPU
8989
{BB3C0698-1736-491C-B621-A78D00CBF0CA}.CodeQL|Any CPU.ActiveCfg = CodeQL|Any CPU
90-
{BB3C0698-1736-491C-B621-A78D00CBF0CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
91-
{BB3C0698-1736-491C-B621-A78D00CBF0CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
90+
{BB3C0698-1736-491C-B621-A78D00CBF0CA}.Debug|Any CPU.ActiveCfg = Release|Any CPU
91+
{BB3C0698-1736-491C-B621-A78D00CBF0CA}.Debug|Any CPU.Build.0 = Release|Any CPU
9292
{BB3C0698-1736-491C-B621-A78D00CBF0CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
93-
{BB3C0698-1736-491C-B621-A78D00CBF0CA}.Release|Any CPU.Build.0 = Release|Any CPU
9493
{E78E32F6-B94F-4ED3-9A33-3CE500C61AE6}.CodeQL|Any CPU.ActiveCfg = CodeQL|Any CPU
9594
{E78E32F6-B94F-4ED3-9A33-3CE500C61AE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
9695
{E78E32F6-B94F-4ED3-9A33-3CE500C61AE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
9796
{E78E32F6-B94F-4ED3-9A33-3CE500C61AE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
98-
{E78E32F6-B94F-4ED3-9A33-3CE500C61AE6}.Release|Any CPU.Build.0 = Release|Any CPU
9997
{6E25A829-BABC-41EE-80C2-56FACE3AA49B}.CodeQL|Any CPU.ActiveCfg = CodeQL|Any CPU
10098
{6E25A829-BABC-41EE-80C2-56FACE3AA49B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10199
{6E25A829-BABC-41EE-80C2-56FACE3AA49B}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -107,20 +105,18 @@ Global
107105
{83CA0C3E-7B9E-4CFA-A0A6-1258940964CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
108106
{83CA0C3E-7B9E-4CFA-A0A6-1258940964CB}.Release|Any CPU.Build.0 = Release|Any CPU
109107
{116A502B-8196-4005-A067-2F8CA7ABC247}.CodeQL|Any CPU.ActiveCfg = CodeQL|Any CPU
110-
{116A502B-8196-4005-A067-2F8CA7ABC247}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
111-
{116A502B-8196-4005-A067-2F8CA7ABC247}.Debug|Any CPU.Build.0 = Debug|Any CPU
108+
{116A502B-8196-4005-A067-2F8CA7ABC247}.Debug|Any CPU.ActiveCfg = Release|Any CPU
109+
{116A502B-8196-4005-A067-2F8CA7ABC247}.Debug|Any CPU.Build.0 = Release|Any CPU
112110
{116A502B-8196-4005-A067-2F8CA7ABC247}.Release|Any CPU.ActiveCfg = Release|Any CPU
113111
{116A502B-8196-4005-A067-2F8CA7ABC247}.Release|Any CPU.Build.0 = Release|Any CPU
114112
{772C5611-EB06-4878-A758-CEFF519764E0}.CodeQL|Any CPU.ActiveCfg = CodeQL|Any CPU
115113
{772C5611-EB06-4878-A758-CEFF519764E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
116114
{772C5611-EB06-4878-A758-CEFF519764E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
117115
{772C5611-EB06-4878-A758-CEFF519764E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
118-
{772C5611-EB06-4878-A758-CEFF519764E0}.Release|Any CPU.Build.0 = Release|Any CPU
119116
{1D706A97-2F8A-46ED-81FD-2AD17E4710F3}.CodeQL|Any CPU.ActiveCfg = CodeQL|Any CPU
120117
{1D706A97-2F8A-46ED-81FD-2AD17E4710F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
121118
{1D706A97-2F8A-46ED-81FD-2AD17E4710F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
122119
{1D706A97-2F8A-46ED-81FD-2AD17E4710F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
123-
{1D706A97-2F8A-46ED-81FD-2AD17E4710F3}.Release|Any CPU.Build.0 = Release|Any CPU
124120
EndGlobalSection
125121
GlobalSection(SolutionProperties) = preSolution
126122
HideSolutionNode = FALSE

‎samples/idunno.Authentication.Basic.Sample.net6/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Reflection.Metadata.Ecma335;
21
using System.Security.Claims;
32
using idunno.Authentication.Basic;
43
using Microsoft.AspNetCore.Authorization;

‎samples/idunno.Authentication.Basic.Sample/idunno.Authentication.Basic.Sample.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<Configurations>Debug;Release;CodeQL</Configurations>
66
</PropertyGroup>
77

8+
<PropertyGroup>
9+
<!-- Supress out of support warnings -->
10+
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
11+
</PropertyGroup>
12+
813
<ItemGroup>
914
<None Update="Views\**\*;Areas\**\Views">
1015
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>

‎samples/idunno.Authentication.Certificate.Sample/idunno.Authentication.Certificate.Sample.csproj

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.1</TargetFramework>
5-
<CheckEolTargetFramework>false</CheckEolTargetFramework>
5+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
66
<EnableNETAnalyzers>false</EnableNETAnalyzers>
77
<Configurations>Debug;Release;CodeQL</Configurations>
88
</PropertyGroup>
99

10-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<PropertyGroup>
11+
<!-- Disable breaking on nuget warning about packages with vulnerabilties because I know it's EOL -->
12+
<NoWarn>$(NoWarn);NU1903;NU1902</NoWarn>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
1116
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
1217
<WarningsAsErrors>NU1605</WarningsAsErrors>
1318
</PropertyGroup>

‎src/Directory.Build.props

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup Condition="'$(Configuration)' != 'CodeQL'">
30-
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All" />
31-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="All" />
30+
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.2.4" PrivateAssets="All" />
31+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.139" PrivateAssets="All" />
3232
</ItemGroup>
3333

3434
<ItemGroup>

‎src/idunno.Authentication.Basic/BasicAuthenticationHandler.cs

+22-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,26 @@ internal class BasicAuthenticationHandler : AuthenticationHandler<BasicAuthentic
1919
{
2020
private const string _Scheme = "Basic";
2121

22+
#pragma warning disable IDE0079
23+
#pragma warning disable IDE0090
24+
2225
private readonly UTF8Encoding _utf8ValidatingEncoding = new UTF8Encoding(false, true);
2326

27+
#pragma warning restore IDE0090
28+
#pragma warning restore IDE0079
29+
2430
private readonly Encoding _iso88591ValidatingEncoding = Encoding.GetEncoding("ISO-8859-1",new EncoderExceptionFallback(), new DecoderExceptionFallback());
2531

32+
#if NET8_0_OR_GREATER
33+
public BasicAuthenticationHandler(
34+
IOptionsMonitor<BasicAuthenticationOptions> options,
35+
ILoggerFactory logger,
36+
UrlEncoder encoder) : base(options, logger, encoder)
37+
{
38+
}
39+
40+
[Obsolete("ISystemClock is obsolete, use TimeProvider on AuthenticationSchemeOptions instead.")]
41+
#endif
2642
public BasicAuthenticationHandler(
2743
IOptionsMonitor<BasicAuthenticationOptions> options,
2844
ILoggerFactory logger,
@@ -45,7 +61,12 @@ public BasicAuthenticationHandler(
4561

4662
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
4763
{
64+
#if NET6_0_OR_GREATER
65+
string authorizationHeader = Request.Headers.Authorization;
66+
#else
4867
string authorizationHeader = Request.Headers["Authorization"];
68+
#endif
69+
4970
if (string.IsNullOrEmpty(authorizationHeader))
5071
{
5172
return AuthenticateResult.NoResult();
@@ -105,7 +126,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
105126
}
106127
else
107128
{
108-
throw new ArgumentOutOfRangeException(nameof(Options), "Unknown EncodingPrefence");
129+
throw new ArgumentOutOfRangeException(nameof(Options), "Unknown EncodingPreference");
109130
}
110131
}
111132
catch (Exception ex)

‎src/idunno.Authentication.Basic/idunno.Authentication.Basic.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
<PropertyGroup>
44
<Description>ASP.NET Core middleware that enables an application to support basic authentication.</Description>
5-
<TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
5+
<TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
66
<PackageTags>aspnetcore;authentication;security;basicauth</PackageTags>
77
<Configurations>Debug;Release;CodeQL</Configurations>
88
</PropertyGroup>
99

1010
<PropertyGroup>
11+
<!-- Supress out of support warnings -->
12+
<NoWarn>$(NoWarn);NETSDK1138</NoWarn>
13+
</PropertyGroup>
14+
15+
<PropertyGroup>
1116
<CheckEolTargetFramework>false</CheckEolTargetFramework>
1217
</PropertyGroup>
1318

‎src/idunno.Authentication.SharedKey/SharedKeyAuthenticationHandler.cs

+18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ namespace idunno.Authentication.SharedKey
1818
{
1919
internal class SharedKeyAuthenticationHandler : AuthenticationHandler<SharedKeyAuthenticationOptions>
2020
{
21+
#if NET8_0_OR_GREATER
22+
public SharedKeyAuthenticationHandler(
23+
IOptionsMonitor<SharedKeyAuthenticationOptions> options,
24+
ILoggerFactory logger,
25+
UrlEncoder encoder) : base(options, logger, encoder)
26+
{
27+
}
2128

29+
[Obsolete("ISystemClock is obsolete, use TimeProvider on AuthenticationSchemeOptions instead.")]
30+
#endif
2231
public SharedKeyAuthenticationHandler(
2332
IOptionsMonitor<SharedKeyAuthenticationOptions> options,
2433
ILoggerFactory logger,
@@ -41,7 +50,12 @@ public SharedKeyAuthenticationHandler(
4150

4251
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
4352
{
53+
#if NET6_0_OR_GREATER
54+
string? authorizationHeader = Request.Headers.Authorization;
55+
#else
4456
string? authorizationHeader = Request.Headers["Authorization"];
57+
#endif
58+
4559
if (string.IsNullOrEmpty(authorizationHeader))
4660
{
4761
return AuthenticateResult.NoResult();
@@ -160,8 +174,12 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
160174
}
161175
Request.Body.Position = currentPosition;
162176

177+
#if NET5_0_OR_GREATER
178+
var calculatedContentHash = MD5.HashData(new UTF8Encoding(false).GetBytes(body));
179+
#else
163180
using var md5 = MD5.Create();
164181
var calculatedContentHash = md5.ComputeHash(new UTF8Encoding(false).GetBytes(body));
182+
#endif
165183

166184
byte[] providedContentHash;
167185
try

‎src/idunno.Authentication.SharedKey/SharedKeyAuthenticationOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SharedKeyAuthenticationOptions : AuthenticationSchemeOptions
2020
set { base.Events = value; }
2121
}
2222

23-
public Func<string, byte[]> KeyResolver { get; set; } = (keyId) => Array.Empty<byte>();
23+
public Func<string, byte[]> KeyResolver { get; set; } = (keyId) => { return Array.Empty<byte>(); };
2424

2525
public TimeSpan MaximumMessageValidity { get; set; } = new TimeSpan(0, 15, 0);
2626
}

‎src/idunno.Authentication.SharedKey/SharedKeyHttpMessageHandler.cs

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ namespace idunno.Authentication.SharedKey
1212
{
1313
public class SharedKeyHttpMessageHandler : DelegatingHandler
1414
{
15+
16+
#pragma warning disable IDE0079
17+
#pragma warning disable IDE0290
18+
1519
public SharedKeyHttpMessageHandler(string keyId, byte[] key)
1620
{
1721
KeyId = keyId;
@@ -22,12 +26,20 @@ public SharedKeyHttpMessageHandler(string keyId, string key) : this(keyId, Conve
2226
{
2327
}
2428

29+
#pragma warning restore IDE0290
30+
#pragma warning restore IDE0079
31+
32+
2533
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
2634
{
35+
#if NET6_0_OR_GREATER
36+
ArgumentNullException.ThrowIfNull(request);
37+
#else
2738
if (request == null)
2839
{
2940
throw new ArgumentNullException(nameof(request));
3041
}
42+
#endif
3143

3244
// Time stamp the request if it's not already timestamped so we can support expiry.
3345
if (request.Headers.Date == null)

‎src/idunno.Authentication.SharedKey/idunno.Authentication.SharedKey.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>ASP.NET Core middleware that enables an application to support a type of shared key authentication.</Description>
5-
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
5+
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0;net8.0</TargetFrameworks>
66
<PackageTags>aspnetcore;authentication;security</PackageTags>
77
<Nullable>enable</Nullable>
88
<Configurations>Debug;Release;CodeQL</Configurations>

‎test/Directory.Build.props

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@
55
<IsPublishable>False</IsPublishable>
66
</PropertyGroup>
77

8+
<PropertyGroup>
9+
<!-- Disable breaking on nuget warning about packages with vulnerabilties because I need to use the lowest
10+
version possible as the baseline for aspnet.all -->
11+
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1903;NU1902</WarningsNotAsErrors>
12+
</PropertyGroup>
13+
814
<!-- These packages must have matching versions. Do not believe Dependabot when it tries to update them individually -->
915
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
11-
<PackageReference Include="Microsoft.CodeCoverage" Version="17.9.0" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
17+
<PackageReference Include="Microsoft.CodeCoverage" Version="17.10.0" />
1218
</ItemGroup>
1319

1420
<ItemGroup>
15-
<PackageReference Include="coverlet.collector" Version="6.0.1">
21+
<PackageReference Include="coverlet.collector" Version="6.0.2">
1622
<PrivateAssets>all</PrivateAssets>
1723
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1824
</PackageReference>

0 commit comments

Comments
 (0)
Please sign in to comment.