Kaydet (Commit) d3d720b1 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst 050d74b5
......@@ -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 ) )
......
......@@ -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
......
......@@ -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: */
......@@ -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 )
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment