DL Logo

PDCrypt Definitions

PDCryptFilterStringProc

Header: PDExpT.h:5132

Syntax

#define PDCryptFilterStringProc CosCryptStringProc

PDCrypt Enumerations

GCHTextType

Header: PDExpT.h:4379

Enum Constants

kGCHTTipText=1
kGCHTMiniText
kGCHTLargeText

Used By

PDCrypt Typedefs

PDCryptBatchHandler

Header: PDExpT.h:5265

Syntax

typedef struct _t_PDCryptBatchHandler *PDCryptBatchHandler;

Used In

PDCryptFilterHandler

Header: PDExpT.h:5169

Syntax

typedef struct _t_PDCryptFilterHandler *PDCryptFilterHandler;

Used In

PDCryptHandler

Header: PDExpT.h:5496

Syntax

typedef struct _t_PDCryptHandler *PDCryptHandler;

Used By

PDCrypt Callback Signatures

PDCryptAuthorizeExProc

Header: PDExpT.h:4760

Description

Replaces PDCryptAuthorizeProc. PDPerms are obsolete, but Acrobat still supports old security handlers.

It is called whenever Acrobat needs to get authorization data and/or check permissions for operations.

Syntax

PDPermReqStatus PDCryptAuthorizeExProc(PDDoc pdDoc, PDPermReqObj reqObj, PDPermReqOpr reqOpr, void *authData);

Parameters

pdDoc
The document for which the request is made.
reqObj
The object type that is the focus of the request: it is one of the PDPermReqObj values.
reqOpr
The operation type that is the focus of the request: it is one of the PDPermReqOpr values.
authData
Authorization data. Its format is security handler-specific.

Returns

The status of the request. It is one of the PDPermReqStatus values.

Used In

PDCryptAuthorizeProc

Header: PDExpT.h:4438

Description

A callback for PDCryptHandler. It is called by PDDocAuthorize() when a user tries to set security for an encrypted document and by a PDAuthProc() when a user tries to open a file.

It must decide, based on the contents of the authorization data structure, whether the user is permitted to open the file, and what permissions the user has for this file. The authorization data structure is available for making this decision. Alternate implementations may not require authorization data and may, for example, make authorization decisions based on data contained in the security data structure (use PDCryptNewSecurityDataProc()).

This callback must not obtain the authorization data (for example, by displaying a user interface into which a user can type a password). Obtaining authorization data is handled by the security handler's PDCryptGetAuthDataProc(), which must be called before this callback. Instead, PDCryptAuthorizeProc() must work with whatever authorization data is passed to it.

It is legitimate for this callback to be called with NULL authorization data; the Acrobat viewer's built-in authProc does this in order to support authorization methods that do not require authorization data.

When this callback is invoked to determine whether a user is permitted to open a file, permWanted is set to pdPermOpen. In this case, the file's contents are not yet decrypted (since this callback is being asked to permit decryption), and some calls must be avoided. For example, a call that causes a page to be parsed results in an error, since the encrypted contents are parsed. In general, it is safe to obtain information about the presence or absence of things, or the number of things, and to examine any part of a document at the Cos level.

Syntax

PDPerms PDCryptAuthorizeProc(PDDoc pdDoc, void *authData, PDPerms permWanted);

Parameters

pdDoc
The document for which authorized permissions are being requested.
authData
Authorization data. Its format is security handler-specific; each handler can select its own authorization data format.
permWanted
The permissions being requested. It is either pdPermOpen (if the file is being opened) or pdPermSecure (if a request is being made to change the document's security settings).

Returns

The permissions granted based on authData. For opening, the permissions returned usually should be pdPermOpen and some or all of pdPermPrint, pdPermEdit, and pdPermCopy. For setting security, permissions returned should be pdPermAll. However, if authorization fails, 0 should be returned.

Used In

PDCryptBatchAuthorizeProc

Header: PDExpT.h:4988

Description

A callback for PDCryptBatchHandler. It is called when a PDF file is opened. It is first called with NULL authData for the case without a user password. It is called again with authorization data provided for the security handler that matches the one used in the PDF file.

Note: This function is called a batch operation and therefore should not display any user interface. During a batch operation, a file will first be opened with the pdPermSecure bit set. It will then be opened with the pdPermOpen bit set.

Syntax

PDPermReqStatus PDCryptBatchAuthorizeProc(PDDoc pdDoc, PDPermReqObj reqObj, PDPermReqOpr reqOpr, void *authData);

Parameters

pdDoc
IN/OUT The document being opened.
reqObj
IN/OUT The object type that is the focus of the request: it is one of the PDPermReqObj values.
reqOpr
IN/OUT The operation type that is the focus of the request: it is one of the PDPermReqOpr values.
authData
IN/OUT Authorization data. Its format is security handler-specific.

Returns

PDPermReqStatus

Used In

PDCryptBatchFreeAuthDataProc

Header: PDExpT.h:5000

Description

A callback for PDCryptBatchHandler. If provided, it must be used to free authData acquired via BatchGetAuthData() or BatchNewAuthData(). If no BatchFreeAuthData() function is provided, a default one will be used which calls ASfree() on the authData if it is non- NULL.

Syntax

void PDCryptBatchFreeAuthDataProc(void *authData);

Parameters

authData
IN/OUT Authorization data. Its format is security handler-specific.

Used In

PDCryptBatchNewAuthDataProc

Header: PDExpT.h:4966

Description

A callback for PDCryptBatchHandler. It is different from the regular PDCryptHandler NewAuthData function. It creates and returns a void * which is the authorization data for the batch security handler. This data should be used to batch both open files and secure files. Therefore, make sure to provide password information for both the pdPermOpen and pdPermSecure cases. This data will be passed to the PDCryptBatchAuthorizeProc() callback and eventually to PDCryptBatchFreeAuthDataProc() to free the data. This authorization data is collected before any files are opened in the batch sequence. It is permitted to display a user interface at this point since the batch operation has not started yet. The data applies to all files, and therefore could represent one or more passwords which can be enumerated in the BatchAuthorize function which receives the batch authorization data.

Syntax

void *PDCryptBatchNewAuthDataProc(void);

Used In

PDCryptBatchParamDescProc

Header: PDExpT.h:4947

Description

A callback for PDCryptBatchHandler. The developer should provide information about the current batch settings for the security handler. Batch settings are provided as a read-only ASCab that is passed to the function. A writable ASCab is also provided, which should be used to store parameter information about the security handler. The description information should be stored starting in the paramDesc ASCab using ASText objects starting with key " 1".

Syntax

void PDCryptBatchParamDescProc(const ASCab settings, ASCab paramDesc);

Parameters

settings
IN/OUT Batch settings.
paramDesc
IN/OUT Description information.

Example

key=" 1", value="Title: API Reference" (ASText object)

Used In

PDCryptBatchPostSequenceProc

Header: PDExpT.h:5028

Description

A callback for PDCryptBatchHandler. This function is called at the end of a batch sequence after all files have been processed. Any memory that was allocated in the BatchPreSequence() call should be cleaned up in this callback.

Syntax

void PDCryptBatchPostSequenceProc(ASCab settings);

Parameters

settings
IN/OUT Batch settings.

Used In

PDCryptBatchPreSequenceProc

Header: PDExpT.h:5019

Description

A callback for PDCryptBatchHandler. This function is called at the beginning of a batch sequence before any files have been opened. This allows a security handler to be called back with the ASCab of settings that were filled out by the BatchShowDialog() function, or by an ASCab that was read in from disk. Pointers of security information are not serialized to disk, and therefore a security information structure may need to be regenerated based on other security information in the ASCab. It is permitted for the BatchPreSequence() callback to put up a user interface asking the user for more information since the batch sequence has not started yet. If this function returns false, the viewer will assume that the command cannot be executed and will cancel the sequence.

Syntax

ASBool PDCryptBatchPreSequenceProc(ASCab settings);

Parameters

settings
IN/OUT Batch settings.

Returns

See above.

Used In

PDCryptBatchShowDialogProc

Header: PDExpT.h:4932

Description

A callback for PDCryptBatchHandler. This callback puts up a dialog box that allows a user to enter data that will be used to batch secure a series of files. The data is stored in an ASCab which is part of a batch sequence file. The actual security data, including password(s), should be stored as a pointer in the ASCab so that password information is not serialized to disk. Pointers are not serialized from ASCab objects, but ASText objects, ASInt32 objects, and ASBool objects are serialized.

Syntax

ASBool PDCryptBatchShowDialogProc(ASCab settings);

Parameters

settings
IN/OUT An object of type ASCab.

Returns

true indicates success.

Used In

PDCryptBatchUpdateSecurityDataProc

Header: PDExpT.h:5046

Description

A callback for PDCryptBatchHandler. This function should update the crypt handler's security data without bringing up a dialog. This data is provided by a PDCryptBatchShowDialogProc(). The current security data can be obtained by calling PDDocGetNewSecurityData().

Note: This function is called a batch operation and therefore should not display any user interface.

Syntax

ASBool PDCryptBatchUpdateSecurityDataProc(PDDoc pdDoc, ASCab settings, ASAtom *cryptHandler, void **secDataP);

Parameters

pdDoc
The document whose data is updated.
settings
An object of type ASCab.
cryptHandler
An object of type ASAtom.
secDataP
A pointer to the document's security data.

Returns

This function should return true unless there is a problem with the batch data for this security handler.

Used In

PDCryptCanParseEncryptDictProc

Header: PDExpT.h:4847

Description

(Optional) This call is used to provide PDCrypt handler interoperability. When an encrypted document is being opened and the security handler specified in the encryption dictionary is not present, this callback is used to determine if one of the registered security handlers can be used to open the document.

Syntax

ASBool PDCryptCanParseEncryptDictProc(PDDoc pdDoc, CosObj encryptDict);

Parameters

pdDoc
The document being opened.
encryptDict
The encryption dictionary.

Returns

true if the handler supports the format of encryptDict.

Used In

PDCryptDisplaySecurityDataProc

Header: PDExpT.h:4827

Description

Called when the security handler should bring up a document (security) information dialog box with the current settings. It also should return true when the user wants to change the settings.

If this callback is not supplied, the default information dialog is displayed with PDPerms bits information (an Acrobat 4.x-equivalent dialog).

Syntax

ASBool PDCryptDisplaySecurityDataProc(PDDoc pdDoc, ASAtom cryptHandler);

Parameters

pdDoc
IN/OUT The document whose information is displayed.
cryptHandler
IN/OUT The registered name of the handler.

Returns

true if the handler wishes a callback to change the settings, false otherwise.

Used In

PDCryptEncryptDocMetadata

Header: PDExpT.h:4891

Description

(Optional) A callback for PDCryptHandler. It determines whether a document's metadata will be encrypted. If this call is not implemented, the metadata is always encrypted. Note that documents with plain text metadata can be opened only by Acrobat versions 6.0 and later.

Syntax

ASBool PDCryptEncryptDocMetadata(PDDoc pdDoc);

Parameters

pdDoc
IN The document being encrypted.

Returns

true if document metadata should be encrypted.

Used In

PDCryptFillEncryptDictProc

Header: PDExpT.h:4650

Description

A callback for PDCryptHandler. It is called when an encrypted document is saved. It fills the document's Encryption dictionary with whatever information the security handler wants to store in the document.

Normally this callback is called after PDCryptUpdateSecurityDataProc(). The security data structure can be obtained with a call to PDDocGetNewSecurityData(), and encryptDict is filled based on this data.

The sequencing of events that the viewer performs during creation of the encryptDict is as follows:

  • The viewer creates the encryptDict.
  • The viewer adds the Filter attribute to the dictionary.
  • The viewer calls this PDCryptFillEncryptDictProc() to allow the security handler to add its own attributes to the dictionary.
  • The viewer calls the PDCryptNewCryptDataExProc() (the PDCryptNewCryptDataProc() if unsuccessful) to get the algorithm version, key, and key length.
  • The viewer checks if the V attribute has been added to the dictionary and, if not, it sets V to the algorithm version.
  • The viewer sets the Length attribute if V is 2 or greater.
  • The viewer adds the encryptDict to the document.

Related Methods

Syntax

void PDCryptFillEncryptDictProc(PDDoc pdDoc, CosObj encryptDict);

Parameters

pdDoc
IN/OUT The document to save.
encryptDict
IN/OUT A dictionary Cos object to fill with whatever information the security handler wants to store in the PDF file. Unlike all other strings and streams, direct object elements of the encryptDict are not encrypted automatically. If you want them encrypted, you must encrypt them before inserting them into the dictionary.

Used In

PDCryptFilterAuthorizeProc

Header: PDExpT.h:5106

Description

(Optional) A callback for PDCryptFilterHandler. Acrobat's security mechanism calls this method to determine whether the user should have access to this filter.

Syntax

ASBool PDCryptFilterAuthorizeProc(CosDoc dP, ASAtom filterName, CosObj encryptDict, ASBool bEncrypt, ASBool bUIAllowed);

Parameters

dP
The document for which to perform authorization.
filterName
The name of the security filter.
encryptDict
The encryption dictionary to use.
bEncrypt
true if authorization is for an encryption operation, false if it is for a decryption operation.
bUIAllowed
true if the caller can bring up the security dialogs as needed, false otherwise.

Returns

true if the user has access to this filter, false otherwise.

Used In

PDCryptFilterGetDataProc

Header: PDExpT.h:5129

Description

(Optional) A callback for PDCryptFilterHandler. Acrobat's security mechanism calls this method to retrieve the encryption/decryption key for this filter. It is called only when the filter's encryption method is V2.

Syntax

ASInt32 PDCryptFilterGetDataProc(CosDoc dP, ASAtom filterName, char **key, ASBool bNewKey, ASBool bUIAllowed);

Parameters

dP
The document whose data is retrieved.
filterName
The name of the security filter.
key
(Filled by the method) A pointer to the encryption/decryption key.
bNewKey
true if you want to retrieve a new key (changed since opening the file), false otherwise.
bUIAllowed
true if the caller can bring up the security dialogs as needed, false otherwise.

Used In

PDCryptFilterStreamProc

Header: PDExpT.h:5081

Description

(Optional) A callback for PDCryptFilterHandler. Callbacks that conform to this prototype are called to encrypt or decrypt streams from a document.

The first call to a procedure of this type must fill out an ASCryptStmRec structure with pointers to callback routines for various types of stream access; see ASCryptStmProcs().

Syntax

void PDCryptFilterStreamProc(CosDoc dP, ASAtom filterName, ASCryptStm stm, ASBool handOff, CosObj params, ASInt32 stmLength);

Parameters

dP
The document containing the stream.
filterName
The name of the security filter in use.
stm
The security stream structure containing the stream itself, access information, and an ASCryptStmRec. This callback function is called upon opening the stream; the first call must initialize the stream.
handOff
true if the method should close the base stream when it closes the filter, false otherwise.
params
A Cos object containing parameters for the operation, as specified for the filter.
stmLength
For a decryption operation, the requested number of bytes; for an encryption operation, the number of bytes in the stream contained in stm.

Used In

PDCryptFreeAuthDataProc

Header: PDExpT.h:4701

Description

(Optional) A callback for PDCryptHandler. It is used to free authorization data acquired via PDCryptNewAuthDataProc(). If this callback is omitted, the viewer defaults to freeing the data using ASfree().

Syntax

void PDCryptFreeAuthDataProc(PDDoc pdDoc, void *authData);

Parameters

pdDoc
IN/OUT The document whose authorization data is freed.
authData
IN/OUT (Filled by the callback) A pointer to the document's authorization data.

Used In

PDCryptFreeCryptDataProc

Header: PDExpT.h:4715

Description

(Optional) A callback for PDCryptHandler. It is used to free authorization data acquired via PDCryptNewCryptDataProc(). If this callback is omitted, the viewer defaults to freeing the data using ASfree().

Syntax

void PDCryptFreeCryptDataProc(PDDoc pdDoc, char *cryptData);

Parameters

pdDoc
IN/OUT The document whose encryption/decryption data is freed.
cryptData
IN/OUT (Filled by the callback) A pointer to the document's encryption/decryption data.

Used In

PDCryptFreeSecurityDataProc

Header: PDExpT.h:4687

Description

(Optional) A callback for PDCryptHandler. It is used to free security data acquired via PDCryptNewSecurityDataProc(). If this callback is omitted, the viewer defaults to freeing the data using ASfree().

Syntax

void PDCryptFreeSecurityDataProc(PDDoc pdDoc, void *secData);

Parameters

pdDoc
IN/OUT The document whose security data is freed.
secData
IN/OUT (Filled by the callback) A pointer to the document's security data.

Used In

PDCryptGetAuthDataExProc

Header: PDExpT.h:4783

Description

Replaces PDCryptGetAuthDataProc(). It is called whenever Acrobat needs to get authorization data and/or check permissions for operations.

PDPerms are obsolete. Acrobat provides permission controls, but Acrobat still supports old security handlers.

Related Methods

Syntax

ASBool PDCryptGetAuthDataExProc(PDDoc pdDoc, PDPermReqObj reqObj, PDPermReqOpr reqOpr, void **authDataP);

Parameters

pdDoc
The document for which the request is made.
reqObj
The object type that is the focus of the request: it is one of the PDPermReqObj values.
reqOpr
The operation type that is the focus of the request: it is one of the PDPermReqOpr values.
authDataP
A pointer to an authorization data structure. Its format is security handler-specific.

Returns

true unless the operation should be cancelled (for example, if the user cancels a dialog), false otherwise.

Used In

PDCryptGetAuthDataProc

Header: PDExpT.h:4492

Description

A callback for PDCryptHandler. This callback is called from a PDAuthProc when a file is opened after PDCryptNewSecurityDataProc() is called.

The callback must determine the user's authorization properties for the document by obtaining authorization data, such as a user interface log in or password entry. It populates an authorization data structure with this data.

This callback may call the security handler's PDCryptNewAuthDataProc() to allocate the authorization data structure. The use of an authorization data structure is optional (an implementation may wish to contain authorization data within the security data structure). The authorization data structure is subsequently used by the security handler's PDCryptAuthorizeProc() to determine whether the user is authorized to open the file.

A security handler can specify the standard password dialog box by using AVCryptGetPassword(). In this case, authData is a char *.

Syntax

ASBool PDCryptGetAuthDataProc(PDDoc pdDoc, PDPerms permWanted, void **authDataP);

Parameters

pdDoc
The document to open.
permWanted
Either pdPermOpen or pdPermSecure. Since this value is also passed to PDCryptAuthorizeProc(), it may not be necessary for this callback to use permWanted.
authDataP
A pointer to the authorization data structure. Set it to NULL if it is not used.

Returns

true unless the operation should be cancelled (for example, if the user cancels a dialog), false otherwise.

Used In

PDCryptGetDocPermsProc

Header: PDExpT.h:4876

Description

A callback for PDCryptHandler. This function should extract and return information about the document permissions to display for the user: whether the user can print, edit, copy text and graphics, edit notes and do form fill in and signing.

The permissions returned are logically AND-ed with the document permissions returned by any other permissions handlers, and displayed to the user. All crypt handlers should implement this call so that consolidated permissions can be displayed. To display your own crypt handler's permissions, implement PDCryptDisplaySecurityDataProc().

If this callback is absent, Acrobat assumes that all the operations on the document are allowed.

Related Methods

Syntax

void PDCryptGetDocPermsProc(PDDoc pdDoc, ASBool perms [PDPermReqObjLast] [PDPermReqOprLast], ASInt16 *version);

Parameters

pdDoc
The document whose permissions are obtained.
perms
(Filled by the callback) An array of the document's permissions. For each combination of PDPermReqObj and PDPermReqOpr, the value is true if the operation is allowed for the object, false if it is not.
version
(Filled by the callback) A pointer to the version number of PDPermReqObj and PDPermReqOpr with which this crypt handler is compatible (specified by the constant PDPermReqVersion).

Used In

PDCryptGetInfoTextProc

Header: PDExpT.h:4911

Description

(Optional) A callback for PDCryptHandler. It provides information for display about document security settings.

Syntax

ASText PDCryptGetInfoTextProc(PDDoc pdDoc, GCHTextType textType);

Parameters

pdDoc
IN The document.
textType
IN The text that should be used:
Value
Description
Text used for a security tool tip. It should be short. Its default is "This document is secured."
Text used for a security hover. It should be medium length. Its default is "This document has been encrypted and may use..."
Text use for Toast on Windows. It can have a longer length. There is no default.

Returns

The ASText value owned by the caller. Use a default value of NULL.

Used In

PDCryptGetSecurityInfoProc

Header: PDExpT.h:4673

Description

(Optional) A callback for PDCryptHandler. It is called by PDDocGetNewSecurityInfo(). It extracts the security information from the security data structure, and returns the security information.

This function is also used after a Save As... to reset the permissions according to the current document.

A default set of permissions is used if this callback is absent:

pdInfoCanPrint|pdInfoCanEdit|pdInfoCanCopy|pdInfoCanEditNotes

See PDPerms.

Related Methods

Syntax

void PDCryptGetSecurityInfoProc(PDDoc pdDoc, ASUns32 *secInfo);

Parameters

pdDoc
The document whose security information is obtained.
secInfo
(Filled by the callback) The document's security information. The value must be an OR of the Security Info Flags. All unused bits in must be set to 1.

Used In

PDCryptNewAuthDataProc

Header: PDExpT.h:4455

Description

(Optional) A callback for PDCryptHandler. It creates a new empty authorization data structure. This structure is subsequently filled by PDCryptGetAuthDataProc(), then passed to PDCryptAuthorizeProc() and eventually to ASfree().

This callback is not called by the Acrobat viewer, but a security handler may use it if it wishes. The Acrobat viewer's standard security handler does not use this method.

Syntax

void *PDCryptNewAuthDataProc(PDDoc pdDoc);

Parameters

pdDoc
The document for which a new authorization data structure is created.

Returns

The newly created authorization data structure.

Used In

PDCryptNewCryptDataExProc

Header: PDExpT.h:4738

Description

A callback for PDCryptHandler. It sets up the key to be passed to initialize the RC4 cipher for encryption and decryption of a PDF file. It is called when an encrypted document is opened or saved.

The key is truncated when the length is greater than the viewer currently supports. Data is freed by PDCryptFreeCryptDataProc() if provided. Otherwise, ASfree() is used.

Related Methods

Syntax

void PDCryptNewCryptDataExProc(PDDoc pdDoc, char **cryptData, ASInt32 *cryptDataLen, ASInt32 *cryptVersion);

Parameters

pdDoc
IN/OUT The document for which the key is set.
cryptData
IN/OUT (Filled by the callback) The key. cryptData must be allocated by ASmalloc() because the Acrobat viewer will free it using ASfree().
cryptDataLen
IN/OUT (Filled by the callback) The number of bytes in cryptData. It cannot be greater than 5 bytes.
cryptVersion
IN/OUT The Cos crypt version, which is the version of the algorithm that is used to encrypt and decrypt document data. cryptVersion equal to 0 is treated as cryptVersion equal to 1 to maintain backward compatibility.

Used In

PDCryptNewCryptDataProc

Header: PDExpT.h:4612

Description

A callback for PDCryptHandler. It sets up the key to be passed to initialize the RC4 cipher for encryption and decryption of a PDF file. It is called when an encrypted document is opened or saved.

Related Methods

Syntax

void PDCryptNewCryptDataProc(PDDoc pdDoc, char **cryptData, ASInt32 *cryptDataLen);

Parameters

pdDoc
IN/OUT The document for which the key is set.
cryptData
IN/OUT (Filled by the callback) The key. cryptData must be allocated by ASmalloc() because the Acrobat viewer will free it using ASfree().
cryptDataLen
IN/OUT (Filled by the callback) The number of bytes in cryptData. It cannot be greater than 5 bytes.

Used In

PDCryptNewSecurityDataFromOriginalDocProc

Header: PDExpT.h:4811

Description

Called when the application needs to open a rolled back portion of the original document. A rolled back document is the original portion of the document when it is digitally signed. This functionality is used for document modification detection.

A rolled back document still requires authorization data which should be identical to the original document's. However, the authDataP structure is unique to each security handler; therefore, it cannot be duplicated by the application.

This callback is intended for opening a rolled back document silently by asking the security handler to provide authorization data for it. The security handler should be able to duplicate the security data associated with the original document and supply for the rolled back document. The callee is expected to authorize subsequent callbacks, including Crypt Filters.

If this callback is not provided, the security handler is asked for authorization data via a normal call such as PDCryptGetAuthDataExProc(). The side effect might include the security handler's prompting for a password for the rolled back document.

Syntax

ASBool PDCryptNewSecurityDataFromOriginalDocProc(PDDoc pdDoc, CosObj encryptDict, PDDoc alreadyOpenedDoc, CosObj openedEncryptDict, void **authDataP);

Parameters

pdDoc
The document for which the request is made (a rolled back document).
encryptDict
An encryption dictionary for pdDoc. It is here just in case the security handler might need it.
alreadyOpenedDoc
The original PDDoc from which the rolled back document is extracted. It is provided so that the security handler can get security data out for the rolled back document.
openedEncryptDict
The encryption dictionary of the original PDDoc.
authDataP
Used to return security data for the rolled back document.

Returns

true unless the security handler cannot provide authorization data for the requested document.

Used In

PDCryptNewSecurityDataProc

Header: PDExpT.h:4535

Description

(Optional) A callback for PDCryptHandler. It creates and populates a new structure that contains whatever security-related information the security handler requires (for example, permissions, whether the file has owner and/or user passwords, owner and/or user passwords, or other data used internally by the security handler). If encryptDict is not NULL, the structure should be populated based on the encryptDict parameter's contents. This method is intended only to initialize the security data structure.

This callback is called under two circumstances:

  • When a document is opened, it is called with encryptDict set to the document's Encryption dictionary. The handler should then populate the new security data structure with data that is obtained from the Encryption dictionary.
  • When the user chooses a new encryption method, it is called without an encryptDict. The handler should return a security data structure with default values.

If a security handler does not have this callback, the document's newSecurityData field is set to NULL.

If a file is to be saved, then PDCryptUpdateSecurityDataProc() is subsequently called to allow user interface modification of the contents.

Security data is freed using PDCryptFreeSecurityDataProc(). If PDCryptFreeSecurityDataProc() is not defined, ASfree() is used.

Syntax

void *PDCryptNewSecurityDataProc(PDDoc pdDoc, CosObj encryptDict);

Parameters

pdDoc
The document for which a new security data structure is created.
encryptDict
If encryptDict is a dictionary, this callback must initialize the security data so that it corresponds to the dictionary. Otherwise, it must set up default values in the security data structure.

Returns

The newly created security data structure.

Used In

PDCryptReservedProc

Header: PDExpT.h:4833

Description

(Optional) A callback for PDCryptHandler. It is used by the Acrobat WebBuy proprietary method of passing crypt data.

Syntax

void *PDCryptReservedProc(void);

Used In

PDCryptReservedProc2

Header: PDExpT.h:4916

Description

(Optional) Used by Acrobat for Automated Permission Testing.

Syntax

void *PDCryptReservedProc2(PDDoc pdDoc, ASCab settings);

Used In

PDCryptUpdateSecurityDataProc

Header: PDExpT.h:4596

Description

A callback for PDCryptHandler. It updates the security data structure that was created by PDCryptNewSecurityDataProc(). This structure can be obtained by calling PDDocGetNewSecurityData(). The security data structure of the previously saved file can be obtained with a call to PDDocGetSecurityData().

The security data structure should be updated to reflect the encryption parameters that will be used when saving the file (this information is usually obtained via dialogs). The encryption parameters are transferred to the Encrypt dictionary by a subsequent callback to PDCryptFillEncryptDictProc().

The security data should be allocated by ASmalloc() or a related function. Security data is freed using PDCryptFreeSecurityDataProc(). If PDCryptFreeSecurityDataProc() is not defined, ASfree() is used.

The callback can also update the security handler itself. For example, the standard encryption handler switches to no encryption if no passwords or permissions are set in the security dialog box. Return ASAtomNull in cryptHandler if no encryption is used in the saved file.

Syntax

ASBool PDCryptUpdateSecurityDataProc(PDDoc pdDoc, ASAtom *cryptHandler, void **secDataP);

Parameters

pdDoc
The document whose security data is updated.
cryptHandler
The current security handler for pdDoc. It can be modified to change the security handler. Encryption is turned off if ASAtomNull is set.
secDataP
(Required) A security data structure. Its content and organization is up to the security handler.

Returns

true unless the operation should be cancelled (for example, the user clicked on the Cancel button).

Used In

PDCryptValidateSecurityDataProc

Header: PDExpT.h:4559

Description

(Optional) A callback for PDCryptHandler. It validates the security data structure, which specifies the user's permissions. This callback may modify the security data structure (for example, because the user is not authorized to change the security as they requested). A client may have called PDDocNewSecurityData() to obtain a new security data structure, then modified it, and then called PDDocSetNewSecurityData() to change the document security. This callback should be called before actually setting the document's security data.

This callback is not called automatically by the Acrobat viewer. It must be called, if desired, by the security handler's PDCryptUpdateSecurityDataProc().

Syntax

void PDCryptValidateSecurityDataProc(PDDoc pdDoc, void *secData);

Parameters

pdDoc
IN/OUT The document whose security data is validated.
secData
IN/OUT (May be modified by the callback) The document's security data.

Used In

PDCrypt Structures

_t_PDCryptBatchHandler

Header: PDExpT.h:5180

Description

Callbacks used to open secured files and to modify security settings while batch processing a list of files. These callbacks are not called while opening files through the user interface. In addition, the regular PDCryptHandler functions are not called during batch operations.

Syntax

struct _t_PDCryptBatchHandler {
ASSize_t size;
Set this to sizeof(PDCryptBatchHandlerRec).
PDCryptBatchShowDialogProc BatchShowDialog;
This function should display a dialog box that allows a user to enter data that will be used to batch secure a series of files. The data is stored in an ASCab which is part of a Batch sequence file. The actual security data, including password(s), should be stored as a pointer in the ASCabinet so that password information is not serialized to disk. Pointers are not serialized from ASCab objects, but ASText objects, ASInt32 objects, and ASBool objects are serialized.
PDCryptBatchParamDescProc BatchParamDesc;
The developer should provide information about the current batch settings for the security handler. Batch settings are provided as a read-only ASCab which is passed in to the function. A writeable ASCab is also provided, which should be used to store parameter information about the security handler. The description information should be stored starting in the paramDesc ASCab using ASText objects starting with key "1".
PDCryptBatchNewAuthDataProc BatchNewAuthData;

This is different from the regular PDCryptHandler NewAuthData function. It creates and returns a void * which is the authorization data for the batch security handler. This data should be used to batch both open files and secure files. Therefore, make sure to provide password information for both the pdPermOpen and pdPermSecure cases, and pass to Authorize and eventually to ASfree().

This authorization data is collected before any files are opened in the Batch sequence. It is permitted to display a user interface at this point since the Batch operation has not started yet. The data applies to all files, and therefore could represent one or more passwords which can be enumerated in the BatchAuthorize function which receives the Batch authData.

PDCryptBatchAuthorizeProc BatchAuthorize;
Called when a PDF file is opened. It is first called with NULL authData for the case without a user password. It is called again with authorization data provided for the security handler that matches the one used in the PDF file. During a Batch operation, a file will first be opened with the pdPermSecure bit set. It will then be opened with the pdPermOpen bit set.
PDCryptBatchFreeAuthDataProc BatchFreeAuthData;
If provided, this must be used to free the authData acquired via BatchGetAuthData or BatchNewAuthData. If no BatchFreeAuthData function is provided, a default one will be used which calls ASfree() on the authData if it is non- NULL.
PDCryptBatchUpdateSecurityDataProc BatchUpdateSecurityData;
This function should update the crypt handler's security data without bringing up a dialog. This data is provided by a PDCryptShowBatchDialogProc(). The current security data can be obtained by calling PDDocGetNewSecurityData(). This function should return true unless there is a problem with the batch data for this security handler.
PDCryptBatchPreSequenceProc BatchPreSequence;

This function is called at the beginning of a Batch sequence before any files have been opened. This allows a security handler to be called back with the ASCab of settings that were filled out by the BatchShowDialog() function, or by an ASCabinet that was read in from disk. Pointers of security information are not serialized to disk, and therefore a security information structure may need to be regenerated based on other security information in the ASCabinet.

It is permitted for the BatchPreSequence callback to display a user interface asking the user for more information since the Batch sequence has not started yet.

If this function returns false, the viewer will assume that the command cannot be executed, and will cancel the sequence.

PDCryptBatchPostSequenceProc BatchPostSequence;
This function is called at the end of a Batch sequence after all files have been processed. Any memory that was allocated in the BatchPreSequence call should be cleaned up in this callback.
} PDCryptBatchHandlerRec;

Used In

_t_PDCryptFilterHandler

Header: PDExpT.h:5152

Description

    PDCrypt Filter support:
  • Encryption callback routines are optional. However, the security handler is responsible for not allowing the application to cause a Full Save.
  • String encryption/decryption support is not required.
  • The DecryptStream callback can be NULL if the crypt filter handler does not perform encryption/decryption on its own. In such cases, GetDataProc must be supplied.
  • Crypt Filter handlers are expected to return 0 length buffer (or EOF) when unauthorized access is made.

The CryptStringProcs string callback is expected to return the desired buffer size (the required destination buffer length) when NULL is passed as the destination buffer. This mechanism is to allow a different buffer length upon encryption/decryption.

About the ASCryptStm in the callback: upon the first call (back) to Encrypt/Decrypt stream procs, the handler is expected to fill out an ASCryptStmRec. ASCryptStm has pointers to callback routines for various stream access. Subsequent stream access is made to these callback routines. See ASExpT.h for the ASCryptStmRec definition.

Syntax

struct _t_PDCryptFilterHandler {
ASSize_t size;
Set this to sizeof(PDCryptFilterHandlerRec).
Called to get crypt data when the application's built-in method is used.
PDCryptFilterStreamProc DecryptStream;
PDCryptFilterStreamProc EncryptStream;
PDCryptFilterStringProc DecryptString;
PDCryptFilterStringProc EncryptString;
} PDCryptFilterHandlerRec;

Used In

_t_PDCryptHandler

Header: PDExpT.h:5275

Description

A data structure containing callbacks that implement a security handler. The callbacks implement the security handler functions. For example, they get authorization data such as a password from the user, set permissions, read and write security-related data in a PDF file, and so on.

Syntax

struct _t_PDCryptHandler {
ASSize_t size;
Set this to sizeof(PDCryptHandlerRec). PDRegisterCryptHandler uses this to determine if the caller was compiled with an old version of this structure declaration. PDRegisterCryptHandler() will raise genErrBadParam if the size does not correspond to a known size of this struct.

This function will be called when a user tries to open or set security for an encrypted document. PermsWanted will be either pdPermOpen or pdPermSecure. This function should return the permissions granted based on the authData. For opening, the permissions returned usually should be pdPermOpen and some or all of pdPermPrint, pdPermEdit, and pdPermCopy. For setting security, permissions returned should be pdPermAll. However, if authorization fails, 0 should be returned. The function is first called with authData equal to NULL. If that fails, GetAuthData is called and the authData from it is passed to Authorize.

If this function is called to authorize Open, decryption will not yet have been installed. So while any part of the document may be examined, some calls must be avoided. For example, a call that causes a page to be parsed will probably result in an error since the encrypted contents will be parsed. In general, it is safe to obtain information about the presence or absence of things, or the number of things, and to examine any part of a document at the Cos level.

Creates and returns a new struct that can be filled out and passed to Authorize and eventually to ASfree(). This function is not called by the standard security mechanism but may be called by extensions that want to gain access to a protected document. This function need not be implemented if clients can simply allocate data using ASmalloc(). In fact, the standard CryptHandler does not.
This function obtains authorization data from the user. As with Authorize, permsWanted will be either pdPermOpen or pdPermSecure. This function should allocate authData to be used by Authorize. The function should return true unless the operation should be cancelled (for example, if the user cancels a dialog). A crypt handler can specify the standard password dialog box by using AVCryptGetPassword(). In this case, the authData will be a char * that should be freed using ASfree() after Authorize is called.
PDCryptNewSecurityDataProc NewSecurityData;
Creates a new struct that contains information corresponding to information in the security dialog. If encryptDict is a dictionary, initialize the security data to correspond to the dictionary. Otherwise, set up defaults. This function will be called when opening a document with encryptDict set to the document's encryptDict. It will also be called when a user chooses new encryption.
PDCryptValidateSecurityDataProc ValidateSecurityData;
Validates the security data, modifying it as necessary. A client may have called PDDocNewSecurityData() to obtain a new security data structure, then modified it, and then called PDDocSetNewSecurityData() to change the document security. This is called before actually setting the document's security data.
PDCryptUpdateSecurityDataProc UpdateSecurityData;
This function should update the crypt handler's security data, usually by displaying a dialog. The current security data can be obtained by calling PDDocGetNewSecurityData(). Like GetAuthData, this function should return true unless cancelled. The security data should be created with ASmalloc() so that it can later be freed by ASfree(). The function can also update the cryptHandler itself. For example, the built-in encryption switches to no encryption if no passwords or permissions are set in the security dialog.
Sets up the key to be passed to initialize the RC4 cipher for encryption and decryption. The length may not be greater than 5 to satisfy the current US export control regulations. Data should be allocated by ASmalloc() or a relative so that it may be freed by ASfree().
PDCryptFillEncryptDictProc FillEncryptDict;
This function should fill the encryption dictionary with whatever information is to be stored in the document. Unlike all other strings and streams, direct object elements of the encryption dictionary are not encrypted automatically. They must be encrypted before they are inserted into the dictionary.
PDCryptGetSecurityInfoProc GetSecurityInfo;
This function should return information about security for display to the user: whether the document has owner and user passwords and whether the user password enables printing, editing, copying text and graphics, and editing notes. See PDexpt.h for possible permissions. All other bits in secInfo should be set to 1. This function is also used after a SaveAs to reset the permissions according to the current document.
PDCryptFreeSecurityDataProc FreeSecurityData;
If provided, this must be used to free securityData acquired via NewSecurityData.
If provided, must be used to free authData acquired via GetAuthData or NewAuthData.
PDCryptFreeCryptDataProc FreeCryptData;
If provided, this must be used to free cryptData acquired via NewCryptData.
PDCryptNewCryptDataExProc NewCryptDataEx;
Sets up the key to be passed to initialize the RC4 cipher and the version of algorithm for encryption and decryption. The key will be truncated when the length is greater than the viewer currently supports. Data will be freed by FreeCryptData if provided. Otherwise, ASfree() is used.
This was added to replace PDCryptGetAuthDataProc(). There are now new permission controls. PDPerms are obsolete. Yet, the viewer still supports the old security handler. It is called whenever the viewer needs to get authorization data and/or check permission for operation(s).
PDCryptGetAuthDataExProc GetAuthDataEx;
This was added to replace PDCryptGetAuthDataProc(). There are now new permission controls. PDPerms are obsolete. Yet, the viewer still supports the old security handler. It is called whenever the viewer needs to get authorization data and/or check permission for operation(s).
PDCryptDisplaySecurityDataProc DisplaySecurityData;
When the security handler is called, it should pop up a dialog box with current permission settings. This callback was added to provide the security handler with a way to display its custom permission settings. It should return true if it wants a callback to modify security settings. Otherwise, it should return false.
PDCryptReservedProc GetReservedData;
Used for the Acrobat Web Buy proprietary method of passing encrypted data.
PDCryptBatchHandler CryptBatchHandler;
A pointer to the PDCryptBatchHandler structure. If this parameter is non- NULL, the security handler will work in a Batch environment, either for decrypting PDF files or encrypting them on Save with a new security handler.
PDCryptCanParseEncryptDictProc CanParseEncryptDict;
This call is used to provide PDCrypt handler interoperability. When an encrypted ducument is being opened and the security handler specified in the encryption dictionary is not present, the viewer will call this function on existing security handlers to see if one of them can be used to open the document.
PDCryptFilterHandler CryptFilterHandler;
A pointer to the PDCryptFilterHandler structure. If this parameter is non- NULL, the security handler supports the Crypt Filter.
This function should return information about the document permissions for display to the user: whether the user can print, edit, copy text and graphics, edit notes and do form fill in and signing. See PDexpt.h for possible permissions.
PDCryptEncryptDocMetadata EncryptDocMetadata;
It determines whether a document's metadata will be encrypted. If this call is not implemented, the metadata is always encrypted.
PDCryptNewSecurityDataFromOriginalDocProc NewSecurityDataFromOrgDoc;

Used for opening a rolled back document (the original portion of a signed document). If this call is not implemented, the security handler is asked for authorization. Since authorization is already requested for the document, this would be the second authorization call for the rolled back part.

The callee is expected to authorize the opening of this document using an already opened document, including the subsequent callback to authorize the Crypt Filter(s).

Used by Acrobat to display user interface information about the document.
PDCryptReservedProc2 SetTestPerms;
} PDCryptHandlerRec;

Used In

PDCrypt Functions

PDCryptAuthorizeFilterAccess

Header: PDProcs.h:10883

Description

Gets authorization to encrypt or decrypt an embedded file, where that file's cryptographic filter is not the one used to open the document in which the file is embedded.

Syntax

ASBool PDCryptAuthorizeFilterAccess(PDDoc doc, ASAtom handlerName, ASAtom filterName, ASBool bEncrypt);

Parameters

doc
The document containing the embedded file whose filter access is requested.
handlerName
The security handler containing the Authorize() callback procedure to run.
filterName
The ASAtom corresponding to the name of the security filter used by the embedded file.
bEncrypt
When true, the access is required for an encryption operation. When false, it is a decryption operation.

Returns

true if the authorization succeeds, false otherwise.

Exceptions

is raised if there is no security handler registered for the document.

PDRegisterCryptHandler

Header: PDProcs.h:2602

Description

Registers a new security handler with the Acrobat viewer.

Syntax

void PDRegisterCryptHandler(PDCryptHandler handler, const char *pdfName, const char *userName);

Parameters

handler
A pointer to a structure that contains the security handler's callback functions. This structure must not be freed after calling PDRegisterCryptHandler().
pdfName
The name of the security handler as it will appear in the PDF file. This name is also used by PDDocSetNewCryptHandler(). Storage for this name can be freed after PDRegisterCryptHandler() has been called.
userName
The name of the security handler as it will be shown in menus. This name can be localized into different languages. Storage for this name can be freed after PDRegisterCryptHandler() has been called.

Exceptions

is raised if the security handler's size field is incorrect.
is raised if either pdfName or userName are already in use by a registered security handler.
is raised is memory is exhausted. Other exceptions may be raised as well.

PDRegisterCryptHandlerEx

Header: PDProcs.h:6126

Description

Registers a new security handler with the Acrobat viewer. It is the same as PDRegisterCryptHandler() except that it accepts a client data parameter.

Syntax

void PDRegisterCryptHandlerEx(PDCryptHandler handler, const char *pdfName, const char *userName, void *clientData);

Parameters

handler
A pointer to a structure that contains the security handler's callback functions. This structure must not be freed after calling PDRegisterCryptHandlerEx().
pdfName
The name of the security handler as it will appear in the PDF file. This name is also used by PDDocSetNewCryptHandler(). Storage for this name can be freed after PDRegisterCryptHandlerEx() has been called.
userName
The name of the security handler as it will be shown in menus. This name can be localized to different languages. Storage for this name can be freed after PDRegisterCryptHandlerEx() has been called.
clientData
A pointer to user-supplied data to store with the handler.

Exceptions

is raised if the security handler's size field is incorrect.
is raised if either pdfName or userName are already in use by a registered security handler.
is raised is memory is exhausted.