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-2024 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 
12 #include <PDF/VerificationResult.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>
21 #include <vector>
22 
23 namespace pdftron { namespace PDF {
24 
25 
30 {
31 public:
32  //enums:
33 
40  e_unknown = 5,
42  };
44  // No changes to the document shall be permitted; any change to the document shall invalidate the signature.
46  // Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature.
48  // Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
50  // Represents the absence of any document permissions during retrieval; not to be used during setting
52  };
54  // Locks all form fields.
56  // Locks only those form fields specified.
57  e_include = 1,
58  // Locks only those form fields not specified.
60  };
61 
64 
70  DigitalSignatureField(const PDF::Field& in_field);
71 
77  bool HasCryptographicSignature() const;
78 
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 
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 
274 
279  void ClearSignature();
280 
287  VerificationResult Verify(const VerificationOptions& in_opts) const;
288 
294  bool IsCertification() const;
295 
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 
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
DigitalSignatureField & operator=(const DigitalSignatureField &other)
void CreateSigDictForCustomSigning(const UString &in_filter_name, const SubFilterType &in_subfilter_type, const UInt32 in_contents_size_to_reserve)
void SetPreferredDigestAlgorithm(Crypto::DigestAlgorithm::Type in_digest_algorithm_type, const bool in_make_mandatory=true)
void UseSubFilter(const SubFilterType in_subfilter_type, const bool in_make_mandatory=true)
DocumentPermissions GetDocumentPermissions() const
void CertifyOnNextSave(const UString &in_pkcs12_keyfile_path, const UString &in_password)
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)
size_t SignatureHandlerId
void SetFieldPermissions(const FieldPermissions in_action, const std::vector< UString > &in_field_names_list=std::vector< UString >())
static bool SetDigSigLogFilename(const UString &filename)
void TimestampOnNextSave(const TimestampingConfiguration &in_timestamping_config, const VerificationOptions &in_timestamp_response_verification_options)
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)
void CreateSigDictForCustomCertification(const UString &in_filter_name, const SubFilterType &in_subfilter_type, const UInt32 in_contents_size_to_reserve)
void SetLocation(const UString &in_location)
std::vector< UString > GetLockedFields() const
bool EnableLTVOfflineVerification(const VerificationResult &in_verification_result) const
void SignOnNextSave(const UString &in_pkcs12_keyfile_path, const UString &in_password)
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
Crypto::X509Certificate GetSignerCertFromCMS() const
void CertifyOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id)
void SetSigDictTimeOfSigning(const PDF::Date &in_date)
TRN_UChar UChar
Definition: BasicTypes.h:12
VerificationResult Verify(const VerificationOptions &in_opts) const
void SetReason(const UString &in_reason)
void SetDocumentPermissions(DocumentPermissions in_perms)
std::vector< Common::ByteRange > GetByteRanges() const
TimestampingResult GenerateContentsWithEmbeddedTimestamp(const TimestampingConfiguration &in_timestamping_config, const VerificationOptions &in_timestamp_response_verification_options)
void SetContactInfo(const UString &in_contact_info)
static std::vector< UChar > GenerateESSSigningCertPAdESAttribute(const Crypto::X509Certificate &in_signer_cert, const Crypto::DigestAlgorithm::Type in_digest_algorithm_type)
std::vector< std::vector< Crypto::X509Certificate > > GetCertPathsFromCMS() const
static std::vector< UChar > GenerateCMSSignedAttributes(const std::vector< UChar > &in_digest_buf, const std::vector< UChar > &in_custom_signedattributes_buf=std::vector< UChar >())
void SignOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id)
DigitalSignatureField(const DigitalSignatureField &other)
std::vector< UChar > GetCert(UInt32 in_index) const
SubFilterType GetSubFilter() const
std::vector< UChar > CalculateDigest(const Crypto::DigestAlgorithm::Type in_digest_algorithm_type=Crypto::DigestAlgorithm::e_SHA256) const