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

4b0772
From e809625c2ca9f0c026aab9b5c2d13ced628c13e9 Mon Sep 17 00:00:00 2001
4b0772
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
4b0772
Date: Tue, 22 Mar 2022 17:22:22 +0000
4b0772
Subject: [PATCH 3/5] CVE-2022-26306 add Initialization Vectors to password
4b0772
 storage
4b0772
4b0772
old ones default to the current all zero case and continue to work
4b0772
as before
4b0772
4b0772
Change-Id: I6fe3b02fafcce1b5e7133e77e76a5118177d77af
4b0772
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131974
4b0772
Tested-by: Jenkins
4b0772
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
4b0772
(cherry picked from commit 192fa1e3bfc6269f2ebb91716471485a56074aea)
4b0772
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132306
4b0772
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
4b0772
(cherry picked from commit ab77587ec300f5c30084471000663c46ddf25dad)
4b0772
---
4b0772
 .../schema/org/openoffice/Office/Common.xcs   |  10 ++
4b0772
 .../passwordcontainer/passwordcontainer.cxx   | 127 ++++++++++++------
4b0772
 .../passwordcontainer/passwordcontainer.hxx   |  63 +++++++--
4b0772
 3 files changed, 151 insertions(+), 49 deletions(-)
4b0772
4b0772
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
4b0772
index 922efc33cca7..8d87d00d5369 100644
4b0772
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
4b0772
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
4b0772
@@ -27,6 +27,11 @@
4b0772
       <info>
4b0772
         <desc>Contains a container for passwords.</desc>
4b0772
       </info>
4b0772
+      <prop oor:name="InitializationVector" oor:type="xs:string">
4b0772
+        <info>
4b0772
+          <desc>Contains an initialization vector for the password encryption.</desc>
4b0772
+        </info>
4b0772
+      </prop>
4b0772
       <prop oor:name="Password" oor:type="xs:string" oor:localized="false">
4b0772
         <info>
4b0772
           <desc>Contains a password encoded with the master password.</desc>
4b0772
@@ -954,6 +959,11 @@
4b0772
         </info>
4b0772
         <value>false</value>
4b0772
       </prop>
4b0772
+      <prop oor:name="MasterInitializationVector" oor:type="xs:string">
4b0772
+        <info>
4b0772
+          <desc>Contains an initialization vector for the master password encryption.</desc>
4b0772
+        </info>
4b0772
+      </prop>
4b0772
       <prop oor:name="Master" oor:type="xs:string" oor:nillable="false">
4b0772
         <info>
4b0772
           <desc>Contains the master password encrypted by itself.</desc>
4b0772
diff --git a/svl/source/passwordcontainer/passwordcontainer.cxx b/svl/source/passwordcontainer/passwordcontainer.cxx
4b0772
index b674844f91d3..ef79470a2cb6 100644
4b0772
--- a/svl/source/passwordcontainer/passwordcontainer.cxx
4b0772
+++ b/svl/source/passwordcontainer/passwordcontainer.cxx
4b0772
@@ -181,15 +181,18 @@ PassMap StorageItem::getInfo()
4b0772
 
4b0772
     Sequence< OUString > aNodeNames     = ConfigItem::GetNodeNames( "Store" );
4b0772
     sal_Int32 aNodeCount = aNodeNames.getLength();
4b0772
-    Sequence< OUString > aPropNames( aNodeCount );
4b0772
+    Sequence< OUString > aPropNames( aNodeCount * 2);
4b0772
 
4b0772
     std::transform(aNodeNames.begin(), aNodeNames.end(), aPropNames.begin(),
4b0772
         [](const OUString& rName) -> OUString {
4b0772
             return "Store/Passwordstorage['" + rName + "']/Password"; });
4b0772
+    std::transform(aNodeNames.begin(), aNodeNames.end(), aPropNames.getArray() + aNodeCount,
4b0772
+        [](const OUString& rName) -> OUString {
4b0772
+            return "Store/Passwordstorage['" + rName + "']/InitializationVector"; });
4b0772
 
4b0772
     Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aPropNames );
4b0772
 
4b0772
-    if( aPropertyValues.getLength() != aNodeCount )
4b0772
+    if( aPropertyValues.getLength() != aNodeCount * 2)
4b0772
     {
4b0772
         OSL_FAIL( "Problems during reading" );
4b0772
         return aResult;
4b0772
@@ -205,14 +208,16 @@ PassMap StorageItem::getInfo()
4b0772
             OUString aName = aUrlUsr[1];
4b0772
 
4b0772
             OUString aEPasswd;
4b0772
+            OUString aIV;
4b0772
             aPropertyValues[aNodeInd] >>= aEPasswd;
4b0772
+            aPropertyValues[aNodeInd + aNodeCount] >>= aIV;
4b0772
 
4b0772
             PassMap::iterator aIter = aResult.find( aUrl );
4b0772
             if( aIter != aResult.end() )
4b0772
-                aIter->second.emplace_back( aName, aEPasswd );
4b0772
+                aIter->second.emplace_back( aName, aEPasswd, aIV );
4b0772
             else
4b0772
             {
4b0772
-                NamePassRecord aNewRecord( aName, aEPasswd );
4b0772
+                NamePassRecord aNewRecord( aName, aEPasswd, aIV );
4b0772
                 std::vector< NamePassRecord > listToAdd( 1, aNewRecord );
4b0772
 
4b0772
                 aResult.insert( PairUrlRecord( aUrl, listToAdd ) );
4b0772
@@ -276,17 +281,19 @@ sal_Int32 StorageItem::getStorageVersion()
4b0772
     return nResult;
4b0772
 }
4b0772
 
4b0772
-bool StorageItem::getEncodedMP( OUString& aResult )
4b0772
+bool StorageItem::getEncodedMP( OUString& aResult, OUString& aResultIV )
4b0772
 {
4b0772
     if( hasEncoded )
4b0772
     {
4b0772
         aResult = mEncoded;
4b0772
+        aResultIV = mEncodedIV;
4b0772
         return true;
4b0772
     }
4b0772
 
4b0772
-    Sequence< OUString > aNodeNames( 2 );
4b0772
+    Sequence< OUString > aNodeNames( 3 );
4b0772
     aNodeNames[0] = "HasMaster";
4b0772
     aNodeNames[1] = "Master";
4b0772
+    aNodeNames[2] = "MasterInitializationVector";
4b0772
 
4b0772
     Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aNodeNames );
4b0772
 
4b0772
@@ -298,32 +305,37 @@ bool StorageItem::getEncodedMP( OUString& aResult )
4b0772
 
4b0772
     aPropertyValues[0] >>= hasEncoded;
4b0772
     aPropertyValues[1] >>= mEncoded;
4b0772
+    aPropertyValues[2] >>= mEncodedIV;
4b0772
 
4b0772
     aResult = mEncoded;
4b0772
+    aResultIV = mEncodedIV;
4b0772
 
4b0772
     return hasEncoded;
4b0772
 }
4b0772
 
4b0772
 
4b0772
-void StorageItem::setEncodedMP( const OUString& aEncoded, bool bAcceptEmpty )
4b0772
+void StorageItem::setEncodedMP( const OUString& aEncoded, const OUString& aEncodedIV, bool bAcceptEmpty )
4b0772
 {
4b0772
-    Sequence< OUString > sendNames(3);
4b0772
-    Sequence< uno::Any > sendVals(3);
4b0772
+    Sequence< OUString > sendNames(4);
4b0772
+    Sequence< uno::Any > sendVals(4);
4b0772
 
4b0772
     sendNames[0] = "HasMaster";
4b0772
     sendNames[1] = "Master";
4b0772
-    sendNames[2] = "StorageVersion";
4b0772
+    sendNames[2] = "MasterInitializationVector";
4b0772
+    sendNames[3] = "StorageVersion";
4b0772
 
4b0772
     bool bHasMaster = ( !aEncoded.isEmpty() || bAcceptEmpty );
4b0772
     sendVals[0] <<= bHasMaster;
4b0772
     sendVals[1] <<= aEncoded;
4b0772
-    sendVals[2] <<= nCurrentStorageVersion;
4b0772
+    sendVals[2] <<= aEncodedIV;
4b0772
+    sendVals[3] <<= nCurrentStorageVersion;
4b0772
 
4b0772
     ConfigItem::SetModified();
4b0772
     ConfigItem::PutProperties( sendNames, sendVals );
4b0772
 
4b0772
     hasEncoded = bHasMaster;
4b0772
     mEncoded = aEncoded;
4b0772
+    mEncodedIV = aEncodedIV;
4b0772
 }
4b0772
 
4b0772
 
4b0772
@@ -359,11 +371,13 @@ void StorageItem::update( const OUString& aURL, const NamePassRecord& aRecord )
4b0772
     forIndex.push_back( aURL );
4b0772
     forIndex.push_back( aRecord.GetUserName() );
4b0772
 
4b0772
-    Sequence< beans::PropertyValue > sendSeq(1);
4b0772
+    Sequence< beans::PropertyValue > sendSeq(2);
4b0772
 
4b0772
-    sendSeq[0].Name  = "Store/Passwordstorage['" + createIndex( forIndex ) + "']/Password";
4b0772
+    sendSeq[0].Name  = "Store/Passwordstorage['" + createIndex( forIndex ) + "']/InitializationVector";
4b0772
+    sendSeq[0].Value <<= aRecord.GetPersistentIV();
4b0772
 
4b0772
-    sendSeq[0].Value <<= aRecord.GetPersPasswords();
4b0772
+    sendSeq[1].Name  = "Store/Passwordstorage['" + createIndex( forIndex ) + "']/Password";
4b0772
+    sendSeq[1].Value <<= aRecord.GetPersPasswords();
4b0772
 
4b0772
     ConfigItem::SetModified();
4b0772
     ConfigItem::SetSetProperties( "Store", sendSeq );
4b0772
@@ -424,7 +438,7 @@ void SAL_CALL PasswordContainer::disposing( const EventObject& )
4b0772
     }
4b0772
 }
4b0772
 
4b0772
-std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLine, const OUString& aMasterPasswd, css::task::PasswordRequestMode mode )
4b0772
+std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLine, const OUString& aIV, const OUString& aMasterPasswd, css::task::PasswordRequestMode mode )
4b0772
 {
4b0772
     if( !aMasterPasswd.isEmpty() )
4b0772
     {
4b0772
@@ -439,9 +453,16 @@ std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLin
4b0772
             for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
4b0772
                 code[ ind ] = static_cast<char>(aMasterPasswd.copy( ind*2, 2 ).toUInt32(16));
4b0772
 
4b0772
+            unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0};
4b0772
+            if (!aIV.isEmpty())
4b0772
+            {
4b0772
+                for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
4b0772
+                    iv[ ind ] = static_cast<char>(aIV.copy( ind*2, 2 ).toUInt32(16));
4b0772
+            }
4b0772
+
4b0772
             rtlCipherError result = rtl_cipher_init (
4b0772
                     aDecoder, rtl_Cipher_DirectionDecode,
4b0772
-                    code, RTL_DIGEST_LENGTH_MD5, nullptr, 0 );
4b0772
+                    code, RTL_DIGEST_LENGTH_MD5, iv, RTL_DIGEST_LENGTH_MD5 );
4b0772
 
4b0772
             if( result == rtl_Cipher_E_None )
4b0772
             {
4b0772
@@ -474,7 +495,7 @@ std::vector< OUString > PasswordContainer::DecodePasswords( const OUString& aLin
4b0772
         "Can't decode!", css::uno::Reference<css::uno::XInterface>(), mode);
4b0772
 }
4b0772
 
4b0772
-OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, const OUString& aMasterPasswd )
4b0772
+OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines, const OUString& aIV, const OUString& aMasterPasswd)
4b0772
 {
4b0772
     if( !aMasterPasswd.isEmpty() )
4b0772
     {
4b0772
@@ -491,9 +512,16 @@ OUString PasswordContainer::EncodePasswords(const std::vector< OUString >& lines
4b0772
             for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
4b0772
                 code[ ind ] = static_cast<char>(aMasterPasswd.copy( ind*2, 2 ).toUInt32(16));
4b0772
 
4b0772
+            unsigned char iv[RTL_DIGEST_LENGTH_MD5] = {0};
4b0772
+            if (!aIV.isEmpty())
4b0772
+            {
4b0772
+                for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ )
4b0772
+                    iv[ ind ] = static_cast<char>(aIV.copy( ind*2, 2 ).toUInt32(16));
4b0772
+            }
4b0772
+
4b0772
             rtlCipherError result = rtl_cipher_init (
4b0772
                     aEncoder, rtl_Cipher_DirectionEncode,
4b0772
-                    code, RTL_DIGEST_LENGTH_MD5, nullptr, 0 );
4b0772
+                    code, RTL_DIGEST_LENGTH_MD5, iv, RTL_DIGEST_LENGTH_MD5 );
4b0772
 
4b0772
             if( result == rtl_Cipher_E_None )
4b0772
             {
4b0772
@@ -561,7 +589,7 @@ void PasswordContainer::UpdateVector( const OUString& aURL, std::vector< NamePas
4b0772
 
4b0772
             if( aRecord.HasPasswords( PERSISTENT_RECORD ) )
4b0772
             {
4b0772
-                aNPIter.SetPersPasswords( aRecord.GetPersPasswords() );
4b0772
+                aNPIter.SetPersPasswords( aRecord.GetPersPasswords(), aRecord.GetPersistentIV() );
4b0772
 
4b0772
                 if( writeFile )
4b0772
                 {
4b0772
@@ -594,7 +622,8 @@ UserRecord PasswordContainer::CopyToUserRecord( const NamePassRecord& aRecord, b
4b0772
     {
4b0772
         try
4b0772
         {
4b0772
-            ::std::vector< OUString > aDecodedPasswords = DecodePasswords( aRecord.GetPersPasswords(), GetMasterPassword( aHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER );
4b0772
+            ::std::vector< OUString > aDecodedPasswords = DecodePasswords( aRecord.GetPersPasswords(), aRecord.GetPersistentIV(),
4b0772
+                                                                           GetMasterPassword( aHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER );
4b0772
             aPasswords.insert( aPasswords.end(), aDecodedPasswords.begin(), aDecodedPasswords.end() );
4b0772
         }
4b0772
         catch( NoMasterException& )
4b0772
@@ -639,6 +668,19 @@ void SAL_CALL PasswordContainer::addPersistent( const OUString& Url, const OUStr
4b0772
     PrivateAdd( Url, UserName, Passwords, PERSISTENT_RECORD, aHandler );
4b0772
 }
4b0772
 
4b0772
+OUString PasswordContainer::createIV()
4b0772
+{
4b0772
+    rtlRandomPool randomPool = mRandomPool.get();
4b0772
+    unsigned char iv[RTL_DIGEST_LENGTH_MD5];
4b0772
+    rtl_random_getBytes(randomPool, iv, RTL_DIGEST_LENGTH_MD5);
4b0772
+    OUStringBuffer aBuffer;
4b0772
+    for (sal_uInt8 i : iv)
4b0772
+    {
4b0772
+        aBuffer.append(OUString::number(i >> 4, 16));
4b0772
+        aBuffer.append(OUString::number(i & 15, 16));
4b0772
+    }
4b0772
+    return aBuffer.makeStringAndClear();
4b0772
+}
4b0772
 
4b0772
 void PasswordContainer::PrivateAdd( const OUString& Url, const OUString& UserName, const Sequence< OUString >& Passwords, char Mode, const Reference< XInteractionHandler >& aHandler )
4b0772
 {
4b0772
@@ -646,7 +688,11 @@ void PasswordContainer::PrivateAdd( const OUString& Url, const OUString& UserNam
4b0772
     ::std::vector< OUString > aStorePass = comphelper::sequenceToContainer< std::vector<OUString> >( Passwords );
4b0772
 
4b0772
     if( Mode == PERSISTENT_RECORD )
4b0772
-        aRecord.SetPersPasswords( EncodePasswords( aStorePass, GetMasterPassword( aHandler ) ) );
4b0772
+    {
4b0772
+        OUString sIV = createIV();
4b0772
+        OUString sEncodedPasswords = EncodePasswords( aStorePass, sIV, GetMasterPassword( aHandler ) );
4b0772
+        aRecord.SetPersPasswords( sEncodedPasswords, sIV );
4b0772
+    }
4b0772
     else if( Mode == MEMORY_RECORD )
4b0772
         aRecord.SetMemPasswords( aStorePass );
4b0772
     else
4b0772
@@ -839,10 +885,10 @@ OUString const & PasswordContainer::GetMasterPassword( const Reference< XInterac
4b0772
 
4b0772
     if( m_aMasterPasswd.isEmpty() && aHandler.is() )
4b0772
     {
4b0772
-        OUString aEncodedMP;
4b0772
+        OUString aEncodedMP, aEncodedMPIV;
4b0772
         bool bDefaultPassword = false;
4b0772
 
4b0772
-        if( !m_pStorageFile->getEncodedMP( aEncodedMP ) )
4b0772
+        if( !m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) )
4b0772
             aRMode = PasswordRequestMode_PASSWORD_CREATE;
4b0772
         else if ( aEncodedMP.isEmpty() )
4b0772
         {
4b0772
@@ -864,14 +910,15 @@ OUString const & PasswordContainer::GetMasterPassword( const Reference< XInterac
4b0772
                         m_aMasterPasswd = aPass;
4b0772
                         std::vector< OUString > aMaster( 1, m_aMasterPasswd );
4b0772
 
4b0772
-                        m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
4b0772
+                        OUString sIV = createIV();
4b0772
+                        m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, sIV, m_aMasterPasswd ), sIV );
4b0772
                     }
4b0772
                     else
4b0772
                     {
4b0772
                         if (m_pStorageFile->getStorageVersion() == 0)
4b0772
                             aPass = ReencodeAsOldHash(aPass);
4b0772
 
4b0772
-                        std::vector< OUString > aRM( DecodePasswords( aEncodedMP, aPass, aRMode ) );
4b0772
+                        std::vector< OUString > aRM( DecodePasswords( aEncodedMP, aEncodedMPIV, aPass, aRMode ) );
4b0772
                         if( aRM.empty() || aPass != aRM[0] )
4b0772
                         {
4b0772
                             bAskAgain = true;
4b0772
@@ -1028,7 +1075,8 @@ Sequence< UrlRecord > SAL_CALL PasswordContainer::getAllPersistent( const Refere
4b0772
             {
4b0772
                 sal_Int32 oldLen = aUsers.getLength();
4b0772
                 aUsers.realloc( oldLen + 1 );
4b0772
-                aUsers[ oldLen ] = UserRecord( aNP.GetUserName(), comphelper::containerToSequence( DecodePasswords( aNP.GetPersPasswords(), GetMasterPassword( xHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER ) ) );
4b0772
+                aUsers[ oldLen ] = UserRecord( aNP.GetUserName(), comphelper::containerToSequence( DecodePasswords( aNP.GetPersPasswords(), aNP.GetPersistentIV(),
4b0772
+                                                                                                                    GetMasterPassword( xHandler ), css::task::PasswordRequestMode_PASSWORD_ENTER ) ) );
4b0772
             }
4b0772
 
4b0772
         if( aUsers.hasElements() )
4b0772
@@ -1045,12 +1093,12 @@ Sequence< UrlRecord > SAL_CALL PasswordContainer::getAllPersistent( const Refere
4b0772
 sal_Bool SAL_CALL PasswordContainer::authorizateWithMasterPassword( const uno::Reference< task::XInteractionHandler >& xHandler )
4b0772
 {
4b0772
     bool bResult = false;
4b0772
-    OUString aEncodedMP;
4b0772
+    OUString aEncodedMP, aEncodedMPIV;
4b0772
     uno::Reference< task::XInteractionHandler > xTmpHandler = xHandler;
4b0772
     ::osl::MutexGuard aGuard( mMutex );
4b0772
 
4b0772
     // the method should fail if there is no master password
4b0772
-    if( m_pStorageFile && m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) )
4b0772
+    if( m_pStorageFile && m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) )
4b0772
     {
4b0772
         if ( aEncodedMP.isEmpty() )
4b0772
         {
4b0772
@@ -1118,8 +1166,8 @@ sal_Bool SAL_CALL PasswordContainer::changeMasterPassword( const uno::Reference<
4b0772
 
4b0772
         bool bCanChangePassword = true;
4b0772
         // if there is already a stored master password it should be entered by the user before the change happen
4b0772
-        OUString aEncodedMP;
4b0772
-        if( !m_aMasterPasswd.isEmpty() || m_pStorageFile->getEncodedMP( aEncodedMP ) )
4b0772
+        OUString aEncodedMP, aEncodedMPIV;
4b0772
+        if( !m_aMasterPasswd.isEmpty() || m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) )
4b0772
             bCanChangePassword = authorizateWithMasterPassword( xTmpHandler );
4b0772
 
4b0772
         if ( bCanChangePassword )
4b0772
@@ -1138,7 +1186,8 @@ sal_Bool SAL_CALL PasswordContainer::changeMasterPassword( const uno::Reference<
4b0772
                 // store the new master password
4b0772
                 m_aMasterPasswd = aPass;
4b0772
                 std::vector< OUString > aMaster( 1, m_aMasterPasswd );
4b0772
-                m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
4b0772
+                OUString aIV = createIV();
4b0772
+                m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, aIV, m_aMasterPasswd ), aIV );
4b0772
 
4b0772
                 // store all the entries with the new password
4b0772
                 for ( const auto& rURL : aPersistent )
4b0772
@@ -1163,7 +1212,7 @@ void SAL_CALL PasswordContainer::removeMasterPassword()
4b0772
     if ( m_pStorageFile )
4b0772
     {
4b0772
         m_aMasterPasswd.clear();
4b0772
-        m_pStorageFile->setEncodedMP( OUString() ); // let the master password be removed from configuration
4b0772
+        m_pStorageFile->setEncodedMP( OUString(), OUString() ); // let the master password be removed from configuration
4b0772
     }
4b0772
 }
4b0772
 
4b0772
@@ -1174,8 +1223,8 @@ sal_Bool SAL_CALL PasswordContainer::hasMasterPassword(  )
4b0772
     if ( !m_pStorageFile )
4b0772
         throw uno::RuntimeException();
4b0772
 
4b0772
-    OUString aEncodedMP;
4b0772
-    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) );
4b0772
+    OUString aEncodedMP, aEncodedMPIV;
4b0772
+    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) );
4b0772
 }
4b0772
 
4b0772
 sal_Bool SAL_CALL PasswordContainer::allowPersistentStoring( sal_Bool bAllow )
4b0772
@@ -1222,8 +1271,8 @@ sal_Bool SAL_CALL PasswordContainer::useDefaultMasterPassword( const uno::Refere
4b0772
 
4b0772
         bool bCanChangePassword = true;
4b0772
         // if there is already a stored nondefault master password it should be entered by the user before the change happen
4b0772
-        OUString aEncodedMP;
4b0772
-        if( m_pStorageFile->getEncodedMP( aEncodedMP ) && !aEncodedMP.isEmpty() )
4b0772
+        OUString aEncodedMP, aEncodedMPIV;
4b0772
+        if( m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) && !aEncodedMP.isEmpty() )
4b0772
             bCanChangePassword = authorizateWithMasterPassword( xTmpHandler );
4b0772
 
4b0772
         if ( bCanChangePassword )
4b0772
@@ -1240,7 +1289,7 @@ sal_Bool SAL_CALL PasswordContainer::useDefaultMasterPassword( const uno::Refere
4b0772
 
4b0772
                 // store the empty string to flag the default master password
4b0772
                 m_aMasterPasswd = aPass;
4b0772
-                m_pStorageFile->setEncodedMP( OUString(), true );
4b0772
+                m_pStorageFile->setEncodedMP( OUString(), OUString(), true );
4b0772
 
4b0772
                 // store all the entries with the new password
4b0772
                 for ( const auto& rURL : aPersistent )
4b0772
@@ -1264,8 +1313,8 @@ sal_Bool SAL_CALL PasswordContainer::isDefaultMasterPasswordUsed()
4b0772
     if ( !m_pStorageFile )
4b0772
         throw uno::RuntimeException();
4b0772
 
4b0772
-    OUString aEncodedMP;
4b0772
-    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) && aEncodedMP.isEmpty() );
4b0772
+    OUString aEncodedMP, aEncodedMPIV;
4b0772
+    return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP, aEncodedMPIV ) && aEncodedMP.isEmpty() );
4b0772
 }
4b0772
 
4b0772
 
4b0772
diff --git a/svl/source/passwordcontainer/passwordcontainer.hxx b/svl/source/passwordcontainer/passwordcontainer.hxx
4b0772
index bf43b5903602..0454437b9dc2 100644
4b0772
--- a/svl/source/passwordcontainer/passwordcontainer.hxx
4b0772
+++ b/svl/source/passwordcontainer/passwordcontainer.hxx
4b0772
@@ -34,6 +34,7 @@
4b0772
 #include <unotools/configitem.hxx>
4b0772
 #include <ucbhelper/interactionrequest.hxx>
4b0772
 
4b0772
+#include <rtl/random.h>
4b0772
 #include <rtl/ref.hxx>
4b0772
 #include <osl/mutex.hxx>
4b0772
 
4b0772
@@ -52,11 +53,12 @@ class NamePassRecord
4b0772
     ::std::vector< OUString >                      m_aMemPass;
4b0772
 
4b0772
     // persistent passwords are encrypted in one string
4b0772
-    bool                                                  m_bHasPersPass;
4b0772
+    bool                                           m_bHasPersPass;
4b0772
     OUString                                       m_aPersPass;
4b0772
+    OUString                                       m_aPersistentIV;
4b0772
 
4b0772
     void InitArrays( bool bHasMemoryList, const ::std::vector< OUString >& aMemoryList,
4b0772
-                     bool bHasPersistentList, const OUString& aPersistentList )
4b0772
+                     bool bHasPersistentList, const OUString& aPersistentList, const OUString& aPersistentIV )
4b0772
     {
4b0772
         m_bHasMemPass = bHasMemoryList;
4b0772
         if ( bHasMemoryList )
4b0772
@@ -64,7 +66,10 @@ class NamePassRecord
4b0772
 
4b0772
         m_bHasPersPass = bHasPersistentList;
4b0772
         if ( bHasPersistentList )
4b0772
+        {
4b0772
             m_aPersPass = aPersistentList;
4b0772
+            m_aPersistentIV = aPersistentIV;
4b0772
+        }
4b0772
     }
4b0772
 
4b0772
 public:
4b0772
@@ -76,11 +81,12 @@ public:
4b0772
     {
4b0772
     }
4b0772
 
4b0772
-    NamePassRecord( const OUString& aName, const OUString& aPersistentList )
4b0772
+    NamePassRecord( const OUString& aName, const OUString& aPersistentList, const OUString& aPersistentIV )
4b0772
         : m_aName( aName )
4b0772
         , m_bHasMemPass( false )
4b0772
         , m_bHasPersPass( true )
4b0772
         , m_aPersPass( aPersistentList )
4b0772
+        , m_aPersistentIV( aPersistentIV )
4b0772
     {
4b0772
     }
4b0772
 
4b0772
@@ -89,7 +95,8 @@ public:
4b0772
         , m_bHasMemPass( false )
4b0772
         , m_bHasPersPass( false )
4b0772
     {
4b0772
-        InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass, aRecord.m_bHasPersPass, aRecord.m_aPersPass );
4b0772
+        InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass,
4b0772
+                    aRecord.m_bHasPersPass, aRecord.m_aPersPass, aRecord.m_aPersistentIV );
4b0772
     }
4b0772
 
4b0772
     NamePassRecord& operator=( const NamePassRecord& aRecord )
4b0772
@@ -100,7 +107,9 @@ public:
4b0772
 
4b0772
             m_aMemPass.clear();
4b0772
             m_aPersPass.clear();
4b0772
-            InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass, aRecord.m_bHasPersPass, aRecord.m_aPersPass );
4b0772
+            m_aPersistentIV.clear();
4b0772
+            InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass,
4b0772
+                        aRecord.m_bHasPersPass, aRecord.m_aPersPass, aRecord.m_aPersistentIV );
4b0772
         }
4b0772
         return *this;
4b0772
     }
4b0772
@@ -136,15 +145,24 @@ public:
4b0772
         return OUString();
4b0772
     }
4b0772
 
4b0772
+    OUString GetPersistentIV() const
4b0772
+    {
4b0772
+        if ( m_bHasPersPass )
4b0772
+            return m_aPersistentIV;
4b0772
+
4b0772
+        return OUString();
4b0772
+    }
4b0772
+
4b0772
     void SetMemPasswords( const ::std::vector< OUString >& aMemList )
4b0772
     {
4b0772
         m_aMemPass = aMemList;
4b0772
         m_bHasMemPass = true;
4b0772
     }
4b0772
 
4b0772
-    void SetPersPasswords( const OUString& aPersList )
4b0772
+    void SetPersPasswords( const OUString& aPersList, const OUString& aPersIV )
4b0772
     {
4b0772
         m_aPersPass = aPersList;
4b0772
+        m_aPersistentIV = aPersIV;
4b0772
         m_bHasPersPass = true;
4b0772
     }
4b0772
 
4b0772
@@ -159,6 +177,7 @@ public:
4b0772
         {
4b0772
             m_bHasPersPass = false;
4b0772
             m_aPersPass.clear();
4b0772
+            m_aPersistentIV.clear();
4b0772
         }
4b0772
     }
4b0772
 
4b0772
@@ -182,6 +201,7 @@ private:
4b0772
     PasswordContainer*     mainCont;
4b0772
     bool                   hasEncoded;
4b0772
     OUString        mEncoded;
4b0772
+    OUString        mEncodedIV;
4b0772
 
4b0772
     virtual void            ImplCommit() override;
4b0772
 
4b0772
@@ -202,8 +222,8 @@ public:
4b0772
 
4b0772
     sal_Int32 getStorageVersion();
4b0772
 
4b0772
-    bool getEncodedMP( OUString& aResult );
4b0772
-    void setEncodedMP( const OUString& aResult, bool bAcceptEmpty = false );
4b0772
+    bool getEncodedMP( OUString& aResult, OUString& aResultIV );
4b0772
+    void setEncodedMP( const OUString& aResult, const OUString& aResultIV, bool bAcceptEmpty = false );
4b0772
     void setUseStorage( bool bUse );
4b0772
     bool useStorage();
4b0772
 
4b0772
@@ -224,6 +244,29 @@ private:
4b0772
     css::uno::Reference< css::lang::XComponent > mComponent;
4b0772
     SysCredentialsConfig mUrlContainer;
4b0772
 
4b0772
+    class RandomPool
4b0772
+    {
4b0772
+    private:
4b0772
+        rtlRandomPool m_aRandomPool;
4b0772
+    public:
4b0772
+        RandomPool() : m_aRandomPool(rtl_random_createPool())
4b0772
+        {
4b0772
+        }
4b0772
+        rtlRandomPool get()
4b0772
+        {
4b0772
+            return m_aRandomPool;
4b0772
+        }
4b0772
+        ~RandomPool()
4b0772
+        {
4b0772
+            // Clean up random pool memory
4b0772
+            rtl_random_destroyPool(m_aRandomPool);
4b0772
+        }
4b0772
+    };
4b0772
+
4b0772
+    RandomPool mRandomPool;
4b0772
+
4b0772
+    OUString createIV();
4b0772
+
4b0772
     /// @throws css::uno::RuntimeException
4b0772
     css::uno::Sequence< css::task::UserRecord > CopyToUserRecordSequence(
4b0772
                                         const ::std::vector< NamePassRecord >& original,
4b0772
@@ -274,10 +317,10 @@ css::task::UrlRecord find(
4b0772
                               const css::uno::Reference< css::task::XInteractionHandler >& Handler );
4b0772
 
4b0772
     /// @throws css::uno::RuntimeException
4b0772
-    static ::std::vector< OUString > DecodePasswords( const OUString& aLine, const OUString& aMasterPassword, css::task::PasswordRequestMode mode );
4b0772
+    static ::std::vector< OUString > DecodePasswords( const OUString& aLine, const OUString& aIV, const OUString& aMasterPassword, css::task::PasswordRequestMode mode );
4b0772
 
4b0772
     /// @throws css::uno::RuntimeException
4b0772
-    static OUString EncodePasswords(const std::vector< OUString >& lines, const OUString& aMasterPassword );
4b0772
+    static OUString EncodePasswords(const std::vector< OUString >& lines, const OUString& aIV, const OUString& aMasterPassword );
4b0772
 
4b0772
 public:
4b0772
     PasswordContainer( const css::uno::Reference< css::uno::XComponentContext >& );
4b0772
-- 
4b0772
2.37.3
4b0772