diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-09-28 18:26:44 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-09-28 18:30:24 +0200 |
commit | d3d720b14c0bbfc849f8562d02b471e223e1b0bc (patch) | |
tree | 6e85a07fb4f30d1b8284b4286625b81144d3e9ce /sdext | |
parent | 050d74b558f896ab510a31bcffde2e0346fc5bd8 (diff) |
rhbz#826526 Inform user about unsupported PDF encryption formats
...with a crudely reused "Version Incompatibility" message box (TODO: improve),
rather than keeping asking for a password.
Change-Id: I8239232704a4426af7a14a729840d184a502d2df
Diffstat (limited to 'sdext')
-rw-r--r-- | sdext/source/pdfimport/inc/pdfihelper.hxx | 4 | ||||
-rw-r--r-- | sdext/source/pdfimport/inc/pdfparse.hxx | 3 | ||||
-rw-r--r-- | sdext/source/pdfimport/misc/pwdinteract.cxx | 41 | ||||
-rw-r--r-- | sdext/source/pdfimport/pdfparse/pdfentries.cxx | 15 | ||||
-rw-r--r-- | sdext/source/pdfimport/wrapper/wrapper.cxx | 64 |
5 files changed, 95 insertions, 32 deletions
diff --git a/sdext/source/pdfimport/inc/pdfihelper.hxx b/sdext/source/pdfimport/inc/pdfihelper.hxx index d8f7d3c60e44..ad4774aadd46 100644 --- a/sdext/source/pdfimport/inc/pdfihelper.hxx +++ b/sdext/source/pdfimport/inc/pdfihelper.hxx @@ -196,6 +196,10 @@ namespace pdfi bool bFirstTry, const rtl::OUString& rDocName ); + + void reportUnsupportedEncryptionFormat( + com::sun::star::uno::Reference< + com::sun::star::task::XInteractionHandler > const & handler); } #define USTR(x) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( x ) ) diff --git a/sdext/source/pdfimport/inc/pdfparse.hxx b/sdext/source/pdfimport/inc/pdfparse.hxx index df3e4259ab1a..5e87b89a164a 100644 --- a/sdext/source/pdfimport/inc/pdfparse.hxx +++ b/sdext/source/pdfimport/inc/pdfparse.hxx @@ -253,6 +253,9 @@ struct PDFFile : public PDFContainer virtual PDFEntry* clone() const; bool isEncrypted() const; + + bool usesSupportedEncryptionFormat() const; + // this method checks whether rPwd is compatible with // either user or owner password and sets up decrypt data in that case // returns true if decryption can be done diff --git a/sdext/source/pdfimport/misc/pwdinteract.cxx b/sdext/source/pdfimport/misc/pwdinteract.cxx index e5fb674047bc..81cdcb832208 100644 --- a/sdext/source/pdfimport/misc/pwdinteract.cxx +++ b/sdext/source/pdfimport/misc/pwdinteract.cxx @@ -26,9 +26,14 @@ * ************************************************************************/ +#include "sal/config.h" + +#include <cassert> #include "pdfihelper.hxx" +#include <boost/noncopyable.hpp> +#include <com/sun/star/task/ErrorCodeRequest.hpp> #include <com/sun/star/task/XInteractionHandler.hpp> #include <com/sun/star/task/XInteractionRequest.hpp> #include <com/sun/star/task/XInteractionPassword.hpp> @@ -36,8 +41,9 @@ #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/compbase2.hxx> +#include <cppuhelper/implbase1.hxx> #include <cppuhelper/basemutex.hxx> - +#include <tools/errcode.hxx> using namespace com::sun::star; @@ -125,6 +131,32 @@ void SAL_CALL PDFPasswordRequest::select() throw (uno::RuntimeException) m_bSelected = true; } +class UnsupportedEncryptionFormatRequest: + public cppu::WeakImplHelper1< task::XInteractionRequest >, + private boost::noncopyable +{ +public: + UnsupportedEncryptionFormatRequest() {} + +private: + virtual ~UnsupportedEncryptionFormatRequest() {} + + virtual uno::Any SAL_CALL getRequest() throw (uno::RuntimeException) { + return uno::makeAny( + task::ErrorCodeRequest( + OUString(), uno::Reference< uno::XInterface >(), + ERRCODE_IO_WRONGVERSION)); + //TODO: should be something more informative than crudely reused + // ERRCODE_IO_WRONGVERSION + } + + virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > + SAL_CALL getContinuations() throw (uno::RuntimeException) { + return + uno::Sequence< uno::Reference< task::XInteractionContinuation > >(); + } +}; + } // namespace namespace pdfi @@ -159,6 +191,13 @@ bool getPassword( const uno::Reference< task::XInteractionHandler >& xHandler, return bSuccess; } +void reportUnsupportedEncryptionFormat( + uno::Reference< task::XInteractionHandler > const & handler) +{ + assert(handler.is()); + handler->handle(new UnsupportedEncryptionFormatRequest); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sdext/source/pdfimport/pdfparse/pdfentries.cxx b/sdext/source/pdfimport/pdfparse/pdfentries.cxx index 259d700adc78..9a7855492685 100644 --- a/sdext/source/pdfimport/pdfparse/pdfentries.cxx +++ b/sdext/source/pdfimport/pdfparse/pdfentries.cxx @@ -1224,17 +1224,22 @@ static bool check_user_password( const OString& rPwd, PDFFileImplData* pData ) return bValid; } +bool PDFFile::usesSupportedEncryptionFormat() const +{ + return m_pData->m_bStandardHandler && + m_pData->m_nAlgoVersion >= 1 && + m_pData->m_nAlgoVersion <= 2 && + m_pData->m_nStandardRevision >= 2 && + m_pData->m_nStandardRevision <= 3; +} + bool PDFFile::setupDecryptionData( const OString& rPwd ) const { if( !impl_getData()->m_bIsEncrypted ) return rPwd.isEmpty(); // check if we can handle this encryption at all - if( ! m_pData->m_bStandardHandler || - m_pData->m_nAlgoVersion < 1 || - m_pData->m_nAlgoVersion > 2 || - m_pData->m_nStandardRevision < 2 || - m_pData->m_nStandardRevision > 3 ) + if( ! usesSupportedEncryptionFormat() ) return false; if( ! m_pData->m_aCipher ) diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index 61d4b29af31b..2d76fff27419 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -927,38 +927,50 @@ static bool checkEncryption( const rtl::OUString& o_rIsEncrypted = pPDFFile->isEncrypted(); if( o_rIsEncrypted ) { - bool bAuthenticated = false; - if( !io_rPwd.isEmpty() ) + if( pPDFFile->usesSupportedEncryptionFormat() ) { - rtl::OString aIsoPwd = rtl::OUStringToOString( io_rPwd, - RTL_TEXTENCODING_ISO_8859_1 ); - bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd.getStr() ); - } - if( bAuthenticated ) - bSuccess = true; - else - { - if( i_xIHdl.is() ) + bool bAuthenticated = false; + if( !io_rPwd.isEmpty() ) + { + rtl::OString aIsoPwd = rtl::OUStringToOString( io_rPwd, + RTL_TEXTENCODING_ISO_8859_1 ); + bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd.getStr() ); + } + if( bAuthenticated ) + bSuccess = true; + else { - bool bEntered = false; - do + if( i_xIHdl.is() ) { - bEntered = getPassword( i_xIHdl, io_rPwd, ! bEntered, i_rDocName ); - rtl::OString aIsoPwd = rtl::OUStringToOString( io_rPwd, - RTL_TEXTENCODING_ISO_8859_1 ); - bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd.getStr() ); - } while( bEntered && ! bAuthenticated ); + bool bEntered = false; + do + { + bEntered = getPassword( i_xIHdl, io_rPwd, ! bEntered, i_rDocName ); + rtl::OString aIsoPwd = rtl::OUStringToOString( io_rPwd, + RTL_TEXTENCODING_ISO_8859_1 ); + bAuthenticated = pPDFFile->setupDecryptionData( aIsoPwd.getStr() ); + } while( bEntered && ! bAuthenticated ); + } + + OSL_TRACE( "password: %s", bAuthenticated ? "matches" : "does not match" ); + bSuccess = bAuthenticated; + } + if( bAuthenticated ) + { + rtl::OUStringBuffer aBuf( 128 ); + aBuf.appendAscii( "_OOO_pdfi_Credentials_" ); + aBuf.append( pPDFFile->getDecryptionKey() ); + io_rPwd = aBuf.makeStringAndClear(); } - - OSL_TRACE( "password: %s", bAuthenticated ? "matches" : "does not match" ); - bSuccess = bAuthenticated; } - if( bAuthenticated ) + else if( i_xIHdl.is() ) { - rtl::OUStringBuffer aBuf( 128 ); - aBuf.appendAscii( "_OOO_pdfi_Credentials_" ); - aBuf.append( pPDFFile->getDecryptionKey() ); - io_rPwd = aBuf.makeStringAndClear(); + reportUnsupportedEncryptionFormat( i_xIHdl ); + //TODO: this should either be handled further down the + // call stack, or else information that this has already + // been handled should be passed down the call stack, so + // that SfxBaseModel::load does not show an additional + // "General Error" message box } } else |