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 
Permitted changes are filling in forms, instantiating page templates, and signing....
Definition: fs_signature.h:283
SignatureType GetSignatureType()
Get signature type.
Signature type: time stamp.
Definition: fs_signature.h:243
PAdES level: B-LT.
Definition: fs_signature.h:261
APFlags
Enumeration for signature appearance flags.
Definition: fs_signature.h:177
common::Progressive StartVerify(const void *client_data=0, common::PauseCallback *pause=0)
Start verifying the intergrity of current signature if current signature is signed.
void * FS_HANDLE
Handle type.
Definition: fs_basictypes.h:216
Signature digest algorithm: sha256 algorithm.
Definition: fs_signature.h:227
FieldMDPAction GetFieldMDPAction()
Get FieldMDP("MDP" means modification detection and prevention) action type.
Verification state of the time stamp is valid.
Definition: fs_signature.h:153
static void Release()
Release time stamp server manager.
The document has been changed outside of signature scope, but the changed is permitted.
Definition: fs_signature.h:167
TimeStampServer & operator=(const TimeStampServer &other)
Assign operator.
uint32 GetState()
Get current state.
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.
Definition: fs_basictypes.h:432
PAdESLevel
Enumeration for PAdES level.
Definition: fs_signature.h:251
No Field MDP action.
Definition: fs_signature.h:298
Fail to create socket during sending request process.
Definition: fs_signature.h:1595
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.
bool IsEmpty() const
Check whether current object is empty or not.
PAdES level: B-B.
Definition: fs_signature.h:257
If set, show label on signature appearance.
Definition: fs_signature.h:181
bool GetByteRangeArray(uint32 out_byte_range_array[4])
Get the byte ranges data, including 4 elements.
CFX_Object Object
Object type.
Definition: fs_basictypes.h:219
void SetFilter(const char *filter)
Set filter.
Definition: fs_common.h:568
Definition: fs_signature.h:1584
Unknown signature.
Definition: fs_signature.h:113
static ErrorCode Initialize()
Initialize time stamp server manager.
Signature key name: contact information.
Definition: fs_signature.h:211
Verification state of the time stamp issuer is valid.
Definition: fs_signature.h:161
Not a PAdES signature.
Definition: fs_signature.h:253
DateTime GetSignTime()
Get time of signing.
PAdES level: B-T.
Definition: fs_signature.h:259
Header file for PDF form related definitions and classes.
Certificate's path is wrong.
Definition: fs_signature.h:1289
static void RemoveServer(int index)
Remove a time stamp server from the manager, by index.
File stream interface, reading & writing.
Definition: fx_stream.h:669
Signature key name: location.
Definition: fs_signature.h:207
Header file for common definitions and classes.
~Signature()
Destructor.
Definition: fs_signature.h:334
void SetCertChain(const WStringArray &cert_chain)
Set a certificate chain.
Signature key name: distinguish name.
Definition: fs_signature.h:213
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
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.
PAdES level: B-LTA.
Definition: fs_signature.h:263
File reading interface.
Definition: fx_stream.h:566
If set, show distinguish name on signature appearance.
Definition: fs_signature.h:187
Header file for file operation related definitions and functions.
uint32 GetAppearanceFlags()
Get signature appearance flags.
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...
Flags of form fields (except specified form fields) will be set read-only.
Definition: fs_signature.h:314
Certificate for verifying issuer is revoked.
Definition: fs_signature.h:141
ErrorCode
Enumeration for error code.
Definition: fs_basictypes.h:236
Signature digest algorithm: sha1 algorithm.
Definition: fs_signature.h:225
CertValidity
Enumeration for certificate validity.
Definition: fs_signature.h:1277
Certificate's password is wrong.
Definition: fs_signature.h:1287
Fail to get data during sending request process.
Definition: fs_signature.h:1605
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
States
Enumeration for signature states.
Definition: fs_signature.h:111
String GetSubFilter()
Get sub filter.
Signature type: ordinary.
Definition: fs_signature.h:241
Fail to receive data during sending request process.
Definition: fs_signature.h:1601
The document has not been changed within the scope of the signature.
Definition: fs_signature.h:135
If set, show location on signature appearance.
Definition: fs_signature.h:189
SendRequestResult
Enumeration for the result of sending time stamp request.
Definition: fs_signature.h:1591
void SetImage(const common::Image &image, int frame_index)
Set an image for the signature appearance, with a specified frame index.
String GetCertificateInfo(const char *key)
Get certificate information.
Verification state of a signature is invalid.
Definition: fs_signature.h:123
bool IsTimeStamp()
Check if current signature is a time stamp signature.
No changes to the PDF document (which is signed by the signture) are permitted. Any change to this ki...
Definition: fs_signature.h:278
PDFDoc GetDocument()
Get the PDF document, which current signature belongs to.
virtual void Release()=0
A callback function used to release current callback object itself.
WStringArray GetFieldMDPActionFields()
Get the field name array which is used for FieldMDP action.
Certificate's private key cannot be gotten.
Definition: fs_signature.h:1293
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.
void SetKeyValue(KeyName key, const wchar_t *value)
Set the string value for specified key name.
bool IsSigned()
Check whether current signature is signed or not.
DocPermission GetDocPermission()
Get document permission for current signature.
Definition: fs_pdfform.h:145
Verification state of a signature is valid.
Definition: fs_signature.h:121
BYTE STRING CLASS.
Definition: fx_string.h:317
FieldMDPAction
Enumeration for signature FieldMDP("MDP" means modification detection and prevention) action type.
Definition: fs_signature.h:296
No time stamp or not check time stamp.
Definition: fs_signature.h:149
Signature key name: text content.
Definition: fs_signature.h:215
void SetSubFilter(const char *sub_filter)
Set sub filter.
Fail to connect during sending request process.
Definition: fs_signature.h:1597
static void SetDefaultServer(int index)
Set default time stamp server object by index.
PAdESLevel GetPAdESLevel()
Get PAdES level.
bool operator !=(const TimeStampServer &other) const
Not equal operator.
Definition: fs_signature.h:93
PDFDoc GetSignedVersionDocument(const wchar_t *file_path)
Get the PDF document in the signed version in which current signature was signed.
bool operator==(const TimeStampServer &other) const
Equal operator.
Signature key name: reason.
Definition: fs_signature.h:209
Unsupported signature.
Definition: fs_signature.h:127
bool IsEmpty() const
Check whether current object is empty or not.
Certificate's data is error.
Definition: fs_signature.h:1285
Certificate is expired.
Definition: fs_signature.h:1281
Not check the issuer.
Definition: fs_signature.h:145
If set, show bitmap on signature appearance.
Definition: fs_signature.h:193
If set, show Foxit flag on signature appearance.
Definition: fs_signature.h:179
Verification state of the time stamp is expired.
Definition: fs_signature.h:157
void SetDocPermission(DocPermission permission)
Set document permission for current signature.
SignatureType
Enumeration for signature type.
Definition: fs_signature.h:239
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.
Verification state of the time stamp time is valid, since the times is before the expiration date.
Definition: fs_signature.h:163
WString GetCert(int32 index) const
Get a certificate from current signature's certificate chain by index.
bool ClearSignedData()
Clear the data and appearance if current signature is singed and verified valid.
Signature digest algorithm: sha512 algorithm.
Definition: fs_signature.h:231
static int GetServerCount()
Get time stamp server count.
Verification state of the issuer is valid.
Definition: fs_signature.h:137
Foxit namespace.
Definition: fs_compare.h:27
The document has been changed within the scope of the signature. (This indicates that signature is in...
Definition: fs_signature.h:131
SendRequestResult SendTimeStampRequest(const String &request)
Send time stamp request.
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
Permitted changes are the same as for 2, as well as annotation creation, deletion,...
Definition: fs_signature.h:288
String GetTimeStampMessage()
Get time stamp message.
common::Bitmap GetBitmap()
Get a bitmap which is used for the signature appearance.
Signature digest algorithm: sha384 algorithm.
Definition: fs_signature.h:229
Cannot get verify relevant information.
Definition: fs_signature.h:165
Definition: fx_basic.h:3752
Header file for image and bitmap related definitions and classes.
Signature does not have any data for signing.
Definition: fs_signature.h:115
Definition: fs_pdfobject.h:763
PAdES level: none.
Definition: fs_signature.h:255
Fail to send data during sending request process.
Definition: fs_signature.h:1599
WString GetKeyValue(KeyName key)
Get the string value for specified key name.
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.
virtual bool IsNeedPadData()=0
A callback function used to check whether to return all contents with padding zero or not,...
Signature key name: signer.
Definition: fs_signature.h:205
Certificate is unsupport type.
Definition: fs_signature.h:1283
#define NULL
The null-pointer value.
Definition: fx_system.h:767
Fail to request during sending request process.
Definition: fs_signature.h:1603
Definition: fs_pdfdoc.h:389
void SetDefaultContentsLength(uint32 default_length)
Set the default length of signature contents which represents signature value (known as signed data).
State
Enumeration for progress state.
Definition: fs_common.h:575
FX_INT32 int32
32-bit signed integer.
Definition: fs_basictypes.h:196
Definition: fs_image.h:430
The document has been changed outside of signature scope, and the changed invalidate the signature.
Definition: fs_signature.h:169
static int GetServerIndex(const TimeStampServer &server)
Get the index of a speicified time stamp server object.
DigestAlgorithm
Enumeration for signature digest algorithm.
Definition: fs_signature.h:223
Definition: fs_basictypes.h:226
String GetFilter()
Get filter.
Out of memory during sending request process.
Definition: fs_signature.h:1607
static TimeStampServer GetServer(int index)
Get time stamp server with specified index.
Signature(const interform::Field &field)
Constructor, with parent class object.
The signature is a time stamp signature.
Definition: fs_signature.h:151
Non expected byte range.
Definition: fs_signature.h:129
Specified form fields' flags will be set read-only.
Definition: fs_signature.h:308
If set, show text content on signature appearance.
Definition: fs_signature.h:195
Send request successfully.
Definition: fs_signature.h:1593
Signed signature.
Definition: fs_signature.h:119
If set, show signing time on signature appearance.
Definition: fs_signature.h:185
void SetAppearanceContent(const String &appearance_content)
Set customized appearance content (as low level drawing operation commands) for signed signature appe...
Definition: fs_signature.h:1270
static TimeStampServer GetDefaultServer()
Get default time stamp server object.
WIDE STRING CLASS.
Definition: fx_string.h:1452
All form fields' flags will be set read-only.
Definition: fs_signature.h:302
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
Definition: fs_image.h:36
Definition: fs_signature.h:1478
virtual String GetDigest(const void *client_data)=0
A callback function used to get the digest after the calculation process is finished.
Certificate is valid.
Definition: fs_signature.h:1279
Verification state of the time stamp is invalid.
Definition: fs_signature.h:155
Certificate is not set to sign a signature.
Definition: fs_signature.h:1291
void SetFieldMDPActionFields(const FieldMDPAction &action, const WStringArray &field_array)
Set FieldMDP("MDP" means modification detection and prevention) action names array.
DocPermission
Enumeration for signature document permission.
Definition: fs_signature.h:271
void SetAppearanceFlags(uint32 appearance_flags)
Set signature appearance flags.
TimeStampServer(const TimeStampServer &other)
Constructor, with another time stamp server object.
void SetSignTime(const DateTime &sign_time)
Set time of signing.
FX_UINT32 uint32
32-bit unsigned integer.
Definition: fs_basictypes.h:198
Unsigned signature.
Definition: fs_signature.h:117
Signature cannot be trusted (containing aggression).
Definition: fs_signature.h:133
objects::PDFDictionary * GetSignatureDict() const
Get signature dictionary.
Definition: fs_basictypes.h:399
No restriction.
Definition: fs_signature.h:273
void SetBitmap(const common::Bitmap &bitmap)
Set a bitmap for the signature appearance.