You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by ar...@apache.org on 2022/06/17 17:38:03 UTC

[openoffice] branch catalina updated (48a4b4ec7c -> f6e08dbf8d)

This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a change to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git


    from 48a4b4ec7c Merge AOO41X into catalina
     new 92a8346003 Decode all data
     new 21e981f512 Re-encode silently using the new encoding
     new 6e45d63ad7 Generate IV's
     new 3cbd74816a Fix compilation under Windows
     new 8fafcfcb98 Do not attempt to remove entries from an empty structure
     new fe09cdbe8a Copy data because iterators could be invalidated
     new f6e08dbf8d Fix crash under Windows

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 main/svl/source/inc/passwordcontainer.hxx          |  37 ++++-
 .../source/passwordcontainer/passwordcontainer.cxx | 178 +++++++++++++++------
 2 files changed, 163 insertions(+), 52 deletions(-)


[openoffice] 06/07: Copy data because iterators could be invalidated

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit fe09cdbe8a936f064d5fb852216373e51e44e216
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Fri Jun 3 10:55:18 2022 +0200

    Copy data because iterators could be invalidated
    
    (cherry picked from commit a1a746b3aa762f45e2be14f8d65d0b384c6c516f)
---
 main/svl/source/inc/passwordcontainer.hxx             |  2 +-
 .../source/passwordcontainer/passwordcontainer.cxx    | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/main/svl/source/inc/passwordcontainer.hxx b/main/svl/source/inc/passwordcontainer.hxx
index 3547f65d0e..871cad23ce 100644
--- a/main/svl/source/inc/passwordcontainer.hxx
+++ b/main/svl/source/inc/passwordcontainer.hxx
@@ -270,7 +270,7 @@ private:
                                         const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler )
                                                         throw(::com::sun::star::uno::RuntimeException);
 bool createUrlRecord( 
-    const PassMap::iterator & rIter, 
+    const PairUrlRecord & rPair,
     bool bName,
     const ::rtl::OUString & aName,
     const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler,
diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index c9b91fec5f..5c581d46df 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -857,7 +857,7 @@ Sequence< UserRecord > PasswordContainer::FindUsr( const list< NamePassRecord >&
 //-------------------------------------------------------------------------
 
 bool PasswordContainer::createUrlRecord(
-    const PassMap::iterator & rIter,
+    const PairUrlRecord & rPair,
     bool bName,
     const ::rtl::OUString & aName,
     const Reference< XInteractionHandler >& aHandler,
@@ -867,18 +867,18 @@ bool PasswordContainer::createUrlRecord(
     if ( bName )
     {
         Sequence< UserRecord > aUsrRec
-            = FindUsr( rIter->second, aName, aHandler );
+            = FindUsr( rPair.second, aName, aHandler );
         if( aUsrRec.getLength() )
         {
-            rRec = UrlRecord( rIter->first, aUsrRec );
+            rRec = UrlRecord( rPair.first, aUsrRec );
             return true;
         }
     }
     else
     {
         rRec = UrlRecord(
-            rIter->first,
-            CopyToUserRecordSequence( rIter->second, aHandler ) );
+            rPair.first,
+            CopyToUserRecordSequence( rPair.second, aHandler ) );
         return true;
     }
     return false;
@@ -904,10 +904,14 @@ UrlRecord PasswordContainer::find(
         {
             // first look for <url>/somename and then look for <url>/somename/...
             PassMap::iterator aIter = m_aContainer.find( aUrl );
+            // Note that this iterator may be invalidated by the
+            // side-effects of createUrlRecord(), so we have to work with a
+            // copy of the pointed elements
             if( aIter != m_aContainer.end() )
             {
+                const PairUrlRecord rPairUrlRecord = *aIter;
                 UrlRecord aRec;
-                if ( createUrlRecord( aIter, bName, aName, aHandler, aRec ) )
+                if ( createUrlRecord( rPairUrlRecord, bName, aName, aHandler, aRec ) )
                   return aRec;
             }
             else
@@ -919,8 +923,9 @@ UrlRecord PasswordContainer::find(
                 aIter = m_aContainer.lower_bound( tmpUrl );
                 if( aIter != m_aContainer.end() && aIter->first.match( tmpUrl ) )
                 {
+                    const PairUrlRecord rPairUrlRecord = *aIter;
                     UrlRecord aRec;
-                    if ( createUrlRecord( aIter, bName, aName, aHandler, aRec ) )
+                    if ( createUrlRecord( rPairUrlRecord, bName, aName, aHandler, aRec ) )
                       return aRec;
                 }
             }


[openoffice] 05/07: Do not attempt to remove entries from an empty structure

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 8fafcfcb98acba54c92178660e195f5a635bf9d3
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Fri Jun 3 10:54:08 2022 +0200

    Do not attempt to remove entries from an empty structure
    
    (cherry picked from commit 9c3ea9f6efc0f26d0db7f02ac520950b41ca0956)
---
 main/svl/source/passwordcontainer/passwordcontainer.cxx | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index 07e45a7299..c9b91fec5f 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -1154,9 +1154,6 @@ void SAL_CALL PasswordContainer::removeAllPersistent() throw(RuntimeException)
             {
                 // TODO/LATER: should the password be converted to MemoryPassword?
                 aNPIter->RemovePasswords( PERSISTENT_RECORD );
-
-                if ( m_pStorageFile )
-                    m_pStorageFile->remove( aIter->first, aNPIter->GetUserName() ); // remove record ( aURL, aName )
             }
 
             if( !aNPIter->HasPasswords( MEMORY_RECORD ) )


[openoffice] 07/07: Fix crash under Windows

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit f6e08dbf8d9d287fb6116da97c4fe17df99b042a
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Tue Jun 14 22:57:41 2022 +0200

    Fix crash under Windows
    
    MSVC 2008 does not allow operator[] on an empty std::vector
    
    (cherry picked from commit e08dab5466ec183daca089b964db4a2c56fa06ee)
---
 main/svl/source/passwordcontainer/passwordcontainer.cxx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index 5c581d46df..ff7f3da14a 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -542,7 +542,8 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords(const ::rtl::OUStri
 
             rtlCipherError result = rtl_cipher_init (
                     aDecoder, rtl_Cipher_DirectionDecode,
-                    code, RTL_DIGEST_LENGTH_MD5, &iv[0], iv.size() );
+                    code, RTL_DIGEST_LENGTH_MD5, (iv.size()? &iv[0] : NULL),
+                    iv.size() );
             if( result == rtl_Cipher_E_None )
             {
                 ::rtl::ByteSequence aSeq = getBufFromAsciiLine( aLine );
@@ -596,7 +597,8 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords(const ::rtl::OUStri
 
             rtlCipherError result = rtl_cipher_init (
                     aEncoder, rtl_Cipher_DirectionEncode,
-                    code, RTL_DIGEST_LENGTH_MD5, &iv[0], iv.size() );
+                    code, RTL_DIGEST_LENGTH_MD5, (iv.size()? &iv[0] : NULL),
+                    iv.size() );
 
             if( result == rtl_Cipher_E_None )
             {


[openoffice] 03/07: Generate IV's

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 6e45d63ad73f1e431af90849a3ae82d717c39ad4
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Sat May 21 09:54:54 2022 +0200

    Generate IV's
    
    (cherry picked from commit d155fee95ad7cc2d95056ec2261767dc21ea10d7)
---
 main/svl/source/inc/passwordcontainer.hxx          | 15 ++++-
 .../source/passwordcontainer/passwordcontainer.cxx | 72 +++++++++++++++++-----
 2 files changed, 68 insertions(+), 19 deletions(-)

diff --git a/main/svl/source/inc/passwordcontainer.hxx b/main/svl/source/inc/passwordcontainer.hxx
index 339f455ed9..3547f65d0e 100644
--- a/main/svl/source/inc/passwordcontainer.hxx
+++ b/main/svl/source/inc/passwordcontainer.hxx
@@ -304,6 +304,7 @@ bool createUrlRecord(
 
     /** Decode passwords on a line with the given master password.
      *
+     * @param aName name for the passwords. It can be a user name, for example.
      * @param aLine line with passwords to decode.
      * @param aMasterPassword master password to use.
      *
@@ -311,10 +312,20 @@ bool createUrlRecord(
      *
      * @return the decoded passwords.
      */
-    ::std::vector< ::rtl::OUString > DecodePasswords( const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPassword )
+    ::std::vector< ::rtl::OUString > DecodePasswords( const ::rtl::OUString& aName, const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPassword )
                                                         throw(::com::sun::star::uno::RuntimeException);
     
-    ::rtl::OUString EncodePasswords( ::std::vector< ::rtl::OUString > lines, const ::rtl::OUString& aMasterPassword )
+    /** Encode passwords on a line with the given master password.
+     *
+     * @param aName name for the passwords. It can be a user name, for example.
+     * @param lines lines with passwords to decode.
+     * @param aMasterPassword master password to use.
+     *
+     * The encoding is selected by mOldPasswordEncoding.
+     *
+     * @return the decoded passwords.
+     */
+    ::rtl::OUString EncodePasswords( const ::rtl::OUString& aName, ::std::vector< ::rtl::OUString > lines, const ::rtl::OUString& aMasterPassword )
                                                         throw(::com::sun::star::uno::RuntimeException);
 
     /** Actually change the master password, re-encoding all stored passwords.
diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index 88f9083813..c95b3f1a82 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -507,7 +507,24 @@ static void decodeMasterPassword(const ::rtl::OUString& aMasterPasswd,
 
 //-------------------------------------------------------------------------
 
-vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPasswd ) throw(RuntimeException)
+/** Prepare the IV.
+ *
+ * @param iv vector to prepare. Its contents are destroyed.
+ * @param masterPasswdCode master password as output from decodeMasterPassword.
+ * @param name name of the password to decrypt.
+ */
+static void prepareIV(std::vector<sal_uInt8>& iv, const unsigned char *masterPasswordCode, const ::rtl::OUString &aName) {
+    std::vector<sal_uInt8> ivSource;
+    ivSource.assign(masterPasswordCode, masterPasswordCode + RTL_DIGEST_LENGTH_MD5);
+    ::rtl::OString encodedName = ::rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8 );
+    ivSource.insert(ivSource.end(), encodedName.getStr(), encodedName.getStr() + encodedName.getLength());
+    iv.resize(RTL_DIGEST_LENGTH_MD5);
+    rtl_digest_MD5(ivSource.data(), ivSource.size(),
+                   iv.data(), iv.size());
+}
+
+//-------------------------------------------------------------------------
+vector< ::rtl::OUString > PasswordContainer::DecodePasswords(const ::rtl::OUString& aName, const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPasswd ) throw(RuntimeException)
 {
     if( aMasterPasswd.getLength() )
     {
@@ -516,13 +533,16 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
 
         if( aDecoder )
         {
+            std::vector<sal_uInt8> iv;
             unsigned char code[RTL_DIGEST_LENGTH_MD5];
             decodeMasterPassword(aMasterPasswd, code, mOldPasswordEncoding);
+            if (!mOldPasswordEncoding) {
+                prepareIV(iv, code, aName);
+            }
 
             rtlCipherError result = rtl_cipher_init (
                     aDecoder, rtl_Cipher_DirectionDecode,
-                    code, RTL_DIGEST_LENGTH_MD5, NULL, 0 );
-
+                    code, RTL_DIGEST_LENGTH_MD5, iv.data(), iv.size() );
             if( result == rtl_Cipher_E_None )
             {
                 ::rtl::ByteSequence aSeq = getBufFromAsciiLine( aLine );
@@ -556,7 +576,7 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
 
 //-------------------------------------------------------------------------
 
-::rtl::OUString PasswordContainer::EncodePasswords( vector< ::rtl::OUString > lines, const ::rtl::OUString& aMasterPasswd ) throw(RuntimeException)
+::rtl::OUString PasswordContainer::EncodePasswords( const ::rtl::OUString& aName, vector< ::rtl::OUString > lines, const ::rtl::OUString& aMasterPasswd ) throw(RuntimeException)
 {
     if( aMasterPasswd.getLength() )
     {
@@ -567,13 +587,16 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
 
         if( aEncoder )
         {
-
+            std::vector<sal_uInt8> iv;
             unsigned char code[RTL_DIGEST_LENGTH_MD5];
             decodeMasterPassword(aMasterPasswd, code, false);
+            if (!mOldPasswordEncoding) {
+                prepareIV(iv, code, aName);
+            }
 
             rtlCipherError result = rtl_cipher_init (
                     aEncoder, rtl_Cipher_DirectionEncode,
-                    code, RTL_DIGEST_LENGTH_MD5, NULL, 0 );
+                    code, RTL_DIGEST_LENGTH_MD5, iv.data(), iv.size() );
 
             if( result == rtl_Cipher_E_None )
             {
@@ -633,6 +656,15 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
 
 //-------------------------------------------------------------------------
 
+
+/** Return the "name" to use for the master password. */
+static const ::rtl::OUString& getMasterPasswordName(void) {
+    static const ::rtl::OUString value = ::rtl::OUString::createFromAscii( "Master" );
+    return value;
+}
+
+//-------------------------------------------------------------------------
+
 void PasswordContainer::doChangeMasterPassword(const ::rtl::OUString& aPass) {
     // get all the persistent entries if it is possible
     Sequence< UrlRecord > aPersistent = getAllPersistent( uno::Reference< task::XInteractionHandler >() );
@@ -643,7 +675,7 @@ void PasswordContainer::doChangeMasterPassword(const ::rtl::OUString& aPass) {
     // store the new master password
     m_aMasterPasswd = aPass;
     vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd );
-    m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
+    m_pStorageFile->setEncodedMP( EncodePasswords( getMasterPasswordName(), aMaster, m_aMasterPasswd ) );
 
     // store all the entries with the new password
     for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ )
@@ -700,7 +732,7 @@ UserRecord PasswordContainer::CopyToUserRecord( const NamePassRecord& aRecord, s
     {
         try
         {
-            ::std::vector< ::rtl::OUString > aDecodedPasswords = DecodePasswords( aRecord.GetPersPasswords(), GetMasterPassword( aHandler ) );
+            ::std::vector< ::rtl::OUString > aDecodedPasswords = DecodePasswords( aRecord.GetUserName(), aRecord.GetPersPasswords(), GetMasterPassword( aHandler ) );
             aPasswords.insert( aPasswords.end(), aDecodedPasswords.begin(), aDecodedPasswords.end() );
         }
         catch( NoMasterException& )
@@ -757,7 +789,7 @@ void PasswordContainer::PrivateAdd( const ::rtl::OUString& Url, const ::rtl::OUS
     ::std::vector< ::rtl::OUString > aStorePass = copySequenceToVector( Passwords );
 
     if( Mode == PERSISTENT_RECORD )
-        aRecord.SetPersPasswords( EncodePasswords( aStorePass, GetMasterPassword( aHandler ) ) );
+        aRecord.SetPersPasswords( EncodePasswords( aRecord.GetUserName(), aStorePass, GetMasterPassword( aHandler ) ) );
     else if( Mode == MEMORY_RECORD )
         aRecord.SetMemPasswords( aStorePass );
     else
@@ -974,20 +1006,26 @@ UrlRecord PasswordContainer::find(
                         m_aMasterPasswd = aPass;
                         vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd );
 
-                        m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
+                        m_pStorageFile->setEncodedMP( EncodePasswords( getMasterPasswordName(), aMaster, m_aMasterPasswd ) );
                     }
                     else
                     {
-                        vector< ::rtl::OUString > aRM( DecodePasswords( aEncodedMP, aPass ) );
+                        vector< ::rtl::OUString > aRM( DecodePasswords( getMasterPasswordName(), aEncodedMP, aPass ) );
                         if( !aRM.size() || !aPass.equals( aRM[0] ) )
                         {
                             // Try the old encoding
                             mOldPasswordEncoding = true;
-                            aRM = DecodePasswords( aEncodedMP, aPass );
-                            if (aRM.size() && aPass.equals(aRM[0])) {
-                                // Update the master password to the new encoding and update all stored passwords.
-                                m_aMasterPasswd = aPass;
-                                doChangeMasterPassword(aPass);
+                            try {
+                                aRM = DecodePasswords( getMasterPasswordName(), aEncodedMP, aPass );
+                                if (aRM.size() && aPass.equals(aRM[0])) {
+                                    // Update all passwords to the new encoding
+                                    m_aMasterPasswd = aPass;
+                                    doChangeMasterPassword(aPass);
+                                }
+                                mOldPasswordEncoding = false;
+                            } catch (...) {
+                                mOldPasswordEncoding = false;
+                                throw;
                             }
                         }
                         if( !aRM.size() || !aPass.equals( aRM[0] ) )
@@ -1156,7 +1194,7 @@ Sequence< UrlRecord > SAL_CALL PasswordContainer::getAllPersistent( const Refere
             {
                 sal_Int32 oldLen = aUsers.getLength();
                 aUsers.realloc( oldLen + 1 );
-                aUsers[ oldLen ] = UserRecord( aNPIter->GetUserName(), copyVectorToSequence( DecodePasswords( aNPIter->GetPersPasswords(), GetMasterPassword( xHandler ) ) ) );
+                aUsers[ oldLen ] = UserRecord( aNPIter->GetUserName(), copyVectorToSequence( DecodePasswords( aNPIter->GetUserName(), aNPIter->GetPersPasswords(), GetMasterPassword( xHandler ) ) ) );
             }
 
         if( aUsers.getLength() )


[openoffice] 01/07: Decode all data

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 92a8346003d4c6e6c3d38544f11f35d6032d02be
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Fri Mar 18 20:34:04 2022 +0100

    Decode all data
    
    (cherry picked from commit 38299684fdf0ae17ce0b666ddf85ee6def708c43)
---
 .../source/passwordcontainer/passwordcontainer.cxx | 29 ++++++++++++++++------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index 572879de40..dba73730da 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -481,6 +481,26 @@ void SAL_CALL PasswordContainer::disposing( const EventObject& ) throw(RuntimeEx
 
 //-------------------------------------------------------------------------
 
+/**
+ * @brief Decode a master password.
+ *
+ * @param aMasterPassword master password to decode.
+ * It must contain RTL_DIGEST_LENGTH_MD5 * 2 characters.
+ * @param code buffer to hold the decoded password.
+ * It must contain RTL_DIGEST_LENGTH_MD5 characters.
+ */
+static void decodeMasterPassword(const ::rtl::OUString& aMasterPasswd,
+                                 unsigned char *code)
+{
+    OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!\n" );
+    const sal_Unicode *aMasterBuf = aMasterPasswd.getStr();
+    for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
+        code[ ind ] = (char)((((aMasterBuf[ind * 2] - 'a') & 15) << 4) |
+                             ((aMasterBuf[ind * 2 + 1] - 'a') & 15));
+}
+
+//-------------------------------------------------------------------------
+
 vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPasswd ) throw(RuntimeException)
 {
     if( aMasterPasswd.getLength() )
@@ -490,11 +510,8 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
 
         if( aDecoder )
         {
-            OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!\n" );
-
             unsigned char code[RTL_DIGEST_LENGTH_MD5];
-            for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
-                code[ ind ] = (char)(aMasterPasswd.copy( ind*2, 2 ).toInt32(16));
+            decodeMasterPassword(aMasterPasswd, code);
 
             rtlCipherError result = rtl_cipher_init (
                     aDecoder, rtl_Cipher_DirectionDecode,
@@ -544,11 +561,9 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
 
         if( aEncoder )
         {
-            OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!\n" );
 
             unsigned char code[RTL_DIGEST_LENGTH_MD5];
-            for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
-                code[ ind ] = (char)(aMasterPasswd.copy( ind*2, 2 ).toInt32(16));
+            decodeMasterPassword(aMasterPasswd, code);
 
             rtlCipherError result = rtl_cipher_init (
                     aEncoder, rtl_Cipher_DirectionEncode,


[openoffice] 02/07: Re-encode silently using the new encoding

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 21e981f512aaf1f6c4e8b9397ff08ee7269482a7
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Sun Apr 17 14:14:17 2022 +0200

    Re-encode silently using the new encoding
    
    (cherry picked from commit 6ff9643461b887420b71bf1d2ad693ebda458a86)
---
 main/svl/source/inc/passwordcontainer.hxx          | 20 +++++-
 .../source/passwordcontainer/passwordcontainer.cxx | 77 ++++++++++++++--------
 2 files changed, 70 insertions(+), 27 deletions(-)

diff --git a/main/svl/source/inc/passwordcontainer.hxx b/main/svl/source/inc/passwordcontainer.hxx
index 5136b60f4f..339f455ed9 100644
--- a/main/svl/source/inc/passwordcontainer.hxx
+++ b/main/svl/source/inc/passwordcontainer.hxx
@@ -249,6 +249,8 @@ private:
     StorageItem* m_pStorageFile;
     ::osl::Mutex mMutex;
     ::rtl::OUString m_aMasterPasswd; // master password is set when the string is not empty
+    /// True if we detected the older password encoding (pre-4.1.13)
+    bool mOldPasswordEncoding;
     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mComponent;
     SysCredentialsConfig mUrlContainer;
 
@@ -300,12 +302,28 @@ bool createUrlRecord(
                               const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler )
                                                         throw(::com::sun::star::uno::RuntimeException);
 
+    /** Decode passwords on a line with the given master password.
+     *
+     * @param aLine line with passwords to decode.
+     * @param aMasterPassword master password to use.
+     *
+     * The encoding is selected by mOldPasswordEncoding.
+     *
+     * @return the decoded passwords.
+     */
     ::std::vector< ::rtl::OUString > DecodePasswords( const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPassword )
                                                         throw(::com::sun::star::uno::RuntimeException);
     
     ::rtl::OUString EncodePasswords( ::std::vector< ::rtl::OUString > lines, const ::rtl::OUString& aMasterPassword )
                                                         throw(::com::sun::star::uno::RuntimeException);
-    
+
+    /** Actually change the master password, re-encoding all stored passwords.
+     *
+     * @param apass new password to set.
+     *
+     * Updates m_aMasterPasswd.
+     */
+    void doChangeMasterPassword(const ::rtl::OUString& aPass);
 public:
     PasswordContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& );
     ~PasswordContainer();
diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index dba73730da..88f9083813 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -427,7 +427,7 @@ void StorageItem::Commit()
 //-------------------------------------------------------------------------
 
 PasswordContainer::PasswordContainer( const Reference<XMultiServiceFactory>& xServiceFactory ):
-    m_pStorageFile( NULL )
+    m_pStorageFile( NULL ), mOldPasswordEncoding(false)
 {
     // m_pStorageFile->Notify() can be called
     ::osl::MutexGuard aGuard( mMutex );
@@ -488,15 +488,21 @@ void SAL_CALL PasswordContainer::disposing( const EventObject& ) throw(RuntimeEx
  * It must contain RTL_DIGEST_LENGTH_MD5 * 2 characters.
  * @param code buffer to hold the decoded password.
  * It must contain RTL_DIGEST_LENGTH_MD5 characters.
+ * @param oldEncoding use the encoding pre-AOO-4.1.12 if true
  */
 static void decodeMasterPassword(const ::rtl::OUString& aMasterPasswd,
-                                 unsigned char *code)
+                                 unsigned char *code, bool oldEncoding)
 {
     OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!\n" );
     const sal_Unicode *aMasterBuf = aMasterPasswd.getStr();
-    for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
-        code[ ind ] = (char)((((aMasterBuf[ind * 2] - 'a') & 15) << 4) |
-                             ((aMasterBuf[ind * 2 + 1] - 'a') & 15));
+    for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ ) {
+        if (!oldEncoding) {
+            code[ ind ] = (char)((((aMasterBuf[ind * 2] - 'a') & 15) << 4) |
+                                 ((aMasterBuf[ind * 2 + 1] - 'a') & 15));
+        } else {
+            code[ ind ] = (char)(aMasterPasswd.copy( ind*2, 2 ).toInt32(16));
+        }
+    }
 }
 
 //-------------------------------------------------------------------------
@@ -511,7 +517,7 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
         if( aDecoder )
         {
             unsigned char code[RTL_DIGEST_LENGTH_MD5];
-            decodeMasterPassword(aMasterPasswd, code);
+            decodeMasterPassword(aMasterPasswd, code, mOldPasswordEncoding);
 
             rtlCipherError result = rtl_cipher_init (
                     aDecoder, rtl_Cipher_DirectionDecode,
@@ -563,7 +569,7 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
         {
 
             unsigned char code[RTL_DIGEST_LENGTH_MD5];
-            decodeMasterPassword(aMasterPasswd, code);
+            decodeMasterPassword(aMasterPasswd, code, false);
 
             rtlCipherError result = rtl_cipher_init (
                     aEncoder, rtl_Cipher_DirectionEncode,
@@ -627,6 +633,29 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUStr
 
 //-------------------------------------------------------------------------
 
+void PasswordContainer::doChangeMasterPassword(const ::rtl::OUString& aPass) {
+    // get all the persistent entries if it is possible
+    Sequence< UrlRecord > aPersistent = getAllPersistent( uno::Reference< task::XInteractionHandler >() );
+
+    // remove the master password and the entries persistence
+    removeMasterPassword();
+
+    // store the new master password
+    m_aMasterPasswd = aPass;
+    vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd );
+    m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
+
+    // store all the entries with the new password
+    for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ )
+        for ( int nNameInd = 0; nNameInd< aPersistent[nURLInd].UserList.getLength(); nNameInd++ )
+            addPersistent( aPersistent[nURLInd].Url,
+                           aPersistent[nURLInd].UserList[nNameInd].UserName,
+                           aPersistent[nURLInd].UserList[nNameInd].Passwords,
+                           uno::Reference< task::XInteractionHandler >() );
+}
+
+//-------------------------------------------------------------------------
+
 void PasswordContainer::UpdateVector( const ::rtl::OUString& aURL, list< NamePassRecord >& toUpdate, NamePassRecord& aRecord, sal_Bool writeFile ) throw(RuntimeException)
 {
     for( list< NamePassRecord >::iterator aNPIter = toUpdate.begin(); aNPIter != toUpdate.end(); aNPIter++ )
@@ -951,6 +980,17 @@ UrlRecord PasswordContainer::find(
                     {
                         vector< ::rtl::OUString > aRM( DecodePasswords( aEncodedMP, aPass ) );
                         if( !aRM.size() || !aPass.equals( aRM[0] ) )
+                        {
+                            // Try the old encoding
+                            mOldPasswordEncoding = true;
+                            aRM = DecodePasswords( aEncodedMP, aPass );
+                            if (aRM.size() && aPass.equals(aRM[0])) {
+                                // Update the master password to the new encoding and update all stored passwords.
+                                m_aMasterPasswd = aPass;
+                                doChangeMasterPassword(aPass);
+                            }
+                        }
+                        if( !aRM.size() || !aPass.equals( aRM[0] ) )
                         {
                             bAskAgain = sal_True;
                             aRMode = PasswordRequestMode_PASSWORD_REENTER;
@@ -1214,25 +1254,7 @@ sal_Bool SAL_CALL PasswordContainer::changeMasterPassword( const uno::Reference<
 
             if ( aPass.getLength() )
             {
-                // get all the persistent entries if it is possible
-                Sequence< UrlRecord > aPersistent = getAllPersistent( uno::Reference< task::XInteractionHandler >() );
-
-                // remove the master password and the entries persistence
-                removeMasterPassword();
-
-                // store the new master password
-                m_aMasterPasswd = aPass;
-                vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd );
-                m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
-
-                // store all the entries with the new password
-                for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ )
-                    for ( int nNameInd = 0; nNameInd< aPersistent[nURLInd].UserList.getLength(); nNameInd++ )
-                        addPersistent( aPersistent[nURLInd].Url,
-                                       aPersistent[nURLInd].UserList[nNameInd].UserName,
-                                       aPersistent[nURLInd].UserList[nNameInd].Passwords,
-                                       uno::Reference< task::XInteractionHandler >() );
-
+                doChangeMasterPassword(aPass);
                 bResult = sal_True;
             }
         }
@@ -1248,6 +1270,9 @@ void SAL_CALL PasswordContainer::removeMasterPassword()
     // remove all the stored passwords and the master password
     removeAllPersistent();
 
+    // Make sure we will not use the older encoding in the future
+    mOldPasswordEncoding = false;
+
     ::osl::MutexGuard aGuard( mMutex );
     if ( m_pStorageFile )
     {


[openoffice] 04/07: Fix compilation under Windows

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch catalina
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 3cbd74816abc333142698c1e3f26cecf082dccc9
Author: Arrigo Marchiori <ar...@yahoo.it>
AuthorDate: Sat May 28 18:18:27 2022 +0200

    Fix compilation under Windows
    
    std::vector::data() is C++11
    (cherry picked from commit 9f3d6185dd3bf26d71701995848768c052c8e417)
---
 main/svl/source/passwordcontainer/passwordcontainer.cxx | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/main/svl/source/passwordcontainer/passwordcontainer.cxx b/main/svl/source/passwordcontainer/passwordcontainer.cxx
index c95b3f1a82..07e45a7299 100644
--- a/main/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/main/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -519,8 +519,8 @@ static void prepareIV(std::vector<sal_uInt8>& iv, const unsigned char *masterPas
     ::rtl::OString encodedName = ::rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8 );
     ivSource.insert(ivSource.end(), encodedName.getStr(), encodedName.getStr() + encodedName.getLength());
     iv.resize(RTL_DIGEST_LENGTH_MD5);
-    rtl_digest_MD5(ivSource.data(), ivSource.size(),
-                   iv.data(), iv.size());
+    rtl_digest_MD5(&ivSource[0], ivSource.size(),
+                   &iv[0], iv.size());
 }
 
 //-------------------------------------------------------------------------
@@ -542,7 +542,7 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords(const ::rtl::OUStri
 
             rtlCipherError result = rtl_cipher_init (
                     aDecoder, rtl_Cipher_DirectionDecode,
-                    code, RTL_DIGEST_LENGTH_MD5, iv.data(), iv.size() );
+                    code, RTL_DIGEST_LENGTH_MD5, &iv[0], iv.size() );
             if( result == rtl_Cipher_E_None )
             {
                 ::rtl::ByteSequence aSeq = getBufFromAsciiLine( aLine );
@@ -596,7 +596,7 @@ vector< ::rtl::OUString > PasswordContainer::DecodePasswords(const ::rtl::OUStri
 
             rtlCipherError result = rtl_cipher_init (
                     aEncoder, rtl_Cipher_DirectionEncode,
-                    code, RTL_DIGEST_LENGTH_MD5, iv.data(), iv.size() );
+                    code, RTL_DIGEST_LENGTH_MD5, &iv[0], iv.size() );
 
             if( result == rtl_Cipher_E_None )
             {