diff options
-rw-r--r-- | sfx2/source/dialog/filedlghelper.cxx | 46 | ||||
-rw-r--r-- | svx/inc/mscodec.hxx | 40 | ||||
-rw-r--r-- | svx/source/msfilter/mscodec.cxx | 35 | ||||
-rw-r--r-- | uui/source/iahndl.cxx | 93 | ||||
-rw-r--r-- | uui/source/iahndl.hxx | 16 | ||||
-rw-r--r-- | uui/source/passcrtdlg.cxx | 12 | ||||
-rw-r--r-- | uui/source/passcrtdlg.hrc | 27 | ||||
-rw-r--r-- | uui/source/passcrtdlg.hxx | 2 | ||||
-rw-r--r-- | uui/source/passcrtdlg.src | 67 |
9 files changed, 280 insertions, 58 deletions
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index da9bf4a8b04c..33359a45ec96 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -87,6 +87,7 @@ #endif #include <svtools/pickerhelper.hxx> #include <svtools/docpasswdrequest.hxx> +#include <svtools/docmspasswdrequest.hxx> #include <ucbhelper/content.hxx> #include <ucbhelper/commandenvironment.hxx> #include <comphelper/storagehelper.hxx> @@ -556,6 +557,15 @@ void FileDialogHelper_Impl::updateSelectionBox() } // ------------------------------------------------------------------------ +struct CheckMSPasswordCapability +{ + sal_Bool operator() ( const String rFilterName ) + { + return rFilterName.EqualsAscii("MS Word 97"); + } +}; + +// ------------------------------------------------------------------------ struct CheckPasswordCapability { sal_Bool operator() ( const SfxFilter* _pFilter ) @@ -572,8 +582,9 @@ struct CheckPasswordCapability return true; #endif - return _pFilter->IsOwnFormat() && _pFilter->UsesStorage() - && ( SOFFICE_FILEFORMAT_60 <= _pFilter->GetVersion() ); + return ( _pFilter->IsOwnFormat() && _pFilter->UsesStorage() + && ( SOFFICE_FILEFORMAT_60 <= _pFilter->GetVersion() ) ) + || CheckMSPasswordCapability()( _pFilter->GetFilterName() ); } }; @@ -1660,15 +1671,30 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList, if( xInteractionHandler.is() ) { // TODO: find out a way to set the 1-15 char limits on MS Excel 97 filter. - RequestDocumentPassword* pPasswordRequest = new RequestDocumentPassword( - ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)) ); - - uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest ); - xInteractionHandler->handle( rRequest ); - if ( pPasswordRequest->isPassword() ) - rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + if ( CheckMSPasswordCapability()( rFilter ) ) + { + RequestMSDocumentPassword* pMSPasswordRequest = new RequestMSDocumentPassword( + ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)) ); + + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pMSPasswordRequest ); + xInteractionHandler->handle( rRequest ); + if ( pMSPasswordRequest->isPassword() ) + rpSet->Put( SfxStringItem( SID_PASSWORD, pMSPasswordRequest->getPassword() ) ); + else + return ERRCODE_ABORT; + } else - return ERRCODE_ABORT; + { + RequestDocumentPassword* pPasswordRequest = new RequestDocumentPassword( + ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, *(rpURLList->GetObject(0)) ); + + uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest ); + xInteractionHandler->handle( rRequest ); + if ( pPasswordRequest->isPassword() ) + rpSet->Put( SfxStringItem( SID_PASSWORD, pPasswordRequest->getPassword() ) ); + else + return ERRCODE_ABORT; + } } } } diff --git a/svx/inc/mscodec.hxx b/svx/inc/mscodec.hxx index 631990657470..4ee508d661dd 100644 --- a/svx/inc/mscodec.hxx +++ b/svx/inc/mscodec.hxx @@ -239,6 +239,28 @@ public: bool CreateSaltDigest( const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] ); + /** Encodes a block of memory. + + @see rtl_cipher_encode() + + @precond + The codec must be initialized with InitKey() before this function + can be used. The destination buffer must be able to take all + unencoded data from the source buffer (usually this means it must be + as long as or longer than the source buffer). + + @param pData + Unencrypted source data block. + @param nDatLen + Size of the passed source data block. + @param pBuffer + Destination buffer for the encrypted data. + @param nBufLen + Size of the destination buffer. + + @return + true = Encoding was successful (no error occured). + */ bool Encode( const void* pData, sal_Size nDatLen, sal_uInt8* pBuffer, sal_Size nBufLen ); @@ -283,6 +305,24 @@ public: */ bool Skip( sal_Size nDatLen ); + /** Gets salt data and salt digest. + + @precond + The codec must be initialized with InitKey() before this function + can be used. + + @param pSalt + Salt, a random number. + @param pSaltData + Salt data block generated from the salt. + @param pSaltDigest + Salt digest generated from the salt. + */ + void GetEncryptKey ( + const sal_uInt8 pSalt[16], + sal_uInt8 pSaltData[16], + sal_uInt8 pSaltDigest[16]); + private: void GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 pDigest[16] ); diff --git a/svx/source/msfilter/mscodec.cxx b/svx/source/msfilter/mscodec.cxx index 1e6c9de7112f..591bce8f4f6d 100644 --- a/svx/source/msfilter/mscodec.cxx +++ b/svx/source/msfilter/mscodec.cxx @@ -432,11 +432,12 @@ bool MSCodec_Std97::CreateSaltDigest( const sal_uInt8 nSaltData[16], sal_uInt8 n return (result); } -bool MSCodec_Std97::Encode( +bool MSCodec_Std97::Encode ( const void *pData, sal_Size nDatLen, sal_uInt8 *pBuffer, sal_Size nBufLen) { rtlCipherError result; + result = rtl_cipher_encode ( m_hCipher, pData, nDatLen, pBuffer, nBufLen); @@ -498,6 +499,38 @@ void MSCodec_Std97::GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 memcpy(pDigest, pDigestLocal, 16); } +void MSCodec_Std97::GetEncryptKey ( + const sal_uInt8 pSalt[16], + sal_uInt8 pSaltData[16], + sal_uInt8 pSaltDigest[16]) +{ + if (InitCipher(0)) + { + sal_uInt8 pDigest[RTL_DIGEST_LENGTH_MD5]; + sal_uInt8 pBuffer[64]; + + rtl_cipher_encode ( + m_hCipher, pSalt, 16, pSaltData, sizeof(pBuffer)); + + (void)memcpy( pBuffer, pSalt, 16 ); + + pBuffer[16] = 0x80; + (void)memset (pBuffer + 17, 0, sizeof(pBuffer) - 17); + pBuffer[56] = 0x80; + + rtl_digest_updateMD5 ( + m_hDigest, pBuffer, sizeof(pBuffer)); + rtl_digest_rawMD5 ( + m_hDigest, pDigest, sizeof(pDigest)); + + rtl_cipher_encode ( + m_hCipher, pDigest, 16, pSaltDigest, 16); + + (void)memset (pBuffer, 0, sizeof(pBuffer)); + (void)memset (pDigest, 0, sizeof(pDigest)); + } +} + // ============================================================================ } // namespace svx diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx index 30a4d0f48c94..62de20f87a74 100644 --- a/uui/source/iahndl.cxx +++ b/uui/source/iahndl.cxx @@ -63,6 +63,7 @@ #include "com/sun/star/task/XInteractionHandler.hpp" #include "com/sun/star/task/XInteractionHandler2.hpp" #include "com/sun/star/task/DocumentPasswordRequest.hpp" +#include "com/sun/star/task/DocumentMSPasswordRequest.hpp" #include "com/sun/star/task/ErrorCodeIOException.hpp" #include "com/sun/star/task/ErrorCodeRequest.hpp" #include "com/sun/star/task/MasterPasswordRequest.hpp" @@ -1132,6 +1133,15 @@ bool UUIInteractionHelper::handleDialogRequests( return true; } + star::task::DocumentMSPasswordRequest aDocumentMSPasswordRequest; + if (aAnyRequest >>= aDocumentMSPasswordRequest) + { + handleMSPasswordRequest(aDocumentMSPasswordRequest.Mode, + rRequest->getContinuations(), + aDocumentMSPasswordRequest.Name); + return true; + } + star::task::PasswordRequest aPasswordRequest; if (aAnyRequest >>= aPasswordRequest) { @@ -1839,6 +1849,48 @@ UUIInteractionHelper::executePasswordDialog( } void +UUIInteractionHelper::executeMSPasswordDialog( + LoginErrorInfo & rInfo, + star::task::PasswordRequestMode nMode, + ::rtl::OUString aDocName) + SAL_THROW((star::uno::RuntimeException)) +{ + try + { + vos::OGuard aGuard(Application::GetSolarMutex()); + + std::auto_ptr< ResMgr > + xManager(ResMgr::CreateResMgr(CREATEVERSIONRESMGR_NAME(uui))); + if( nMode == star::task::PasswordRequestMode_PASSWORD_CREATE ) + { + std::auto_ptr< PasswordCreateDialog > + xDialog(new PasswordCreateDialog( + getParentProperty(), xManager.get(), true)); + + rInfo.SetResult(xDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : + ERRCODE_BUTTON_CANCEL); + rInfo.SetPassword( xDialog->GetPassword() ); + } + else + { + std::auto_ptr< PasswordDialog > + xDialog(new PasswordDialog( + getParentProperty(), nMode, xManager.get(), aDocName )); + + rInfo.SetResult(xDialog->Execute() == RET_OK ? ERRCODE_BUTTON_OK : + ERRCODE_BUTTON_CANCEL); + rInfo.SetPassword( xDialog->GetPassword() ); + } + } + catch (std::bad_alloc const &) + { + throw star::uno::RuntimeException( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")), + star::uno::Reference< star::uno::XInterface>()); + } +} + +void UUIInteractionHelper::executeCookieDialog(CntHTTPCookieRequest & rRequest) SAL_THROW((star::uno::RuntimeException)) { @@ -2558,6 +2610,47 @@ UUIInteractionHelper::handlePasswordRequest( } void +UUIInteractionHelper::handleMSPasswordRequest( + star::task::PasswordRequestMode nMode, + star::uno::Sequence< star::uno::Reference< + star::task::XInteractionContinuation > > const & + rContinuations, + ::rtl::OUString aDocumentName ) + SAL_THROW((star::uno::RuntimeException)) +{ + star::uno::Reference< star::task::XInteractionRetry > xRetry; + star::uno::Reference< star::task::XInteractionAbort > xAbort; + star::uno::Reference< star::task::XInteractionPassword > + xPassword; + getContinuations( + rContinuations, 0, 0, &xRetry, &xAbort, 0, &xPassword, 0, 0); + LoginErrorInfo aInfo; + + executeMSPasswordDialog(aInfo, nMode, aDocumentName); + + switch (aInfo.GetResult()) + { + case ERRCODE_BUTTON_OK: + if (xPassword.is()) + { + xPassword->setPassword(aInfo.GetPassword()); + xPassword->select(); + } + break; + + case ERRCODE_BUTTON_RETRY: + if (xRetry.is()) + xRetry->select(); + break; + + default: + if (xAbort.is()) + xAbort->select(); + break; + } +} + +void UUIInteractionHelper::handleCookiesRequest( star::ucb::HandleCookiesRequest const & rRequest, star::uno::Sequence< star::uno::Reference< diff --git a/uui/source/iahndl.hxx b/uui/source/iahndl.hxx index 8b53b071a629..4053f919bf7b 100644 --- a/uui/source/iahndl.hxx +++ b/uui/source/iahndl.hxx @@ -201,6 +201,12 @@ private: ::rtl::OUString aDocumentName) SAL_THROW((com::sun::star::uno::RuntimeException)); + void + executeMSPasswordDialog(LoginErrorInfo & rInfo, + com::sun::star::task::PasswordRequestMode nMode, + ::rtl::OUString aDocumentName) + SAL_THROW((com::sun::star::uno::RuntimeException)); + void executeCookieDialog(CntHTTPCookieRequest & rRequest) SAL_THROW((com::sun::star::uno::RuntimeException)); @@ -280,6 +286,16 @@ private: ::rtl::OUString aDocumentName = ::rtl::OUString()) SAL_THROW((com::sun::star::uno::RuntimeException)); + void + handleMSPasswordRequest( + com::sun::star::task::PasswordRequestMode nMode, + com::sun::star::uno::Sequence< + com::sun::star::uno::Reference< + com::sun::star::task::XInteractionContinuation > > const & + rContinuations, + ::rtl::OUString aDocumentName = ::rtl::OUString()) + SAL_THROW((com::sun::star::uno::RuntimeException)); + void handleCookiesRequest( com::sun::star::ucb::HandleCookiesRequest const & rRequest, diff --git a/uui/source/passcrtdlg.cxx b/uui/source/passcrtdlg.cxx index a57255cddefe..636cd4510ecc 100644 --- a/uui/source/passcrtdlg.cxx +++ b/uui/source/passcrtdlg.cxx @@ -69,19 +69,19 @@ IMPL_LINK( PasswordCreateDialog, OKHdl_Impl, OKButton *, EMPTYARG ) // ----------------------------------------------------------------------- -PasswordCreateDialog::PasswordCreateDialog( Window* _pParent, ResMgr * pResMgr ) +PasswordCreateDialog::PasswordCreateDialog( Window* _pParent, ResMgr * pResMgr, bool bMSCryptoMode) :ModalDialog( _pParent, ResId( DLG_UUI_PASSWORD_CRT, *pResMgr ) ) ,aFTPasswordCrt ( this, ResId( FT_PASSWORD_CRT, *pResMgr ) ) ,aEDPasswordCrt ( this, ResId( ED_PASSWORD_CRT, *pResMgr ) ) ,aFTPasswordRepeat ( this, ResId( FT_PASSWORD_REPEAT, *pResMgr ) ) ,aEDPasswordRepeat ( this, ResId( ED_PASSWORD_REPEAT, *pResMgr ) ) - ,aFTWarning ( this, ResId( FT_PASSWORD_WARNING, *pResMgr ) ) + ,aFTWarning ( this, ResId( bMSCryptoMode ? FT_MSPASSWORD_WARNING : FT_PASSWORD_WARNING, *pResMgr ) ) ,aFixedLine1 ( this, ResId( FL_FIXED_LINE_1, *pResMgr ) ) ,aOKBtn ( this, ResId( BTN_PASSCRT_OK, *pResMgr ) ) ,aCancelBtn ( this, ResId( BTN_PASSCRT_CANCEL, *pResMgr ) ) ,aHelpBtn ( this, ResId( BTN_PASSCRT_HELP, *pResMgr ) ) ,pResourceMgr ( pResMgr ) - ,nMinLen(5) + ,nMinLen( bMSCryptoMode ? 1 : 5 ) { FreeResource(); @@ -90,6 +90,12 @@ PasswordCreateDialog::PasswordCreateDialog( Window* _pParent, ResMgr * pResMgr ) aOKBtn.Enable( sal_False ); + if ( bMSCryptoMode ) + { + aEDPasswordCrt.SetMaxTextLen( 15 ); + aEDPasswordRepeat.SetMaxTextLen( 15 ); + } + long nLabelWidth = aFTWarning.GetSizePixel().Width(); long nLabelHeight = aFTWarning.GetSizePixel().Height(); long nTextWidth = aFTWarning.GetCtrlTextWidth( aFTWarning.GetText() ); diff --git a/uui/source/passcrtdlg.hrc b/uui/source/passcrtdlg.hrc index 4c10fa92fddd..54a09494e2ab 100644 --- a/uui/source/passcrtdlg.hrc +++ b/uui/source/passcrtdlg.hrc @@ -28,19 +28,20 @@ * ************************************************************************/ -#ifndef UUI_PASSCRTDLG_HRC
-#define UUI_PASSCRTDLG_HRC
+#ifndef UUI_PASSCRTDLG_HRC +#define UUI_PASSCRTDLG_HRC -// local identifiers
-#define BTN_PASSCRT_CANCEL 1
-#define ED_PASSWORD_CRT 2
-#define FT_PASSWORD_REPEAT 3
-#define FT_PASSWORD_WARNING 4
-#define ED_PASSWORD_REPEAT 5
-#define FL_FIXED_LINE_1 6
-#define BTN_PASSCRT_OK 7
-#define BTN_PASSCRT_HELP 8
-#define FT_PASSWORD_CRT 9
+// local identifiers +#define BTN_PASSCRT_CANCEL 1 +#define ED_PASSWORD_CRT 2 +#define FT_PASSWORD_REPEAT 3 +#define FT_PASSWORD_WARNING 4 +#define ED_PASSWORD_REPEAT 5 +#define FL_FIXED_LINE_1 6 +#define BTN_PASSCRT_OK 7 +#define BTN_PASSCRT_HELP 8 +#define FT_PASSWORD_CRT 9 +#define FT_MSPASSWORD_WARNING 10 -#endif // UUI_PASSCRTDLG_HRC
+#endif // UUI_PASSCRTDLG_HRC diff --git a/uui/source/passcrtdlg.hxx b/uui/source/passcrtdlg.hxx index 0fefc10d09ba..b4f0f61644d6 100644 --- a/uui/source/passcrtdlg.hxx +++ b/uui/source/passcrtdlg.hxx @@ -58,7 +58,7 @@ class PasswordCreateDialog : public ModalDialog DECL_LINK( EditHdl_Impl, Edit * ); public: - PasswordCreateDialog( Window* pParent, ResMgr * pResMgr ); + PasswordCreateDialog( Window* pParent, ResMgr * pResMgr, bool bMSCryptoMode = false ); String GetPassword() const { return aEDPasswordCrt.GetText(); } }; diff --git a/uui/source/passcrtdlg.src b/uui/source/passcrtdlg.src index cdfc9d380079..13f1ea688620 100644 --- a/uui/source/passcrtdlg.src +++ b/uui/source/passcrtdlg.src @@ -34,7 +34,7 @@ #include <ids.hrc> #endif #ifndef UUI_PASSCRTDLG_HRC -#include "passcrtdlg.hrc"
+#include "passcrtdlg.hrc" #endif ModalDialog DLG_UUI_PASSWORD_CRT @@ -44,61 +44,68 @@ ModalDialog DLG_UUI_PASSWORD_CRT Moveable = TRUE ; OutputSize = TRUE ; SVLook = TRUE ; - Size = MAP_APPFONT( 145, 129 );
+ Size = MAP_APPFONT( 145, 129 ); FixedText FT_PASSWORD_CRT { - Pos = MAP_APPFONT( 3, 4 );
- Size = MAP_APPFONT( 139, 9 );
- Text [ en-US ] = "Enter password";
+ Pos = MAP_APPFONT( 3, 4 ); + Size = MAP_APPFONT( 139, 9 ); + Text [ en-US ] = "Enter password"; }; Edit ED_PASSWORD_CRT { Border = TRUE ; - Pos = MAP_APPFONT( 3, 17 );
+ Pos = MAP_APPFONT( 3, 17 ); Size = MAP_APPFONT( 139, 13 ); PassWord = TRUE ; }; Edit ED_PASSWORD_REPEAT { Border = TRUE ; - Pos = MAP_APPFONT( 3, 47 );
+ Pos = MAP_APPFONT( 3, 47 ); Size = MAP_APPFONT( 139, 13 ); PassWord = TRUE ; }; OKButton BTN_PASSCRT_OK { - Pos = MAP_APPFONT( 27, 110 );
+ Pos = MAP_APPFONT( 27, 110 ); Size = MAP_APPFONT( 37, 15 ); DefButton = TRUE ; }; CancelButton BTN_PASSCRT_CANCEL { - Pos = MAP_APPFONT( 66, 110 );
- Size = MAP_APPFONT( 37, 15 );
+ Pos = MAP_APPFONT( 66, 110 ); + Size = MAP_APPFONT( 37, 15 ); }; HelpButton BTN_PASSCRT_HELP { - Pos = MAP_APPFONT( 105, 110 );
- Size = MAP_APPFONT( 37, 15 );
+ Pos = MAP_APPFONT( 105, 110 ); + Size = MAP_APPFONT( 37, 15 ); }; - FixedText FT_PASSWORD_REPEAT
- {
- Pos = MAP_APPFONT( 3, 34 );
- Size = MAP_APPFONT( 139, 9 );
- Text [ en-US ] = "Reenter password";
- };
- FixedText FT_PASSWORD_WARNING
- {
- Pos = MAP_APPFONT( 4, 64 );
- Size = MAP_APPFONT( 137, 40 );
- Text [ en-US ] = "WARNING: If you lose or forget the password, it cannot be recovered. It is advisable to keep passwords in a safe place. Passwords are case-sensitive and at least five characters long.";
- WordBreak = TRUE;
- };
- FixedLine FL_FIXED_LINE_1
- {
- Pos = MAP_APPFONT( 0, 104 );
- Size = MAP_APPFONT( 145, 6 );
+ FixedText FT_PASSWORD_REPEAT + { + Pos = MAP_APPFONT( 3, 34 ); + Size = MAP_APPFONT( 139, 9 ); + Text [ en-US ] = "Reenter password"; + }; + FixedText FT_PASSWORD_WARNING + { + Pos = MAP_APPFONT( 4, 64 ); + Size = MAP_APPFONT( 137, 40 ); + Text [ en-US ] = "WARNING: If you lose or forget the password, it cannot be recovered. It is advisable to keep passwords in a safe place. Passwords are case-sensitive and at least five characters long."; + WordBreak = TRUE; + }; + FixedText FT_MSPASSWORD_WARNING + { + Pos = MAP_APPFONT( 4, 64 ); + Size = MAP_APPFONT( 137, 40 ); + Text [ en-US ] = "WARNING: If you lose or forget the password, it cannot be recovered. It is advisable to keep passwords in a safe place. Passwords are case-sensitive and at most fifteen characters long."; + WordBreak = TRUE; + }; + FixedLine FL_FIXED_LINE_1 + { + Pos = MAP_APPFONT( 0, 104 ); + Size = MAP_APPFONT( 145, 6 ); }; - Text [ en-US ] = "Enter Password";
+ Text [ en-US ] = "Enter Password"; }; |