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

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