1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLSECURITY_DOCUMENTSIGNATUREHELPER_HXX
25 #define _XMLSECURITY_DOCUMENTSIGNATUREHELPER_HXX
26 
27 #include <com/sun/star/uno/Reference.h>
28 #include <rtl/ustring.hxx>
29 #include "xmlsecurity/sigstruct.hxx"
30 
31 #ifndef _STLP_VECTOR
32 #include <vector>
33 #endif
34 
35 
36 namespace com {
37 namespace sun {
38 namespace star {
39 namespace io {
40     class XStream; }
41 namespace embed {
42     class XStorage; }
43 }}}
44 
45 namespace css = com::sun::star;
46 
47 
48 /**********************************************************
49  DocumentSignatureHelper
50 
51  Helper class for signing and verifieng document signatures
52 
53  Functions:
54  1. help to create a list of content to be signed/verified
55 
56  **********************************************************/
57 
58 enum DocumentSignatureMode { SignatureModeDocumentContent, SignatureModeMacros, SignatureModePackage };
59 
60 enum DocumentSignatureAlgorithm
61 {
62     OOo2Document,
63     OOo3_0Document,
64     OOo3_2Document
65 };
66 
67 struct SignatureStreamHelper
68 {
69     css::uno::Reference < css::embed::XStorage >    xSignatureStorage;
70     css::uno::Reference < css::io::XStream >        xSignatureStream;
71 };
72 
73 
74 class DocumentSignatureHelper
75 {
76 public:
77 
78     static SignatureStreamHelper OpenSignatureStream(
79         const css::uno::Reference < css::embed::XStorage >& rxStore, sal_Int32 nOpenMode,
80         DocumentSignatureMode eDocSigMode );
81     static std::vector< rtl::OUString > CreateElementList(
82         const css::uno::Reference < css::embed::XStorage >& rxStore,
83         const ::rtl::OUString rRootStorageName, DocumentSignatureMode eMode,
84         const DocumentSignatureAlgorithm mode);
85     static bool isODFPre_1_2(const ::rtl::OUString & sODFVersion);
86     static bool isOOo3_2_Signature(const SignatureInformation & sigInfo);
87     static DocumentSignatureAlgorithm getDocumentAlgorithm(
88         const ::rtl::OUString & sODFVersion, const SignatureInformation & sigInfo);
89     static bool checkIfAllFilesAreSigned( const ::std::vector< ::rtl::OUString > & sElementList,
90         const SignatureInformation & sigInfo, const DocumentSignatureAlgorithm alg);
91 	static bool equalsReferenceUriManifestPath(
92         const ::rtl::OUString & rUri, const ::rtl::OUString & rPath);
93     static ::rtl::OUString GetDocumentContentSignatureDefaultStreamName();
94 	static ::rtl::OUString GetScriptingContentSignatureDefaultStreamName();
95     static ::rtl::OUString GetPackageSignatureDefaultStreamName();
96 
97 };
98 
99 #endif // _XMLSECURITY_XMLSIGNATUREHELPER_HXX
100