- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DigitalSignatureField.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
3 // Consult legal.txt regarding legal and license information.
4 //---------------------------------------------------------------------------------------
5
6 #ifndef PDFTRON_H_CPPPDFDigitalSignatureField
7 #define PDFTRON_H_CPPPDFDigitalSignatureField
8 #include <C/PDF/TRN_DigitalSignatureField.h>
9 #include <C/PDF/TRN_VerificationResult.h>
10
11 #include <PDF/VerificationOptions.h>
12 #include <PDF/VerificationResult.h>
13 #include <PDF/TimestampingConfiguration.h>
14 #include <Common/BasicTypes.h>
15 #include <Common/UString.h>
16 #include <PDF/PDFDoc.h>
17 #include <Crypto/X509Certificate.h>
18 #include <Common/ByteRange.h>
19 #include <PDF/CMSSignatureOptions.h>
20 #include <Crypto/AlgorithmIdentifier.h>
21 #include <vector>
22
23 namespace pdftron { namespace PDF {
24
25
29 class DigitalSignatureField
30 {
31 public:
32 //enums:
33
34 enum SubFilterType {
35 e_adbe_x509_rsa_sha1 = 0,
36 e_adbe_pkcs7_detached = 1,
37 e_adbe_pkcs7_sha1 = 2,
38 e_ETSI_CAdES_detached = 3,
39 e_ETSI_RFC3161 = 4,
40 e_unknown = 5,
41 e_absent = 6
42 };
43 enum DocumentPermissions {
44 // No changes to the document shall be permitted; any change to the document shall invalidate the signature.
45 e_no_changes_allowed = 1,
46 // Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature.
47 e_formfilling_signing_allowed = 2,
48 // Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
49 e_annotating_formfilling_signing_allowed = 3,
50 // Represents the absence of any document permissions during retrieval; not to be used during setting
51 e_unrestricted = 4
52 };
53 enum FieldPermissions {
54 // Locks all form fields.
55 e_lock_all = 0,
56 // Locks only those form fields specified.
57 e_include = 1,
58 // Locks only those form fields not specified.
59 e_exclude = 2
60 };
61
62 DigitalSignatureField(const DigitalSignatureField& other);
63 DigitalSignatureField& operator= (const DigitalSignatureField& other);
64
70 DigitalSignatureField(const PDF::Field& in_field);
71
77 bool HasCryptographicSignature() const;
78
84 SubFilterType GetSubFilter() const;
85
91 UString GetSignatureName() const;
92
101 Date GetSigningTime() const;
102
108 UString GetLocation() const;
109
115 UString GetReason() const;
116
122 UString GetContactInfo() const;
123
130 std::vector<UChar> GetCert(UInt32 in_index) const;
131
137 UInt32 GetCertCount() const;
138
144 bool HasVisibleAppearance() const;
145
151 void SetContactInfo(const UString& in_contact_info);
152
158 void SetLocation(const UString& in_location);
159
165 void SetReason(const UString& in_reason);
166
173 #ifdef SWIG
174 // We use an std::vector of UTF-8 std::strings for SWIG, because SWIG has trouble with mapping UString to string when it's in a vector<UString>.
175 void SetFieldPermissions(const FieldPermissions in_action, const std::vector<std::string>& in_field_names = std::vector<std::string>());
176 #else
177
183 void SetFieldPermissions(const FieldPermissions in_action, const std::vector<UString>& in_field_names_list = std::vector<UString>());
184 void SetFieldPermissions(const FieldPermissions in_action, const UString* in_field_names_list, const size_t in_field_names_list_size);
185 #endif
186
192 void SetDocumentPermissions(DocumentPermissions in_perms);
193
200 void SignOnNextSave(const UString& in_pkcs12_keyfile_path, const UString& in_password);
201
209 void SignOnNextSave(const UChar* in_pkcs12_buffer, size_t in_buf_size, const UString& in_password);
210
216 void SignOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id);
217
224 void CertifyOnNextSave(const UString& in_pkcs12_keyfile_path, const UString& in_password);
225
233 void CertifyOnNextSave(const UChar* in_pkcs12_buffer, size_t in_buf_size, const UString& in_password);
234
240 void CertifyOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id);
241
247 SDF::Obj GetSDFObj() const;
248
254 bool IsLockedByDigitalSignature() const;
255
261 #ifdef SWIG
262 // We use an std::vector of UTF-8 std::strings for SWIG, because SWIG has trouble with mapping UString to string when it's in a vector<UString>.
263 std::vector<std::string> GetLockedFields() const;
264 #else
265 std::vector<UString> GetLockedFields() const;
266 #endif
267
273 DocumentPermissions GetDocumentPermissions() const;
274
279 void ClearSignature();
280
287 VerificationResult Verify(const VerificationOptions& in_opts) const;
288
294 bool IsCertification() const;
295
304 Crypto::X509Certificate GetSignerCertFromCMS() const;
305
323 std::vector<Common::ByteRange> GetByteRanges() const;
324
336 std::vector<std::vector<Crypto::X509Certificate> > GetCertPathsFromCMS() const;
337
367 bool EnableLTVOfflineVerification(const VerificationResult& in_verification_result) const;
368
407 void TimestampOnNextSave(const TimestampingConfiguration& in_timestamping_config,
408 const VerificationOptions& in_timestamp_response_verification_options);
409
447 TimestampingResult GenerateContentsWithEmbeddedTimestamp(const TimestampingConfiguration& in_timestamping_config,
448 const VerificationOptions& in_timestamp_response_verification_options);
449
456 void UseSubFilter(const SubFilterType in_subfilter_type, const bool in_make_mandatory = true);
457
467 std::vector<UChar> CalculateDigest(const Crypto::DigestAlgorithm::Type in_digest_algorithm_type = Crypto::DigestAlgorithm::e_SHA256) const;
468
475 void SetPreferredDigestAlgorithm(Crypto::DigestAlgorithm::Type in_digest_algorithm_type,
476 const bool in_make_mandatory = true);
477
486 void CreateSigDictForCustomCertification(const UString& in_filter_name,
487 const SubFilterType& in_subfilter_type,
488 const UInt32 in_contents_size_to_reserve);
489
498 void CreateSigDictForCustomSigning(const UString& in_filter_name,
499 const SubFilterType& in_subfilter_type,
500 const UInt32 in_contents_size_to_reserve);
501
514 void SetSigDictTimeOfSigning(const PDF::Date& in_date);
515
516
533 static std::vector<UChar> SignDigest(
534 const std::vector<UChar>& in_digest,
535 const UString& in_pkcs12_keyfile_path,
536 const UString& in_keyfile_password,
537 const bool in_pades_mode,
538 const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
539
556 static std::vector<UChar> SignDigest(
557 const std::vector<UChar>& in_digest,
558 const std::vector<UChar>& in_pkcs12_buffer,
559 const UString& in_keyfile_password,
560 const bool in_pades_mode,
561 const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
562 #ifndef SWIG
563
580 static std::vector<UChar> SignDigest(
581 const UChar* in_digest,
582 const size_t in_digest_size,
583 const UString& in_pkcs12_keyfile_path,
584 const UString& in_keyfile_password,
585 const bool in_pades_mode,
586 const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
587
606 static std::vector<UChar> SignDigest(
607 const UChar* in_digest,
608 const size_t in_digest_size,
609 const UChar* in_pkcs12_buffer,
610 const size_t in_pkcs12_buffer_size,
611 const UString& in_keyfile_password,
612 const bool in_pades_mode,
613 const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
614 #endif
615
635 static std::vector<UChar> GenerateESSSigningCertPAdESAttribute(
636 const Crypto::X509Certificate& in_signer_cert,
637 const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
638
653 static std::vector<UChar> GenerateCMSSignedAttributes(
654 const std::vector<UChar>& in_digest_buf,
655 const std::vector<UChar>& in_custom_signedattributes_buf = std::vector<UChar>());
656 #ifndef SWIG
657
673 static std::vector<UChar> GenerateCMSSignedAttributes(
674 const UChar* in_digest_buf,
675 const size_t in_digest_buf_size,
676 const UChar* in_custom_signedattributes_buf = NULL,
677 const size_t in_custom_signedattributes_buf_size = 0);
678 #endif
679
694 static std::vector<UChar> GenerateCMSSignature(
695 const Crypto::X509Certificate& in_signer_cert,
696 const std::vector<Crypto::X509Certificate>& in_chain_certs_list,
697 const Crypto::ObjectIdentifier& in_digest_algorithm_oid,
698 const Crypto::ObjectIdentifier& in_signature_algorithm_oid,
699 const std::vector<UChar>& in_signature_value_buf,
700 const std::vector<UChar>& in_signedattributes_buf);
701 #ifndef SWIG
702
719 static std::vector<UChar> GenerateCMSSignature(
720 const Crypto::X509Certificate& in_signer_cert,
721 const Crypto::X509Certificate* in_chain_certs_list,
722 const size_t in_chain_certs_list_size,
723 const Crypto::ObjectIdentifier& in_digest_algorithm_oid,
724 const Crypto::ObjectIdentifier& in_signature_algorithm_oid,
725 const UChar* in_signature_value_buf,
726 const size_t in_signature_value_buf_size,
727 const UChar* in_signedattributes_buf,
728 const size_t in_signedattributes_buf_size);
729 #endif
730
746 static std::vector<UChar> GenerateCMSSignature(
747 const Crypto::X509Certificate& signer_cert,
748 const std::vector<Crypto::X509Certificate>& chain_certs_list,
749 const Crypto::AlgorithmIdentifier& digest_algorithm_id,
750 const Crypto::AlgorithmIdentifier& signature_algorithm_id,
751 const std::vector<UChar>& signature_value_buf,
752 const std::vector<UChar>& signedattributes_buf,
753 const CMSSignatureOptions& cms_options = CMSSignatureOptions());
754 #ifndef SWIG
755
773 static std::vector<UChar> GenerateCMSSignature(
774 const Crypto::X509Certificate& signer_cert,
775 const Crypto::X509Certificate* chain_certs_list,
776 const size_t chain_certs_list_size,
777 const Crypto::AlgorithmIdentifier& digest_algorithm_id,
778 const Crypto::AlgorithmIdentifier& signature_algorithm_id,
779 const UChar* signature_value_buf,
780 const size_t signature_value_buf_size,
781 const UChar* signedattributes_buf,
782 const size_t signedattributes_buf_size,
783 const CMSSignatureOptions& cms_options = CMSSignatureOptions());
784 #endif
785
795 static bool SetDigSigLogFilename(const UString& filename);
796
797 // @cond PRIVATE_DOC
798 #ifndef SWIGHIDDEN
799 DigitalSignatureField(TRN_DigitalSignatureField impl);
800 TRN_DigitalSignatureField m_impl;
801 #endif
802 // @endcond
803 };
804
805 #include <Impl/DigitalSignatureField.inl>
806 } //end pdftron
807 } //end PDF
808
809
810 #endif //PDFTRON_H_CPPPDFDigitalSignatureField
TimestampingConfiguration.h
pdftron::PDF::DigitalSignatureField::operator=
DigitalSignatureField & operator=(const DigitalSignatureField &other)
pdftron::PDF::DigitalSignatureField::HasCryptographicSignature
bool HasCryptographicSignature() const
pdftron::PDF::DigitalSignatureField::CreateSigDictForCustomSigning
void CreateSigDictForCustomSigning(const UString &in_filter_name, const SubFilterType &in_subfilter_type, const UInt32 in_contents_size_to_reserve)
pdftron::PDF::DigitalSignatureField::GetSDFObj
SDF::Obj GetSDFObj() const
pdftron::PDF::TimestampingResult
Definition: TimestampingResult.h:21
pdftron::PDF::DigitalSignatureField::SetPreferredDigestAlgorithm
void SetPreferredDigestAlgorithm(Crypto::DigestAlgorithm::Type in_digest_algorithm_type, const bool in_make_mandatory=true)
pdftron::PDF::DigitalSignatureField::e_unrestricted
Definition: DigitalSignatureField.h:51
pdftron::Crypto::X509Certificate
Definition: X509Certificate.h:22
pdftron::PDF::DigitalSignatureField::GetReason
UString GetReason() const
pdftron::PDF::DigitalSignatureField::e_annotating_formfilling_signing_allowed
Definition: DigitalSignatureField.h:49
pdftron::PDF::DigitalSignatureField::UseSubFilter
void UseSubFilter(const SubFilterType in_subfilter_type, const bool in_make_mandatory=true)
CMSSignatureOptions.h
pdftron::PDF::DigitalSignatureField::GetDocumentPermissions
DocumentPermissions GetDocumentPermissions() const
pdftron::PDF::DigitalSignatureField::CertifyOnNextSave
void CertifyOnNextSave(const UString &in_pkcs12_keyfile_path, const UString &in_password)
pdftron::PDF::DigitalSignatureField::GenerateCMSSignature
static std::vector< UChar > GenerateCMSSignature(const Crypto::X509Certificate &in_signer_cert, const std::vector< Crypto::X509Certificate > &in_chain_certs_list, const Crypto::ObjectIdentifier &in_digest_algorithm_oid, const Crypto::ObjectIdentifier &in_signature_algorithm_oid, const std::vector< UChar > &in_signature_value_buf, const std::vector< UChar > &in_signedattributes_buf)
pdftron::SDF::SignatureHandlerId
size_t SignatureHandlerId
Definition: SignatureHandler.h:21
UString.h
pdftron::PDF::DigitalSignatureField::SetFieldPermissions
void SetFieldPermissions(const FieldPermissions in_action, const std::vector< UString > &in_field_names_list=std::vector< UString >())
pdftron::PDF::DigitalSignatureField::e_ETSI_CAdES_detached
Definition: DigitalSignatureField.h:38
pdftron::PDF::DigitalSignatureField::SetDigSigLogFilename
static bool SetDigSigLogFilename(const UString &filename)
pdftron::PDF::DigitalSignatureField::e_include
Definition: DigitalSignatureField.h:57
pdftron::PDF::DigitalSignatureField::e_unknown
Definition: DigitalSignatureField.h:40
pdftron::PDF::DigitalSignatureField::TimestampOnNextSave
void TimestampOnNextSave(const TimestampingConfiguration &in_timestamping_config, const VerificationOptions &in_timestamp_response_verification_options)
pdftron::PDF::DigitalSignatureField::GetContactInfo
UString GetContactInfo() const
pdftron::PDF::DigitalSignatureField::SignDigest
static std::vector< UChar > SignDigest(const std::vector< UChar > &in_digest, const UString &in_pkcs12_keyfile_path, const UString &in_keyfile_password, const bool in_pades_mode, const Crypto::DigestAlgorithm::Type in_digest_algorithm_type)
pdftron::PDF::DigitalSignatureField::CreateSigDictForCustomCertification
void CreateSigDictForCustomCertification(const UString &in_filter_name, const SubFilterType &in_subfilter_type, const UInt32 in_contents_size_to_reserve)
pdftron::Crypto::ObjectIdentifier
Definition: ObjectIdentifier.h:18
pdftron::PDF::DigitalSignatureField::e_adbe_pkcs7_detached
Definition: DigitalSignatureField.h:36
pdftron::PDF::TimestampingConfiguration
Definition: TimestampingConfiguration.h:21
pdftron::PDF::Date
Definition: Date.h:28
pdftron::PDF::DigitalSignatureField::e_lock_all
Definition: DigitalSignatureField.h:55
pdftron::PDF::DigitalSignatureField::e_ETSI_RFC3161
Definition: DigitalSignatureField.h:39
pdftron::Crypto::DigestAlgorithm::e_SHA256
Definition: DigestAlgorithm.h:23
pdftron::PDF::DigitalSignatureField::e_adbe_pkcs7_sha1
Definition: DigitalSignatureField.h:37
pdftron::PDF::DigitalSignatureField::SetLocation
void SetLocation(const UString &in_location)
pdftron::PDF::VerificationOptions
Definition: VerificationOptions.h:21
X509Certificate.h
pdftron::PDF::DigitalSignatureField::GetLockedFields
std::vector< UString > GetLockedFields() const
pdftron::PDF::DigitalSignatureField::DocumentPermissions
DocumentPermissions
Definition: DigitalSignatureField.h:43
pdftron::PDF::DigitalSignatureField
Definition: DigitalSignatureField.h:29
pdftron::PDF::DigitalSignatureField::EnableLTVOfflineVerification
bool EnableLTVOfflineVerification(const VerificationResult &in_verification_result) const
pdftron::PDF::DigitalSignatureField::SignOnNextSave
void SignOnNextSave(const UString &in_pkcs12_keyfile_path, const UString &in_password)
pdftron::UInt32
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
pdftron::PDF::DigitalSignatureField::GetSignerCertFromCMS
Crypto::X509Certificate GetSignerCertFromCMS() const
pdftron::PDF::CMSSignatureOptions
Definition: CMSSignatureOptions.h:19
pdftron::PDF::DigitalSignatureField::FieldPermissions
FieldPermissions
Definition: DigitalSignatureField.h:53
pdftron::PDF::DigitalSignatureField::e_adbe_x509_rsa_sha1
Definition: DigitalSignatureField.h:35
pdftron::PDF::DigitalSignatureField::CertifyOnNextSaveWithCustomHandler
void CertifyOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id)
pdftron::PDF::DigitalSignatureField::e_exclude
Definition: DigitalSignatureField.h:59
pdftron::PDF::DigitalSignatureField::SetSigDictTimeOfSigning
void SetSigDictTimeOfSigning(const PDF::Date &in_date)
pdftron::UChar
TRN_UChar UChar
Definition: BasicTypes.h:12
pdftron::PDF::DigitalSignatureField::Verify
VerificationResult Verify(const VerificationOptions &in_opts) const
pdftron::PDF::DigitalSignatureField::e_formfilling_signing_allowed
Definition: DigitalSignatureField.h:47
PDFDoc.h
VerificationResult.h
pdftron::PDF::DigitalSignatureField::GetSignatureName
UString GetSignatureName() const
pdftron::PDF::DigitalSignatureField::IsCertification
bool IsCertification() const
pdftron::PDF::DigitalSignatureField::e_absent
Definition: DigitalSignatureField.h:41
pdftron::PDF::DigitalSignatureField::SetReason
void SetReason(const UString &in_reason)
pdftron::PDF::DigitalSignatureField::GetCertCount
UInt32 GetCertCount() const
pdftron::PDF::DigitalSignatureField::GetSigningTime
Date GetSigningTime() const
pdftron::PDF::DigitalSignatureField::SetDocumentPermissions
void SetDocumentPermissions(DocumentPermissions in_perms)
BasicTypes.h
pdftron::PDF::DigitalSignatureField::GetByteRanges
std::vector< Common::ByteRange > GetByteRanges() const
pdftron::PDF::DigitalSignatureField::ClearSignature
void ClearSignature()
pdftron::PDF::VerificationResult
Definition: VerificationResult.h:25
pdftron::PDF::DigitalSignatureField::GenerateContentsWithEmbeddedTimestamp
TimestampingResult GenerateContentsWithEmbeddedTimestamp(const TimestampingConfiguration &in_timestamping_config, const VerificationOptions &in_timestamp_response_verification_options)
pdftron::PDF::DigitalSignatureField::GetLocation
UString GetLocation() const
pdftron::PDF::DigitalSignatureField::SetContactInfo
void SetContactInfo(const UString &in_contact_info)
pdftron::PDF::DigitalSignatureField::e_no_changes_allowed
Definition: DigitalSignatureField.h:45
pdftron::PDF::DigitalSignatureField::GenerateESSSigningCertPAdESAttribute
static std::vector< UChar > GenerateESSSigningCertPAdESAttribute(const Crypto::X509Certificate &in_signer_cert, const Crypto::DigestAlgorithm::Type in_digest_algorithm_type)
pdftron::PDF::DigitalSignatureField::GetCertPathsFromCMS
std::vector< std::vector< Crypto::X509Certificate > > GetCertPathsFromCMS() const
pdftron::PDF::DigitalSignatureField::GenerateCMSSignedAttributes
static std::vector< UChar > GenerateCMSSignedAttributes(const std::vector< UChar > &in_digest_buf, const std::vector< UChar > &in_custom_signedattributes_buf=std::vector< UChar >())
pdftron::PDF::DigitalSignatureField::SignOnNextSaveWithCustomHandler
void SignOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id)
pdftron::PDF::DigitalSignatureField::DigitalSignatureField
DigitalSignatureField(const DigitalSignatureField &other)
pdftron::PDF::DigitalSignatureField::GetCert
std::vector< UChar > GetCert(UInt32 in_index) const
pdftron::PDF::Field
Definition: Field.h:69
ByteRange.h
pdftron::PDF::DigitalSignatureField::SubFilterType
SubFilterType
Definition: DigitalSignatureField.h:34
VerificationOptions.h
pdftron::SDF::Obj
Definition: Obj.h:40
pdftron::Crypto::AlgorithmIdentifier
Definition: AlgorithmIdentifier.h:20
pdftron::PDF::DigitalSignatureField::IsLockedByDigitalSignature
bool IsLockedByDigitalSignature() const
pdftron::PDF::DigitalSignatureField::GetSubFilter
SubFilterType GetSubFilter() const
pdftron::PDF::DigitalSignatureField::HasVisibleAppearance
bool HasVisibleAppearance() const
pdftron::PDF::DigitalSignatureField::CalculateDigest
std::vector< UChar > CalculateDigest(const Crypto::DigestAlgorithm::Type in_digest_algorithm_type=Crypto::DigestAlgorithm::e_SHA256) const
pdftron::UString
Definition: UString.h:27
pdftron::Crypto::DigestAlgorithm::Type
Type
Definition: DigestAlgorithm.h:21
AlgorithmIdentifier.h