summaryrefslogtreecommitdiff
path: root/include/oox
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2019-09-03 21:08:34 +0300
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-05-25 10:04:15 +0200
commitb9353394f46e46485fd148f2842f0c1e8e5322e3 (patch)
treebf3dcc20cafbc00275c7154858379361b5147ff9 /include/oox
parent2f17679a46ca1336cb82ef652e09f423c5b8923d (diff)
[MS-OFFCRYPTO] convert oox implementation into UNO service
To permit pluggable crypto services, abstract existing implementation behind an XPackageEncryption API. Previous code already had two halfway-polymorphic classes (agile and standard 2007 engine), so we're not adding much additional layers. As MS crypto always uses OLE storage to wrap content into one single file, current implementation passes all substorage names down into XPackageEncryption APi, so different downstream implementations (e.g. for MS RMS, or Azure AIP) are possible. Because OleStorage classes are internal to LibO core, access is provided via XInput/XOutput stream API function. Change-Id: Icc32a4e0ce215090c3b739f1dcaa0654b36b7f08 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/84436 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'include/oox')
-rw-r--r--include/oox/crypto/AgileEngine.hxx6
-rw-r--r--include/oox/crypto/CryptTools.hxx4
-rw-r--r--include/oox/crypto/CryptoEngine.hxx6
-rw-r--r--include/oox/crypto/DocumentDecryption.hxx22
-rw-r--r--include/oox/crypto/DocumentEncryption.hxx17
-rw-r--r--include/oox/crypto/Standard2007Engine.hxx6
-rw-r--r--include/oox/crypto/StrongEncryptionDataSpace.hxx76
7 files changed, 106 insertions, 31 deletions
diff --git a/include/oox/crypto/AgileEngine.hxx b/include/oox/crypto/AgileEngine.hxx
index b4aeec6de5be..ac028533d71c 100644
--- a/include/oox/crypto/AgileEngine.hxx
+++ b/include/oox/crypto/AgileEngine.hxx
@@ -25,7 +25,7 @@ namespace oox {
}
namespace oox {
-namespace core {
+namespace crypto {
struct OOX_DLLPUBLIC AgileEncryptionInfo
{
@@ -125,7 +125,7 @@ public:
void writeEncryptionInfo(BinaryXOutputStream& rStream) override;
- void encrypt(css::uno::Reference<css::io::XInputStream>& rxInputStream,
+ void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
css::uno::Reference<css::io::XOutputStream>& rxOutputStream,
sal_uInt32 nSize) override;
@@ -141,7 +141,7 @@ public:
bool setupEncryptionKey(OUString const & rPassword);
};
-} // namespace core
+} // namespace crypto
} // namespace oox
#endif
diff --git a/include/oox/crypto/CryptTools.hxx b/include/oox/crypto/CryptTools.hxx
index 4e8d8e586922..31d90efcbc49 100644
--- a/include/oox/crypto/CryptTools.hxx
+++ b/include/oox/crypto/CryptTools.hxx
@@ -27,7 +27,7 @@
#include <memory>
namespace oox {
-namespace core {
+namespace crypto {
/** Rounds up the input to the nearest multiple
*
@@ -114,7 +114,7 @@ public:
};
-} // namespace core
+} // namespace crypto
} // namespace oox
#endif
diff --git a/include/oox/crypto/CryptoEngine.hxx b/include/oox/crypto/CryptoEngine.hxx
index 8a947f10d106..72bde8920dfc 100644
--- a/include/oox/crypto/CryptoEngine.hxx
+++ b/include/oox/crypto/CryptoEngine.hxx
@@ -25,7 +25,7 @@ namespace oox {
}
namespace oox {
-namespace core {
+namespace crypto {
class CryptoEngine
{
@@ -53,14 +53,14 @@ public:
virtual bool setupEncryption(const OUString& rPassword) = 0;
- virtual void encrypt(css::uno::Reference<css::io::XInputStream> & rxInputStream,
+ virtual void encrypt(const css::uno::Reference<css::io::XInputStream> & rxInputStream,
css::uno::Reference<css::io::XOutputStream> & rxOutputStream,
sal_uInt32 nSize) = 0;
virtual bool checkDataIntegrity() = 0;
};
-} // namespace core
+} // namespace crypto
} // namespace oox
#endif
diff --git a/include/oox/crypto/DocumentDecryption.hxx b/include/oox/crypto/DocumentDecryption.hxx
index 7919fa7a40f3..2c058121c1b7 100644
--- a/include/oox/crypto/DocumentDecryption.hxx
+++ b/include/oox/crypto/DocumentDecryption.hxx
@@ -17,7 +17,6 @@
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
-#include <oox/crypto/CryptoEngine.hxx>
#include <rtl/ustring.hxx>
namespace com::sun::star {
@@ -25,29 +24,24 @@ namespace com::sun::star {
namespace io { class XInputStream; }
namespace io { class XStream; }
namespace uno { class XComponentContext; }
+ namespace packages { class XPackageEncryption; }
}
namespace oox::ole { class OleStorage; }
namespace oox {
-namespace core {
+namespace crypto {
class DocumentDecryption
{
private:
- enum CryptoType
- {
- UNKNOWN,
- STANDARD_2007,
- AGILE
- };
-
- oox::ole::OleStorage& mrOleStorage;
- std::unique_ptr<CryptoEngine> mEngine;
- CryptoType mCryptoType;
+ css::uno::Reference< css::uno::XComponentContext > mxContext;
+ oox::ole::OleStorage& mrOleStorage;
+ css::uno::Sequence<css::beans::NamedValue> maStreamsSequence;
+ css::uno::Reference< css::packages::XPackageEncryption > mxPackageEncryption;
public:
- DocumentDecryption(oox::ole::OleStorage& rOleStorage);
+ DocumentDecryption(const css::uno::Reference< css::uno::XComponentContext >& rxContext, oox::ole::OleStorage& rOleStorage);
bool decrypt(const css::uno::Reference< css::io::XStream >& xDocumentStream);
bool readEncryptionInfo();
@@ -57,7 +51,7 @@ public:
};
-} // namespace core
+} // namespace crypto
} // namespace oox
#endif
diff --git a/include/oox/crypto/DocumentEncryption.hxx b/include/oox/crypto/DocumentEncryption.hxx
index 9be7c99bb41c..17480652aa8d 100644
--- a/include/oox/crypto/DocumentEncryption.hxx
+++ b/include/oox/crypto/DocumentEncryption.hxx
@@ -14,38 +14,43 @@
#include <oox/dllapi.h>
#include <com/sun/star/uno/Reference.hxx>
-#include <oox/crypto/Standard2007Engine.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
#include <rtl/ustring.hxx>
namespace com::sun::star {
namespace io { class XStream; }
+ namespace packages { class XPackageEncryption; }
+ namespace beans { struct NamedValue; }
+ namespace uno { class XComponentContext; }
}
namespace oox::ole { class OleStorage; }
namespace oox {
-namespace core {
+namespace crypto {
class DocumentEncryption
{
private:
+ css::uno::Reference< css::uno::XComponentContext > mxContext;
css::uno::Reference< css::io::XStream > mxDocumentStream;
oox::ole::OleStorage& mrOleStorage;
OUString maPassword;
- Standard2007Engine mEngine;
+ css::uno::Reference< css::packages::XPackageEncryption > mxPackageEncryption;
+ const css::uno::Sequence< css::beans::NamedValue >& mMediaEncData;
public:
- DocumentEncryption(
+ DocumentEncryption(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
css::uno::Reference< css::io::XStream > const & xDocumentStream,
oox::ole::OleStorage& rOleStorage,
- const OUString& aPassword);
+ const css::uno::Sequence< css::beans::NamedValue >& rMediaEncData);
bool encrypt();
};
-} // namespace core
+} // namespace crypto
} // namespace oox
#endif
diff --git a/include/oox/crypto/Standard2007Engine.hxx b/include/oox/crypto/Standard2007Engine.hxx
index 7583447319c6..4a6eaae9e43c 100644
--- a/include/oox/crypto/Standard2007Engine.hxx
+++ b/include/oox/crypto/Standard2007Engine.hxx
@@ -23,7 +23,7 @@ namespace oox {
}
namespace oox {
-namespace core {
+namespace crypto {
class OOX_DLLPUBLIC Standard2007Engine final : public CryptoEngine
{
@@ -45,7 +45,7 @@ public:
bool checkDataIntegrity() override;
- void encrypt(css::uno::Reference<css::io::XInputStream>& rxInputStream,
+ void encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
css::uno::Reference<css::io::XOutputStream>& rxOutputStream,
sal_uInt32 nSize) override;
@@ -55,7 +55,7 @@ public:
};
-} // namespace core
+} // namespace crypto
} // namespace oox
#endif
diff --git a/include/oox/crypto/StrongEncryptionDataSpace.hxx b/include/oox/crypto/StrongEncryptionDataSpace.hxx
new file mode 100644
index 000000000000..d287970e6519
--- /dev/null
+++ b/include/oox/crypto/StrongEncryptionDataSpace.hxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_OOX_CRYPTO_STRONGENCRYPTINDATASPACE_HXX
+#define INCLUDED_OOX_CRYPTO_STRONGENCRYPTINDATASPACE_HXX
+
+#include <oox/dllapi.h>
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/packages/XPackageEncryption.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <oox/crypto/CryptoEngine.hxx>
+
+namespace com::sun::star::uno
+{
+class XComponentContext;
+}
+
+namespace oox
+{
+namespace crypto
+{
+class OOX_DLLPUBLIC StrongEncryptionDataSpace final
+ : public cppu::WeakImplHelper<css::lang::XServiceInfo, css::packages::XPackageEncryption>
+{
+ css::uno::Reference<css::uno::XComponentContext> mxContext;
+ std::unique_ptr<CryptoEngine> mCryptoEngine;
+
+ css::uno::Reference<css::io::XInputStream>
+ getStream(const css::uno::Sequence<css::beans::NamedValue>& rStreams,
+ const rtl::OUString sStreamName);
+
+public:
+ StrongEncryptionDataSpace(const css::uno::Reference<css::uno::XComponentContext>& rxContext);
+
+ // Decryption
+
+ virtual sal_Bool SAL_CALL generateEncryptionKey(const OUString& rPassword) override;
+ virtual sal_Bool SAL_CALL
+ readEncryptionInfo(const css::uno::Sequence<css::beans::NamedValue>& aStreams) override;
+ virtual sal_Bool SAL_CALL
+ decrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream,
+ css::uno::Reference<css::io::XOutputStream>& rxOutputStream) override;
+
+ virtual sal_Bool SAL_CALL checkDataIntegrity() override;
+
+ // Encryption
+
+ virtual css::uno::Sequence<css::beans::NamedValue>
+ SAL_CALL encrypt(const css::uno::Reference<css::io::XInputStream>& rxInputStream) override;
+
+ virtual sal_Bool SAL_CALL
+ setupEncryption(const css::uno::Sequence<css::beans::NamedValue>& rMediaEncData) override;
+
+ virtual css::uno::Sequence<css::beans::NamedValue>
+ SAL_CALL createEncryptionData(const OUString& rPassword) override;
+
+ // com.sun.star.lang.XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+};
+
+} // namespace crypto
+} // namespace oox
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */