From 5e7652ef88b8ff4a376777f86319d57234d92fcf Mon Sep 17 00:00:00 2001 From: TekH Date: Sun, 25 Oct 2026 18:49:08 +0100 Subject: [PATCH] Refactor and rename to DocumentService Renamed namespaces and projects from DocumentOperator to DocumentService, updating all references accordingly. Refactored PdfSignatureAppearanceDto and related enums to use properties with init accessors for improved clarity. Removed and re-added IPkcs11SelfTestStatusProvider with updated namespace. Simplified dependency injection by removing DocumentOperatorApplication registration. Updated appsettings.json with a specific AssetsRootPath. Incremented version numbers in project files for a new release. Introduced PdfSignatureClient and IPdfSignatureClient for PDF digital-signing operations. Updated project files to use newer Microsoft.Extensions package versions. Removed all DocumentOperator references, completing the transition to DocumentService. Added new DTOs and enums for PDF signature options and appearance. --- .../Common/Dto/PdfSignatureAppearanceDto.cs | 96 --------- .../Services/IPkcs11SelfTestStatusProvider.cs | 8 - .../DependencyInjection.cs | 18 -- .../DocumentOperator.Application.csproj | 15 -- .../Controllers/PdfSignatureController.cs | 4 +- .../DocumentService.API.csproj | 9 +- DocumentService.API/Program.cs | 2 - DocumentService.API/appsettings.json | 2 +- .../Common/Configuration}/Pkcs11Options.cs | 3 +- .../Common/DTOs}/PdfSignOptionsDto.cs | 6 +- .../Common/DTOs/PdfSignatureAppearanceDto.cs | 171 ++++++++++++++++ .../DTOs}/PdfSignatureCertificationLevel.cs | 2 +- .../DTOs}/PdfSignatureCheckResultDto.cs | 2 +- .../Common/DTOs}/Pkcs11SelfTestStatusDto.cs | 2 +- .../IPdfDigitalSignatureService.cs | 4 +- .../IPkcs11SelfTestStatusProvider.cs | 8 + .../SignPdf/SignPdfCommand.cs | 6 +- DocumentService.Client/Client.cs | 2 + .../Clients/PdfSignatureClient.cs | 25 +++ .../DocumentService.Client.csproj | 8 +- .../Extensions/ServiceCollectionExtensions.cs | 3 + .../Interfaces/IPdfSignatureClient.cs | 19 ++ .../Models/Requests/SignPdfRequest.cs | 190 ++++++++++++++++++ .../ServiceCollectionExtensions.cs | 4 +- ...ocumentService.Infrastructure.Crypt.csproj | 14 +- .../Helper/PdfCertificationLevelExtensions.cs | 4 +- .../Services/PdfDigitalSignatureService.cs | 6 +- .../Services/Pkcs11ExternalSigner.cs | 2 +- .../Services/Pkcs11InteropBootstrap.cs | 2 +- .../Services/Pkcs11PdfSigningRsa.cs | 2 +- .../Services/Pkcs11SelfTestStatusStore.cs | 4 +- .../Services/Pkcs11SessionRunner.cs | 2 +- .../Pkcs11StartupSelfTestHostedService.cs | 4 +- .../Services/Pkcs11ToolBridge.cs | 2 +- 34 files changed, 463 insertions(+), 188 deletions(-) delete mode 100644 DocumentOperator.Application/Common/Dto/PdfSignatureAppearanceDto.cs delete mode 100644 DocumentOperator.Application/Common/Interfaces/Services/IPkcs11SelfTestStatusProvider.cs delete mode 100644 DocumentOperator.Application/DependencyInjection.cs delete mode 100644 DocumentOperator.Application/DocumentOperator.Application.csproj rename {DocumentOperator.Application/Common/Configurations => DocumentService.Application/Common/Configuration}/Pkcs11Options.cs (96%) rename {DocumentOperator.Application/Common/Dto => DocumentService.Application/Common/DTOs}/PdfSignOptionsDto.cs (85%) create mode 100644 DocumentService.Application/Common/DTOs/PdfSignatureAppearanceDto.cs rename {DocumentOperator.Application/Common/Enums => DocumentService.Application/Common/DTOs}/PdfSignatureCertificationLevel.cs (91%) rename {DocumentOperator.Application/Common/Dto => DocumentService.Application/Common/DTOs}/PdfSignatureCheckResultDto.cs (96%) rename {DocumentOperator.Application/Common/Dto => DocumentService.Application/Common/DTOs}/Pkcs11SelfTestStatusDto.cs (80%) rename {DocumentOperator.Application/Common/Interfaces/Services => DocumentService.Application/Common/Interfaces}/IPdfDigitalSignatureService.cs (92%) create mode 100644 DocumentService.Application/Common/Interfaces/IPkcs11SelfTestStatusProvider.cs rename {DocumentOperator.Application => DocumentService.Application}/SignPdf/SignPdfCommand.cs (80%) create mode 100644 DocumentService.Client/Clients/PdfSignatureClient.cs create mode 100644 DocumentService.Client/Interfaces/IPdfSignatureClient.cs create mode 100644 DocumentService.Client/Models/Requests/SignPdfRequest.cs diff --git a/DocumentOperator.Application/Common/Dto/PdfSignatureAppearanceDto.cs b/DocumentOperator.Application/Common/Dto/PdfSignatureAppearanceDto.cs deleted file mode 100644 index 4497d36..0000000 --- a/DocumentOperator.Application/Common/Dto/PdfSignatureAppearanceDto.cs +++ /dev/null @@ -1,96 +0,0 @@ -namespace DocumentOperator.Application.Common.Dto; - -/// -/// -/// -public enum PdfSignatureCoordinateUnit -{ - /// - /// - /// - Point = 0, - - /// - /// - /// - Inch = 1 -} - -/// -/// -/// -public enum PdfSignatureCoordinateOrigin -{ - /// - /// - /// - BottomLeft = 0, - - /// - /// - /// - TopLeft = 1 -} - -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// -public sealed record PdfSignatureAppearanceDto( - int PageNumber, - double Left, - double Bottom, - double Width, - double Height, - bool ShowLabels = false, - bool ShowName = false, - bool ShowDate = false, - bool ShowReason = false, - bool ShowLocation = false, - bool ShowDistinguishedName = false, - string DateTimeFormat = "dd.MM.yyyy HH:mm:ss zzz", - PdfSignatureCoordinateUnit CoordinateUnit = PdfSignatureCoordinateUnit.Point, - PdfSignatureCoordinateOrigin CoordinateOrigin = PdfSignatureCoordinateOrigin.BottomLeft) -{ - /// - /// - /// - /// - /// - /// - /// - /// - public sealed record FontDto(string FamilyName = "Helvetica", float Size = 10, bool IsBold = false, bool IsItalic = false, bool IsUnderline = false) - { - /// - /// - /// - public RgbaColorDto Color { get; init; } = new(); - } - - /// - /// - /// - /// - /// - /// - public sealed record RgbaColorDto(double R = 0, double G = 0, double B = 0); - - /// - /// - /// - public FontDto Font { get; init; } = new(); -} diff --git a/DocumentOperator.Application/Common/Interfaces/Services/IPkcs11SelfTestStatusProvider.cs b/DocumentOperator.Application/Common/Interfaces/Services/IPkcs11SelfTestStatusProvider.cs deleted file mode 100644 index 7633b1d..0000000 --- a/DocumentOperator.Application/Common/Interfaces/Services/IPkcs11SelfTestStatusProvider.cs +++ /dev/null @@ -1,8 +0,0 @@ -using DocumentOperator.Application.Common.Dto; - -namespace DocumentOperator.Application.Common.Interfaces.Services; - -public interface IPkcs11SelfTestStatusProvider -{ - Pkcs11SelfTestStatusDto GetStatus(); -} diff --git a/DocumentOperator.Application/DependencyInjection.cs b/DocumentOperator.Application/DependencyInjection.cs deleted file mode 100644 index a5087ae..0000000 --- a/DocumentOperator.Application/DependencyInjection.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace DocumentOperator.Application; - -public static class DependencyInjection -{ - public static IServiceCollection AddDocumentOperatorApplication(this IServiceCollection services, IConfiguration configuration) - { - services.AddMediatR(cfg => - { - cfg.LicenseKey = configuration.GetValue("LuckyPennySoftLicenseKey"); - cfg.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly); - }); - - return services; - } -} diff --git a/DocumentOperator.Application/DocumentOperator.Application.csproj b/DocumentOperator.Application/DocumentOperator.Application.csproj deleted file mode 100644 index dd6be39..0000000 --- a/DocumentOperator.Application/DocumentOperator.Application.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - net8.0 - enable - enable - - - - - - - - - diff --git a/DocumentService.API/Controllers/PdfSignatureController.cs b/DocumentService.API/Controllers/PdfSignatureController.cs index d9efb40..03ed893 100644 --- a/DocumentService.API/Controllers/PdfSignatureController.cs +++ b/DocumentService.API/Controllers/PdfSignatureController.cs @@ -1,5 +1,5 @@ -using DocumentOperator.Application.Common.Dto; -using DocumentOperator.Application.SignPdf; +using DocumentService.Application.Common.DTOs; +using DocumentService.Application.SignPdf; using DocumentService.Domain.Common.Exceptions; using MediatR; using Microsoft.AspNetCore.Mvc; diff --git a/DocumentService.API/DocumentService.API.csproj b/DocumentService.API/DocumentService.API.csproj index fdfc245..139ff92 100644 --- a/DocumentService.API/DocumentService.API.csproj +++ b/DocumentService.API/DocumentService.API.csproj @@ -9,10 +9,10 @@ Digital Data GmbH Digital Data GmbH DocumentOperator.API - 1.1.0 - 1.1.0.0 - 1.1.0.0 - 1.1.0 + 2.0.0 + 2.1.0.0 + 2.1.0.0 + 2.1.0 Copyright © 2026 Digital Data GmbH. All rights reserved. PDF Document Operations REST API - Validation, Swiss QR Code extraction, attachments, merge, annotation, stamp operations powered by DevExpress Office File API pdf document operator validation swiss-qr-code annotations stamp devexpress @@ -36,7 +36,6 @@ - diff --git a/DocumentService.API/Program.cs b/DocumentService.API/Program.cs index 8943e98..cabe9bd 100644 --- a/DocumentService.API/Program.cs +++ b/DocumentService.API/Program.cs @@ -10,7 +10,6 @@ using DocumentService.Infrastructure; using DocumentService.Infrastructure.Crypt.DependencyInjection; using DocumentService.API.Middleware; using DocumentService.API.Configuration; -using DocumentOperator.Application; var builder = WebApplication.CreateBuilder(args); @@ -52,7 +51,6 @@ try // ======================================== builder.Services.AddApplication(builder.Configuration); // Application Layer (MediatR, FluentValidation, Behaviors) builder.Services.AddInfrastructure(); // Infrastructure Layer (DevExpress, Services) - builder.Services.AddDocumentOperatorApplication(builder.Configuration); // PDF signing Application (MediatR) builder.Services.AddCryptInfrastructure(builder.Configuration); // PKCS#11 PDF signing (DevExpress) builder.Services.AddControllers(); // Controllers (Controller-based API) diff --git a/DocumentService.API/appsettings.json b/DocumentService.API/appsettings.json index 37726c1..a7c98a6 100644 --- a/DocumentService.API/appsettings.json +++ b/DocumentService.API/appsettings.json @@ -100,7 +100,7 @@ }, "Crypt": { "Pkcs11": { - "AssetsRootPath": null, + "AssetsRootPath": "E:\\DataFiles\\Digital Data\\DocumentService.API\\resources", "SlotId": 2021549410, "TokenLabel": "CompanyProdToken", "ProxySocket": "tcp://172.24.12.64:5657", diff --git a/DocumentOperator.Application/Common/Configurations/Pkcs11Options.cs b/DocumentService.Application/Common/Configuration/Pkcs11Options.cs similarity index 96% rename from DocumentOperator.Application/Common/Configurations/Pkcs11Options.cs rename to DocumentService.Application/Common/Configuration/Pkcs11Options.cs index 7ed64e6..8cbc250 100644 --- a/DocumentOperator.Application/Common/Configurations/Pkcs11Options.cs +++ b/DocumentService.Application/Common/Configuration/Pkcs11Options.cs @@ -1,7 +1,6 @@ -using DocumentOperator.Application.Common.Enums; using System.ComponentModel.DataAnnotations; -namespace DocumentOperator.Application.Common.Configurations; +namespace DocumentService.Application.Common.Configuration; /// /// Represents PKCS#11 signing configuration for PDF signing workflows. diff --git a/DocumentOperator.Application/Common/Dto/PdfSignOptionsDto.cs b/DocumentService.Application/Common/DTOs/PdfSignOptionsDto.cs similarity index 85% rename from DocumentOperator.Application/Common/Dto/PdfSignOptionsDto.cs rename to DocumentService.Application/Common/DTOs/PdfSignOptionsDto.cs index 47d5e27..877ef0f 100644 --- a/DocumentOperator.Application/Common/Dto/PdfSignOptionsDto.cs +++ b/DocumentService.Application/Common/DTOs/PdfSignOptionsDto.cs @@ -1,6 +1,4 @@ -using DocumentOperator.Application.Common.Enums; - -namespace DocumentOperator.Application.Common.Dto; +namespace DocumentService.Application.Common.DTOs; /// /// @@ -40,7 +38,7 @@ public sealed record PdfSignOptionsDto /// /// /// - public string ApplicationName { get; set; } = null!; + public string? ApplicationName { get; set; } /// /// diff --git a/DocumentService.Application/Common/DTOs/PdfSignatureAppearanceDto.cs b/DocumentService.Application/Common/DTOs/PdfSignatureAppearanceDto.cs new file mode 100644 index 0000000..2f1ec9e --- /dev/null +++ b/DocumentService.Application/Common/DTOs/PdfSignatureAppearanceDto.cs @@ -0,0 +1,171 @@ +namespace DocumentService.Application.Common.DTOs; + +/// +/// +/// +public enum PdfSignatureCoordinateUnit +{ + /// + /// + /// + Point = 0, + + /// + /// + /// + Inch = 1 +} + +/// +/// +/// +public enum PdfSignatureCoordinateOrigin +{ + /// + /// + /// + BottomLeft = 0, + + /// + /// + /// + TopLeft = 1 +} + +/// +/// +/// +public sealed record PdfSignatureAppearanceDto +{ + /// + /// + /// + public int PageNumber { get; init; } + + /// + /// + /// + public double Left { get; init; } + + /// + /// + /// + public double Bottom { get; init; } + + /// + /// + /// + public double Width { get; init; } + + /// + /// + /// + public double Height { get; init; } + + /// + /// + /// + public bool ShowLabels { get; init; } + + /// + /// + /// + public bool ShowName { get; init; } + + /// + /// + /// + public bool ShowDate { get; init; } + + /// + /// + /// + public bool ShowReason { get; init; } + + /// + /// + /// + public bool ShowLocation { get; init; } + + /// + /// + /// + public bool ShowDistinguishedName { get; init; } + + /// + /// + /// + public string DateTimeFormat { get; init; } = "dd.MM.yyyy HH:mm:ss zzz"; + + /// + /// + /// + public PdfSignatureCoordinateUnit CoordinateUnit { get; init; } = PdfSignatureCoordinateUnit.Point; + + /// + /// + /// + public PdfSignatureCoordinateOrigin CoordinateOrigin { get; init; } = PdfSignatureCoordinateOrigin.BottomLeft; + + /// + /// + /// + public FontDto Font { get; init; } = new(); + + /// + /// + /// + public sealed record FontDto + { + /// + /// + /// + public string FamilyName { get; init; } = "Helvetica"; + + /// + /// + /// + public float Size { get; init; } = 10; + + /// + /// + /// + public bool IsBold { get; init; } + + /// + /// + /// + public bool IsItalic { get; init; } + + /// + /// + /// + public bool IsUnderline { get; init; } + + /// + /// + /// + public RgbaColorDto Color { get; init; } = new(); + } + + /// + /// + /// + public sealed record RgbaColorDto + { + /// + /// + /// + public double R { get; init; } + + /// + /// + /// + public double G { get; init; } + + /// + /// + /// + public double B { get; init; } + } +} diff --git a/DocumentOperator.Application/Common/Enums/PdfSignatureCertificationLevel.cs b/DocumentService.Application/Common/DTOs/PdfSignatureCertificationLevel.cs similarity index 91% rename from DocumentOperator.Application/Common/Enums/PdfSignatureCertificationLevel.cs rename to DocumentService.Application/Common/DTOs/PdfSignatureCertificationLevel.cs index d8078e9..fa0eef1 100644 --- a/DocumentOperator.Application/Common/Enums/PdfSignatureCertificationLevel.cs +++ b/DocumentService.Application/Common/DTOs/PdfSignatureCertificationLevel.cs @@ -1,4 +1,4 @@ -namespace DocumentOperator.Application.Common.Enums; +namespace DocumentService.Application.Common.DTOs; /// /// diff --git a/DocumentOperator.Application/Common/Dto/PdfSignatureCheckResultDto.cs b/DocumentService.Application/Common/DTOs/PdfSignatureCheckResultDto.cs similarity index 96% rename from DocumentOperator.Application/Common/Dto/PdfSignatureCheckResultDto.cs rename to DocumentService.Application/Common/DTOs/PdfSignatureCheckResultDto.cs index 2aa4575..1dc0aac 100644 --- a/DocumentOperator.Application/Common/Dto/PdfSignatureCheckResultDto.cs +++ b/DocumentService.Application/Common/DTOs/PdfSignatureCheckResultDto.cs @@ -1,4 +1,4 @@ -namespace DocumentOperator.Application.Common.Dto; +namespace DocumentService.Application.Common.DTOs; public sealed record PdfSignaturePrincipalDto( string? CommonName, diff --git a/DocumentOperator.Application/Common/Dto/Pkcs11SelfTestStatusDto.cs b/DocumentService.Application/Common/DTOs/Pkcs11SelfTestStatusDto.cs similarity index 80% rename from DocumentOperator.Application/Common/Dto/Pkcs11SelfTestStatusDto.cs rename to DocumentService.Application/Common/DTOs/Pkcs11SelfTestStatusDto.cs index 81751f8..36da8ac 100644 --- a/DocumentOperator.Application/Common/Dto/Pkcs11SelfTestStatusDto.cs +++ b/DocumentService.Application/Common/DTOs/Pkcs11SelfTestStatusDto.cs @@ -1,4 +1,4 @@ -namespace DocumentOperator.Application.Common.Dto; +namespace DocumentService.Application.Common.DTOs; public sealed record Pkcs11SelfTestStatusDto( bool Completed, diff --git a/DocumentOperator.Application/Common/Interfaces/Services/IPdfDigitalSignatureService.cs b/DocumentService.Application/Common/Interfaces/IPdfDigitalSignatureService.cs similarity index 92% rename from DocumentOperator.Application/Common/Interfaces/Services/IPdfDigitalSignatureService.cs rename to DocumentService.Application/Common/Interfaces/IPdfDigitalSignatureService.cs index 5dc5fdb..16bdf53 100644 --- a/DocumentOperator.Application/Common/Interfaces/Services/IPdfDigitalSignatureService.cs +++ b/DocumentService.Application/Common/Interfaces/IPdfDigitalSignatureService.cs @@ -1,6 +1,6 @@ -using DocumentOperator.Application.Common.Dto; +using DocumentService.Application.Common.DTOs; -namespace DocumentOperator.Application.Common.Interfaces.Services; +namespace DocumentService.Application.Common.Interfaces; /// /// Defines PDF digital-signing operations for the application boundary. diff --git a/DocumentService.Application/Common/Interfaces/IPkcs11SelfTestStatusProvider.cs b/DocumentService.Application/Common/Interfaces/IPkcs11SelfTestStatusProvider.cs new file mode 100644 index 0000000..4be3496 --- /dev/null +++ b/DocumentService.Application/Common/Interfaces/IPkcs11SelfTestStatusProvider.cs @@ -0,0 +1,8 @@ +using DocumentService.Application.Common.DTOs; + +namespace DocumentService.Application.Common.Interfaces; + +public interface IPkcs11SelfTestStatusProvider +{ + Pkcs11SelfTestStatusDto GetStatus(); +} diff --git a/DocumentOperator.Application/SignPdf/SignPdfCommand.cs b/DocumentService.Application/SignPdf/SignPdfCommand.cs similarity index 80% rename from DocumentOperator.Application/SignPdf/SignPdfCommand.cs rename to DocumentService.Application/SignPdf/SignPdfCommand.cs index d88967a..abb1e56 100644 --- a/DocumentOperator.Application/SignPdf/SignPdfCommand.cs +++ b/DocumentService.Application/SignPdf/SignPdfCommand.cs @@ -1,8 +1,8 @@ -using DocumentOperator.Application.Common.Dto; -using DocumentOperator.Application.Common.Interfaces.Services; +using DocumentService.Application.Common.DTOs; +using DocumentService.Application.Common.Interfaces; using MediatR; -namespace DocumentOperator.Application.SignPdf; +namespace DocumentService.Application.SignPdf; public sealed record SignPdfCommand : IRequest { diff --git a/DocumentService.Client/Client.cs b/DocumentService.Client/Client.cs index 2bc6f4b..9dd6b0d 100644 --- a/DocumentService.Client/Client.cs +++ b/DocumentService.Client/Client.cs @@ -90,6 +90,8 @@ public static class Client public static IZugferdClient Zugferd => GetRequiredServiceOfScope(); + public static IPdfSignatureClient Signature => GetRequiredServiceOfScope(); + public static IWorkflowsClient Workflows => GetRequiredServiceOfScope(); #endregion } diff --git a/DocumentService.Client/Clients/PdfSignatureClient.cs b/DocumentService.Client/Clients/PdfSignatureClient.cs new file mode 100644 index 0000000..8e4cca1 --- /dev/null +++ b/DocumentService.Client/Clients/PdfSignatureClient.cs @@ -0,0 +1,25 @@ +using DocumentService.Client.Interfaces; +using DocumentService.Client.Models.Requests; +using Microsoft.Extensions.Logging; +using System.Net.Http; + +namespace DocumentService.Client.Clients; + +/// +/// Implementation of the PDF digital-signing client. +/// +public class PdfSignatureClient(HttpClient httpClient, ILogger logger) : BaseDocumentClient(httpClient, logger), IPdfSignatureClient +{ + /// + public async Task SignAsync(byte[] pdfBytes, SignPdfOptions options, byte[]? signatureImageBytes = null, CancellationToken cancellationToken = default) + { + var request = new SignPdfRequest + { + Base64Pdf = ToBase64(pdfBytes), + Base64SignatureImage = signatureImageBytes is null ? null : ToBase64(signatureImageBytes), + Options = options + }; + + return await SendJsonForStreamAsync("/api/pdf/signature/sign", request, cancellationToken); + } +} diff --git a/DocumentService.Client/DocumentService.Client.csproj b/DocumentService.Client/DocumentService.Client.csproj index 38e3720..e0e4f50 100644 --- a/DocumentService.Client/DocumentService.Client.csproj +++ b/DocumentService.Client/DocumentService.Client.csproj @@ -1,4 +1,4 @@ - + net462;net480;net8.0 @@ -11,9 +11,9 @@ icon.png http://git.dd:3000/AppStd/Rec.git digital data document service api client - 1.2.2 - 1.2.2.0 - 1.2.2.0 + 1.3.2 + 1.3.2.0 + 1.3.2.0 enable enable diff --git a/DocumentService.Client/Extensions/ServiceCollectionExtensions.cs b/DocumentService.Client/Extensions/ServiceCollectionExtensions.cs index f045ba1..26a7a20 100644 --- a/DocumentService.Client/Extensions/ServiceCollectionExtensions.cs +++ b/DocumentService.Client/Extensions/ServiceCollectionExtensions.cs @@ -53,6 +53,9 @@ public static class ServiceCollectionExtensions services.AddHttpClient(ConfigureClient) .ConfigurePrimaryHttpMessageHandler(configureHandler); + services.AddHttpClient(ConfigureClient) + .ConfigurePrimaryHttpMessageHandler(configureHandler); + // Conversion client is registered but all methods throw NotImplementedException // until the server-side endpoints are ready. services.AddHttpClient(ConfigureClient) diff --git a/DocumentService.Client/Interfaces/IPdfSignatureClient.cs b/DocumentService.Client/Interfaces/IPdfSignatureClient.cs new file mode 100644 index 0000000..f0bc966 --- /dev/null +++ b/DocumentService.Client/Interfaces/IPdfSignatureClient.cs @@ -0,0 +1,19 @@ +using DocumentService.Client.Models.Requests; + +namespace DocumentService.Client.Interfaces; + +/// +/// Client for PDF digital signing. +/// +public interface IPdfSignatureClient +{ + /// + /// Digitally signs a PDF (Base64 JSON). + /// + /// PDF to sign + /// Signing options (metadata + appearance) + /// Optional signature image (PNG/JPEG) + /// Cancellation token + /// Signed PDF as stream + Task SignAsync(byte[] pdfBytes, SignPdfOptions options, byte[]? signatureImageBytes = null, CancellationToken cancellationToken = default); +} diff --git a/DocumentService.Client/Models/Requests/SignPdfRequest.cs b/DocumentService.Client/Models/Requests/SignPdfRequest.cs new file mode 100644 index 0000000..31a2d5a --- /dev/null +++ b/DocumentService.Client/Models/Requests/SignPdfRequest.cs @@ -0,0 +1,190 @@ +namespace DocumentService.Client.Models.Requests; + +/// +/// Request DTO for the PDF digital-signing endpoint (JSON payload). +/// +public sealed record SignPdfRequest +{ + /// + /// Base64-encoded PDF to sign. + /// + public required string Base64Pdf { get; init; } + + /// + /// Optional Base64-encoded signature image (PNG/JPEG). + /// + public string? Base64SignatureImage { get; init; } + + /// + /// Signing options (metadata + appearance). + /// + public required SignPdfOptions Options { get; init; } +} + +/// +/// Signing metadata and appearance options. +/// +public sealed record SignPdfOptions +{ + /// + /// Document element id embedded into the signature metadata. + /// + public long DocumentElementId { get; init; } + + /// + /// Signer name. + /// + public required string Name { get; init; } + + /// + /// Signing reason. + /// + public string? Reason { get; init; } + + /// + /// Signing location. + /// + public string? Location { get; init; } + + /// + /// Signer email (optional contact info). + /// + public string? Email { get; init; } + + /// + /// Signer phone (optional contact info). + /// + public string? Phone { get; init; } + + /// + /// Application name embedded into the signature metadata. + /// + public string? ApplicationName { get; init; } + + /// + /// Certification level applied to the signature. + /// + public PdfSignatureCertificationLevel CertificationLevel { get; init; } + + /// + /// Optional visual appearance of the signature field. + /// + public PdfSignatureAppearance? Appearance { get; init; } +} + +/// +/// Visual appearance of the signature field. +/// +public sealed record PdfSignatureAppearance +{ + /// + /// Page number (1-based) where the signature is placed. + /// + public int PageNumber { get; init; } + + /// + /// Left bound of the signature field. + /// + public double Left { get; init; } + + /// + /// Bottom bound of the signature field. + /// + public double Bottom { get; init; } + + /// + /// Width of the signature field. + /// + public double Width { get; init; } + + /// + /// Height of the signature field. + /// + public double Height { get; init; } + + public bool ShowLabels { get; init; } + public bool ShowName { get; init; } + public bool ShowDate { get; init; } + public bool ShowReason { get; init; } + public bool ShowLocation { get; init; } + public bool ShowDistinguishedName { get; init; } + + /// + /// Date/time format used in the signature appearance. + /// + public string DateTimeFormat { get; init; } = "dd.MM.yyyy HH:mm:ss zzz"; + + /// + /// Coordinate unit of the signature bounds. + /// + public PdfSignatureCoordinateUnit CoordinateUnit { get; init; } = PdfSignatureCoordinateUnit.Point; + + /// + /// Coordinate origin of the signature bounds. + /// + public PdfSignatureCoordinateOrigin CoordinateOrigin { get; init; } = PdfSignatureCoordinateOrigin.BottomLeft; + + /// + /// Font settings of the signature appearance. + /// + public PdfSignatureFont Font { get; init; } = new(); +} + +/// +/// Font settings of the signature appearance. +/// +public sealed record PdfSignatureFont +{ + public string FamilyName { get; init; } = "Helvetica"; + public float Size { get; init; } = 10; + public bool IsBold { get; init; } + public bool IsItalic { get; init; } + public bool IsUnderline { get; init; } + public PdfSignatureColor Color { get; init; } = new(); +} + +/// +/// RGB color (0-255 channels) of the signature appearance font. +/// +public sealed record PdfSignatureColor +{ + public double R { get; init; } + public double G { get; init; } + public double B { get; init; } +} + +/// +/// Certification level of the PDF signature. +/// +public enum PdfSignatureCertificationLevel +{ + /// All changes are allowed. + NoCertification = 0, + + /// No changes are allowed. + NoChangesAllowed, + + /// Allows form filling and signing. + FillForms, + + /// Allows form filling, annotation and signing. + FillFormsAndAnnotate +} + +/// +/// Coordinate unit of the signature bounds. +/// +public enum PdfSignatureCoordinateUnit +{ + Point = 0, + Inch = 1 +} + +/// +/// Coordinate origin of the signature bounds. +/// +public enum PdfSignatureCoordinateOrigin +{ + BottomLeft = 0, + TopLeft = 1 +} diff --git a/DocumentService.Infrastructure.Crypt/DependencyInjection/ServiceCollectionExtensions.cs b/DocumentService.Infrastructure.Crypt/DependencyInjection/ServiceCollectionExtensions.cs index 80e9c03..5d90d7c 100644 --- a/DocumentService.Infrastructure.Crypt/DependencyInjection/ServiceCollectionExtensions.cs +++ b/DocumentService.Infrastructure.Crypt/DependencyInjection/ServiceCollectionExtensions.cs @@ -1,5 +1,5 @@ -using DocumentOperator.Application.Common.Configurations; -using DocumentOperator.Application.Common.Interfaces.Services; +using DocumentService.Application.Common.Configuration; +using DocumentService.Application.Common.Interfaces; using DocumentService.Infrastructure.Crypt.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Configuration; diff --git a/DocumentService.Infrastructure.Crypt/DocumentService.Infrastructure.Crypt.csproj b/DocumentService.Infrastructure.Crypt/DocumentService.Infrastructure.Crypt.csproj index 69f0dcc..dcc8df4 100644 --- a/DocumentService.Infrastructure.Crypt/DocumentService.Infrastructure.Crypt.csproj +++ b/DocumentService.Infrastructure.Crypt/DocumentService.Infrastructure.Crypt.csproj @@ -10,12 +10,12 @@ - - - - - - + + + + + + @@ -29,7 +29,7 @@ - + diff --git a/DocumentService.Infrastructure.Crypt/Helper/PdfCertificationLevelExtensions.cs b/DocumentService.Infrastructure.Crypt/Helper/PdfCertificationLevelExtensions.cs index 7bafb4a..aa3445f 100644 --- a/DocumentService.Infrastructure.Crypt/Helper/PdfCertificationLevelExtensions.cs +++ b/DocumentService.Infrastructure.Crypt/Helper/PdfCertificationLevelExtensions.cs @@ -1,5 +1,5 @@ -using DevExpress.Pdf; -using DocumentOperator.Application.Common.Enums; +using DevExpress.Pdf; +using DocumentService.Application.Common.DTOs; namespace DocumentService.Infrastructure.Crypt.Helper; diff --git a/DocumentService.Infrastructure.Crypt/Services/PdfDigitalSignatureService.cs b/DocumentService.Infrastructure.Crypt/Services/PdfDigitalSignatureService.cs index c01ddb0..c78a667 100644 --- a/DocumentService.Infrastructure.Crypt/Services/PdfDigitalSignatureService.cs +++ b/DocumentService.Infrastructure.Crypt/Services/PdfDigitalSignatureService.cs @@ -1,9 +1,9 @@ using DevExpress.Office.DigitalSignatures; using DevExpress.Pdf; using DocumentService.Domain.Common.Exceptions; -using DocumentOperator.Application.Common.Configurations; -using DocumentOperator.Application.Common.Dto; -using DocumentOperator.Application.Common.Interfaces.Services; +using DocumentService.Application.Common.Configuration; +using DocumentService.Application.Common.DTOs; +using DocumentService.Application.Common.Interfaces; using DocumentService.Infrastructure.Crypt.Helper; using Microsoft.Extensions.Options; using System.Formats.Asn1; diff --git a/DocumentService.Infrastructure.Crypt/Services/Pkcs11ExternalSigner.cs b/DocumentService.Infrastructure.Crypt/Services/Pkcs11ExternalSigner.cs index 8562810..52f76db 100644 --- a/DocumentService.Infrastructure.Crypt/Services/Pkcs11ExternalSigner.cs +++ b/DocumentService.Infrastructure.Crypt/Services/Pkcs11ExternalSigner.cs @@ -1,4 +1,4 @@ -using DocumentOperator.Application.Common.Configurations; +using DocumentService.Application.Common.Configuration; using DevExpress.Office.DigitalSignatures; using DevExpress.Pdf; diff --git a/DocumentService.Infrastructure.Crypt/Services/Pkcs11InteropBootstrap.cs b/DocumentService.Infrastructure.Crypt/Services/Pkcs11InteropBootstrap.cs index 8686b2b..5d20306 100644 --- a/DocumentService.Infrastructure.Crypt/Services/Pkcs11InteropBootstrap.cs +++ b/DocumentService.Infrastructure.Crypt/Services/Pkcs11InteropBootstrap.cs @@ -1,4 +1,4 @@ -using DocumentOperator.Application.Common.Configurations; +using DocumentService.Application.Common.Configuration; namespace DocumentService.Infrastructure.Crypt.Services; diff --git a/DocumentService.Infrastructure.Crypt/Services/Pkcs11PdfSigningRsa.cs b/DocumentService.Infrastructure.Crypt/Services/Pkcs11PdfSigningRsa.cs index 9ed7cfb..449c086 100644 --- a/DocumentService.Infrastructure.Crypt/Services/Pkcs11PdfSigningRsa.cs +++ b/DocumentService.Infrastructure.Crypt/Services/Pkcs11PdfSigningRsa.cs @@ -1,4 +1,4 @@ -using DocumentOperator.Application.Common.Configurations; +using DocumentService.Application.Common.Configuration; using Net.Pkcs11Interop.Common; using Net.Pkcs11Interop.HighLevelAPI; using System.Security.Cryptography; diff --git a/DocumentService.Infrastructure.Crypt/Services/Pkcs11SelfTestStatusStore.cs b/DocumentService.Infrastructure.Crypt/Services/Pkcs11SelfTestStatusStore.cs index fe4f2f8..4210ded 100644 --- a/DocumentService.Infrastructure.Crypt/Services/Pkcs11SelfTestStatusStore.cs +++ b/DocumentService.Infrastructure.Crypt/Services/Pkcs11SelfTestStatusStore.cs @@ -1,5 +1,5 @@ -using DocumentOperator.Application.Common.Dto; -using DocumentOperator.Application.Common.Interfaces.Services; +using DocumentService.Application.Common.DTOs; +using DocumentService.Application.Common.Interfaces; using System.Threading; namespace DocumentService.Infrastructure.Crypt.Services; diff --git a/DocumentService.Infrastructure.Crypt/Services/Pkcs11SessionRunner.cs b/DocumentService.Infrastructure.Crypt/Services/Pkcs11SessionRunner.cs index 0cf66eb..d4ac47b 100644 --- a/DocumentService.Infrastructure.Crypt/Services/Pkcs11SessionRunner.cs +++ b/DocumentService.Infrastructure.Crypt/Services/Pkcs11SessionRunner.cs @@ -1,4 +1,4 @@ -using DocumentOperator.Application.Common.Configurations; +using DocumentService.Application.Common.Configuration; using Net.Pkcs11Interop.Common; using Net.Pkcs11Interop.HighLevelAPI; diff --git a/DocumentService.Infrastructure.Crypt/Services/Pkcs11StartupSelfTestHostedService.cs b/DocumentService.Infrastructure.Crypt/Services/Pkcs11StartupSelfTestHostedService.cs index ed062fd..ea00d59 100644 --- a/DocumentService.Infrastructure.Crypt/Services/Pkcs11StartupSelfTestHostedService.cs +++ b/DocumentService.Infrastructure.Crypt/Services/Pkcs11StartupSelfTestHostedService.cs @@ -1,5 +1,5 @@ -using DocumentOperator.Application.Common.Configurations; -using DocumentOperator.Application.Common.Dto; +using DocumentService.Application.Common.Configuration; +using DocumentService.Application.Common.DTOs; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; diff --git a/DocumentService.Infrastructure.Crypt/Services/Pkcs11ToolBridge.cs b/DocumentService.Infrastructure.Crypt/Services/Pkcs11ToolBridge.cs index d9278bc..3e3a2d8 100644 --- a/DocumentService.Infrastructure.Crypt/Services/Pkcs11ToolBridge.cs +++ b/DocumentService.Infrastructure.Crypt/Services/Pkcs11ToolBridge.cs @@ -1,4 +1,4 @@ -using DocumentOperator.Application.Common.Configurations; +using DocumentService.Application.Common.Configuration; using System.Diagnostics; using System.Security.Cryptography;