Skip to content

Commit

Permalink
Fix project setup. Fix package tagging.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjrdk committed Jun 7, 2022
1 parent 14279e6 commit d78334d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions shared.proj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.0.0</Version>
<Version>2.1.1</Version>
<Authors>Jacob Reimers</Authors>
<Company>Reimers.dk</Company>
<Product>OpenCertServer</Product>
Expand All @@ -9,7 +9,7 @@
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>https://github.com/jjrdk/opencertserver</PackageProjectUrl>
<RepositoryUrl>https://github.com/jjrdk/opencertserver</RepositoryUrl>
<Tags>X509 Certificate EST RFC7030 RFC8555</Tags>
<PackageTags>X509 Certificate SSL TLS EST ACME RFC7030 RFC8555</PackageTags>
<Description>ASP.NET Core implementation of RFC 7030 certificate authority and issuer and RFC8555 client and server.</Description>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<langVersion>latest</langVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>OpenCertServer.Acme.Abstractions</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>opencertserver.acme.abstractions</AssemblyName>
</PropertyGroup>
<Import Project="../../shared.proj"/>
<Import Project="../../shared.proj" />

<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.18.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using Abstractions.Model.Exceptions;
using Abstractions.Services;
using Filters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Account = Abstractions.HttpModel.Account;

//[AllowAnonymous]
[AddNextNonce]
public class AccountController : ControllerBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace OpenCertServer.Acme.Server.Extensions
using Configuration;
using DnsClient;
using Filters;
using Microsoft.AspNetCore.Authorization.Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -28,7 +29,7 @@ public static IServiceCollection AddAcmeServer(
{
services.AddControllers().AddApplicationPart(typeof(ServiceCollectionExtensions).Assembly);

services.AddScoped<IAcmeRequestProvider, DefaultRequestProvider>();
services.AddScoped<IAcmeRequestProvider, DefaultRequestProvider>();//.AddAuthorization();

services.AddScoped<IRequestValidationService, DefaultRequestValidationService>();
services.AddScoped<INonceService, DefaultNonceService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class AcmeMiddlewareExtensions
{
public static IApplicationBuilder UseAcmeServer(this IApplicationBuilder builder)
{
return builder.UseMiddleware<AcmeMiddleware>();
return builder.UseMiddleware<AcmeMiddleware>().UseRouting().UseEndpoints(e=>e.MapControllers());
}
}
}
9 changes: 8 additions & 1 deletion src/opencertserver.ca/CertificateAuthority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Pkcs;
Expand Down Expand Up @@ -305,7 +306,13 @@ public void Dispose()
/// <returns></returns>
private static byte[] Base64DecodeBytes(string base64EncodedData)
{
var s = base64EncodedData.Trim().Replace(" ", "+").Replace('-', '+').Replace('_', '/');
var s = base64EncodedData
.Replace(" ", "+")
.Replace('-', '+')
.Replace('_', '/')
.Replace("\n", "")
.Replace("\r", "")
.Trim();
switch (s.Length % 4)
{
case 0:
Expand Down
14 changes: 8 additions & 6 deletions src/opencertserver.est.server/CertificateServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,28 @@ public static IServiceCollection AddEstServer(

private static IServiceCollection InnerAddEstServer(this IServiceCollection services)
{
return services.AddTransient<CaCertHandler>()
return services
.AddTransient<CaCertHandler>()
.AddTransient<SimpleEnrollHandler>()
.AddTransient<SimpleReEnrollHandler>()
.AddCertificateForwarding(
o => { o.HeaderConverter = x => new X509Certificate2(Convert.FromBase64String(x)); })
.AddRouting();
.AddRouting()
.AddAuthorization()
.AddAuthentication().Services;
}

public static IApplicationBuilder UseEstServer(this IApplicationBuilder app, IAuthorizeData? enrollPolicy = null, IAuthorizeData? reEnrollPolicy = null)
{
const string? wellKnownEst = "/.well-known/est";
return app
//.UseCertificateForwarding()
//.UseAuthentication()
//.UseAuthorization()
.UseCertificateForwarding()
.UseAuthentication()
.UseRouting()
.UseAuthorization()
.UseEndpoints(
e =>
{
e.MapControllers();
e.MapGet(
wellKnownEst + "/cacert",
async ctx =>
Expand Down
8 changes: 5 additions & 3 deletions tests/opencertserver.est.server.tests/WebServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ private static IWebHostBuilder CreateHostBuilder(
webBuilder.ConfigureServices(
sc =>
{
sc.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme).AddCertificate();
sc.AddAuthorization().AddEstServer(rsaPrivate, ecdsaPrivate);
sc.ConfigureOptions<ConfigureCertificateAuthenticationOptions>();
sc.AddAuthorization()
.AddEstServer(rsaPrivate, ecdsaPrivate)
.ConfigureOptions<ConfigureCertificateAuthenticationOptions>()
.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme)
.AddCertificate();
})
.Configure(app => app.UseEstServer());
webBuilder.ConfigureKestrel(
Expand Down

0 comments on commit d78334d

Please sign in to comment.