PoDoFo 1.1.0
Loading...
Searching...
No Matches
PdfSignerCms.h
1
7#ifndef PDF_SIGNER_CMS_H
8#define PDF_SIGNER_CMS_H
9
10#include <chrono>
11#include "PdfSigner.h"
12
13extern "C"
14{
15 // OpenSSL forward
16 struct evp_pkey_st;
17}
18
19namespace PoDoFo
20{
21 class CmsContext;
22
23 using PdfSigningService = std::function<void(bufferview hashToSign, bool dryrun, charbuff& signedHash)>;
24 using PdfSignedHashHandler = std::function<void(bufferview signedhHash, bool dryrun)>;
25
27 {
28 None = 0,
37 ServiceDoDryRun = 2,
38 };
39
40 struct PODOFO_API PdfSignerCmsParams final
41 {
42 PdfSignatureType SignatureType = PdfSignatureType::PAdES_B;
43 [[deprecated("Encryption should be automatically detected from the public key in the certificate")]]
44 PdfSignatureEncryption Encryption = PdfSignatureEncryption::RSA;
45 PdfHashingAlgorithm Hashing = PdfHashingAlgorithm::SHA256;
46 PdfSigningService SigningService;
47 nullable<std::chrono::seconds> SigningTimeUTC;
48 PdfSignedHashHandler SignedHashHandler;
49 PdfSignerCmsFlags Flags = PdfSignerCmsFlags::None;
50 };
51
53 {
54 None = 0,
58 AsOctetString = 2,
59 };
60
63 class PODOFO_API PdfSignerCms : public PdfSigner
64 {
65 public:
73 const PdfSignerCmsParams& parameters = { });
74
79 PdfSignerCms(const bufferview& cert, const PdfSignerCmsParams& parameters = { });
80
82
83 public:
84 void AppendData(const bufferview& data) override;
85 void ComputeSignature(charbuff& buffer, bool dryrun) override;
86 void FetchIntermediateResult(charbuff& result) override;
87 void ComputeSignatureDeferred(const bufferview& processedResult, charbuff& contents, bool dryrun) override;
88 void Reset() override;
89 std::string GetSignatureFilter() const override;
90 std::string GetSignatureSubFilter() const override;
91 std::string GetSignatureType() const override;
92 bool SkipBufferClear() const override;
93
98 void AddAttribute(const std::string_view& nid, const bufferview& attr, PdfSignatureAttributeFlags flags = PdfSignatureAttributeFlags::None);
99
104 void ReserveAttributeSize(unsigned attrSize);
105
106 public:
107 const PdfSignerCmsParams& GetParameters() const { return m_parameters; }
108
109 private:
110 void ensureEventBasedSigning();
111 void ensureDeferredSigning();
112 void checkContextInitialized();
113 void ensureContextInitialized();
114 void resetContext();
115 void doSign(const bufferview& input, charbuff& output);
116 void tryEnlargeSignatureContents(charbuff& contents);
117 private:
118 nullable<bool> m_deferredSigning;
119 charbuff m_certificate;
120 std::unique_ptr<CmsContext> m_cmsContext;
121 struct evp_pkey_st* m_privKey;
122 PdfSignerCmsParams m_parameters;
123 unsigned m_reservedSize;
124
125 // Temporary buffer variables
126 // NOTE: Don't clear it in Reset() override
127 charbuff m_encryptedHash;
128 };
129}
130
131ENABLE_BITMASK_OPERATORS(PoDoFo::PdfSignerCmsFlags);
132ENABLE_BITMASK_OPERATORS(PoDoFo::PdfSignatureAttributeFlags);
133
134#endif // PDF_SIGNER_CMS_H
This class computes a CMS signature according to RFC 5652.
Definition PdfSignerCms.h:64
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
PdfSignatureAttributeFlags
Definition PdfSignerCms.h:53
@ SignedAttribute
The input is interpreted as a raw octet string.
@ None
Do not add a default appearrance.
cspan< char > bufferview
Convenient read-only char buffer span.
Definition basetypes.h:19
PdfSignerCmsFlags
Definition PdfSignerCms.h:27
@ ServiceDoWrapDigest
When supplying an external PdfSigningService, specify if the service should be called for a dry run.