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-2021 by PDFTron Systems 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>
19 #include <vector>
20 
21 namespace pdftron { namespace PDF {
22 
23 
28 {
29 public:
30  //enums:
31 
38  e_unknown = 5,
40  };
42  // No changes to the document shall be permitted; any change to the document shall invalidate the signature.
44  // Permitted changes shall be filling in forms, instantiating page templates, and signing; other changes shall invalidate the signature.
46  // Permitted changes shall be the same as for 2, as well as annotation creation, deletion, and modification; other changes shall invalidate the signature.
48  // Represents the absence of any document permissions during retrieval; not to be used during setting
50  };
52  // Locks all form fields.
54  // Locks only those form fields specified.
55  e_include = 1,
56  // Locks only those form fields not specified.
58  };
59 
62 
68  DigitalSignatureField(const PDF::Field& in_field);
69 
75  bool HasCryptographicSignature() const;
76 
83 
89  UString GetSignatureName() const;
90 
99  Date GetSigningTime() const;
100 
106  UString GetLocation() const;
107 
113  UString GetReason() const;
114 
120  UString GetContactInfo() const;
121 
128  std::vector<UChar> GetCert(UInt32 in_index) const;
129 
135  UInt32 GetCertCount() const;
136 
142  bool HasVisibleAppearance() const;
143 
149  void SetContactInfo(const UString& in_contact_info);
150 
156  void SetLocation(const UString& in_location);
157 
163  void SetReason(const UString& in_reason);
164 
171 #ifdef SWIG
172 // 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>.
173  void SetFieldPermissions(const FieldPermissions in_action, const std::vector<std::string>& in_field_names = std::vector<std::string>());
174 #else
175 
181  void SetFieldPermissions(const FieldPermissions in_action, const std::vector<UString>& in_field_names_list = std::vector<UString>());
182  void SetFieldPermissions(const FieldPermissions in_action, const UString* in_field_names_list, const size_t in_field_names_list_size);
183 #endif
184 
191 
198  void SignOnNextSave(const UString& in_pkcs12_keyfile_path, const UString& in_password);
199 
207  void SignOnNextSave(const UChar* in_pkcs12_buffer, size_t in_buf_size, const UString& in_password);
208 
214  void SignOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id);
215 
222  void CertifyOnNextSave(const UString& in_pkcs12_keyfile_path, const UString& in_password);
223 
231  void CertifyOnNextSave(const UChar* in_pkcs12_buffer, size_t in_buf_size, const UString& in_password);
232 
238  void CertifyOnNextSaveWithCustomHandler(const SDF::SignatureHandlerId in_signature_handler_id);
239 
245  SDF::Obj GetSDFObj() const;
246 
252  bool IsLockedByDigitalSignature() const;
253 
259 #ifdef SWIG
260 // 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>.
261  std::vector<std::string> GetLockedFields() const;
262 #else
263  std::vector<UString> GetLockedFields() const;
264 #endif
265 
272 
277  void ClearSignature();
278 
285  VerificationResult Verify(const VerificationOptions& in_opts) const;
286 
292  bool IsCertification() const;
293 
303 
321  std::vector<Common::ByteRange> GetByteRanges() const;
322 
334  std::vector<std::vector<Crypto::X509Certificate> > GetCertPathsFromCMS() const;
335 
365  bool EnableLTVOfflineVerification(const VerificationResult& in_verification_result) const;
366 
405  void TimestampOnNextSave(const TimestampingConfiguration& in_timestamping_config,
406  const VerificationOptions& in_timestamp_response_verification_options);
407 
444  const VerificationOptions& in_timestamp_response_verification_options);
445 
452  void UseSubFilter(const SubFilterType in_subfilter_type, const bool in_make_mandatory = true);
453 
463  std::vector<UChar> CalculateDigest(const Crypto::DigestAlgorithm::Type in_digest_algorithm_type = Crypto::DigestAlgorithm::e_SHA256) const;
464 
471  void SetPreferredDigestAlgorithm(Crypto::DigestAlgorithm::Type in_digest_algorithm_type,
472  const bool in_make_mandatory = true);
473 
482  void CreateSigDictForCustomCertification(const UString& in_filter_name,
483  const SubFilterType& in_subfilter_type,
484  const UInt32 in_contents_size_to_reserve);
485 
494  void CreateSigDictForCustomSigning(const UString& in_filter_name,
495  const SubFilterType& in_subfilter_type,
496  const UInt32 in_contents_size_to_reserve);
497 
507  void SetSigDictTimeOfSigning(const PDF::Date& in_date);
508 
509 #ifdef SWIG
510 
520  static std::vector<UChar> SignDigest(
521  const std::vector<UChar>& in_digest,
522  const UString& in_pkcs12_keyfile_path,
523  const UString& in_keyfile_password,
524  const bool in_pades_mode,
525  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
526 
537  static std::vector<UChar> SignDigest(
538  const std::vector<UChar>& in_digest,
539  const std::vector<UChar>& in_pkcs12_buffer,
540  const UString& in_keyfile_password,
541  const bool in_pades_mode,
542  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
543 #else
544 
555  static std::vector<UChar> SignDigest(
556  const UChar* in_digest,
557  const size_t in_digest_size,
558  const UString& in_pkcs12_keyfile_path,
559  const UString& in_keyfile_password,
560  const bool in_pades_mode,
561  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
562 
575  static std::vector<UChar> SignDigest(
576  const UChar* in_digest,
577  const size_t in_digest_size,
578  const UChar* in_pkcs12_buffer,
579  const size_t in_pkcs12_buffer_size,
580  const UString& in_keyfile_password,
581  const bool in_pades_mode,
582  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
583 #endif
584 
585 // @cond PRIVATE_DOC
586 #ifndef SWIGHIDDEN
587  DigitalSignatureField(TRN_DigitalSignatureField impl);
588  TRN_DigitalSignatureField m_impl;
589 #endif
590 // @endcond
591 };
592 
593 #include <Impl/DigitalSignatureField.inl>
594 } //end pdftron
595 } //end PDF
596 
597 
598 #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)
size_t SignatureHandlerId
void SetFieldPermissions(const FieldPermissions in_action, const std::vector< UString > &in_field_names_list=std::vector< UString >())
void TimestampOnNextSave(const TimestampingConfiguration &in_timestamping_config, const VerificationOptions &in_timestamp_response_verification_options)
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
static std::vector< UChar > SignDigest(const UChar *in_digest, const size_t in_digest_size, const UString &in_pkcs12_keyfile_path, const UString &in_keyfile_password, const bool in_pades_mode, const Crypto::DigestAlgorithm::Type in_digest_algorithm_type)
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)
std::vector< std::vector< Crypto::X509Certificate > > GetCertPathsFromCMS() const
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