Blame SOURCES/0003-CVE-2022-26306-add-Initialization-Vectors-to-passwor.patch

9d1203
From a3046cfa58bdfa2a1b9ea6287a021230830f056f Mon Sep 17 00:00:00 2001
9d1203
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
9d1203
Date: Tue, 22 Mar 2022 17:22:22 +0000
9d1203
Subject: [PATCH] add Initialization Vectors to password storage
9d1203
9d1203
old ones default to the current all zero case and continue to work
9d1203
as before
9d1203
9d1203
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131974
9d1203
Tested-by: Jenkins
9d1203
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
9d1203
(cherry picked from commit 192fa1e3bfc6269f2ebb91716471485a56074aea)
9d1203
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132306
9d1203
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
9d1203
(cherry picked from commit ab77587ec300f5c30084471000663c46ddf25dad)
9d1203
9d1203
Change-Id: I6fe3b02fafcce1b5e7133e77e76a5118177d77af
9d1203
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133907
9d1203
Tested-by: Michael Stahl <michael.stahl@allotropia.de>
9d1203
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
9d1203
---
9d1203
 .../schema/org/openoffice/Office/Common.xcs   |  10 ++
9d1203
 .../passwordcontainer/passwordcontainer.cxx   | 127 ++++++++++++------
9d1203
 .../passwordcontainer/passwordcontainer.hxx   |  63 +++++++--
9d1203
 3 files changed, 151 insertions(+), 49 deletions(-)
9d1203
9d1203
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
9d1203
index b033b29b60d7..e57d26ab3366 100644
9d1203
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
9d1203
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
9d1203
@@ -27,6 +27,11 @@
9d1203
       <info>
9d1203
         <desc>Contains a container for passwords.</desc>
9d1203
       </info>
9d1203
+      <prop oor:name="InitializationVector" oor:type="xs:string">
9d1203
+        <info>
9d1203
+          <desc>Contains an initialization vector for the password encryption.</desc>
9d1203
+        </info>
9d1203
+      </prop>
9d1203
       <prop oor:name="Password" oor:type="xs:string" oor:localized="false">
9d1203
         <info>
9d1203
           <desc>Contains a password encoded with the master password.</desc>
9d1203
@@ -923,6 +928,11 @@
9d1203
         </info>
9d1203
         <value>false</value>
9d1203
       </prop>
9d1203
+      <prop oor:name="MasterInitializationVector" oor:type="xs:string">
9d1203
+        <info>
9d1203
+          <desc>Contains an initialization vector for the master password encryption.</desc>
9d1203
+        </info>
9d1203
+      </prop>
9d1203
       <prop oor:name="Master" oor:type="xs:string" oor:nillable="false">
9d1203
         <info>
9d1203
           <desc>Contains the master password encrypted by itself.</desc>
9d1203
diff --git a/svl/source/passwordcontainer/passwordcontainer.cxx b/svl/source/passwordcontainer/passwordcontainer.cxx
9d1203
index ff0b40df4016..380188ef495c 100644
9d1203
--- a/svl/source/passwordcontainer/passwordcontainer.cxx
9d1203
+++ b/svl/source/passwordcontainer/passwordcontainer.cxx
9d1203
@@ -184,15 +184,18 @@ PassMap StorageItem::getInfo()
9d1203
 
9d1203
     Sequence< OUString > aNodeNames     = ConfigItem::GetNodeNames( "Store" );
9d1203
     sal_Int32 aNodeCount = aNodeNames.getLength();
9d1203
-    Sequence< OUString > aPropNames( aNodeCount );
9d1203
+    Sequence< OUString > aPropNames( aNodeCount * 2);
9d1203
 
9d1203
     std::transform(aNodeNames.begin(), aNodeNames.end(), aPropNames.begin(),
9d1203
         [](const OUString& rName) -> OUString {
9d1203
             return "Store/Passwordstorage['" + rName + "']/Password"; });
9d1203
+    std::transform(aNodeNames.begin(), aNodeNames.end(), aPropNames.getArray() + aNodeCount,
9d1203
+        [](const OUString& rName) -> OUString {
9d1203
+            return "Store/Passwordstorage['" + rName + "']/InitializationVector"; });
9d1203
 
9d1203
     Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aPropNames );
9d1203
 
9d1203
-    if( aPropertyValues.getLength() != aNodeCount )
9d1203
+    if( aPropertyValues.getLength() != aNodeCount * 2)
9d1203
     {
9d1203
         OSL_FAIL( "Problems during reading" );
9d1203
         return aResult;
9d1203
@@ -208,14 +211,16 @@ PassMap StorageItem::getInfo()
9d1203
             OUString aName = aUrlUsr[1];
9d1203
 
9d1203
             OUString aEPasswd;
9d1203
+            OUString aIV;
9d1203
             aPropertyValues[aNodeInd] >>= aEPasswd;
9d1203
+            aPropertyValues[aNodeInd + aNodeCount] >>= aIV;
9d1203
 
9d1203
             PassMap::iterator aIter = aResult.find( aUrl );
9d1203
             if( aIter != aResult.end() )
9d1203
-                aIter->second.emplace_back( aName, aEPasswd );
9d1203
+                aIter->second.emplace_back( aName, aEPasswd, aIV );
9d1203
             else
9d1203
             {
9d1203
-                NamePassRecord aNewRecord( aName, aEPasswd );
9d1203
+                NamePassRecord aNewRecord( aName, aEPasswd, aIV );
9d1203
                 std::vector< NamePassRecord > listToAdd( 1, aNewRecord );
9d1203
 
9d1203
                 aResult.insert( PairUrlRecord( aUrl, listToAdd ) );
9d1203
@@ -279,17 +284,19 @@ sal_Int32 StorageItem::getStorageVersion()
9d1203
     return nResult;
9d1203
 }
9d1203
 
9d1203
-bool StorageItem::getEncodedMP( OUString& aResult )
9d1203
+bool StorageItem::getEncodedMP( OUString& aResult, OUString& aResultIV )
9d1203
 {
9d1203
     if( hasEncoded )
9d1203
     {
9d1203
         aResult = mEncoded;
9d1203
+        aResultIV = mEncodedIV;
9d1203
         return true;
9d1203
     }
9d1203
 
9d1203
-    Sequence< OUString > aNodeNames( 2 );
9d1203
+    Sequence< OUString > aNodeNames( 3 );
9d1203
     aNodeNames[0] = "HasMaster";
9d1203
     aNodeNames[1] = "Master";
9d1203
+    aNodeNames[2] = "MasterInitializationVector";
9d1203
 
9d1203
     Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aNodeNames );
9d1203
 
9d1203
@@ -301,32 +308,37 @@ bool StorageItem::getEncodedMP( OUString& aResult )
9d1203
 
9d1203
     aPropertyValues[0] >>= hasEncoded;
9d1203
     aPropertyValues[1] >>= mEncoded;
9d1203
+    aPropertyValues[2] >>= mEncodedIV;
9d1203
 
9d1203
     aResult = mEncoded;
9d1203
+    aResultIV = mEncodedIV;
9d1203
 
9d1203
     return hasEncoded;
9d1203
 }
9d1203
 
9d1203
 
9d1203
-void StorageItem::setEncodedMP( const OUString& aEncoded, bool bAcceptEmpty )
9d1203
+void StorageItem::setEncodedMP( const OUString& aEncoded, const OUString& aEncodedIV, bool bAcceptEmpty )
9d1203
 {
9d1203
-    Sequence< OUString > sendNames(3);
9d1203
-    Sequence< uno::Any > sendVals(3);
9d1203
+    Sequence< OUString > sendNames(4);
9d1203
+    Sequence< uno::Any > sendVals(4);
9d1203
 
9d1203
     sendNames[0] = "HasMaster";
9d1203
     sendNames[1] = "Master";
9d1203
-    sendNames[2] = "StorageVersion";
9d1203
+    sendNames[2] = "MasterInitializationVector";
9d1203
+    sendNames[3] = "StorageVersion";
9d1203
 
9d1203
     bool bHasMaster = ( !aEncoded.isEmpty() || bAcceptEmpty );
9d1203
     sendVals[0] <<= bHasMaster;
9d1203
     sendVals[1] <<= aEncoded;
9d1203
-    sendVals[2] <<= nCurrentStorageVersion;
9d1203
+    sendVals[2] <<= aEncodedIV;
9d1203
+    sendVals[3] <<= nCurrentStorageVersion;
9d1203
 
9d1203
     ConfigItem::SetModified();
9d1203
     ConfigItem::PutProperties( sendNames, sendVals );
9d1203
 
9d1203
     hasEncoded = bHasMaster;
9d1203
     mEncoded = aEncoded;
9d1203
+    mEncodedIV = aEncodedIV;
9d1203
 }
9d1203
 
9d1203
 
9d1203
@@ -362,11 +374,13 @@ void StorageItem::update( const OUString& aURL, const NamePassRecord& aRecord )
9d1203
     forIndex.push_back( aURL );
9d1203
     forIndex.push_back( aRecord.GetUserName() );
9d1203
 
9d1203
-    Sequence< beans::PropertyValue > sendSeq(1);
9d1203
+    Sequence< beans::PropertyValue > sendSeq(2);
9d1203
 
9d1203
-    sendSeq[0].Name  = "Store/Passwordstorage['" + createIndex( forIndex ) + "']/Password";
9d1203
+    sendSeq[0].Name  = "Store/Passwordstorage['" + createIndex( { aURL, aRecord.GetUserName() } ) + "']/InitializationVector";
9d1203
+    sendSeq[0].Value <<= aRecord.GetPersistentIV();
9d1203
 
9d1203
-    sendSeq[0].Value <<= aRecord.GetPersPasswords();
9d1203
+    sendSeq[1].Name  = "Store/Passwordstorage['" + createIndex( forIndex ) + "']/Password";
9d1203
+    sendSeq[1].Value <<= aRecord.GetPersPasswords();
9d1203
 
9d1203
     ConfigItem::SetModified();
9d1203
     ConfigItem::SetSetProperties( "Store", sendSeq );
9d1203
@@ -427,7 +441,7 @@ void SAL_CALL PasswordContainer::disposing( const EventObject& )
9d1203
     }
9d1203
 }
9d1203
 
9d1203
-std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLine, const OUString& aMasterPasswd, css::task::PasswordRequestMode mode )
9d1203
+std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLine, const OUString& aIV, const OUString& aMasterPasswd, css::task::PasswordRequestMode mode )
9d1203
 {
9d1203
     if( !aMasterPasswd.isEmpty() )
9d1203
     {
9d1203
@@ -442,9 +456,16 @@ std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLin
9d1203
             for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
9d1203
                 code[ ind ] = static_cast<char>(aMasterPasswd.copy( ind*2, 2 ).toUInt32(16));
9d1203
 
9d1203
+            unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0};
9d1203
+            if (!aIV.isEmpty())
9d1203
+            {
9d1203
+                for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
9d1203
+                    iv[ ind ] = static_cast<char>(aIV.copy( ind*2, 2 ).toUInt32(16));
9d1203
+            }
9d1203
+
9d1203
             rtlCipherError result = rtl_cipher_init (
9d1203
                     aDecoder, rtl_Cipher_DirectionDecode,
9d1203
-                    code, RTL_DIGEST_LENGTH_MD5, nullptr, 0 );
9d1203
+                    code, RTL_DIGEST_LENGTH_MD5, iv, RTL_DIGEST_LENGTH_MD5 );
9d1203
 
9d1203
             if( result == rtl_Cipher_E_None )
9d1203
             {
9d1203
@@ -477,7 +498,7 @@ std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLin
9d1203
         "Can't decode!", css::uno::Reference<css::uno::XInterface>(), mode);
9d1203
 }
9d1203
 
9d1203
-OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, const OUString& aMasterPasswd )
9d1203
+OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, const OUString& aIV, const OUString& aMasterPasswd)
9d1203
 {
9d1203
     if( !aMasterPasswd.isEmpty() )
9d1203
     {
9d1203
@@ -494,9 +515,16 @@ OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines
9d1203
             for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
9d1203
                 code[ ind ] = static_cast<char>(aMasterPasswd.copy( ind*2, 2 ).toUInt32(16));
9d1203
 
9d1203
+            unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0};
9d1203
+            if (!aIV.isEmpty())
9d1203
+            {
9d1203
+                for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
9d1203
+                    iv[ ind ] = static_cast<char>(aIV.copy( ind*2, 2 ).toUInt32(16));
9d1203
+            }
9d1203
+
9d1203
             rtlCipherError result = rtl_cipher_init (
9d1203
                     aEncoder, rtl_Cipher_DirectionEncode,
9d1203
-                    code, RTL_DIGEST_LENGTH_MD5, nullptr, 0 );
9d1203
+                    code, RTL_DIGEST_LENGTH_MD5, iv, RTL_DIGEST_LENGTH_MD5 );
9d1203
 
9d1203
             if( result == rtl_Cipher_E_None )
9d1203
             {
9d1203
@@ -564,7 +592,7 @@ void PasswordContainer::UpdateVector( const OUString& aURL, std::vector< NamePas
9d1203
 
9d1203
             if( aRecord.HasPasswords( PERSISTENT_RECORD ) )
9d1203
             {
9d1203
-                aNPIter.SetPersPasswords( aRecord.GetPersPasswords() );
9d1203
+                aNPIter.SetPersPasswords( aRecord.GetPersPasswords(), aRecord.GetPersistentIV() );
9d1203
 
9d1203
                 if( writeFile )
9d1203
                 {
9d1203
@@ -597,7 +625,8 @@ UserRecord PasswordContainer::CopyToUserRecord( const NamePassRecord& aRecord, b
9d1203
     {
9d1203
         try
9d1203
         {
9d1203
-            ::std::vector< OUString > aDecodedPasswords = DecodePasswords( aRecord.GetPersPasswords(), GetMasterPassword( aHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER );
9d1203
+            ::std::vector< OUString > aDecodedPasswords = DecodePasswords( aRecord.GetPersPasswords(), aRecord.GetPersistentIV(),
9d1203
+                                                                           GetMasterPassword( aHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER );
9d1203
             aPasswords.insert( aPasswords.end(), aDecodedPasswords.begin(), aDecodedPasswords.end() );
9d1203
         }
9d1203
         catch( NoMasterException& )
9d1203
@@ -642,6 +671,19 @@ void SAL_CALL PasswordContainer::addPersistent( const OUString& Url, const OUStr
9d1203
     PrivateAdd( Url, UserName, Passwords, PERSISTENT_RECORD, aHandler );
9d1203
 }
9d1203
 
9d1203
+OUString PasswordContainer::createIV()
9d1203
+{
9d1203
+    rtlRandomPool randomPool = mRandomPool.get();
9d1203
+    unsigned char iv[RTL_DIGEST_LENGTH_MD5];
9d1203
+    rtl_random_getBytes(randomPool, iv, RTL_DIGEST_LENGTH_MD5);
9d1203
+    OUStringBuffer aBuffer;
9d1203
+    for (sal_uInt8 i : iv)
9d1203
+    {
9d1203
+        aBuffer.append(OUString::number(i >> 4, 16));
9d1203
+        aBuffer.append(OUString::number(i & 15, 16));
9d1203
+    }
9d1203
+    return aBuffer.makeStringAndClear();
9d1203
+}
9d1203
 
9d1203
 void PasswordContainer::PrivateAdd( const OUString& Url, const OUString& UserName, const Sequence< OUString >& Passwords, char Mode, const Reference< XInteractionHandler >& aHandler )
9d1203
 {
9d1203
@@ -649,7 +691,11 @@ void PasswordContainer::PrivateAdd( const OUString& Url, const OUString& UserNam
9d1203
     ::std::vector< OUString > aStorePass = comphelper::sequenceToContainer< std::vector<OUString> >( Passwords );
9d1203
 
9d1203
     if( Mode == PERSISTENT_RECORD )
9d1203
-        aRecord.SetPersPasswords( EncodePasswords( aStorePass, GetMasterPassword( aHandler ) ) );
9d1203
+    {
9d1203
+        OUString sIV = createIV();
9d1203
+        OUString sEncodedPasswords = EncodePasswords( aStorePass, sIV, GetMasterPassword( aHandler ) );
9d1203
+        aRecord.SetPersPasswords( sEncodedPasswords, sIV );
9d1203
+    }
9d1203
     else if( Mode == MEMORY_RECORD )
9d1203
         aRecord.SetMemPasswords( aStorePass );
9d1203
     else
9d1203
@@ -842,10 +888,10 @@ OUString const & PasswordContainer::GetMasterPassword( const Reference< XInterac
9d1203
 
9d1203
     if( m_aMasterPasswd.isEmpty() && aHandler.is() )
9d1203
     {
9d1203
-        OUString aEncodedMP;
9d1203
+        OUString aEncodedMP, aEncodedMPIV;
9d1203
         bool bDefaultPassword = false;
9d1203
 
9d1203
-        if( !m_pStorageFile->getEncodedMP( aEncodedMP ) )
9d1203
+        if( !m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) )
9d1203
             aRMode = PasswordRequestMode_PASSWORD_CREATE;
9d1203
         else if ( aEncodedMP.isEmpty() )
9d1203
         {
9d1203
@@ -867,14 +913,15 @@ OUString const & PasswordContainer::GetMasterPassword( const Reference< XInterac
9d1203
                         m_aMasterPasswd = aPass;
9d1203
                         std::vector< OUString > aMaster( 1, m_aMasterPasswd );
9d1203
 
9d1203
-                        m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
9d1203
+                        OUString sIV = createIV();
9d1203
+                        m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, sIV, m_aMasterPasswd ), sIV );
9d1203
                     }
9d1203
                     else
9d1203
                     {
9d1203
                         if (m_pStorageFile->getStorageVersion() == 0)
9d1203
                             aPass = ReencodeAsOldHash(aPass);
9d1203
 
9d1203
-                        std::vector< OUString > aRM( DecodePasswords( aEncodedMP, aPass, aRMode ) );
9d1203
+                        std::vector< OUString > aRM( DecodePasswords( aEncodedMP, aEncodedMPIV, aPass, aRMode ) );
9d1203
                         if( aRM.empty() || aPass != aRM[0] )
9d1203
                         {
9d1203
                             bAskAgain = true;
9d1203
@@ -1031,7 +1078,8 @@ Sequence< UrlRecord > SAL_CALL PasswordContainer::getAllPersistent( const Refere
9d1203
             {
9d1203
                 sal_Int32 oldLen = aUsers.getLength();
9d1203
                 aUsers.realloc( oldLen + 1 );
9d1203
-                aUsers[ oldLen ] = UserRecord( aNP.GetUserName(), comphelper::containerToSequence( DecodePasswords( aNP.GetPersPasswords(), GetMasterPassword( xHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER ) ) );
9d1203
+                aUsers[ oldLen ] = UserRecord( aNP.GetUserName(), comphelper::containerToSequence( DecodePasswords( aNP.GetPersPasswords(), aNP.GetPersistentIV(),
9d1203
+                                                                                                                    GetMasterPassword( xHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER ) ) );
9d1203
             }
9d1203
 
9d1203
         if( aUsers.hasElements() )
9d1203
@@ -1048,12 +1096,12 @@ Sequence< UrlRecord > SAL_CALL PasswordContainer::getAllPersistent( const Refere
9d1203
 sal_Bool SAL_CALL PasswordContainer::authorizateWithMasterPassword( const uno::Reference< task::XInteractionHandler >& xHandler )
9d1203
 {
9d1203
     bool bResult = false;
9d1203
-    OUString aEncodedMP;
9d1203
+    OUString aEncodedMP, aEncodedMPIV;
9d1203
     uno::Reference< task::XInteractionHandler > xTmpHandler = xHandler;
9d1203
     ::osl::MutexGuard aGuard( mMutex );
9d1203
 
9d1203
     // the method should fail if there is no master password
9d1203
-    if( m_pStorageFile && m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) )
9d1203
+    if( m_pStorageFile && m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) )
9d1203
     {
9d1203
         if ( aEncodedMP.isEmpty() )
9d1203
         {
9d1203
@@ -1122,8 +1170,8 @@ sal_Bool SAL_CALL PasswordContainer::changeMasterPassword( const uno::Reference<
9d1203
 
9d1203
         bool bCanChangePassword = true;
9d1203
         // if there is already a stored master password it should be entered by the user before the change happen
9d1203
-        OUString aEncodedMP;
9d1203
-        if( !m_aMasterPasswd.isEmpty() || m_pStorageFile->getEncodedMP( aEncodedMP ) )
9d1203
+        OUString aEncodedMP, aEncodedMPIV;
9d1203
+        if( !m_aMasterPasswd.isEmpty() || m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) )
9d1203
             bCanChangePassword = authorizateWithMasterPassword( xTmpHandler );
9d1203
 
9d1203
         if ( bCanChangePassword )
9d1203
@@ -1142,7 +1190,8 @@ sal_Bool SAL_CALL PasswordContainer::changeMasterPassword( const uno::Reference<
9d1203
                 // store the new master password
9d1203
                 m_aMasterPasswd = aPass;
9d1203
                 std::vector< OUString > aMaster( 1, m_aMasterPasswd );
9d1203
-                m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
9d1203
+                OUString aIV = createIV();
9d1203
+                m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, aIV, m_aMasterPasswd ), aIV );
9d1203
 
9d1203
                 // store all the entries with the new password
9d1203
                 for ( const auto& rURL : aPersistent )
9d1203
@@ -1167,7 +1216,7 @@ void SAL_CALL PasswordContainer::removeMasterPassword()
9d1203
     if ( m_pStorageFile )
9d1203
     {
9d1203
         m_aMasterPasswd.clear();
9d1203
-        m_pStorageFile->setEncodedMP( OUString() ); // let the master password be removed from configuration
9d1203
+        m_pStorageFile->setEncodedMP( OUString(), OUString() ); // let the master password be removed from configuration
9d1203
     }
9d1203
 }
9d1203
 
9d1203
@@ -1178,8 +1227,8 @@ sal_Bool SAL_CALL PasswordContainer::hasMasterPassword(  )
9d1203
     if ( !m_pStorageFile )
9d1203
         throw uno::RuntimeException();
9d1203
 
9d1203
-    OUString aEncodedMP;
9d1203
-    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) );
9d1203
+    OUString aEncodedMP, aEncodedMPIV;
9d1203
+    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) );
9d1203
 }
9d1203
 
9d1203
 sal_Bool SAL_CALL PasswordContainer::allowPersistentStoring( sal_Bool bAllow )
9d1203
@@ -1226,8 +1275,8 @@ sal_Bool SAL_CALL PasswordContainer::useDefaultMasterPassword( const uno::Refere
9d1203
 
9d1203
         bool bCanChangePassword = true;
9d1203
         // if there is already a stored nondefault master password it should be entered by the user before the change happen
9d1203
-        OUString aEncodedMP;
9d1203
-        if( m_pStorageFile->getEncodedMP( aEncodedMP ) && !aEncodedMP.isEmpty() )
9d1203
+        OUString aEncodedMP, aEncodedMPIV;
9d1203
+        if( m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) && !aEncodedMP.isEmpty() )
9d1203
             bCanChangePassword = authorizateWithMasterPassword( xTmpHandler );
9d1203
 
9d1203
         if ( bCanChangePassword )
9d1203
@@ -1244,7 +1293,7 @@ sal_Bool SAL_CALL PasswordContainer::useDefaultMasterPassword( const uno::Refere
9d1203
 
9d1203
                 // store the empty string to flag the default master password
9d1203
                 m_aMasterPasswd = aPass;
9d1203
-                m_pStorageFile->setEncodedMP( OUString(), true );
9d1203
+                m_pStorageFile->setEncodedMP( OUString(), OUString(), true );
9d1203
 
9d1203
                 // store all the entries with the new password
9d1203
                 for ( const auto& rURL : aPersistent )
9d1203
@@ -1268,8 +1317,8 @@ sal_Bool SAL_CALL PasswordContainer::isDefaultMasterPasswordUsed()
9d1203
     if ( !m_pStorageFile )
9d1203
         throw uno::RuntimeException();
9d1203
 
9d1203
-    OUString aEncodedMP;
9d1203
-    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) && aEncodedMP.isEmpty() );
9d1203
+    OUString aEncodedMP, aEncodedMPIV;
9d1203
+    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) && aEncodedMP.isEmpty() );
9d1203
 }
9d1203
 
9d1203
 
9d1203
diff --git a/svl/source/passwordcontainer/passwordcontainer.hxx b/svl/source/passwordcontainer/passwordcontainer.hxx
9d1203
index cf5c717d0c9e..4e3a6629139e 100644
9d1203
--- a/svl/source/passwordcontainer/passwordcontainer.hxx
9d1203
+++ b/svl/source/passwordcontainer/passwordcontainer.hxx
9d1203
@@ -33,6 +33,7 @@
9d1203
 #include <unotools/configitem.hxx>
9d1203
 #include <ucbhelper/interactionrequest.hxx>
9d1203
 
9d1203
+#include <rtl/random.h>
9d1203
 #include <rtl/ref.hxx>
9d1203
 #include <osl/mutex.hxx>
9d1203
 
9d1203
@@ -51,11 +52,12 @@ class NamePassRecord
9d1203
     ::std::vector< OUString >                      m_aMemPass;
9d1203
 
9d1203
     // persistent passwords are encrypted in one string
9d1203
-    bool                                                  m_bHasPersPass;
9d1203
+    bool                                           m_bHasPersPass;
9d1203
     OUString                                       m_aPersPass;
9d1203
+    OUString                                       m_aPersistentIV;
9d1203
 
9d1203
     void InitArrays( bool bHasMemoryList, const ::std::vector< OUString >& aMemoryList,
9d1203
-                     bool bHasPersistentList, const OUString& aPersistentList )
9d1203
+                     bool bHasPersistentList, const OUString& aPersistentList, const OUString& aPersistentIV )
9d1203
     {
9d1203
         m_bHasMemPass = bHasMemoryList;
9d1203
         if ( bHasMemoryList )
9d1203
@@ -63,7 +65,10 @@ class NamePassRecord
9d1203
 
9d1203
         m_bHasPersPass = bHasPersistentList;
9d1203
         if ( bHasPersistentList )
9d1203
+        {
9d1203
             m_aPersPass = aPersistentList;
9d1203
+            m_aPersistentIV = aPersistentIV;
9d1203
+        }
9d1203
     }
9d1203
 
9d1203
 public:
9d1203
@@ -75,11 +80,12 @@ public:
9d1203
     {
9d1203
     }
9d1203
 
9d1203
-    NamePassRecord( const OUString& aName, const OUString& aPersistentList )
9d1203
+    NamePassRecord( const OUString& aName, const OUString& aPersistentList, const OUString& aPersistentIV )
9d1203
         : m_aName( aName )
9d1203
         , m_bHasMemPass( false )
9d1203
         , m_bHasPersPass( true )
9d1203
         , m_aPersPass( aPersistentList )
9d1203
+        , m_aPersistentIV( aPersistentIV )
9d1203
     {
9d1203
     }
9d1203
 
9d1203
@@ -88,7 +94,8 @@ public:
9d1203
         , m_bHasMemPass( false )
9d1203
         , m_bHasPersPass( false )
9d1203
     {
9d1203
-        InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass, aRecord.m_bHasPersPass, aRecord.m_aPersPass );
9d1203
+        InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass,
9d1203
+                    aRecord.m_bHasPersPass, aRecord.m_aPersPass, aRecord.m_aPersistentIV );
9d1203
     }
9d1203
 
9d1203
     NamePassRecord& operator=( const NamePassRecord& aRecord )
9d1203
@@ -99,7 +106,9 @@ public:
9d1203
 
9d1203
             m_aMemPass.clear();
9d1203
             m_aPersPass.clear();
9d1203
-            InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass, aRecord.m_bHasPersPass, aRecord.m_aPersPass );
9d1203
+            m_aPersistentIV.clear();
9d1203
+            InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass,
9d1203
+                        aRecord.m_bHasPersPass, aRecord.m_aPersPass, aRecord.m_aPersistentIV );
9d1203
         }
9d1203
         return *this;
9d1203
     }
9d1203
@@ -135,15 +144,24 @@ public:
9d1203
         return OUString();
9d1203
     }
9d1203
 
9d1203
+    OUString GetPersistentIV() const
9d1203
+    {
9d1203
+        if ( m_bHasPersPass )
9d1203
+            return m_aPersistentIV;
9d1203
+
9d1203
+        return OUString();
9d1203
+    }
9d1203
+
9d1203
     void SetMemPasswords( const ::std::vector< OUString >& aMemList )
9d1203
     {
9d1203
         m_aMemPass = aMemList;
9d1203
         m_bHasMemPass = true;
9d1203
     }
9d1203
 
9d1203
-    void SetPersPasswords( const OUString& aPersList )
9d1203
+    void SetPersPasswords( const OUString& aPersList, const OUString& aPersIV )
9d1203
     {
9d1203
         m_aPersPass = aPersList;
9d1203
+        m_aPersistentIV = aPersIV;
9d1203
         m_bHasPersPass = true;
9d1203
     }
9d1203
 
9d1203
@@ -158,6 +176,7 @@ public:
9d1203
         {
9d1203
             m_bHasPersPass = false;
9d1203
             m_aPersPass.clear();
9d1203
+            m_aPersistentIV.clear();
9d1203
         }
9d1203
     }
9d1203
 
9d1203
@@ -181,6 +200,7 @@ private:
9d1203
     PasswordContainer*     mainCont;
9d1203
     bool                   hasEncoded;
9d1203
     OUString        mEncoded;
9d1203
+    OUString        mEncodedIV;
9d1203
 
9d1203
     virtual void            ImplCommit() override;
9d1203
 
9d1203
@@ -201,8 +221,8 @@ public:
9d1203
 
9d1203
     sal_Int32 getStorageVersion();
9d1203
 
9d1203
-    bool getEncodedMP( OUString& aResult );
9d1203
-    void setEncodedMP( const OUString& aResult, bool bAcceptEnmpty = false );
9d1203
+    bool getEncodedMP( OUString& aResult, OUString& aResultIV );
9d1203
+    void setEncodedMP( const OUString& aResult, const OUString& aResultIV, bool bAcceptEmpty = false );
9d1203
     void setUseStorage( bool bUse );
9d1203
     bool useStorage();
9d1203
 
9d1203
@@ -223,6 +243,29 @@ private:
9d1203
     css::uno::Reference< css::lang::XComponent > mComponent;
9d1203
     SysCredentialsConfig mUrlContainer;
9d1203
 
9d1203
+    class RandomPool
9d1203
+    {
9d1203
+    private:
9d1203
+        rtlRandomPool m_aRandomPool;
9d1203
+    public:
9d1203
+        RandomPool() : m_aRandomPool(rtl_random_createPool())
9d1203
+        {
9d1203
+        }
9d1203
+        rtlRandomPool get()
9d1203
+        {
9d1203
+            return m_aRandomPool;
9d1203
+        }
9d1203
+        ~RandomPool()
9d1203
+        {
9d1203
+            // Clean up random pool memory
9d1203
+            rtl_random_destroyPool(m_aRandomPool);
9d1203
+        }
9d1203
+    };
9d1203
+
9d1203
+    RandomPool mRandomPool;
9d1203
+
9d1203
+    OUString createIV();
9d1203
+
9d1203
     /// @throws css::uno::RuntimeException
9d1203
     css::uno::Sequence< css::task::UserRecord > CopyToUserRecordSequence(
9d1203
                                         const ::std::vector< NamePassRecord >& original,
9d1203
@@ -273,10 +316,10 @@ css::task::UrlRecord find(
9d1203
                               const css::uno::Reference< css::task::XInteractionHandler >& Handler );
9d1203
 
9d1203
     /// @throws css::uno::RuntimeException
9d1203
-    static ::std::vector< OUString > DecodePasswords( const OUString& aLine, const OUString& aMasterPassword, css::task::PasswordRequestMode mode );
9d1203
+    static ::std::vector< OUString > DecodePasswords( const OUString& aLine, const OUString& aIV, const OUString& aMasterPassword, css::task::PasswordRequestMode mode );
9d1203
 
9d1203
     /// @throws css::uno::RuntimeException
9d1203
-    static OUString EncodePasswords(const std::vector< OUString >& lines, const OUString& aMasterPassword );
9d1203
+    static OUString EncodePasswords(const std::vector< OUString >& lines, const OUString& aIV, const OUString& aMasterPassword );
9d1203
 
9d1203
 public:
9d1203
     PasswordContainer( const css::uno::Reference< css::lang::XMultiServiceFactory >& );
9d1203
-- 
9d1203
2.37.1
9d1203