LibreOffice Module sc (master)  1
tabprotection.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <sal/types.h>
23 
24 #include "global.hxx"
25 #include "rangelst.hxx"
26 #include <memory>
27 
28 class ScDocument;
30 
32 {
34  PASSHASH_SHA1_UTF8, // tdf#115483 this is UTF8, previous one is wrong UTF16
38 };
39 
42 {
43  OUString maAlgorithmName;
44  OUString maHashValue;
45  OUString maSaltValue;
46  sal_uInt32 mnSpinCount;
47 
48  ScOoxPasswordHash() : mnSpinCount(0) {}
49  bool hasPassword() const { return !maHashValue.isEmpty(); }
50  void clear()
51  {
52  // Keep algorithm and spin count.
53  maHashValue.clear();
54  maSaltValue.clear();
55  }
56  bool verifyPassword( const OUString& aPassText ) const;
57 };
58 
60 {
66 
67  OUString getHashURI(ScPasswordHash eHash);
68 
69  ScPasswordHash getHashTypeFromURI(std::u16string_view rURI);
70 }
71 
73 {
74 public:
75  virtual ~ScPassHashProtectable() = 0;
76 
77  virtual bool isProtected() const = 0;
78  virtual bool isProtectedWithPass() const = 0;
79  virtual void setProtected(bool bProtected) = 0;
80 
81  virtual bool isPasswordEmpty() const = 0;
82  virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
83  virtual void setPassword(const OUString& aPassText) = 0;
84  virtual css::uno::Sequence<sal_Int8> getPasswordHash(
85  ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
86  virtual const ScOoxPasswordHash& getPasswordHash() const = 0;
87  virtual void setPasswordHash(
88  const css::uno::Sequence<sal_Int8>& aPassword,
90  virtual void setPasswordHash( const OUString& rAlgorithmName, const OUString& rHashValue,
91  const OUString& rSaltValue, sal_uInt32 nSpinCount ) = 0;
92  virtual bool verifyPassword(const OUString& aPassText) const = 0;
93 };
94 
96 {
97 public:
98  enum Option
99  {
100  STRUCTURE = 0,
103  };
104 
105  explicit ScDocProtection();
106  explicit ScDocProtection(const ScDocProtection& r);
107  virtual ~ScDocProtection() override;
108 
109  virtual bool isProtected() const override;
110  virtual bool isProtectedWithPass() const override;
111  virtual void setProtected(bool bProtected) override;
112 
113  virtual bool isPasswordEmpty() const override;
114  virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
115  virtual void setPassword(const OUString& aPassText) override;
116  virtual css::uno::Sequence<sal_Int8> getPasswordHash(
117  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
118  virtual const ScOoxPasswordHash& getPasswordHash() const override;
119  virtual void setPasswordHash(
120  const css::uno::Sequence<sal_Int8>& aPassword,
121  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) override;
122  virtual void setPasswordHash( const OUString& rAlgorithmName, const OUString& rHashValue,
123  const OUString& rSaltValue, sal_uInt32 nSpinCount ) override;
124  virtual bool verifyPassword(const OUString& aPassText) const override;
125 
126  bool isOptionEnabled(Option eOption) const;
127  void setOption(Option eOption, bool bEnabled);
128 
129 private:
130  std::unique_ptr<ScTableProtectionImpl> mpImpl;
131 };
132 
136 {
138  sal_uInt32 mnAreserved;
139  sal_uInt32 mnPasswordVerifier;
140  OUString maTitle;
141  ::std::vector< sal_uInt8 > maSecurityDescriptor; // imported as raw BIFF data
142  OUString maSecurityDescriptorXML; // imported from OOXML
144 
145  ScEnhancedProtection() : mnAreserved(0), mnPasswordVerifier(0) {}
146 
148  {
149  return !maSecurityDescriptor.empty() || !maSecurityDescriptorXML.isEmpty();
150  }
151 
152  bool hasPassword() const
153  {
154  return mnPasswordVerifier != 0 || maPasswordHash.hasPassword();
155  }
156 };
157 
167 {
168 public:
169  enum Option
170  {
171  AUTOFILTER = 0,
187  };
188 
189  explicit ScTableProtection();
190  explicit ScTableProtection(const ScTableProtection& r);
191  virtual ~ScTableProtection() override;
192 
193  virtual bool isProtected() const override;
194  virtual bool isProtectedWithPass() const override;
195  virtual void setProtected(bool bProtected) override;
196 
197  virtual bool isPasswordEmpty() const override;
198  virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
199  virtual void setPassword(const OUString& aPassText) override;
200  virtual css::uno::Sequence<sal_Int8> getPasswordHash(
201  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
202  virtual const ScOoxPasswordHash& getPasswordHash() const override;
203  virtual void setPasswordHash(
204  const css::uno::Sequence<sal_Int8>& aPassword,
205  ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) override;
206  virtual void setPasswordHash( const OUString& rAlgorithmName, const OUString& rHashValue,
207  const OUString& rSaltValue, sal_uInt32 nSpinCount ) override;
208  virtual bool verifyPassword(const OUString& aPassText) const override;
209 
210  bool isOptionEnabled(Option eOption) const;
211  void setOption(Option eOption, bool bEnabled);
212 
213  void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt );
214  const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const;
215  bool updateReference( UpdateRefMode, const ScDocument&, const ScRange& rWhere, SCCOL nDx, SCROW nDy, SCTAB nDz );
216  bool isBlockEditable( const ScRange& rRange ) const;
217  bool isSelectionEditable( const ScRangeList& rRangeList ) const;
218 
219 private:
220  std::unique_ptr<ScTableProtectionImpl> mpImpl;
221 };
222 
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool isPasswordEmpty() const =0
bool verifyPassword(const OUString &aPassText) const
ScRangeListRef maRangeList
ScOoxPasswordHash()
spin count, iteration runs
virtual bool isProtected() const =0
sheet protection state container
virtual bool isProtectedWithPass() const =0
OUString maSaltValue
base64 encoded hash value
OOX_DLLPUBLIC sal_uInt16 getPasswordHash(const AttributeList &rAttribs, sal_Int32 nElement)
OUString maHashValue
"SHA-512", ...
NONE
virtual const ScOoxPasswordHash & getPasswordHash() const =0
OUString maAlgorithmName
bool hasSecurityDescriptor() const
OOXML password definitions: algorithmName, hashValue, saltValue, spinCount.
ScPasswordHash
OUString maSecurityDescriptorXML
virtual void setProtected(bool bProtected)=0
SQLUSMALLINT Option
virtual bool verifyPassword(const OUString &aPassText) const =0
OUString getHashURI(ScPasswordHash eHash)
std::unique_ptr< ScTableProtectionImpl > mpImpl
sal_Int16 SCCOL
Definition: types.hxx:21
bool hasPassword() const
Container for the Excel EnhancedProtection feature.
ScPasswordHash getHashTypeFromURI(std::u16string_view rURI)
UpdateRefMode
Definition: global.hxx:310
sal_Int32 SCROW
Definition: types.hxx:17
std::unique_ptr< ScTableProtectionImpl > mpImpl
virtual void setPasswordHash(const css::uno::Sequence< sal_Int8 > &aPassword, ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED)=0
virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED) const =0
sal_uInt32 mnPasswordVerifier
bool hasPassword() const
::std::vector< sal_uInt8 > maSecurityDescriptor
virtual void setPassword(const OUString &aPassText)=0
bool needsPassHashRegen(const ScDocument &rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2=PASSHASH_UNSPECIFIED)
Check for the compatibility of all password hashes.
#define SAL_NO_VTABLE
ScOoxPasswordHash maPasswordHash
sal_uInt32 mnSpinCount
base64 encoded salt value
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
sal_Int16 SCTAB
Definition: types.hxx:22