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 #ifndef INCLUDED_UNOTOOLS_SECURITYOPTIONS_HXX 20 #define INCLUDED_UNOTOOLS_SECURITYOPTIONS_HXX 21 22 #include <unotools/unotoolsdllapi.h> 23 #include <sal/types.h> 24 #include <com/sun/star/uno/Sequence.h> 25 #include <rtl/ustring.hxx> 26 #include <unotools/options.hxx> 27 #include <memory> 28 #include <unordered_map> 29 30 namespace osl { class Mutex; } 31 32 /*-************************************************************************************************************ 33 @short forward declaration to our private date container implementation 34 @descr We use these class as internal member to support small memory requirements. 35 You can create the container if it is necessary. The class which use these mechanism 36 is faster and smaller then a complete implementation! 37 *//*-*************************************************************************************************************/ 38 39 class SvtSecurityOptions_Impl; 40 41 /*-************************************************************************************************************ 42 @short collect information about security features 43 @ATTENTION This class is partially threadsafe. 44 45 @devstatus ready to use 46 *//*-*************************************************************************************************************/ 47 48 class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtSecurityOptions final : public utl::detail::Options 49 { 50 public: 51 52 enum class EOption 53 { 54 SecureUrls, 55 DocWarnSaveOrSend, 56 DocWarnSigning, 57 DocWarnPrint, 58 DocWarnCreatePdf, 59 DocWarnRemovePersonalInfo, 60 DocWarnRecommendPassword, 61 MacroSecLevel, 62 MacroTrustedAuthors, 63 CtrlClickHyperlink, 64 BlockUntrustedRefererLinks 65 }; 66 67 struct Certificate 68 { 69 OUString SubjectName; 70 OUString SerialNumber; 71 OUString RawData; 72 operator ==SvtSecurityOptions::Certificate73 bool operator==(const Certificate& other) const 74 { 75 return SubjectName == other.SubjectName && SerialNumber == other.SerialNumber && RawData == other.RawData; 76 } 77 }; 78 79 public: 80 SvtSecurityOptions(); 81 virtual ~SvtSecurityOptions() override; 82 83 /*-**************************************************************************************************** 84 @short returns readonly state 85 @descr It can be called to get information about the readonly state of a provided item. 86 @param "eOption", specify, which item is queried 87 @return <TRUE/> if item is readonly; <FALSE/> otherwise 88 89 @onerror No error should occur! 90 *//*-*****************************************************************************************************/ 91 92 bool IsReadOnly( EOption eOption ) const; 93 94 /*-**************************************************************************************************** 95 @short interface methods to get and set value of config key "org.openoffice.Office.Common/Security/Scripting/SecureURL" 96 @descr These value displays the list of all trustworthy URLs. 97 zB.: file:/ => All scripts from the local file system including a LAN; 98 private:explorer => Scripts from the Explorer; 99 private:help => Scripts in the help system; 100 private:newmenu => Scripts that are executed by the commands File-New and AutoPilot; 101 private:schedule => Scripts of the scheduler; 102 private:searchfolder => Scripts of the searchfolder; 103 private:user => Scripts that are entered in the URL field. 104 @param "seqURLList", new values to set it in configuration. 105 @return The values which represent current state of internal variable. 106 107 @onerror No error should occur! 108 *//*-*****************************************************************************************************/ 109 110 css::uno::Sequence< OUString > GetSecureURLs( ) const; 111 void SetSecureURLs( const css::uno::Sequence< OUString >& seqURLList ); 112 113 /*-**************************************************************************************************** 114 @short interface methods to get and set value of config key "org.openoffice.Office.Common/Security/Scripting/StarOfficeBasic" 115 @descr These value determines how StarOffice Basic scripts should be handled. 116 It exist 3 different modes: 117 0 = never execute 118 1 = from list 119 2 = always execute 120 121 @ATTENTION These methods don't check for valid or invalid values! 122 Our configuration server can do it ... but these implementation don't get any notifications 123 about wrong commits ...! 124 => If you set an invalid value - nothing will be changed. The information will lost. 125 126 @seealso enum EBasicSecurityMode 127 128 @param "eMode" to set new mode ... Value must defined as an enum of type EBasicSecurityMode! 129 @return An enum value, which present current mode. 130 131 @onerror No error should occur! 132 *//*-*****************************************************************************************************/ 133 134 sal_Int32 GetMacroSecurityLevel ( ) const; 135 void SetMacroSecurityLevel ( sal_Int32 _nLevel ); 136 137 bool IsMacroDisabled ( ) const; 138 139 /** 140 Check whether the given uri is either no dangerous macro-execution 141 URI at all or else the given referer is a trusted source. 142 */ 143 bool isSecureMacroUri(OUString const & uri, OUString const & referer) 144 const; 145 146 /** 147 Check whether the given referer URI is untrusted, and links 148 originating from it should not be accessed. 149 */ 150 bool isUntrustedReferer(OUString const & referer) const; 151 152 /** 153 Check whether the given uri is a trusted location. 154 */ 155 bool isTrustedLocationUri(OUString const & uri) const; 156 157 bool isTrustedLocationUriForUpdatingLinks(OUString const & uri) const; 158 159 std::vector< Certificate > GetTrustedAuthors() const; 160 void SetTrustedAuthors( const std::vector< Certificate >& rAuthors ); 161 162 // for bool options only! 163 bool IsOptionSet ( EOption eOption ) const; 164 void SetOption ( EOption eOption, bool bValue ); 165 bool IsOptionEnabled ( EOption eOption ) const; 166 167 // private methods 168 169 private: 170 171 /*-**************************************************************************************************** 172 @short return a reference to a static mutex 173 @descr These class is partially threadsafe (for de-/initialization only). 174 All access methods aren't safe! 175 We create a static mutex only for one ime and use at different times. 176 @return A reference to a static mutex member. 177 *//*-*****************************************************************************************************/ 178 179 UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetInitMutex(); 180 181 // private member 182 183 private: 184 std::shared_ptr<SvtSecurityOptions_Impl> m_pImpl; 185 186 }; // class SvtSecurityOptions 187 188 // map personal info strings, e.g. authors to 1, 2, 3... for removing personal info 189 typedef ::std::unordered_map< OUString, size_t > SvtSecurityMapPersonalInfoType; 190 191 class UNOTOOLS_DLLPUBLIC SvtSecurityMapPersonalInfo final 192 { 193 SvtSecurityMapPersonalInfoType aInfoIDs; 194 195 public: 196 size_t GetInfoID( const OUString sPersonalInfo ); 197 }; 198 199 #endif // INCLUDED_UNOTOOLS_SECURITYOPTIONS_HXX 200 201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 202