Foxit PDF SDK
fs_signature.h
Go to the documentation of this file.
1 
15 #ifndef FS_SIGNATURE_H_
16 #define FS_SIGNATURE_H_
17 
18 #include "common/fs_common.h"
19 #include "common/file/fs_file.h"
20 #include "common/fs_image.h"
22 
28 namespace foxit {
32 namespace pdf {
93 class Signature FS_FINAL : public interform::Field {
94  public:
111  typedef enum _States {
113  e_StateUnknown = 0x80000000,
115  e_StateNoSignData = 0x00000200,
117  e_StateUnsigned = 0x00000001,
119  e_StateSigned = 0x00000002,
121  e_StateVerifyValid = 0x00000004,
123  e_StateVerifyInvalid = 0x00000008,
131  e_StateVerifyChange = 0x00000080,
135  e_StateVerifyNoChange = 0x00000400,
170  } States;
171 
177  typedef enum _APFlags {
181  e_APFlagLabel = 0x0002,
183  e_APFlagReason = 0x0004,
187  e_APFlagDN = 0x0010,
191  e_APFlagSigner = 0x0040,
193  e_APFlagBitmap = 0x0080,
195  e_APFlagText = 0x0100
196  } APFlags;
197 
203  typedef enum _KeyName {
216  } KeyName;
217 
223  typedef enum _DigestAlgorithm {
232  } DigestAlgorithm;
233 
239  typedef enum _SignatureType {
244  } SignatureType;
245 
251  typedef enum _PAdESLevel {
264  } PAdESLevel;
265 
271  typedef enum _DocPermission {
289  } DocPermission;
290 
296  typedef enum _FieldMDPAction {
315  } FieldMDPAction;
316 
322  typedef enum _LabelName {
353  } LabelName;
354 
355 
361  explicit Signature(const interform::Field& field);
362 
370  Signature(const foxit::pdf::PDFDoc& document, foxit::pdf::objects::PDFDictionary* sig_field_dict);
371 
374 
382  bool IsEmpty() const;
383 
389  bool IsSigned();
390 
409  void SetDocPermission(DocPermission permission);
410 
424 
448  void SetFieldMDPActionFields(const FieldMDPAction& action, const WStringArray& field_array);
449 
457 
474 
531  common::Progressive StartSign(const wchar_t* cert_path, const WString& cert_password,
532  DigestAlgorithm digest_algorithm, const char* save_path,
533  const void* client_data = NULL, common::PauseCallback* pause = NULL);
534 
590  common::Progressive StartSign(foxit::common::file::StreamCallback* cert_file_stream, const WString& cert_password,
591  DigestAlgorithm digest_algorithm, const char* save_path,
592  const void* client_data = NULL, common::PauseCallback* pause = NULL);
593 
648  common::Progressive StartSign(const wchar_t* cert_path, const WString& cert_password,
649  DigestAlgorithm digest_algorithm, const wchar_t* save_path,
650  const void* client_data = NULL, common::PauseCallback* pause = NULL);
651 
705  common::Progressive StartSign(foxit::common::file::StreamCallback* cert_file_stream, const WString& cert_password,
706  DigestAlgorithm digest_algorithm, const wchar_t* save_path,
707  const void* client_data = NULL, common::PauseCallback* pause = NULL);
708 
765  common::Progressive StartSign(const wchar_t* cert_path, const foxit::WString& cert_password,
767  const void* client_data = NULL, foxit::common::PauseCallback* pause = NULL);
768 
826  const void* client_data = NULL, foxit::common::PauseCallback* pause = NULL);
827 
859  common::Progressive StartVerify(const void* client_data = NULL, common::PauseCallback* pause = NULL);
860 
880  String GetCertificateInfo(const char* key);
881 
896  bool GetByteRangeArray(uint32 out_byte_range_array[4]);
897 
924  uint32 GetState();
925 
936  bool ClearSignedData();
937 
944 
958  PDFDoc GetSignedVersionDocument(const wchar_t* file_path);
959 
971 
988  void SetAppearanceFlags(uint32 appearance_flags);
989 
1009  void SetAppearanceContent(const String& appearance_content);
1010 
1018 
1029  void SetSignTime(const DateTime& sign_time);
1030 
1039  String GetFilter();
1060  void SetFilter(const char* filter);
1061 
1070  String GetSubFilter();
1091  void SetSubFilter(const char* sub_filter);
1092 
1105 
1121  void SetKeyValue(KeyName key, const wchar_t* value);
1122 
1140  void SetKeyLabel(LabelName label_name, const wchar_t* label_value);
1141 
1152  WString GetKeyLabel(LabelName label_name);
1153 
1161 
1174  void SetBitmap(const common::Bitmap& bitmap);
1175 
1192  void SetImage(const common::Image& image, int frame_index);
1193 
1210  void SetImage(const char* file_path, int frame_index);
1211 
1228  void SetImage(const wchar_t* file_path, int frame_index);
1229 
1238 
1256  void SetDefaultContentsLength(uint32 default_length);
1257 
1268  int32 GetCertCount() const;
1269 
1284  WString GetCert(int32 index) const;
1285 
1298  void SetCertChain(const WStringArray& cert_chain);
1299 
1307 
1313  bool IsTimeStamp();
1314 
1322 
1323 #ifndef __EMSCRIPTEN_RENDER__
1324  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1325  explicit Signature(FS_HANDLE handle = NULL);
1326 #endif
1327 };
1328 
1339  public:
1345  typedef enum _CertValidity {
1362  } CertValidity;
1363 
1364 
1370  virtual void Release() = 0;
1371 
1390  virtual bool StartCalcDigest(const common::file::ReaderCallback* file, const uint32* byte_range_array,
1391  uint32 size_of_array, const Signature& signature, const void* client_data) = 0;
1392 
1411  virtual common::Progressive::State ContinueCalcDigest(const void* client_data,
1412  const common::PauseCallback* pause) = 0;
1413 
1425  virtual String GetDigest(const void* client_data) = 0;
1426 
1448  virtual String Sign(const void* digest, uint32 digest_length, const wchar_t* cert_path,
1449  const WString& cert_password, Signature::DigestAlgorithm digest_algorithm,
1450  void* client_data) = 0;
1451 
1474  virtual String Sign(const void* digest, uint32 digest_length, foxit::common::file::StreamCallback* cert_file_stream,
1475  const WString& cert_password, Signature::DigestAlgorithm digest_algorithm,
1476  void* client_data) = 0;
1477 
1500  virtual uint32 VerifySigState(const void* digest, uint32 digest_length,
1501  const void* signed_data, uint32 signed_data_len,
1502  void* client_data) = 0;
1503 
1511  virtual bool IsNeedPadData() = 0;
1512 
1532  virtual CertValidity CheckCertificateValidity(const wchar_t* cert_path, const WString& cert_password, void* client_data) = 0;
1533 
1534  protected:
1535  ~SignatureCallback() {}
1536 };
1537 
1538 class TimeStampServer;
1539 
1546 class TimeStampServerMgr FS_FINAL : public Object {
1547  public:
1556  static ErrorCode Initialize();
1566  static void Release();
1567 
1573  static int GetServerCount();
1582  static TimeStampServer GetServer(int index);
1590  static int GetServerIndex(const TimeStampServer& server);
1591 
1606  static void SetDefaultServer(int index);
1616  static void SetDefaultServer(const TimeStampServer& server);
1617 
1628  static TimeStampServer AddServer(const WString& server_name, const WString& server_url, const WString& user_name, const WString& password);
1636  static void RemoveServer(int index);
1646  static void RemoveServer(const TimeStampServer& server);
1647 };
1648 
1652 class TimeStampServer FS_FINAL : public Base {
1653  public:
1659  typedef enum _SendRequestResult {
1677 
1678 
1684  TimeStampServer(const TimeStampServer& other);
1693 
1701  bool operator == (const TimeStampServer& other) const;
1709  bool operator != (const TimeStampServer& other) const;
1710 
1712  ~TimeStampServer();
1713 
1721  bool IsEmpty() const;
1722 
1740 
1741  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1742  explicit TimeStampServer(FS_HANDLE handle);
1743 
1744 };
1745 
1746 } // namespace pdf
1747 } // namespace foxit
1748 #endif // FS_SIGNATURE_H_
1749 
Send request successfully.
Definition: fs_signature.h:1661
If set, show signing time on signature appearance.
Definition: fs_signature.h:185
If set, show distinguish name on signature appearance.
Definition: fs_signature.h:187
common::Bitmap GetBitmap()
Get a bitmap which is used for the signature appearance.
Out of memory during sending request process.
Definition: fs_signature.h:1675
Signature label name for reason.
Definition: fs_signature.h:340
Signature digest algorithm: sha1 algorithm.
Definition: fs_signature.h:225
All form fields' flags will be set read-only.
Definition: fs_signature.h:302
Certificate is unsupport type.
Definition: fs_signature.h:1351
Signature key name: location.
Definition: fs_signature.h:207
The document has been changed outside of signature scope, and the changed invalidate the signature.
Definition: fs_signature.h:169
Certificate's private key cannot be gotten.
Definition: fs_signature.h:1361
Definition: fs_image.h:36
Signature key name: distinguish name.
Definition: fs_signature.h:213
LabelName
Enumeration for signature label name.
Definition: fs_signature.h:322
TimeStampServer(const TimeStampServer &other)
Constructor, with another time stamp server object.
Unsigned signature.
Definition: fs_signature.h:117
If set, show text content on signature appearance.
Definition: fs_signature.h:195
CFX_Object Object
Object type.
Definition: fs_basictypes.h:217
WStringArray GetFieldMDPActionFields()
Get the field name array which is used for FieldMDP action.
static int GetServerIndex(const TimeStampServer &server)
Get the index of a speicified time stamp server object.
If set, show location on signature appearance.
Definition: fs_signature.h:189
TimeStampServer & operator=(const TimeStampServer &other)
Assign operator.
bool IsSigned()
Check whether current signature is signed or not.
Certificate for verifying issuer is revoked.
Definition: fs_signature.h:141
DocPermission GetDocPermission()
Get document permission for current signature.
FieldMDPAction
Enumeration for signature FieldMDP("MDP" means modification detection and prevention) action type.
Definition: fs_signature.h:296
void SetAppearanceContent(const String &appearance_content)
Set customized appearance content (as low level drawing operation commands) for signed signature appe...
Certificate is valid.
Definition: fs_signature.h:1347
SignatureType GetSignatureType()
Get signature type.
Definition: fs_basictypes.h:224
Definition: fs_basictypes.h:430
Verification state of the time stamp is invalid.
Definition: fs_signature.h:155
static int GetServerCount()
Get time stamp server count.
Signature label name for signer.
Definition: fs_signature.h:328
States
Enumeration for signature states.
Definition: fs_signature.h:111
int32 GetCertCount() const
Get the count of certificates in current signature's certificate chain.
KeyName
Enumeration for signature key name.
Definition: fs_signature.h:203
void SetKeyLabel(LabelName label_name, const wchar_t *label_value)
Set the string for specified key label.
Signature type: ordinary.
Definition: fs_signature.h:241
String GetFilter()
Get filter.
The document has not been changed within the scope of the signature.
Definition: fs_signature.h:135
No time stamp or not check time stamp.
Definition: fs_signature.h:149
Certificate's path is wrong.
Definition: fs_signature.h:1357
Header file for file operation related definitions and functions.
void SetSubFilter(const char *sub_filter)
Set sub filter.
DocPermission
Enumeration for signature document permission.
Definition: fs_signature.h:271
File reading interface.
Definition: fx_stream.h:566
No restriction.
Definition: fs_signature.h:273
void SetSignTime(const DateTime &sign_time)
Set time of signing.
virtual uint32 VerifySigState(const void *digest, uint32 digest_length, const void *signed_data, uint32 signed_data_len, void *client_data)=0
A callback function used to verify the integrity of a signature and return the verify state.
WIDE STRING CLASS.
Definition: fx_string.h:1452
static TimeStampServer AddServer(const WString &server_name, const WString &server_url, const WString &user_name, const WString &password)
Add a time stamp server to the manager.
bool operator==(const TimeStampServer &other) const
Equal operator.
Unsupported signature.
Definition: fs_signature.h:127
void SetDocPermission(DocPermission permission)
Set document permission for current signature.
SignatureType
Enumeration for signature type.
Definition: fs_signature.h:239
State
Enumeration for progress state.
Definition: fs_common.h:288
Definition: fs_signature.h:1546
No Field MDP action.
Definition: fs_signature.h:298
Not check the issuer.
Definition: fs_signature.h:145
PAdES level: B-LT.
Definition: fs_signature.h:261
If set, show bitmap on signature appearance.
Definition: fs_signature.h:193
bool IsEmpty() const
Check whether current object is empty or not.
WString GetKeyValue(KeyName key)
Get the string value for specified key name.
Definition: fs_pdfdoc.h:389
virtual CertValidity CheckCertificateValidity(const wchar_t *cert_path, const WString &cert_password, void *client_data)=0
A callback function used to check the validity of a certificate.
FieldMDPAction GetFieldMDPAction()
Get FieldMDP("MDP" means modification detection and prevention) action type.
Unknown signature.
Definition: fs_signature.h:113
Signature key name: contact information.
Definition: fs_signature.h:211
Signature key name for distinguish name.
Definition: fs_signature.h:352
virtual bool StartCalcDigest(const common::file::ReaderCallback *file, const uint32 *byte_range_array, uint32 size_of_array, const Signature &signature, const void *client_data)=0
A callback function used to start a custom digest calculation, mainly to initialize the calculation p...
static TimeStampServer GetServer(int index)
Get time stamp server with specified index.
The document has been changed within the scope of the signature. (This indicates that signature is in...
Definition: fs_signature.h:131
PAdES level: B-T.
Definition: fs_signature.h:259
PDFDoc GetSignedVersionDocument(const wchar_t *file_path)
Get the PDF document in the signed version in which current signature was signed.
SendRequestResult SendTimeStampRequest(const String &request)
Send time stamp request.
Header file for image and bitmap related definitions and classes.
Signature key name: reason.
Definition: fs_signature.h:209
If set, show reason on signature appearance.
Definition: fs_signature.h:183
Signature data is destroyed (that means the signature data cannot be parsed properly).
Definition: fs_signature.h:125
Header file for PDF form related definitions and classes.
virtual common::Progressive::State ContinueCalcDigest(const void *client_data, const common::PauseCallback *pause)=0
A callback function used to continue the custom digest calculation process.
Certificate is expired.
Definition: fs_signature.h:1349
Definition: fs_signature.h:1338
Certificate's password is wrong.
Definition: fs_signature.h:1355
Verification state of the time stamp is expired.
Definition: fs_signature.h:157
bool GetByteRangeArray(uint32 out_byte_range_array[4])
Get the byte ranges data, including 4 elements.
Certificate's data is error.
Definition: fs_signature.h:1353
Certificate for verifying issuer is expired.
Definition: fs_signature.h:143
Verification state of the issuer is unknown.
Definition: fs_signature.h:139
If set, show signer on signature appearance.
Definition: fs_signature.h:191
Verification state of the time stamp time is valid, since the times is before the expiration date.
Definition: fs_signature.h:163
Verification state of the time stamp issuer is valid.
Definition: fs_signature.h:161
common::Progressive StartVerify(const void *client_data=0, common::PauseCallback *pause=0)
Start verifying the intergrity of current signature if current signature is signed.
Not a PAdES signature.
Definition: fs_signature.h:253
Flags of form fields (except specified form fields) will be set read-only.
Definition: fs_signature.h:314
void SetFilter(const char *filter)
Set filter.
ErrorCode
Enumeration for error code.
Definition: fs_basictypes.h:233
String GetTimeStampMessage()
Get time stamp message.
Permitted changes are the same as for 2, as well as annotation creation, deletion,...
Definition: fs_signature.h:288
bool operator !=(const TimeStampServer &other) const
Not equal operator.
CertValidity
Enumeration for certificate validity.
Definition: fs_signature.h:1345
Definition: fs_signature.h:1652
File stream interface, reading & writing.
Definition: fx_stream.h:669
void SetDefaultContentsLength(uint32 default_length)
Set the default length of signature contents which represents signature value (known as signed data).
Fail to receive data during sending request process.
Definition: fs_signature.h:1669
PAdES level: B-LTA.
Definition: fs_signature.h:263
Definition: fx_basic.h:3752
Fail to connect during sending request process.
Definition: fs_signature.h:1665
Signature(const interform::Field &field)
Constructor, with parent class object.
virtual bool IsNeedPadData()=0
A callback function used to check whether to return all contents with padding zero or not,...
DigestAlgorithm
Enumeration for signature digest algorithm.
Definition: fs_signature.h:223
virtual void Release()=0
A callback function used to release current callback object itself.
No changes to the PDF document (which is signed by the signture) are permitted. Any change to this ki...
Definition: fs_signature.h:278
WString GetKeyLabel(LabelName label_name)
Get the string for specified key label.
objects::PDFDictionary * GetSignatureDict() const
Get signature dictionary.
Definition: fs_common.h:281
Definition: fs_pdfform.h:145
Specified form fields' flags will be set read-only.
Definition: fs_signature.h:308
Verification state of the time stamp issuer is unknown.
Definition: fs_signature.h:159
The verified issue is current issuer.
Definition: fs_signature.h:147
void SetBitmap(const common::Bitmap &bitmap)
Set a bitmap for the signature appearance.
FX_UINT32 uint32
32-bit unsigned integer.
Definition: fs_basictypes.h:196
Signature label name for sign time.
Definition: fs_signature.h:346
Signed signature.
Definition: fs_signature.h:119
static void Release()
Release time stamp server manager.
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:214
static TimeStampServer GetDefaultServer()
Get default time stamp server object.
Header file for common definitions and classes.
void SetCertChain(const WStringArray &cert_chain)
Set a certificate chain.
APFlags
Enumeration for signature appearance flags.
Definition: fs_signature.h:177
void SetAppearanceFlags(uint32 appearance_flags)
Set signature appearance flags.
String GetCertificateInfo(const char *key)
Get certificate information.
String GetSubFilter()
Get sub filter.
Verification state of a signature is invalid.
Definition: fs_signature.h:123
SendRequestResult
Enumeration for the result of sending time stamp request.
Definition: fs_signature.h:1659
PDFDoc GetDocument()
Get the PDF document, which current signature belongs to.
void SetKeyValue(KeyName key, const wchar_t *value)
Set the string value for specified key name.
void SetImage(const common::Image &image, int frame_index)
Set an image for the signature appearance, with a specified frame index.
FX_INT32 int32
32-bit signed integer.
Definition: fs_basictypes.h:194
Definition: fs_basictypes.h:397
Verification state of a signature is valid.
Definition: fs_signature.h:121
Fail to create socket during sending request process.
Definition: fs_signature.h:1663
Fail to send data during sending request process.
Definition: fs_signature.h:1667
Fail to get data during sending request process.
Definition: fs_signature.h:1673
Signature key name: text content.
Definition: fs_signature.h:215
Permitted changes are filling in forms, instantiating page templates, and signing....
Definition: fs_signature.h:283
Verification state of the issuer is valid.
Definition: fs_signature.h:137
Signature type: time stamp.
Definition: fs_signature.h:243
Definition: fs_pdfobject.h:785
void SetFieldMDPActionFields(const FieldMDPAction &action, const WStringArray &field_array)
Set FieldMDP("MDP" means modification detection and prevention) action names array.
Foxit namespace.
Definition: fs_compare.h:27
PAdESLevel GetPAdESLevel()
Get PAdES level.
bool IsTimeStamp()
Check if current signature is a time stamp signature.
DateTime GetSignTime()
Get time of signing.
static void RemoveServer(int index)
Remove a time stamp server from the manager, by index.
If set, show Foxit flag on signature appearance.
Definition: fs_signature.h:179
Signature cannot be trusted (containing aggression).
Definition: fs_signature.h:133
BYTE STRING CLASS.
Definition: fx_string.h:317
Certificate is not set to sign a signature.
Definition: fs_signature.h:1359
bool IsEmpty() const
Check whether current object is empty or not.
PAdESLevel
Enumeration for PAdES level.
Definition: fs_signature.h:251
WString GetCert(int32 index) const
Get a certificate from current signature's certificate chain by index.
Signature digest algorithm: sha512 algorithm.
Definition: fs_signature.h:231
Signature label name for location.
Definition: fs_signature.h:334
Signature key name: signer.
Definition: fs_signature.h:205
virtual String GetDigest(const void *client_data)=0
A callback function used to get the digest after the calculation process is finished.
static ErrorCode Initialize()
Initialize time stamp server manager.
#define NULL
The null-pointer value.
Definition: fx_system.h:767
Definition: fs_signature.h:93
Signature digest algorithm: sha384 algorithm.
Definition: fs_signature.h:229
static void SetDefaultServer(int index)
Set default time stamp server object by index.
Cannot get verify relevant information.
Definition: fs_signature.h:165
Signature does not have any data for signing.
Definition: fs_signature.h:115
Signature digest algorithm: sha256 algorithm.
Definition: fs_signature.h:227
PAdES level: none.
Definition: fs_signature.h:255
Verification state of the time stamp is valid.
Definition: fs_signature.h:153
The document has been changed outside of signature scope, but the changed is permitted.
Definition: fs_signature.h:167
Fail to request during sending request process.
Definition: fs_signature.h:1671
~Signature()
Destructor.
Definition: fs_signature.h:373
uint32 GetState()
Get current state.
Definition: fs_image.h:430
virtual String Sign(const void *digest, uint32 digest_length, const wchar_t *cert_path, const WString &cert_password, Signature::DigestAlgorithm digest_algorithm, void *client_data)=0
A callback function used to do signing and return the signed data.
PAdES level: B-B.
Definition: fs_signature.h:257
bool ClearSignedData()
Clear the data and appearance if current signature is singed and verified valid.
If set, show label on signature appearance.
Definition: fs_signature.h:181
common::Progressive StartSign(const wchar_t *cert_path, const WString &cert_password, DigestAlgorithm digest_algorithm, const char *save_path, const void *client_data=0, common::PauseCallback *pause=0)
Start signing current signature if current signature is unsigned.
The signature is a time stamp signature.
Definition: fs_signature.h:151
Non expected byte range.
Definition: fs_signature.h:129
uint32 GetAppearanceFlags()
Get signature appearance flags.