mirror of
https://github.com/MAKS-IT-COM/maksit-certs-ui.git
synced 2025-12-31 04:00:03 +01:00
(feature): app logo, acme routines refactoring
This commit is contained in:
parent
0bbb412e97
commit
d79bec2312
@ -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>
|
||||
|
||||
@ -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" />
|
||||
|
||||
@ -7,6 +7,5 @@
|
||||
|
||||
public string? ResponseText { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
message.Signature = Base64UrlUtility.Encode(
|
||||
_rsa.SignData(Encoding.ASCII.GetBytes($"{message.Protected}.{message.Payload}"),
|
||||
HashAlgorithmName.SHA256,
|
||||
RSASignaturePadding.Pkcs1));
|
||||
|
||||
return message;
|
||||
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);
|
||||
}
|
||||
|
||||
public string GetKeyAuthorization(string token) =>
|
||||
$"{token}.{GetSha256Thumbprint()}";
|
||||
return jwsMessage;
|
||||
|
||||
}
|
||||
|
||||
/// <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() {
|
||||
public string GetKeyAuthorization(string token) {
|
||||
if (!JwkThumbprintUtility.TryGetKeyAuthorization(_jwk, token, out var keyAuthorization, out var errorMessage))
|
||||
throw new Exception(errorMessage);
|
||||
|
||||
var thumbprint = new {
|
||||
e = _jwk.RsaExponent,
|
||||
kty = "RSA",
|
||||
n = _jwk.RsaModulus
|
||||
};
|
||||
return keyAuthorization;
|
||||
|
||||
var json = thumbprint.ToJson();
|
||||
return Base64UrlUtility.Encode(SHA256.HashData(Encoding.UTF8.GetBytes(json)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
BIN
src/MaksIT.WebUI/public/certs-ui-logo-only.png
Normal file
BIN
src/MaksIT.WebUI/public/certs-ui-logo-only.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 214 KiB |
BIN
src/MaksIT.WebUI/public/certs-ui-logo.png
Normal file
BIN
src/MaksIT.WebUI/public/certs-ui-logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 344 KiB |
@ -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 */}
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MaksIT.Core" Version="1.5.6" />
|
||||
<PackageReference Include="MaksIT.Core" Version="1.5.9" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user