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-2022 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 
446  const VerificationOptions& in_timestamp_response_verification_options);
447 
454  void UseSubFilter(const SubFilterType in_subfilter_type, const bool in_make_mandatory = true);
455 
465  std::vector<UChar> CalculateDigest(const Crypto::DigestAlgorithm::Type in_digest_algorithm_type = Crypto::DigestAlgorithm::e_SHA256) const;
466 
473  void SetPreferredDigestAlgorithm(Crypto::DigestAlgorithm::Type in_digest_algorithm_type,
474  const bool in_make_mandatory = true);
475 
484  void CreateSigDictForCustomCertification(const UString& in_filter_name,
485  const SubFilterType& in_subfilter_type,
486  const UInt32 in_contents_size_to_reserve);
487 
496  void CreateSigDictForCustomSigning(const UString& in_filter_name,
497  const SubFilterType& in_subfilter_type,
498  const UInt32 in_contents_size_to_reserve);
499 
512  void SetSigDictTimeOfSigning(const PDF::Date& in_date);
513 
514 
525  static std::vector<UChar> SignDigest(
526  const std::vector<UChar>& in_digest,
527  const UString& in_pkcs12_keyfile_path,
528  const UString& in_keyfile_password,
529  const bool in_pades_mode,
530  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
531 
542  static std::vector<UChar> SignDigest(
543  const std::vector<UChar>& in_digest,
544  const std::vector<UChar>& in_pkcs12_buffer,
545  const UString& in_keyfile_password,
546  const bool in_pades_mode,
547  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
548 #ifndef SWIG
549 
560  static std::vector<UChar> SignDigest(
561  const UChar* in_digest,
562  const size_t in_digest_size,
563  const UString& in_pkcs12_keyfile_path,
564  const UString& in_keyfile_password,
565  const bool in_pades_mode,
566  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
567 
580  static std::vector<UChar> SignDigest(
581  const UChar* in_digest,
582  const size_t in_digest_size,
583  const UChar* in_pkcs12_buffer,
584  const size_t in_pkcs12_buffer_size,
585  const UString& in_keyfile_password,
586  const bool in_pades_mode,
587  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
588 #endif
589 
609  static std::vector<UChar> GenerateESSSigningCertPAdESAttribute(
610  const Crypto::X509Certificate& in_signer_cert,
611  const Crypto::DigestAlgorithm::Type in_digest_algorithm_type);
612 
627  static std::vector<UChar> GenerateCMSSignedAttributes(
628  const std::vector<UChar>& in_digest_buf,
629  const std::vector<UChar>& in_custom_signedattributes_buf = std::vector<UChar>());
630 #ifndef SWIG
631 
647  static std::vector<UChar> GenerateCMSSignedAttributes(
648  const UChar* in_digest_buf,
649  const size_t in_digest_buf_size,
650  const UChar* in_custom_signedattributes_buf = NULL,
651  const size_t in_custom_signedattributes_buf_size = 0);
652 #endif
653 
668  static std::vector<UChar> GenerateCMSSignature(
669  const Crypto::X509Certificate& in_signer_cert,
670  const std::vector<Crypto::X509Certificate>& in_chain_certs_list,
671  const Crypto::ObjectIdentifier& in_digest_algorithm_oid,
672  const Crypto::ObjectIdentifier& in_signature_algorithm_oid,
673  const std::vector<UChar>& in_signature_value_buf,
674  const std::vector<UChar>& in_signedattributes_buf);
675 #ifndef SWIG
676 
693  static std::vector<UChar> GenerateCMSSignature(
694  const Crypto::X509Certificate& in_signer_cert,
695  const Crypto::X509Certificate* in_chain_certs_list,
696  const size_t in_chain_certs_list_size,
697  const Crypto::ObjectIdentifier& in_digest_algorithm_oid,
698  const Crypto::ObjectIdentifier& in_signature_algorithm_oid,
699  const UChar* in_signature_value_buf,
700  const size_t in_signature_value_buf_size,
701  const UChar* in_signedattributes_buf,
702  const size_t in_signedattributes_buf_size);
703 #endif
704 
705 // @cond PRIVATE_DOC
706 #ifndef SWIGHIDDEN
707  DigitalSignatureField(TRN_DigitalSignatureField impl);
708  TRN_DigitalSignatureField m_impl;
709 #endif
710 // @endcond
711 };
712 
713 #include <Impl/DigitalSignatureField.inl>
714 } //end pdftron
715 } //end PDF
716 
717 
718 #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 >())
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