Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / xpdf / xpdf-3.02-ooopwd.patch
blobf773585b3f912e958532a7bb9634370ac43acfe5
1 --- misc/xpdf-3.02/xpdf/SecurityHandler.cc 2007-02-27 23:05:52.000000000 +0100
2 +++ misc/build/xpdf-3.02/xpdf/SecurityHandler.cc 2011-02-03 16:41:49.000000000 +0100
3 @@ -40,7 +40,7 @@
5 encryptDictA->dictLookup("Filter", &filterObj);
6 if (filterObj.isName("Standard")) {
7 - secHdlr = new StandardSecurityHandler(docA, encryptDictA);
8 + secHdlr = new OOoImportSecurityhandler(docA, encryptDictA);
9 } else if (filterObj.isName()) {
10 #ifdef ENABLE_PLUGINS
11 if ((xsh = globalParams->getSecurityHandler(filterObj.getName()))) {
12 @@ -310,6 +310,60 @@
13 return gTrue;
16 +//------------------------------------------------------------------------
17 +// OOoImportSecurityhandler
18 +//------------------------------------------------------------------------
20 +OOoImportSecurityhandler::~OOoImportSecurityhandler()
24 +inline Guchar toNum( Guchar digit )
26 + return (digit >= '0') && digit <= '9'
27 + ? digit - '0'
28 + : (digit >= 'A' && digit <= 'F')
29 + ? digit - 'A' + 10
30 + : (digit >= 'a' && digit <= 'f')
31 + ? digit - 'a' + 10
32 + : Guchar(0xff);
35 +GBool OOoImportSecurityhandler::authorize(void* authData)
37 + if( !ok )
38 + return gFalse;
39 + if( authData )
40 + {
41 + GString* ownerPassword = ((StandardAuthData *)authData)->ownerPassword;
42 + if( ownerPassword )
43 + {
44 + const char* pStr = ownerPassword->getCString();
45 + if( strncmp( pStr, "_OOO_pdfi_Credentials_", 22 ) == 0 )
46 + {
47 + // a hex encoded byte sequence should follow until end of string
48 + // the length must match fileKeyLength
49 + // if this is the case we can assume that the password checked out
50 + // and the file key is valid
51 + // max len is 16 (the size of the fileKey array)
52 + pStr += 22;
53 + size_t i = 0;
54 + while( pStr[0] && pStr[1] && i < sizeof( fileKey ) )
55 + {
56 + fileKey[i++] = (toNum( *pStr++ ) << 4)
57 + | (toNum( *pStr++ ));
58 + }
59 + if( i == size_t(fileKeyLength) )
60 + {
61 + ownerPasswordOk = gTrue;
62 + return gTrue;
63 + }
64 + }
65 + }
66 + }
67 + return StandardSecurityHandler::authorize( authData );
70 #ifdef ENABLE_PLUGINS
72 //------------------------------------------------------------------------
73 --- misc/xpdf-3.02/xpdf/SecurityHandler.h 2007-02-27 23:05:52.000000000 +0100
74 +++ misc/build/xpdf-3.02/xpdf/SecurityHandler.h 2011-02-03 16:26:17.000000000 +0100
75 @@ -103,7 +103,7 @@
76 virtual int getEncVersion() { return encVersion; }
77 virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
79 -private:
80 +protected:
82 int permFlags;
83 GBool ownerPasswordOk;
84 @@ -119,6 +119,17 @@
85 GBool ok;
88 +class OOoImportSecurityhandler : public StandardSecurityHandler
90 +public:
91 + OOoImportSecurityhandler( PDFDoc* docA, Object* encryptDictA )
92 + : StandardSecurityHandler( docA, encryptDictA )
93 + {}
94 + virtual ~OOoImportSecurityhandler();
96 + virtual GBool authorize(void* authData);
97 +};
99 #ifdef ENABLE_PLUGINS
100 //------------------------------------------------------------------------
101 // ExternalSecurityHandler