summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-10-06 17:06:16 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-10-08 17:45:52 +0200
commit3ba169bd68d81980a112998a57ff5d2b638252fa (patch)
treef65e7d1a776e7986e5314ca7490401ddf429bf40 /oox
parentc597581852cf1d3550359dc639f1bb7f6476f419 (diff)
add initial tests for vba encryption
Change-Id: Ic6128ecade39e8947863c9162523e0d9690f0026
Diffstat (limited to 'oox')
-rw-r--r--oox/CppunitTest_oox_vba_encryption.mk50
-rw-r--r--oox/Module_oox.mk1
-rw-r--r--oox/qa/unit/vba_encryption.cxx88
-rw-r--r--oox/source/ole/vbaexport.cxx19
4 files changed, 150 insertions, 8 deletions
diff --git a/oox/CppunitTest_oox_vba_encryption.mk b/oox/CppunitTest_oox_vba_encryption.mk
new file mode 100644
index 000000000000..1f8bb5ceb814
--- /dev/null
+++ b/oox/CppunitTest_oox_vba_encryption.mk
@@ -0,0 +1,50 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,oox_vba_encryption))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,oox_vba_encryption,\
+ oox/qa/unit/vba_encryption \
+))
+
+$(eval $(call gb_CppunitTest_use_api,oox_vba_encryption,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,oox_vba_encryption,\
+ basegfx \
+ comphelper \
+ cppu \
+ cppuhelper \
+ editeng \
+ expwrap \
+ drawinglayer \
+ msfilter \
+ sal \
+ i18nlangtag \
+ oox \
+ sax \
+ sfx \
+ svl \
+ svt \
+ svx \
+ svxcore \
+ sot \
+ tl \
+ unotest \
+ utl \
+ vcl \
+ xo \
+ xmlscript \
+ $(gb_UWINAPI) \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/oox/Module_oox.mk b/oox/Module_oox.mk
index 1c8edf04ed72..4d7a79e3d60c 100644
--- a/oox/Module_oox.mk
+++ b/oox/Module_oox.mk
@@ -19,6 +19,7 @@ $(eval $(call gb_Module_add_targets,oox,\
$(eval $(call gb_Module_add_check_targets,oox,\
CppunitTest_oox_tokenmap \
CppunitTest_oox_vba_compression \
+ CppunitTest_oox_vba_encryption \
))
# vim: set noet sw=4 ts=4:
diff --git a/oox/qa/unit/vba_encryption.cxx b/oox/qa/unit/vba_encryption.cxx
new file mode 100644
index 000000000000..1c7fc02e5827
--- /dev/null
+++ b/oox/qa/unit/vba_encryption.cxx
@@ -0,0 +1,88 @@
+/* -*- 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/.
+ */
+
+#include <unotest/bootstrapfixturebase.hxx>
+
+#include <cppunit/plugin/TestPlugIn.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/TestFixture.h>
+
+#include <oox/ole/vbaexport.hxx>
+#include <algorithm>
+
+class TestVbaEncryption : public test::BootstrapFixtureBase
+{
+public:
+
+ // an initial test for the encryption taken from the spec
+ void testSimple1();
+
+ void testSimple2();
+
+ // avoid the BootstrapFixtureBase::setUp and tearDown
+ virtual void setUp() SAL_OVERRIDE;
+ virtual void tearDown() SAL_OVERRIDE;
+
+ CPPUNIT_TEST_SUITE(TestVbaEncryption);
+ // CPPUNIT_TEST(testSimple1);
+ // CPPUNIT_TEST(testSimple2);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+};
+
+void TestVbaEncryption::testSimple1()
+{
+ sal_uInt8 nSeed = 0x07;
+ sal_uInt8 nProjKey = 0xDF;
+ sal_uInt16 nLength = 0x04;
+ sal_uInt8 pData[] = { 0x00, 0x00, 0x00, 0x00 };
+
+ SvMemoryStream aEncryptedStream(4096, 4096);
+ VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
+ &nSeed, nProjKey);
+ aEncryption.write();
+
+}
+
+void TestVbaEncryption::testSimple2()
+{
+ sal_uInt8 nSeed = 0x15;
+ sal_uInt8 nProjKey = 0xDF;
+ sal_uInt16 nLength = 0x01;
+ sal_uInt8 pData[] = { 0xFF };
+
+ SvMemoryStream aEncryptedStream(4096, 4096);
+ VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
+ &nSeed, nProjKey);
+ aEncryption.write();
+ sal_uInt8 pExpectedData[] = "1517CAF1D6F9D7F9D706";
+ size_t length = sizeof(pExpectedData);
+ aEncryptedStream.Seek(0);
+ for (size_t i = 0; i < length; ++i)
+ {
+ unsigned char val = 0;
+ aEncryptedStream.ReadUChar(val);
+ CPPUNIT_ASSERT_EQUAL((int)pExpectedData[i], (int)sal_uInt8(val));
+ }
+}
+
+void TestVbaEncryption::setUp()
+{
+}
+
+void TestVbaEncryption::tearDown()
+{
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestVbaEncryption);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index 03392034fe0a..5be8730b7ca9 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -47,10 +47,10 @@
#define VBA_USE_ORIGINAL_PROJECT_STREAM 0
#define VBA_USE_ORIGINAL_VBA_PROJECT 0
-#define VBA_ENCRYPTION 0
/* Enable to see VBA Encryption work. For now the input data and length values
* for encryption correspond to the case when the VBA macro is not protected.
*/
+#define VBA_ENCRYPTION 1
namespace {
@@ -344,23 +344,24 @@ void VBACompression::write()
// section 2.4.3
#if VBA_ENCRYPTION
-VBAEncryption::VBAEncryption(const sal_uInt8* pData, const sal_uInt16 length, SvStream& rEncryptedData)
+VBAEncryption::VBAEncryption(const sal_uInt8* pData, const sal_uInt16 length, SvStream& rEncryptedData, sal_uInt8* pSeed, sal_uInt8 nProjKey)
:mpData(pData)
,mnLength(length)
,mrEncryptedData(rEncryptedData)
,mnEncryptedByte1(0)
,mnEncryptedByte2(0)
,mnVersion(2)
- ,mnProjKey(0)
+ ,mnProjKey(nProjKey)
,mnIgnoredLength(0)
- ,mnSeed(0)
+ ,mnSeed(pSeed ? *pSeed : 0x00)
,mnVersionEnc(0)
{
+ if (!pSeed)
+ mnSeed = 0xBE; // sample seed value TODO:Generate random seed values
}
void VBAEncryption::writeSeed()
{
- mnSeed = 0xBE; // sample seed value TODO:Generate random seed values
mrEncryptedData.WriteUInt8(mnSeed);
}
@@ -372,6 +373,7 @@ void VBAEncryption::writeVersionEnc()
void VBAEncryption::writeProjKeyEnc()
{
+ /*
OUString mrProjectCLSID = "{9F10AB9C-89AC-4C0F-8AFB-8E9B96D5F170}"; //TODO:Find the real ProjectId.ProjectClSID
sal_Int32 n = mrProjectCLSID.getLength();
const sal_Unicode* pString = mrProjectCLSID.getStr();
@@ -380,6 +382,7 @@ void VBAEncryption::writeProjKeyEnc()
sal_Unicode character = pString[i];
mnProjKey += character;
}
+ */
sal_uInt8 nProjKeyEnc = mnSeed ^ mnProjKey;
mrEncryptedData.WriteUInt8(nProjKeyEnc);
mnUnencryptedByte1 = mnProjKey;
@@ -877,7 +880,7 @@ void exportPROJECTStream(SvStream& rStrm, css::uno::Reference<css::container::XN
SvMemoryStream aProtectedStream(4096, 4096);
aProtectedStream.WriteUInt32(0x00000000);
const sal_uInt8* pData = static_cast<const sal_uInt8*>(aProtectedStream.GetData());
- VBAEncryption aProtectionState(pData, 4, rStrm);
+ VBAEncryption aProtectionState(pData, 4, rStrm, NULL, 0);
aProtectionState.write();
exportString(rStrm, "\"\r\n");
#else
@@ -890,7 +893,7 @@ void exportPROJECTStream(SvStream& rStrm, css::uno::Reference<css::container::XN
aProtectedStream.Seek(0);
aProtectedStream.WriteUInt8(0x00);
pData = static_cast<const sal_uInt8*>(aProtectedStream.GetData());
- VBAEncryption aProjectPassword(pData, 1, rStrm);
+ VBAEncryption aProjectPassword(pData, 1, rStrm, NULL, 0);
aProjectPassword.write();
exportString(rStrm, "\"\r\n");
#else
@@ -903,7 +906,7 @@ void exportPROJECTStream(SvStream& rStrm, css::uno::Reference<css::container::XN
aProtectedStream.Seek(0);
aProtectedStream.WriteUInt8(0xFF);
pData = static_cast<const sal_uInt8*>(aProtectedStream.GetData());
- VBAEncryption aVisibilityState(pData, 1, rStrm);
+ VBAEncryption aVisibilityState(pData, 1, rStrm, NULL, 0);
aVisibilityState.write();
exportString(rStrm, "\"\r\n\r\n");
#else