1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "xmlsecuritydllapi.h"
26 #include <svl/sigstruct.hxx>
27 #include "xmlsignaturehelper.hxx"
28 #include "documentsignaturehelper.hxx"
30 #include <com/sun/star/xml/crypto/XSEInitializer.hpp>
31 #include <unotools/tempfile.hxx>
33 namespace com::sun::star
53 class XComponentContext
;
56 class PDFSignatureHelper
;
58 /// Manages signatures (addition, removal), used by DigitalSignaturesDialog.
59 class XMLSECURITY_DLLPUBLIC DocumentSignatureManager
62 css::uno::Reference
<css::uno::XComponentContext
> mxContext
;
63 css::uno::Reference
<css::embed::XStorage
> mxStore
;
64 XMLSignatureHelper maSignatureHelper
;
65 std::unique_ptr
<PDFSignatureHelper
> mpPDFSignatureHelper
;
66 SignatureInformations maCurrentSignatureInformations
;
67 DocumentSignatureMode
const meSignatureMode
;
68 css::uno::Sequence
<css::uno::Sequence
<css::beans::PropertyValue
>> m_manifest
;
69 css::uno::Reference
<css::io::XStream
> mxSignatureStream
;
70 css::uno::Reference
<css::frame::XModel
> mxModel
;
71 rtl::Reference
<utl::TempFileFastService
> mxTempSignatureStream
;
72 /// Storage containing all OOXML signatures, unused for ODF.
73 css::uno::Reference
<css::embed::XStorage
> mxTempSignatureStorage
;
74 css::uno::Reference
<css::xml::crypto::XSEInitializer
> mxSEInitializer
;
75 css::uno::Reference
<css::xml::crypto::XXMLSecurityContext
> mxSecurityContext
;
76 css::uno::Reference
<css::xml::crypto::XSEInitializer
> mxGpgSEInitializer
;
77 css::uno::Reference
<css::xml::crypto::XXMLSecurityContext
> mxGpgSecurityContext
;
80 DocumentSignatureManager(const css::uno::Reference
<css::uno::XComponentContext
>& xContext
,
81 DocumentSignatureMode eMode
);
82 ~DocumentSignatureManager();
85 * Checks if a particular stream is a valid xml stream. Those are treated
86 * differently when they are signed (c14n transformation)
88 bool isXML(std::u16string_view rURI
);
91 SignatureStreamHelper
ImplOpenSignatureStream(sal_Int32 nStreamOpenMode
, bool bTempStream
);
92 /// Add a new signature, using xCert as a signing certificate, and rDescription as description.
93 bool add(const css::uno::Reference
<css::security::XCertificate
>& xCert
,
94 const css::uno::Reference
<css::xml::crypto::XXMLSecurityContext
>& xSecurityContext
,
95 const OUString
& rDescription
, sal_Int32
& nSecurityId
, bool bAdESCompliant
,
96 const OUString
& rSignatureLineId
= OUString(),
97 const css::uno::Reference
<css::graphic::XGraphic
>& xValidGraphic
98 = css::uno::Reference
<css::graphic::XGraphic
>(),
99 const css::uno::Reference
<css::graphic::XGraphic
>& xInvalidGraphic
100 = css::uno::Reference
<css::graphic::XGraphic
>());
101 /// Remove signature at nPosition.
102 void remove(sal_uInt16 nPosition
);
103 /// Read signatures from either a temp stream or the real storage.
104 void read(bool bUseTempStream
, bool bCacheLastSignature
= true);
105 /// Write signatures back to the persistent storage.
106 void write(bool bXAdESCompliantIfODF
);
107 /// Lazy creation of PDF helper.
108 PDFSignatureHelper
& getPDFSignatureHelper();
110 // Checks if the document is a kind where it is relevant to distinguish between using XAdES or not
111 bool IsXAdESRelevant();
113 /// Attempts to initialize the platform-specific crypto.
115 /// Get the security environment.
116 css::uno::Reference
<css::xml::crypto::XSecurityEnvironment
> getSecurityEnvironment();
117 css::uno::Reference
<css::xml::crypto::XSecurityEnvironment
> getGpgSecurityEnvironment();
118 css::uno::Reference
<css::xml::crypto::XXMLSecurityContext
> const& getSecurityContext() const;
119 css::uno::Reference
<css::xml::crypto::XXMLSecurityContext
> const& getGpgSecurityContext() const;
120 void setStore(const css::uno::Reference
<css::embed::XStorage
>& xStore
) { mxStore
= xStore
; }
121 XMLSignatureHelper
& getSignatureHelper() { return maSignatureHelper
; }
122 bool hasPDFSignatureHelper() const { return bool(mpPDFSignatureHelper
); }
123 void setSignatureStream(const css::uno::Reference
<css::io::XStream
>& xSignatureStream
)
125 mxSignatureStream
= xSignatureStream
;
127 void setModel(const css::uno::Reference
<css::frame::XModel
>& xModel
);
128 const css::uno::Reference
<css::embed::XStorage
>& getStore() const { return mxStore
; }
129 DocumentSignatureMode
getSignatureMode() const { return meSignatureMode
; }
130 SignatureInformations
& getCurrentSignatureInformations()
132 return maCurrentSignatureInformations
;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */