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  explicit Signature(const interform::Field& field);
323 
331  Signature(const foxit::pdf::PDFDoc& document, foxit::pdf::objects::PDFDictionary* sig_field_dict);
332 
335 
343  bool IsEmpty() const;
344 
350  bool IsSigned();
351 
370  void SetDocPermission(DocPermission permission);
371 
385 
409  void SetFieldMDPActionFields(const FieldMDPAction& action, const WStringArray& field_array);
410 
418 
436 
493  common::Progressive StartSign(const wchar_t* cert_path, const WString& cert_password,
494  DigestAlgorithm digest_algorithm, const char* save_path,
495  const void* client_data = NULL, common::PauseCallback* pause = NULL);
496 
552  common::Progressive StartSign(foxit::common::file::StreamCallback* cert_file_stream, const WString& cert_password,
553  DigestAlgorithm digest_algorithm, const char* save_path,
554  const void* client_data = NULL, common::PauseCallback* pause = NULL);
555 
610  common::Progressive StartSign(const wchar_t* cert_path, const WString& cert_password,
611  DigestAlgorithm digest_algorithm, const wchar_t* save_path,
612  const void* client_data = NULL, common::PauseCallback* pause = NULL);
613 
667  common::Progressive StartSign(foxit::common::file::StreamCallback* cert_file_stream, const WString& cert_password,
668  DigestAlgorithm digest_algorithm, const wchar_t* save_path,
669  const void* client_data = NULL, common::PauseCallback* pause = NULL);
670 
727  common::Progressive StartSign(const wchar_t* cert_path, const foxit::WString& cert_password,
729  const void* client_data = NULL, foxit::common::PauseCallback* pause = NULL);
730 
788  const void* client_data = NULL, foxit::common::PauseCallback* pause = NULL);
789 
821  common::Progressive StartVerify(const void* client_data = NULL, common::PauseCallback* pause = NULL);
822 
842  String GetCertificateInfo(const char* key);
843 
858  bool GetByteRangeArray(uint32 out_byte_range_array[4]);
859 
886  uint32 GetState();
887 
898  bool ClearSignedData();
899 
906 
921  PDFDoc GetSignedVersionDocument(const wchar_t* file_path);
922 
934 
951  void SetAppearanceFlags(uint32 appearance_flags);
952 
972  void SetAppearanceContent(const String& appearance_content);
973 
981 
992  void SetSignTime(const DateTime& sign_time);
993 
1002  String GetFilter();
1023  void SetFilter(const char* filter);
1024 
1033  String GetSubFilter();
1054  void SetSubFilter(const char* sub_filter);
1055 
1068 
1084  void SetKeyValue(KeyName key, const wchar_t* value);
1085 
1093 
1106  void SetBitmap(const common::Bitmap& bitmap);
1107 
1124  void SetImage(const common::Image& image, int frame_index);
1125 
1142  void SetImage(const char* file_path, int frame_index);
1143 
1160  void SetImage(const wchar_t* file_path, int frame_index);
1161 
1170 
1188  void SetDefaultContentsLength(uint32 default_length);
1189 
1200  int32 GetCertCount() const;
1201 
1216  WString GetCert(int32 index) const;
1217 
1230  void SetCertChain(const WStringArray& cert_chain);
1231 
1239 
1245  bool IsTimeStamp();
1246 
1254 
1255 #ifndef __EMSCRIPTEN_RENDER__
1256  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1257  explicit Signature(FS_HANDLE handle = NULL);
1258 #endif
1259 };
1260 
1271  public:
1277  typedef enum _CertValidity {
1294  } CertValidity;
1295 
1296 
1302  virtual void Release() = 0;
1303 
1322  virtual bool StartCalcDigest(const common::file::ReaderCallback* file, const uint32* byte_range_array,
1323  uint32 size_of_array, const Signature& signature, const void* client_data) = 0;
1324 
1343  virtual common::Progressive::State ContinueCalcDigest(const void* client_data,
1344  const common::PauseCallback* pause) = 0;
1345 
1357  virtual String GetDigest(const void* client_data) = 0;
1358 
1380  virtual String Sign(const void* digest, uint32 digest_length, const wchar_t* cert_path,
1381  const WString& cert_password, Signature::DigestAlgorithm digest_algorithm,
1382  void* client_data) = 0;
1383 
1406  virtual String Sign(const void* digest, uint32 digest_length, foxit::common::file::StreamCallback* cert_file_stream,
1407  const WString& cert_password, Signature::DigestAlgorithm digest_algorithm,
1408  void* client_data) = 0;
1409 
1432  virtual uint32 VerifySigState(const void* digest, uint32 digest_length,
1433  const void* signed_data, uint32 signed_data_len,
1434  void* client_data) = 0;
1435 
1443  virtual bool IsNeedPadData() = 0;
1444 
1464  virtual CertValidity CheckCertificateValidity(const wchar_t* cert_path, const WString& cert_password, void* client_data) = 0;
1465 
1466  protected:
1467  ~SignatureCallback() {}
1468 };
1469 
1470 class TimeStampServer;
1471 
1478 class TimeStampServerMgr FS_FINAL : public Object {
1479  public:
1488  static ErrorCode Initialize();
1498  static void Release();
1499 
1505  static int GetServerCount();
1514  static TimeStampServer GetServer(int index);
1522  static int GetServerIndex(const TimeStampServer& server);
1523 
1538  static void SetDefaultServer(int index);
1548  static void SetDefaultServer(const TimeStampServer& server);
1549 
1560  static TimeStampServer AddServer(const WString& server_name, const WString& server_url, const WString& user_name, const WString& password);
1568  static void RemoveServer(int index);
1578  static void RemoveServer(const TimeStampServer& server);
1579 };
1580 
1584 class TimeStampServer FS_FINAL : public Base {
1585  public:
1591  typedef enum _SendRequestResult {
1609 
1610 
1616  TimeStampServer(const TimeStampServer& other);
1625 
1633  bool operator == (const TimeStampServer& other) const;
1641  bool operator != (const TimeStampServer& other) const;
1642 
1644  ~TimeStampServer();
1645 
1653  bool IsEmpty() const;
1654 
1672 
1673  // User is strongly recommended NOT to use this method; otherwise unknown situation may occur.
1674  explicit TimeStampServer(FS_HANDLE handle);
1675 
1676 };
1677 
1678 } // namespace pdf
1679 } // namespace foxit
1680 #endif // FS_SIGNATURE_H_
1681 
Send request successfully.
Definition: fs_signature.h:1593
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:1607
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:1283
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:1293
Definition: fs_image.h:36
Signature key name: distinguish name.
Definition: fs_signature.h:213
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:219
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:1279
SignatureType GetSignatureType()
Get signature type.
Definition: fs_basictypes.h:226
Definition: fs_basictypes.h:432
Verification state of the time stamp is invalid.
Definition: fs_signature.h:155
static int GetServerCount()
Get time stamp server count.
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
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:1289
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:575
Definition: fs_signature.h:1478
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
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:1281
Definition: fs_signature.h:1270
Certificate's password is wrong.
Definition: fs_signature.h:1287
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:1285
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:236
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:1277
Definition: fs_signature.h:1584
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:1601
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:1597
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
objects::PDFDictionary * GetSignatureDict() const
Get signature dictionary.
Definition: fs_common.h:568
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:198
Signed signature.
Definition: fs_signature.h:119
static void Release()
Release time stamp server manager.
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:216
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:1591
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:196
Definition: fs_basictypes.h:399
Verification state of a signature is valid.
Definition: fs_signature.h:121
Fail to create socket during sending request process.
Definition: fs_signature.h:1595
Fail to send data during sending request process.
Definition: fs_signature.h:1599
Fail to get data during sending request process.
Definition: fs_signature.h:1605
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:763
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:1291
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 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:1603
~Signature()
Destructor.
Definition: fs_signature.h:334
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.