[ooo-build-commit] Branch 'ooo/master' - sfx2/inc sfx2/source svx/inc svx/source

Jan Holesovsky kendy at kemper.freedesktop.org
Wed Jul 1 18:01:23 PDT 2009


 sfx2/inc/sfx2/passwd.hxx             |    1 
 sfx2/source/dialog/filedlghelper.cxx |   20 ++++-
 sfx2/source/dialog/passwd.cxx        |    9 ++
 svx/inc/mscodec.hxx                  |   11 ++
 svx/source/msfilter/mscodec.cxx      |  137 ++++++++++++++++++++++++++++++-----
 5 files changed, 157 insertions(+), 21 deletions(-)

New commits:
commit 07004f9311f1efa38c978285da05d3ff3d05b163
Author: Release Engineers <releng at openoffice.org>
Date:   Wed Jul 1 08:58:41 2009 +0000

    CWS-TOOLING: integrate CWS scsheetprotection02
    2009-06-18 16:48:14 +0200 kohei  r273124 : #i102906# Fix a crasher when loading an xls document with unsupported
    encrytpion.
    2009-06-15 14:02:00 +0200 dr  r272982 : #i10000# compiler warnings
    2009-04-13 23:06:21 +0200 kohei  r270740 : Renamed SetData() to SetDataFromDocument(), in order to resolve name clash
    with the method of the same name in class Window.  This caused a compiler
    warning on Solaris Intel.
    2009-04-13 04:09:59 +0200 kohei  r270729 : CWS-TOOLING: rebase CWS scsheetprotection02 to trunk at 270723 (milestone: DEV300:m46)
    2009-02-23 16:13:45 +0100 kohei  r268361 : added tabprotection.obj to the exception file list.  Apparently the older
    versions of boost::shared_ptr rely on C++ exceptions for its implementation.
    2009-02-18 19:59:05 +0100 kohei  r268253 : Switched to using ::boost::shared_ptr to wrap a pimpl class, because using
    ::std::auto_ptr in this header breaks the build on win32.  The MSVC
    implementation of ::std::auto_ptr has some weird quirks...
    2009-02-17 21:47:13 +0100 kohei  r268192 : fixed linkage issue due to library split.
    2009-02-17 04:50:34 +0100 kohei  r267842 : CWS-TOOLING: rebase CWS scsheetprotection02 to trunk at 267171 (milestone: DEV300:m41)
    2009-02-17 02:36:10 +0100 kohei  r267841 : reverted the last commit, to re-surrect the removed src files.
    2009-02-03 22:02:34 +0100 kohei  r267342 : removed the src files to prevent them from being entered into the translation
    process.  The dialogs that need the strings are not yet enabled in the code,
    so their removal will not cause any harm.
    2009-01-14 12:24:29 +0100 dr  r266280 : #i10000# wntmsci12 compiler warnings #4
    2009-01-14 09:35:46 +0100 dr  r266267 : #i10000# wntmsci12 compiler warnings #3
    2009-01-13 15:42:07 +0100 dr  r266231 : #i10000# wntmsci12 compiler warnings #2
    2009-01-13 13:18:28 +0100 dr  r266216 : #i10000# wntmsci12 compiler warnings
    2009-01-07 03:59:11 +0100 kohei  r265943 : remove the fscking compiler warnings.
    2009-01-06 15:55:32 +0100 kohei  r265925 : removed compiler warnings that caused the buildbot build to fail....
    2009-01-05 23:24:59 +0100 kohei  r265888 : Undoing my own local build fix to work around the libmoz... issue.
    2008-12-30 21:39:58 +0100 kohei  r265833 : Duh!  Sheet protection was supposed to be disabled. :-/
    2008-12-23 20:25:55 +0100 kohei  r265792 : recovered the code block that was accidentally removed during cws rebase.
    2008-12-23 19:03:19 +0100 kohei  r265791 : fixed breakage in ods export filter due to rebase to m38.
    2008-12-23 16:41:49 +0100 kohei  r265787 : CWS-TOOLING: rebase CWS scsheetprotection02 to trunk at 265758 (milestone: DEV300:m38)
    2008-12-23 05:37:47 +0100 kohei  r265768 : deliberately forget document and sheet passwords when importing from or
    exporting to excel, to emulate the current behavior.
    2008-12-23 05:12:59 +0100 kohei  r265767 : removed commented-out unused method ScDocument::SetAutoFilterFlags().
    2008-12-23 05:05:19 +0100 kohei  r265766 : removed one duplicate method and made associated changes with the removal,
    and a little more code cleanup.
    2008-12-23 04:24:58 +0100 kohei  r265765 : a typo in in-line comment
    2008-12-23 04:23:08 +0100 kohei  r265764 : remove fprintf statement that blatantly prints out document encryption
    password to stdout.  not a good practice.
    2008-12-23 04:14:21 +0100 kohei  r265763 : we actually don't want to clear all options, because if we do, then
    we would no longer be able to select any cells on a protected sheet.
    2008-12-23 04:07:10 +0100 kohei  r265762 : * minor code cleanup (indentation inconsistencies & use of tab)
    * fixed unprotecting a sheet with password to make it work again.
    2008-12-23 03:22:50 +0100 kohei  r265761 : reverted all the new functionalities to the existing ones, while keeping the new code in
    as much as I could.
    2008-12-22 23:11:08 +0100 kohei  r265760 : in xls export filter, renamed two unknown records into records of known name.
    2008-12-22 22:34:50 +0100 kohei  r265759 : temporarily disable password capability on file export for MS Excel 97.
    2008-12-22 17:01:21 +0100 kohei  r265754 : CWS-TOOLING: rebase CWS scsheetprotection02 to trunk at 264807 (milestone: DEV300:m37)
    2008-11-26 03:12:58 +0100 kohei  r264335 : recovered a method that was actually used.
    2008-11-25 21:51:10 +0100 kohei  r264334 : CWS-TOOLING: rebase CWS scsheetprotection02 to trunk at 264325 (milestone: DEV300:m36)
    2008-10-08 19:57:35 +0200 kohei  r262094 : changed description string to make it less technical.
    2008-10-01 05:56:58 +0200 kohei  r261986 : migrated from the cvs-based cws.
    2008-10-01 05:55:19 +0200 kohei  r261985 : migrated from the cvs-based cws.
    2008-10-01 05:55:00 +0200 kohei  r261984 : migrated from the cvs-based cws.

diff --git a/sfx2/inc/sfx2/passwd.hxx b/sfx2/inc/sfx2/passwd.hxx
index 9125d57..2cc5ba1 100644
--- a/sfx2/inc/sfx2/passwd.hxx
+++ b/sfx2/inc/sfx2/passwd.hxx
@@ -81,6 +81,7 @@ public:
     String			GetConfirm() const { return maConfirmED.GetText(); }
 
     void 			SetMinLen( USHORT Len );
+    void            SetMaxLen( USHORT Len );
     void			SetEditHelpId( ULONG nId ) { maPasswordED.SetHelpId( nId ); }
     void			ShowExtras( USHORT nExtras ) { mnExtras = nExtras; }
 
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index f8d7cc4..c183698 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -560,9 +560,20 @@ struct CheckPasswordCapability
 {
     sal_Bool operator() ( const SfxFilter* _pFilter )
     {
-        return  _pFilter && _pFilter->IsOwnFormat()
-            &&	_pFilter->UsesStorage()
-            &&	( SOFFICE_FILEFORMAT_60 <= _pFilter->GetVersion() );
+        if (!_pFilter)
+            return false;
+
+#if 0 // to be enabled in the future
+        if (_pFilter->GetFilterName().EqualsAscii("MS Excel 97"))
+            // For now, we eanble password protection for Excel 97 as a 
+            // special case.  If we start having more filters supporting
+            // export encryption with password, we should probably switch to
+            // using a filter flag instead.
+            return true;
+#endif
+
+        return _pFilter->IsOwnFormat() && _pFilter->UsesStorage()
+            && ( SOFFICE_FILEFORMAT_60 <= _pFilter->GetVersion() );
     }
 };
 
@@ -1633,11 +1644,12 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
                 sal_Bool bPassWord = sal_False;
                 if ( ( aValue >>= bPassWord ) && bPassWord )
                 {
-                    // ask for the password
+                    // ask for a password
                     uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")), UNO_QUERY );
 
                     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)) );
  
diff --git a/sfx2/source/dialog/passwd.cxx b/sfx2/source/dialog/passwd.cxx
index ca7aa40..628258e 100644
--- a/sfx2/source/dialog/passwd.cxx
+++ b/sfx2/source/dialog/passwd.cxx
@@ -112,6 +112,15 @@ void SfxPasswordDialog::SetMinLen( USHORT nLen )
 
 // -----------------------------------------------------------------------
 
+void SfxPasswordDialog::SetMaxLen( USHORT nLen )
+{
+    maPasswordED.SetMaxTextLen( nLen );
+    maConfirmED.SetMaxTextLen( nLen );
+    EditModifyHdl( NULL );
+}
+
+// -----------------------------------------------------------------------
+
 short SfxPasswordDialog::Execute()
 {
     if ( mnExtras < SHOWEXTRAS_ALL )
diff --git a/svx/inc/mscodec.hxx b/svx/inc/mscodec.hxx
index 66dcf5d..be67b46 100644
--- a/svx/inc/mscodec.hxx
+++ b/svx/inc/mscodec.hxx
@@ -235,6 +235,14 @@ public:
      */
     bool                InitCipher( sal_uInt32 nCounter );
 
+    /** Creates an MD5 digest of salt digest. */
+    bool                CreateSaltDigest( 
+                            const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] );
+
+    bool                Encode(
+                            const void* pData, sal_Size nDatLen,
+                            sal_uInt8* pBuffer, sal_Size nBufLen );
+
     /** Decodes a block of memory.
 
         @see rtl_cipher_decode()
@@ -276,6 +284,9 @@ public:
     bool                Skip( sal_Size nDatLen );
 
 private:
+    void                GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 pDigest[16] );
+
+private:
                         SVX_DLLPRIVATE MSCodec_Std97( const MSCodec_Std97& );
     SVX_DLLPRIVATE MSCodec_Std97&      operator=( const MSCodec_Std97& );
 
diff --git a/svx/source/msfilter/mscodec.cxx b/svx/source/msfilter/mscodec.cxx
index e549fd4..39342fe 100644
--- a/svx/source/msfilter/mscodec.cxx
+++ b/svx/source/msfilter/mscodec.cxx
@@ -37,6 +37,13 @@
 #include <string.h>
 #include <tools/solar.h>
 
+#define DEBUG_MSO_ENCRYPTION_STD97 0
+
+#if DEBUG_MSO_ENCRYPTION_STD97
+#include <stdio.h>
+#endif
+
+
 namespace svx {
 
 // ============================================================================
@@ -241,15 +248,50 @@ MSCodec_Std97::~MSCodec_Std97 ()
     rtl_cipher_destroy (m_hCipher);
 }
 
+#if DEBUG_MSO_ENCRYPTION_STD97    
+static void lcl_PrintKeyData(const sal_uInt8* pKeyData, const char* msg)
+{
+    printf("pKeyData: (%s)\n", msg);
+    for (int j = 0; j < 4; ++j)
+    {
+        for (int i = 0; i < 16; ++i)
+            printf("%2.2x ", pKeyData[j*16+i]);
+        printf("\n");
+    }
+}
+#else
+static void lcl_PrintKeyData(const sal_uInt8* /*pKeyData*/, const char* /*msg*/)
+{
+}
+#endif    
+
+#if DEBUG_MSO_ENCRYPTION_STD97    
+static void lcl_PrintDigest(const sal_uInt8* pDigest, const char* msg)
+{
+    printf("digest: (%s)\n", msg);
+    for (int i = 0; i < 16; ++i)
+        printf("%2.2x ", pDigest[i]);
+    printf("\n");
+}
+#else
+static void lcl_PrintDigest(const sal_uInt8* /*pDigest*/, const char* /*msg*/)
+{
+}
+#endif    
+
 void MSCodec_Std97::InitKey (
     const sal_uInt16 pPassData[16],
     const sal_uInt8  pUnique[16])
 {
+#if DEBUG_MSO_ENCRYPTION_STD97    
+    fprintf(stdout, "MSCodec_Std97::InitKey: --begin\n");fflush(stdout);
+#endif    
     sal_uInt8 pKeyData[64];
     int       i, n;
 
     // Fill PassData into KeyData.
     (void)memset (pKeyData, 0, sizeof(pKeyData));
+    lcl_PrintKeyData(pKeyData, "initial");
     for (i = 0, n = 16; (i < n) && pPassData[i]; i++)
     {
         pKeyData[2*i    ] = sal::static_int_cast< sal_uInt8 >(
@@ -260,12 +302,16 @@ void MSCodec_Std97::InitKey (
     pKeyData[2*i] = 0x80;
     pKeyData[ 56] = sal::static_int_cast< sal_uInt8 >(i << 4);
 
+    lcl_PrintKeyData(pKeyData, "password data");
+
     // Fill raw digest of KeyData into KeyData.
     (void)rtl_digest_updateMD5 (
         m_hDigest, pKeyData, sizeof(pKeyData));
     (void)rtl_digest_rawMD5 (
         m_hDigest, pKeyData, RTL_DIGEST_LENGTH_MD5);
 
+    lcl_PrintKeyData(pKeyData, "raw digest of key data");
+
     // Update digest with KeyData and Unique.
     for (i = 0; i < 16; i++)
     {
@@ -279,6 +325,8 @@ void MSCodec_Std97::InitKey (
     pKeyData[56] = 0x80;
     pKeyData[57] = 0x0a;
 
+    lcl_PrintKeyData(pKeyData, "update digest with padding");
+
     rtl_digest_updateMD5 (
         m_hDigest, &(pKeyData[16]), sizeof(pKeyData) - 16);
 
@@ -286,6 +334,8 @@ void MSCodec_Std97::InitKey (
     rtl_digest_rawMD5 (
         m_hDigest, m_pDigestValue, sizeof(m_pDigestValue));
 
+    lcl_PrintDigest(m_pDigestValue, "digest value");
+
     // Erase KeyData array and leave.
     (void)memset (pKeyData, 0, sizeof(pKeyData));
 }
@@ -294,27 +344,21 @@ bool MSCodec_Std97::VerifyKey (
     const sal_uInt8 pSaltData[16],
     const sal_uInt8 pSaltDigest[16])
 {
+    // both the salt data and salt digest (hash) come from the document being imported.
+
+#if DEBUG_MSO_ENCRYPTION_STD97    
+    fprintf(stdout, "MSCodec_Std97::VerifyKey: \n");
+    lcl_PrintDigest(pSaltData, "salt data");
+    lcl_PrintDigest(pSaltDigest, "salt hash");
+#endif    
     bool result = false;
 
     if (InitCipher(0))
     {
         sal_uInt8 pDigest[RTL_DIGEST_LENGTH_MD5];
-        sal_uInt8 pBuffer[64];
-
-        // Decode SaltData into Buffer.
-        rtl_cipher_decode (
-            m_hCipher, pSaltData, 16, pBuffer, sizeof(pBuffer));
-
-        pBuffer[16] = 0x80;
-        (void)memset (pBuffer + 17, 0, sizeof(pBuffer) - 17);
-        pBuffer[56] = 0x80;
-
-        // Fill raw digest of Buffer into Digest.
-        rtl_digest_updateMD5 (
-            m_hDigest, pBuffer, sizeof(pBuffer));
-        rtl_digest_rawMD5 (
-            m_hDigest, pDigest, sizeof(pDigest));
+        GetDigestFromSalt(pSaltData, pDigest);
 
+        sal_uInt8 pBuffer[16];
         // Decode original SaltDigest into Buffer.
         rtl_cipher_decode (
             m_hCipher, pSaltDigest, 16, pBuffer, sizeof(pBuffer));
@@ -333,7 +377,7 @@ bool MSCodec_Std97::VerifyKey (
 bool MSCodec_Std97::InitCipher (sal_uInt32 nCounter)
 {
     rtlCipherError result;
-    sal_uInt8      pKeyData[64];
+    sal_uInt8      pKeyData[64]; // 512-bit message block
 
     // Initialize KeyData array.
     (void)memset (pKeyData, 0, sizeof(pKeyData));
@@ -358,7 +402,7 @@ bool MSCodec_Std97::InitCipher (sal_uInt32 nCounter)
 
     // Initialize Cipher with KeyData (for decoding).
     result = rtl_cipher_init (
-        m_hCipher, rtl_Cipher_DirectionDecode,
+        m_hCipher, rtl_Cipher_DirectionBoth,
         pKeyData, RTL_DIGEST_LENGTH_MD5, 0, 0);
 
     // Erase KeyData array and leave.
@@ -367,6 +411,38 @@ bool MSCodec_Std97::InitCipher (sal_uInt32 nCounter)
     return (result == rtl_Cipher_E_None);
 }
 
+bool MSCodec_Std97::CreateSaltDigest( const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] )
+{
+#if DEBUG_MSO_ENCRYPTION_STD97
+    lcl_PrintDigest(pSaltData, "salt data");
+#endif    
+    bool result = false;
+
+    if (InitCipher(0))
+    {
+        sal_uInt8 pDigest[RTL_DIGEST_LENGTH_MD5];
+        GetDigestFromSalt(nSaltData, pDigest);
+
+        rtl_cipher_decode (
+            m_hCipher, pDigest, 16, pDigest, sizeof(pDigest));
+
+        (void)memcpy(nSaltDigest, pDigest, 16);
+    }
+
+    return (result);
+}
+
+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);
+
+    return (result == rtl_Cipher_E_None);
+}
+
 bool MSCodec_Std97::Decode (
     const void *pData,   sal_Size nDatLen,
     sal_uInt8  *pBuffer, sal_Size nBufLen)
@@ -395,6 +471,33 @@ bool MSCodec_Std97::Skip( sal_Size nDatLen )
     return bResult;
 }
 
+void MSCodec_Std97::GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 pDigest[16] )
+{
+    sal_uInt8 pBuffer[64];
+    sal_uInt8 pDigestLocal[16];
+
+    // Decode SaltData into Buffer.
+    rtl_cipher_decode (
+        m_hCipher, pSaltData, 16, pBuffer, sizeof(pBuffer));
+
+    // set the 129th bit to make the buffer 128-bit in length.
+    pBuffer[16] = 0x80;
+
+    // erase the rest of the buffer with zeros.
+    (void)memset (pBuffer + 17, 0, sizeof(pBuffer) - 17);
+
+    // set the 441st bit.
+    pBuffer[56] = 0x80;
+
+    // Fill raw digest of Buffer into Digest.
+    rtl_digest_updateMD5 (
+        m_hDigest, pBuffer, sizeof(pBuffer));
+    rtl_digest_rawMD5 (
+        m_hDigest, pDigestLocal, sizeof(pDigestLocal));
+
+    memcpy(pDigest, pDigestLocal, 16);
+}
+
 // ============================================================================
 
 } // namespace svx


More information about the ooo-build-commit mailing list