25 #include <osl/diagnose.h>
26 #include <document.hxx>
30 #define DEBUG_TAB_PROTECTION 0
32 #define URI_SHA1 u"http://www.w3.org/2000/09/xmldsig#sha1"
33 #define URI_SHA256_ODF12 u"http://www.w3.org/2000/09/xmldsig#sha256"
34 #define URI_SHA256_W3C u"http://www.w3.org/2001/04/xmlenc#sha256"
35 #define URI_XLS_LEGACY u"http://docs.oasis-open.org/office/ns/table/legacy-hash-excel"
38 using ::com::sun::star::uno::Sequence;
51 for (
SCTAB i = 0;
i < nTabCount; ++
i)
131 const css::uno::Sequence<sal_Int8>& aPassword,
133 void setPasswordHash(
const OUString& rAlgorithmName,
const OUString& rHashValue,
134 const OUString& rSaltValue, sal_uInt32 nSpinCount );
160 Sequence<sal_Int8> aHash;
190 auto aChars = comphelper::sequenceToContainer<vector<char>>(rPassHash);
192 Sequence<sal_Int8> aNewHash;
210 maPassText(r.maPassText),
211 maPassHash(r.maPassHash),
212 maOptions(r.maOptions),
213 mbEmptyPass(r.mbEmptyPass),
214 mbProtected(r.mbProtected),
217 maPasswordHash(r.maPasswordHash),
218 maEnhancedProtection(r.maEnhancedProtection)
276 Sequence<sal_Int8> aPassHash;
310 return Sequence<sal_Int8>();
321 sal_Int32 nLen = aPassword.getLength();
327 #if DEBUG_TAB_PROTECTION
329 printf(
"%2.2X ", static_cast<sal_uInt8>(n));
335 const OUString& rSaltValue, sal_uInt32 nSpinCount )
337 if (!rHashValue.isEmpty())
359 #if DEBUG_TAB_PROTECTION
360 fprintf(stdout,
"ScTableProtectionImpl::verifyPassword: input = '%s'\n",
365 return aPassText.isEmpty();
378 #if DEBUG_TAB_PROTECTION
379 fprintf(stdout,
"ScTableProtectionImpl::verifyPassword: hash = ");
380 for (sal_Int32
i = 0;
i < aHash.getLength(); ++
i)
381 printf(
"%2.2X ", static_cast<sal_uInt8>(aHash[
i]));
406 if (
maOptions.size() <=
static_cast<size_t>(nOptId) )
408 OSL_FAIL(
"ScTableProtectionImpl::isOptionEnabled: wrong size");
417 if (
maOptions.size() <=
static_cast<size_t>(nOptId) )
419 OSL_FAIL(
"ScTableProtectionImpl::setOption: wrong size");
434 bool bChanged =
false;
437 if (rEnhancedProtection.maRangeList.is())
438 bChanged |= rEnhancedProtection.maRangeList->UpdateReference( eMode, &rDoc, rWhere, nDx, nDy, nDz);
460 return !rEnhancedProtection.hasSecurityDescriptor()
461 && rEnhancedProtection.maRangeList.is() && rEnhancedProtection.maRangeList->In( rRange)
462 && !rEnhancedProtection.hasPassword();
475 if (!rEnhancedProtection.hasSecurityDescriptor() && rEnhancedProtection.maRangeList.is())
477 ScRangeList aList( rEnhancedProtection.maRangeList->GetIntersectedRange( rRange));
478 if (aList.size() == 1 && aList[0] == rRange)
481 if (!rEnhancedProtection.hasPassword())
493 for (
const auto& rEnhancedProtection : maEnhancedProtection)
495 if (!rEnhancedProtection.hasSecurityDescriptor() && rEnhancedProtection.maRangeList.is())
498 if (!rEnhancedProtection.hasPassword())
500 const ScRangeList& rRanges = *rEnhancedProtection.maRangeList;
501 size_t nRanges = rRanges.
size();
502 for (
size_t i=0;
i < nRanges; ++
i)
510 return aResultList.
size() == 1 && aResultList[0] == rRange;
515 if (rRangeList.
empty())
518 for (
size_t i=0, nRanges = rRangeList.
size();
i < nRanges; ++
i)
543 return mpImpl->isProtected();
548 return mpImpl->isProtectedWithPass();
553 mpImpl->setProtected(bProtected);
563 return mpImpl->isPasswordEmpty();
568 return mpImpl->hasPasswordHash(eHash, eHash2);
573 mpImpl->setPassword(aPassText);
578 return mpImpl->getPasswordHash(eHash, eHash2);
583 return mpImpl->getPasswordHash();
589 mpImpl->setPasswordHash(aPassword, eHash, eHash2);
593 const OUString& rSaltValue, sal_uInt32 nSpinCount )
595 mpImpl->setPasswordHash( rAlgorithmName, rHashValue, rSaltValue, nSpinCount);
600 return mpImpl->verifyPassword(aPassText);
605 return mpImpl->isOptionEnabled(eOption);
610 mpImpl->setOption(eOption, bEnabled);
633 return mpImpl->isProtected();
638 return mpImpl->isProtectedWithPass();
643 mpImpl->setProtected(bProtected);
648 return mpImpl->isPasswordEmpty();
653 return mpImpl->hasPasswordHash(eHash, eHash2);
658 mpImpl->setPassword(aPassText);
663 return mpImpl->getPasswordHash(eHash, eHash2);
668 return mpImpl->getPasswordHash();
674 mpImpl->setPasswordHash(aPassword, eHash, eHash2);
678 const OUString& rSaltValue, sal_uInt32 nSpinCount )
680 mpImpl->setPasswordHash( rAlgorithmName, rHashValue, rSaltValue, nSpinCount);
685 return mpImpl->verifyPassword(aPassText);
690 return mpImpl->isOptionEnabled(eOption);
695 mpImpl->setOption(eOption, bEnabled);
700 mpImpl->setEnhancedProtection(rProt);
705 return mpImpl->getEnhancedProtection();
711 return mpImpl->updateReference( eMode, rDoc, rWhere, nDx, nDy, nDz);
716 return mpImpl->isBlockEditable( rRange);
721 return mpImpl->isSelectionEditable( rRangeList);
SC_DLLPUBLIC bool IsDocProtected() const
virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) const override
bool verifyPassword(const OUString &aPassText) const
bool isSelectionEditable(const ScRangeList &rRangeList) const
static SVL_DLLPUBLIC void GetHashPasswordSHA256(css::uno::Sequence< sal_Int8 > &rPassHash, std::u16string_view sPass)
virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) const override
const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const
bool verifyPassword(const OUString &aPassText) const
css::uno::Sequence< sal_Int8 > maPassHash
void setOption(SCSIZE nOptId, bool bEnabled)
virtual bool isPasswordEmpty() const override
sheet protection state container
OUString maSaltValue
base64 encoded hash value
bool isPasswordEmpty() const
virtual bool isProtected() const override
virtual void setPasswordHash(const css::uno::Sequence< sal_Int8 > &aPassword, ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) override
static SVL_DLLPUBLIC void GetHashPassword(css::uno::Sequence< sal_Int8 > &rPassHash, const char *pPass, sal_uInt32 nLen)
virtual bool isProtectedWithPass() const override
OUString maHashValue
"SHA-512", ...
virtual bool isPasswordEmpty() const override
void setOption(Option eOption, bool bEnabled)
virtual void setProtected(bool bProtected) override
bool isOptionEnabled(Option eOption) const
const ScOoxPasswordHash & getPasswordHash() const
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
SC_DLLPUBLIC SCTAB GetTableCount() const
static Sequence< sal_Int8 > hashPassword(const OUString &aPassText, ScPasswordHash eHash)
void push_back(const ScRange &rRange)
OOXML password definitions: algorithmName, hashValue, saltValue, spinCount.
void setPasswordHash(const css::uno::Sequence< sal_Int8 > &aPassword, ScPasswordHash eHash, ScPasswordHash eHash2)
virtual bool verifyPassword(const OUString &aPassText) const override
static OUString GetOoxHashAsBase64(const OUString &rPassword, const OUString &rSaltValue, sal_uInt32 nSpinCount, comphelper::Hash::IterCount eIterCount, std::u16string_view rAlgorithmName)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const
virtual const ScOoxPasswordHash & getPasswordHash() const override
static SVL_DLLPUBLIC void GetHashPasswordSHA1UTF8(css::uno::Sequence< sal_Int8 > &rPassHash, std::u16string_view sPass)
bool updateReference(UpdateRefMode, const ScDocument &, const ScRange &rWhere, SCCOL nDx, SCROW nDy, SCTAB nDz)
void setProtected(bool bProtected)
virtual void setPassword(const OUString &aPassText) override
SC_DLLPUBLIC ScDocProtection * GetDocProtection() const
bool isOptionEnabled(SCSIZE nOptId) const
void setPassword(const OUString &aPassText)
bool isBlockEditable(const ScRange &rRange) const
OUString getHashURI(ScPasswordHash eHash)
std::unique_ptr< ScTableProtectionImpl > mpImpl
bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2) const
Container for the Excel EnhancedProtection feature.
static css::uno::Sequence< sal_Int8 > GetXLHashAsSequence(std::u16string_view aString)
virtual bool isProtected() const override
bool isBlockEditable(const ScRange &rRange) const
virtual void setPasswordHash(const css::uno::Sequence< sal_Int8 > &aPassword, ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) override
bool updateReference(UpdateRefMode, const ScDocument &, const ScRange &rWhere, SCCOL nDx, SCROW nDy, SCTAB nDz)
ScPasswordHash getHashTypeFromURI(std::u16string_view rURI)
virtual void setProtected(bool bProtected) override
std::unique_ptr< ScTableProtectionImpl > mpImpl
::std::vector< ScEnhancedProtection > maEnhancedProtection
virtual const ScOoxPasswordHash & getPasswordHash() const override
void setEnhancedProtection(const ::std::vector< ScEnhancedProtection > &rProt)
virtual ~ScTableProtection() override
bool isProtectedWithPass() const
bool needsPassHashRegen(const ScDocument &rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED)
Check for the compatibility of all password hashes.
ScRangeList GetIntersectedRange(const ScRange &rRange) const
void setEnhancedProtection(const ::std::vector< ScEnhancedProtection > &rProt)
virtual ~ScDocProtection() override
::std::vector< bool > maOptions
virtual ~ScPassHashProtectable()=0
virtual void setPassword(const OUString &aPassText) override
sal_uInt32 mnSpinCount
base64 encoded salt value
ScTableProtectionImpl(SCSIZE nOptSize)
bool isOptionEnabled(Option eOption) const
ScOoxPasswordHash maPasswordHash
virtual bool isProtectedWithPass() const override
bool isSelectionEditable(const ScRangeList &rRangeList) const
virtual bool verifyPassword(const OUString &aPassText) const override
void setOption(Option eOption, bool bEnabled)
SC_DLLPUBLIC const ScTableProtection * GetTabProtection(SCTAB nTab) const