feat(security): add RFC 3161 PDF timestamp tool (#5855)

Co-authored-by: Anthony Stirling <[email protected]>
This commit is contained in:
InstaZDLL
2026-03-24 17:00:33 +00:00
committed by GitHub
co-authored by Anthony Stirling
parent 7b3985e34a
commit 8bbfbd63d7
17 changed files with 1068 additions and 1 deletions
@@ -0,0 +1,33 @@
import { useTranslation } from 'react-i18next';
import { ToolType, useToolOperation } from '@app/hooks/tools/shared/useToolOperation';
import { createStandardErrorHandler } from '@app/utils/toolErrorHandler';
import { TimestampPdfParameters, defaultParameters } from '@app/hooks/tools/timestampPdf/useTimestampPdfParameters';
export const buildTimestampPdfFormData = (parameters: TimestampPdfParameters, file: File): FormData => {
const formData = new FormData();
formData.append('fileInput', file);
formData.append('tsaUrl', parameters.tsaUrl);
return formData;
};
export const timestampPdfOperationConfig = {
toolType: ToolType.singleFile,
buildFormData: buildTimestampPdfFormData,
operationType: 'timestampPdf',
endpoint: '/api/v1/security/timestamp-pdf',
multiFileEndpoint: false,
defaultParameters,
} as const;
export const useTimestampPdfOperation = () => {
const { t } = useTranslation();
return useToolOperation<TimestampPdfParameters>({
...timestampPdfOperationConfig,
getErrorMessage: createStandardErrorHandler(
t('timestampPdf.error.failed', 'An error occurred while timestamping the PDF.')
),
});
};
@@ -0,0 +1,33 @@
import { BaseParameters } from '@app/types/parameters';
import { useBaseParameters, BaseParametersHook } from '@app/hooks/tools/shared/useBaseParameters';
// Fallback presets used only when AppConfig hasn't loaded yet.
// The real presets are served by the backend via /api/v1/config/app-config
// (field: timestampTsaPresets) — single source of truth.
export const FALLBACK_TSA_PRESETS = [
{ label: 'DigiCert', url: 'http://timestamp.digicert.com' },
{ label: 'Sectigo', url: 'http://timestamp.sectigo.com' },
{ label: 'SSL.com', url: 'http://ts.ssl.com' },
{ label: 'FreeTSA', url: 'https://freetsa.org/tsr' },
{ label: 'MeSign', url: 'http://tsa.mesign.com' },
] as const;
export interface TimestampPdfParameters extends BaseParameters {
tsaUrl: string;
}
export const defaultParameters: TimestampPdfParameters = {
tsaUrl: FALLBACK_TSA_PRESETS[0].url,
};
export type TimestampPdfParametersHook = BaseParametersHook<TimestampPdfParameters>;
export const useTimestampPdfParameters = (): TimestampPdfParametersHook => {
return useBaseParameters({
defaultParameters,
endpointName: 'timestamp-pdf',
validateFn: (params) => {
return params.tsaUrl.trim().length > 0;
},
});
};