1 //========================================================================
5 // Copyright 2004 Glyph & Cog, LLC
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2012 Albert Astals Cid <aacid@kde.org>
18 // To see a description of the changes please see the Changelog file that
19 // came with your tarball or type make ChangeLog if you are building from git
21 //========================================================================
23 #ifndef SECURITYHANDLER_H
24 #define SECURITYHANDLER_H
26 #include "poppler-config.h"
28 #ifdef USE_GCC_PRAGMAS
32 #include "goo/gtypes.h"
37 struct XpdfSecurityHandler
;
39 //------------------------------------------------------------------------
41 //------------------------------------------------------------------------
43 class SecurityHandler
{
46 static SecurityHandler
*make(PDFDoc
*docA
, Object
*encryptDictA
);
48 SecurityHandler(PDFDoc
*docA
);
49 virtual ~SecurityHandler();
51 // Returns true if the file is actually unencrypted.
52 virtual GBool
isUnencrypted() { return gFalse
; }
54 // Check the document's encryption. If the document is encrypted,
55 // this will first try <ownerPassword> and <userPassword> (in
56 // "batch" mode), and if those fail, it will attempt to request a
57 // password from the user. This is the high-level function that
58 // calls the lower level functions for the specific security handler
59 // (requesting a password three times, etc.). Returns true if the
60 // document can be opened (if it's unencrypted, or if a correct
61 // password is obtained); false otherwise (encrypted and no correct
63 GBool
checkEncryption(GooString
*ownerPassword
,
64 GooString
*userPassword
);
66 // Create authorization data for the specified owner and user
67 // passwords. If the security handler doesn't support "batch" mode,
68 // this function should return NULL.
69 virtual void *makeAuthData(GooString
*ownerPassword
,
70 GooString
*userPassword
) = 0;
72 // Construct authorization data, typically by prompting the user for
73 // a password. Returns an authorization data object, or NULL to
75 virtual void *getAuthData() = 0;
77 // Free the authorization data returned by makeAuthData or
79 virtual void freeAuthData(void *authData
) = 0;
81 // Attempt to authorize the document, using the supplied
82 // authorization data (which may be NULL). Returns true if
83 // successful (i.e., if at least the right to open the document was
85 virtual GBool
authorize(void *authData
) = 0;
87 // Return the various authorization parameters. These are only
88 // valid after authorize has returned true.
89 virtual int getPermissionFlags() = 0;
90 virtual GBool
getOwnerPasswordOk() = 0;
91 virtual Guchar
*getFileKey() = 0;
92 virtual int getFileKeyLength() = 0;
93 virtual int getEncVersion() = 0;
94 virtual int getEncRevision() = 0;
95 virtual CryptAlgorithm
getEncAlgorithm() = 0;
102 //------------------------------------------------------------------------
103 // StandardSecurityHandler
104 //------------------------------------------------------------------------
106 class StandardSecurityHandler
: public SecurityHandler
{
109 StandardSecurityHandler(PDFDoc
*docA
, Object
*encryptDictA
);
110 virtual ~StandardSecurityHandler();
112 virtual GBool
isUnencrypted();
113 virtual void *makeAuthData(GooString
*ownerPassword
,
114 GooString
*userPassword
);
115 virtual void *getAuthData();
116 virtual void freeAuthData(void *authData
);
117 virtual GBool
authorize(void *authData
);
118 virtual int getPermissionFlags() { return permFlags
; }
119 virtual GBool
getOwnerPasswordOk() { return ownerPasswordOk
; }
120 virtual Guchar
*getFileKey() { return fileKey
; }
121 virtual int getFileKeyLength() { return fileKeyLength
; }
122 virtual int getEncVersion() { return encVersion
; }
123 virtual int getEncRevision() { return encRevision
; }
124 virtual CryptAlgorithm
getEncAlgorithm() { return encAlgorithm
; }
129 GBool ownerPasswordOk
;
134 GBool encryptMetadata
;
135 CryptAlgorithm encAlgorithm
;
137 GooString
*ownerKey
, *userKey
;
138 GooString
*ownerEnc
, *userEnc
;
143 #ifdef ENABLE_PLUGINS
144 //------------------------------------------------------------------------
145 // ExternalSecurityHandler
146 //------------------------------------------------------------------------
148 class ExternalSecurityHandler
: public SecurityHandler
{
151 ExternalSecurityHandler(PDFDoc
*docA
, Object
*encryptDictA
,
152 XpdfSecurityHandler
*xshA
);
153 virtual ~ExternalSecurityHandler();
155 virtual void *makeAuthData(GooString
*ownerPassword
,
156 GooString
*userPassword
);
157 virtual void *getAuthData();
158 virtual void freeAuthData(void *authData
);
159 virtual GBool
authorize(void *authData
);
160 virtual int getPermissionFlags() { return permFlags
; }
161 virtual GBool
getOwnerPasswordOk() { return gFalse
; }
162 virtual Guchar
*getFileKey() { return fileKey
; }
163 virtual int getFileKeyLength() { return fileKeyLength
; }
164 virtual int getEncVersion() { return encVersion
; }
165 virtual int getEncRevision() { return encRevision
; }
166 virtual CryptAlgorithm
getEncAlgorithm() { return encAlgorithm
; }
171 XpdfSecurityHandler
*xsh
;
178 CryptAlgorithm encAlgorithm
;
181 #endif // ENABLE_PLUGINS