diff options
author | Tünde Tóth <toth.tunde@nisz.hu> | 2021-10-12 15:11:48 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-10-26 11:59:19 +0200 |
commit | 1b53c1dfc76f08ca7df40a0673aa50eca700d072 (patch) | |
tree | a1b4d8b32e9a7ff7e0e95670a6358807349f6270 /comphelper | |
parent | 31ded6f8718a90c7b3b9eb36909c2b7a0c6e9b68 (diff) |
tdf#144374 DOCX: export the password for editing
The password for editing wasn't exported in DOCX,
resulting unprotected documents in Writer and
in MSO 2019 or newer.
Change-Id: Ieb8a339795635bc1c4223ccbe2a40ea85222cc2e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123543
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/misc/docpasswordhelper.cxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/comphelper/source/misc/docpasswordhelper.cxx b/comphelper/source/misc/docpasswordhelper.cxx index 980faff14698..81ed4bcfed77 100644 --- a/comphelper/source/misc/docpasswordhelper.cxx +++ b/comphelper/source/misc/docpasswordhelper.cxx @@ -110,6 +110,39 @@ uno::Sequence< beans::PropertyValue > DocPasswordHelper::GenerateNewModifyPasswo } +uno::Sequence<beans::PropertyValue> +DocPasswordHelper::GenerateNewModifyPasswordInfoOOXML(std::u16string_view aPassword) +{ + uno::Sequence<beans::PropertyValue> aResult; + + uno::Sequence<sal_Int8> aSalt = GenerateRandomByteSequence(16); + OUStringBuffer aBuffer; + comphelper::Base64::encode(aBuffer, aSalt); + OUString sSalt = aBuffer.toString(); + + sal_Int32 const nIterationCount = 100000; + OUString sAlgorithm("SHA-512"); + + const OUString sHash(GetOoxHashAsBase64(OUString(aPassword), sSalt, nIterationCount, + comphelper::Hash::IterCount::APPEND, sAlgorithm)); + + if (!sHash.isEmpty()) + { + aResult.realloc(4); + aResult[0].Name = "algorithm-name"; + aResult[0].Value <<= sAlgorithm; + aResult[1].Name = "salt"; + aResult[1].Value <<= sSalt; + aResult[2].Name = "iteration-count"; + aResult[2].Value <<= nIterationCount; + aResult[3].Name = "hash"; + aResult[3].Value <<= sHash; + } + + return aResult; +} + + bool DocPasswordHelper::IsModifyPasswordCorrect( std::u16string_view aPassword, const uno::Sequence< beans::PropertyValue >& aInfo ) { bool bResult = false; |