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 #ifndef INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREHELPER_HXX
21 #define INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREHELPER_HXX
22 
23 #include <com/sun/star/uno/Reference.h>
24 #include <rtl/ustring.hxx>
25 #include <svl/sigstruct.hxx>
26 
27 #include <vector>
28 
29 namespace com {
30 namespace sun {
31 namespace star {
32 namespace io {
33     class XStream; }
34 namespace embed {
35     class XStorage; }
36 }}}
37 
38 namespace com::sun::star::xml::sax { class XDocumentHandler; }
39 
40 enum class DocumentSignatureMode
41 {
42     Content,
43     Macros,
44     Package
45 };
46 
47 enum class DocumentSignatureAlgorithm
48 {
49     OOo2,
50     OOo3_0,
51     OOo3_2
52 };
53 
54 struct SignatureStreamHelper
55 {
56     css::uno::Reference < css::embed::XStorage >    xSignatureStorage;
57     css::uno::Reference < css::io::XStream >        xSignatureStream;
58     /// If this is embed::StorageFormats::OFOPXML, then it's expected that xSignatureStream is an empty reference.
59     sal_Int32 nStorageFormat;
60 
SignatureStreamHelperSignatureStreamHelper61     SignatureStreamHelper()
62         : nStorageFormat(0)
63     {
64     }
65 };
66 
67 namespace DocumentSignatureHelper
68 {
69     SignatureStreamHelper OpenSignatureStream(
70         const css::uno::Reference < css::embed::XStorage >& rxStore, sal_Int32 nOpenMode,
71         DocumentSignatureMode eDocSigMode );
72 
73     std::vector< OUString > CreateElementList(
74         const css::uno::Reference < css::embed::XStorage >& rxStore,
75         DocumentSignatureMode eMode,
76         const DocumentSignatureAlgorithm mode);
77 
78     bool isODFPre_1_2(const OUString & sODFVersion);
79     bool isOOo3_2_Signature(const SignatureInformation & sigInfo);
80 
81     DocumentSignatureAlgorithm getDocumentAlgorithm(
82         const OUString & sODFVersion, const SignatureInformation & sigInfo);
83 
84     bool CanSignWithGPG(const css::uno::Reference < css::embed::XStorage >& rxStore,
85                         const OUString& sOdfVersion);
86 
87     bool checkIfAllFilesAreSigned( const ::std::vector< OUString > & sElementList,
88         const SignatureInformation & sigInfo, const DocumentSignatureAlgorithm alg);
89 
90     bool equalsReferenceUriManifestPath(
91         const OUString & rUri, const OUString & rPath);
92 
93     OUString GetDocumentContentSignatureDefaultStreamName();
94     OUString GetScriptingContentSignatureDefaultStreamName();
95     OUString GetPackageSignatureDefaultStreamName();
96 
97     /// In case the storage is OOXML, prepend a leading '/' and append content type to the element URIs.
98     void AppendContentTypes(const css::uno::Reference<css::embed::XStorage>& xStorage, std::vector<OUString>& rElements);
99 
100     void writeDigestMethod(
101         const css::uno::Reference<css::xml::sax::XDocumentHandler>& xDocumentHandler);
102     void writeSignedProperties(
103         const css::uno::Reference<css::xml::sax::XDocumentHandler>& xDocumentHandler,
104         const SignatureInformation& signatureInfo,
105         const OUString& sDate,
106         const bool bWriteSignatureLineData);
107 };
108 
109 #endif // INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREHELPER_HXX
110 
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
112