Skip to content

Commit

Permalink
netStandard 2.0 compatibility changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
osumoogle committed Jun 25, 2024
1 parent e004d89 commit 53475d3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading;
using System.Threading.Tasks;
using FluffySpoon.AspNet.EncryptWeMust.Certificates;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using static FluffySpoon.AspNet.EncryptWeMust.Certificates.CertificateRenewalStatus;

Expand All @@ -15,7 +14,6 @@ public class LetsEncryptRenewalService : ILetsEncryptRenewalService
private readonly ICertificateProvider _certificateProvider;
private readonly IEnumerable<ICertificateRenewalLifecycleHook> _lifecycleHooks;
private readonly ILogger<ILetsEncryptRenewalService> _logger;
private readonly IHostApplicationLifetime _lifetime;
private readonly SemaphoreSlim _semaphoreSlim;
private readonly LetsEncryptOptions _options;

Expand All @@ -24,19 +22,17 @@ public class LetsEncryptRenewalService : ILetsEncryptRenewalService
public LetsEncryptRenewalService(
ICertificateProvider certificateProvider,
IEnumerable<ICertificateRenewalLifecycleHook> lifecycleHooks,
IHostApplicationLifetime lifetime,
ILogger<ILetsEncryptRenewalService> logger,
LetsEncryptOptions options)
{
_certificateProvider = certificateProvider;
_lifecycleHooks = lifecycleHooks;
_lifetime = lifetime;
_logger = logger;
_options = options;
_semaphoreSlim = new SemaphoreSlim(1);
}

internal static IAbstractCertificate Certificate { get; private set; }
public static IAbstractCertificate Certificate { get; private set; }

public Uri LetsEncryptUri => _options.LetsEncryptUri;

Expand All @@ -55,8 +51,8 @@ public async Task StartAsync(CancellationToken cancellationToken)
await lifecycleHook.OnStartAsync();

_timer = new Timer(async state => await RunOnceWithErrorHandlingAsync(), null, Timeout.InfiniteTimeSpan, TimeSpan.FromHours(1));
_lifetime.ApplicationStarted.Register(() => OnApplicationStarted(cancellationToken));

OnApplicationStarted(cancellationToken);
}

public async Task StopAsync(CancellationToken cancellationToken)
Expand All @@ -82,24 +78,19 @@ public async Task RunOnceAsync()
if (result.Status != Unchanged)
{
// Preload intermediate certs before exposing certificate to the Kestrel
using var chain = new X509Chain
using (var chain = new X509Chain { ChainPolicy = { RevocationMode = X509RevocationMode.NoCheck } })
{
ChainPolicy =
{
RevocationMode = X509RevocationMode.NoCheck
}
};

if (result.Certificate is LetsEncryptX509Certificate x509cert)
{
if (chain.Build(x509cert.GetCertificate()))
{
_logger.LogInformation("Successfully built certificate chain");
}
else
if (result.Certificate is LetsEncryptX509Certificate x509cert)
{
_logger.LogWarning(
"Was not able to build certificate chain. This can cause an outage of your app.");
if (chain.Build(x509cert.GetCertificate()))
{
_logger.LogInformation("Successfully built certificate chain");
}
else
{
_logger.LogWarning(
"Was not able to build certificate chain. This can cause an outage of your app.");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace FluffySpoon.AspNet.EncryptWeMust.Certificates
/// </summary>
public interface IPersistableCertificate : IAbstractCertificate
{
public byte[] RawData { get; }
byte[] RawData { get; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace FluffySpoon.AspNet.EncryptWeMust.Certificates
/// </summary>
public interface IAbstractCertificate
{
public DateTime NotAfter { get; }
public DateTime NotBefore { get; }
DateTime NotAfter { get; }
DateTime NotBefore { get; }
string Thumbprint { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -10,13 +10,13 @@

<ItemGroup>
<PackageReference Include="certes" Version="3.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace FluffySpoon.AspNet.EncryptWeMust.Persistence
{
public class FileChallengePersistenceStrategy : IChallengePersistenceStrategy
{
private readonly string _relativeFilePath;
private readonly string _challengeFilePath;

public FileChallengePersistenceStrategy(string relativeFilePath)
public FileChallengePersistenceStrategy(string challengeFilePath)
{
_relativeFilePath = relativeFilePath;
_challengeFilePath = challengeFilePath;
}

public async Task DeleteAsync(IEnumerable<ChallengeDto> challenges)
Expand Down Expand Up @@ -60,7 +60,7 @@ public Task<IEnumerable<ChallengeDto>> RetrieveAsync()

private string GetChallengesStorePath()
{
return _relativeFilePath + "_Challenges";
return _challengeFilePath + "_Challenges";
}
}
}

0 comments on commit 53475d3

Please sign in to comment.