(feature): app logo, acme routines refactoring

This commit is contained in:
Maksym Sadovnychyy 2025-11-14 21:48:44 +01:00
parent 0bbb412e97
commit d79bec2312
11 changed files with 38 additions and 58 deletions

View File

@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
</ItemGroup>
<ItemGroup>

View File

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MaksIT.Core" Version="1.5.6" />
<PackageReference Include="MaksIT.Core" Version="1.5.9" />
<PackageReference Include="MaksIT.Results" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />

View File

@ -7,6 +7,5 @@
public string? ResponseText { get; set; }
}
}
}

View File

@ -3,14 +3,13 @@
* https://tools.ietf.org/html/rfc4648#section-5
*/
using System.Text;
using System.Security.Cryptography;
using MaksIT.Core.Extensions;
using MaksIT.LetsEncrypt.Entities.Jws;
using MaksIT.Core.Security.JWK;
using MaksIT.Core.Security.JWS;
namespace MaksIT.LetsEncrypt.Services;
public interface IJwsService {
@ -28,72 +27,43 @@ public class JwsService : IJwsService {
public JwsService(RSA rsa) {
_rsa = rsa;
var publicParameters = rsa.ExportParameters(false);
var exp = publicParameters.Exponent;
var mod = publicParameters.Modulus;
_jwk = new Jwk() {
KeyType = JwkKeyType.Rsa.Name,
RsaExponent = Base64UrlUtility.Encode(exp),
RsaModulus = Base64UrlUtility.Encode(mod),
};
if (!JwkGenerator.TryGenerateFromRSA(rsa, out _jwk, out var errorMessage)) {
throw new Exception(errorMessage);
}
}
public void SetKeyId(string location) {
_jwk.KeyId = location;
}
public JwsMessage Encode(ACMEJwsHeader protectedHeader) =>
public JwsMessage Encode(ACMEJwsHeader protectedHeader) {
Encode<string>(null, protectedHeader);
public JwsMessage Encode<T>(T? payload, ACMEJwsHeader protectedHeader) {
protectedHeader.Algorithm = JwkAlgorithm.Rs256.Name;
if (_jwk.KeyId != null) {
protectedHeader.KeyId = _jwk.KeyId;
}
else {
protectedHeader.Key = _jwk;
if (!JwsGenerator.TryEncode(_rsa, _jwk, protectedHeader, out var jwsMessage, out var errorMessage)) {
throw new Exception(errorMessage);
}
var message = new JwsMessage {
Payload = "",
Protected = Base64UrlUtility.Encode(protectedHeader.ToJson())
};
return jwsMessage;
if (payload != null) {
if (payload is string stringPayload)
message.Payload = Base64UrlUtility.Encode(stringPayload);
else
message.Payload = Base64UrlUtility.Encode(payload.ToJson());
}
public JwsMessage Encode<TPayload>(TPayload? payload, ACMEJwsHeader protectedHeader) {
if (!JwsGenerator.TryEncode(_rsa, _jwk, protectedHeader, payload, out var jwsMessage, out var errorMessage)) {
throw new Exception(errorMessage);
}
message.Signature = Base64UrlUtility.Encode(
_rsa.SignData(Encoding.ASCII.GetBytes($"{message.Protected}.{message.Payload}"),
HashAlgorithmName.SHA256,
RSASignaturePadding.Pkcs1));
return jwsMessage;
return message;
}
public string GetKeyAuthorization(string token) =>
$"{token}.{GetSha256Thumbprint()}";
public string GetKeyAuthorization(string token) {
if (!JwkThumbprintUtility.TryGetKeyAuthorization(_jwk, token, out var keyAuthorization, out var errorMessage))
throw new Exception(errorMessage);
return keyAuthorization;
/// <summary>
/// For thumbprint calculation, always build the JSON string manually or use an anonymous object with the correct property order
/// </summary>
/// <returns></returns>
private string GetSha256Thumbprint() {
var thumbprint = new {
e = _jwk.RsaExponent,
kty = "RSA",
n = _jwk.RsaModulus
};
var json = thumbprint.ToJson();
return Base64UrlUtility.Encode(SHA256.HashData(Encoding.UTF8.GetBytes(json)));
}
}

View File

@ -4,6 +4,7 @@
*/
using MaksIT.Core.Extensions;
using MaksIT.Core.Security;
using MaksIT.Core.Security.JWK;
using MaksIT.LetsEncrypt.Entities;
using MaksIT.LetsEncrypt.Entities.Jws;

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

View File

@ -58,7 +58,7 @@ const LoginScreen: FC = () => {
<div className={'w-full max-w-md bg-white rounded-lg shadow-md p-8 space-y-6'} onKeyDown={handleSubmit} tabIndex={0}>
{/* App logo and name above form */}
<div className={'flex justify-center items-center space-x-3 mb-2'}>
<img src={'/logo.png'} alt={'App Logo'} className={'h-12 w-auto'} />
<img src={'/certs-ui-logo-only.png'} alt={'CertsUI'} className={'h-12 w-auto'} />
<span className={'text-2xl font-bold text-gray-800 select-none'}>{import.meta.env.VITE_APP_TITLE}</span>
</div>
{/* Form */}

View File

@ -13,7 +13,7 @@
<PackageReference Include="MaksIT.Results" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
</ItemGroup>
<ItemGroup>

View File

@ -175,31 +175,41 @@ public class CertsFlowService(
var sessionResult = await ConfigureClientAsync(isStaging);
if (!sessionResult.IsSuccess || sessionResult.Value == null)
return sessionResult;
var sessionId = sessionResult.Value.Value;
var initResult = await InitAsync(sessionId, accountId, description, contacts);
if (!initResult.IsSuccess || initResult.Value == null)
return initResult.ToResultOfType<Guid?>(_ => null);
if (accountId == null)
accountId = initResult.Value;
var challengesResult = await NewOrderAsync(sessionId, hostnames, challengeType);
if (!challengesResult.IsSuccess)
return challengesResult.ToResultOfType<Guid?>(_ => null);
if (challengesResult.Value?.Count > 0) {
var challengeResult = await CompleteChallengesAsync(sessionId);
if (!challengeResult.IsSuccess)
return challengeResult.ToResultOfType<Guid?>(default);
}
var getOrderResult = await GetOrderAsync(sessionId, hostnames);
if (!getOrderResult.IsSuccess)
return getOrderResult.ToResultOfType<Guid?>(default);
var certsResult = await GetCertificatesAsync(sessionId, hostnames);
if (!certsResult.IsSuccess)
return certsResult.ToResultOfType<Guid?>(default);
if (!isStaging) {
var applyCertsResult = await ApplyCertificatesAsync(accountId.Value);
if (!applyCertsResult.IsSuccess)
return applyCertsResult.ToResultOfType<Guid?>(_ => null);
}
return Result<Guid?>.Ok(initResult.Value);
}

View File

@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MaksIT.Core" Version="1.5.6" />
<PackageReference Include="MaksIT.Core" Version="1.5.9" />
</ItemGroup>
</Project>