4#ifndef PDF_SIGNER_CMS_H
5#define PDF_SIGNER_CMS_H
15 typedef struct _xmlNode xmlNode;
16 typedef xmlNode* xmlNodePtr;
23 using PdfSigningService = std::function<void(
bufferview hashToSign,
bool dryrun, charbuff& signedHash)>;
24 using PdfSignedHashHandler = std::function<void(
bufferview signedhHash,
bool dryrun)>;
50 SkipDateValidation = 16,
56 PODOFO_SUPPRESS_DEPRECATED_PUSH
57 struct PODOFO_API PdfSignerCmsParams final
59 PdfSignatureType SignatureType = PdfSignatureType::PAdES_B;
60 [[deprecated(
"Unused: the signing algorithm is automatically detected from the public key in the certificate")]]
61 PdfSignatureEncryption Encryption = PdfSignatureEncryption::RSA;
62 PdfHashingAlgorithm Hashing = PdfHashingAlgorithm::SHA256;
63 PdfSigningService SigningService;
64 nullable<std::chrono::seconds> SigningTimeUTC;
65 PdfSignedHashHandler SignedHashHandler;
66 PdfSignerCmsFlags Flags = PdfSignerCmsFlags::None;
68 PODOFO_SUPPRESS_DEPRECATED_POP
82 friend class PdfSigningContext;
90 const PdfSignerCmsParams& parameters = { });
108 void AppendData(
const bufferview& data)
override;
109 void ComputeSignature(charbuff& buffer,
bool dryrun)
override;
110 void FetchIntermediateResult(charbuff& result)
override;
111 void ComputeSignatureDeferred(
const bufferview& processedResult, charbuff& contents,
bool dryrun)
override;
112 void Reset()
override;
113 std::string GetSignatureFilter()
const override;
114 std::string GetSignatureSubFilter()
const override;
115 std::string GetSignatureType()
const override;
116 bool SkipBufferClear()
const override;
138 unsigned GetSignedHashSize()
const;
140 const PdfSignerCmsParams& GetParameters()
const {
return m_parameters; }
144 void Dump(xmlNodePtr signerElem, std::string& temp);
145 void Restore(xmlNodePtr signerElem, charbuff& temp);
147 void ensureEventBasedSigning();
148 void ensureDeferredSigning();
149 void checkContextInitialized();
150 void ensureContextInitialized();
152 bool shouldVerify()
const;
153 bool shouldVerifyTimeStamp()
const;
154 void doSign(
const bufferview& input, charbuff& output);
155 void tryEnlargeSignatureContents(charbuff& contents);
158 charbuff m_certificate;
159 std::unique_ptr<CmsContext> m_cmsContext;
160 struct evp_pkey_st* m_privKey;
161 PdfSignerCmsParams m_parameters;
162 unsigned m_reservedSize;
166 charbuff m_signedHash;
void AddAttribute(const std::string_view &nid, const bufferview &attr, PdfSignatureAttributeFlags flags=PdfSignatureAttributeFlags::None)
Add a signature attribute with given identifier from the input.
Definition PdfSignerCms.cpp:196
void SetTrustedTimestamp(const bufferview &timeStamp)
Set the RFC 3161 timestamp of the signature as the unsigned attribute id-aa-timeStampToken (1....
Definition PdfSignerCms.cpp:210
void ReserveAttributeSize(unsigned attrSize)
Reserve some size in the final signature.
Definition PdfSignerCms.cpp:216
void ValidateSignatureDate(const nullable< PdfDate > &date) override
Validate the signature date against the certificate validity period.
Definition PdfSignerCms.cpp:44
PdfSignerCms(const bufferview &cert, const bufferview &pkey, const PdfSignerCmsParams ¶meters={ })
Load X.509 certificate and supply a ASN.1 DER encoded private key.
Definition PdfSignerCms.cpp:18
Alternative to std::optional that supports reference (but not pointer) types.
Definition nullable.h:24
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
PdfSignatureAttributeFlags
Definition PdfSignerCms.h:71
@ SignedAttribute
The input is interpreted as a raw octet string.
Definition PdfSignerCms.h:74
@ None
The attribute is a signed attribute. By default, it is unsigned.
Definition PdfSignerCms.h:72
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:15
@ None
Do not add a default appearance.
Definition PdfAcroForm.h:16
PdfSignerCmsFlags
Definition PdfSignerCms.h:27
@ ServiceDoDryRun
For signing algorithms that have a random component, make it deterministic Applies to ECDSA,...
Definition PdfSignerCms.h:37
@ ServiceDoWrapDigest
When supplying an external PdfSigningService, specify if the service should be called for a dry run.
Definition PdfSignerCms.h:34
@ Deterministic
Skip the inline verification of the signed hash supplied by an external signing service or by a defer...
Definition PdfSignerCms.h:40
@ SkipVerification
Skip the validation of the signature date against the validity period of the supplied certificate.
Definition PdfSignerCms.h:46