summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-10-07 21:01:42 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-10-08 17:45:53 +0200
commite5f1bba213b8ca9c3b8138ba053da453852ffb87 (patch)
tree62e22a66cd2f034790e1401476349edbbe631837 /oox
parent6970e2bac2b64c50ce04565ef1daea12d8a1df9a (diff)
add test for projkey generation
Change-Id: I42957abbdcf396830713d7ca4eb7539e6c110e11
Diffstat (limited to 'oox')
-rw-r--r--oox/qa/unit/vba_encryption.cxx11
-rw-r--r--oox/source/ole/vbaexport.cxx33
2 files changed, 29 insertions, 15 deletions
diff --git a/oox/qa/unit/vba_encryption.cxx b/oox/qa/unit/vba_encryption.cxx
index 1c7fc02e5827..785c480fc3d5 100644
--- a/oox/qa/unit/vba_encryption.cxx
+++ b/oox/qa/unit/vba_encryption.cxx
@@ -25,6 +25,8 @@ public:
void testSimple2();
+ void testProjKey1();
+
// avoid the BootstrapFixtureBase::setUp and tearDown
virtual void setUp() SAL_OVERRIDE;
virtual void tearDown() SAL_OVERRIDE;
@@ -32,6 +34,7 @@ public:
CPPUNIT_TEST_SUITE(TestVbaEncryption);
// CPPUNIT_TEST(testSimple1);
// CPPUNIT_TEST(testSimple2);
+ CPPUNIT_TEST(testProjKey1);
CPPUNIT_TEST_SUITE_END();
private:
@@ -48,7 +51,6 @@ void TestVbaEncryption::testSimple1()
VBAEncryption aEncryption(pData, nLength, aEncryptedStream,
&nSeed, nProjKey);
aEncryption.write();
-
}
void TestVbaEncryption::testSimple2()
@@ -73,6 +75,13 @@ void TestVbaEncryption::testSimple2()
}
}
+void TestVbaEncryption::testProjKey1()
+{
+ OUString aProjectID("{917DED54-440B-4FD1-A5C1-74ACF261E600}");
+ sal_uInt8 nProjKey = VBAEncryption::calculateProjKey(aProjectID);
+ CPPUNIT_ASSERT_EQUAL((int)0xdf, (int)nProjKey);
+}
+
void TestVbaEncryption::setUp()
{
}
diff --git a/oox/source/ole/vbaexport.cxx b/oox/source/ole/vbaexport.cxx
index e5352ca38aea..20b97410cefe 100644
--- a/oox/source/ole/vbaexport.cxx
+++ b/oox/source/ole/vbaexport.cxx
@@ -384,19 +384,22 @@ void VBAEncryption::writeVersionEnc()
exportHexString(mrEncryptedData, mnVersionEnc);
}
-void VBAEncryption::writeProjKeyEnc()
+sal_uInt8 VBAEncryption::calculateProjKey(const OUString& rProjectKey)
{
- if(!mnProjKey)
+ sal_uInt8 nProjKey = 0;
+ sal_Int32 n = rProjectKey.getLength();
+ const sal_Unicode* pString = rProjectKey.getStr();
+ for (sal_Int32 i = 0; i < n; ++i)
{
- OUString sProjectCLSID = "{9F10AB9C-89AC-4C0F-8AFB-8E9B96D5F170}"; //TODO:Find the real ProjectId.ProjectClSID
- sal_Int32 n = sProjectCLSID.getLength();
- const sal_Unicode* pString = sProjectCLSID.getStr();
- for (sal_Int32 i = 0; i < n; ++i)
- {
- sal_Unicode character = pString[i];
- mnProjKey += character;
- }
+ sal_Unicode character = pString[i];
+ nProjKey += character;
}
+
+ return nProjKey;
+}
+
+void VBAEncryption::writeProjKeyEnc()
+{
sal_uInt8 nProjKeyEnc = mnSeed ^ mnProjKey;
exportHexString(mrEncryptedData, nProjKeyEnc);
mnUnencryptedByte1 = mnProjKey;
@@ -861,7 +864,8 @@ void exportPROJECTStream(SvStream& rStrm, css::uno::Reference<css::container::XN
// section 2.3.1.2 ProjectId
exportString(rStrm, "ID=\"");
- exportString(rStrm, "{9F10AB9C-89AC-4C0F-8AFB-8E9B96D5F170}");
+ OUString aProjectID("{9F10AB9C-89AC-4C0F-8AFB-8E9B96D5F170}");
+ exportString(rStrm, aProjectID);
exportString(rStrm, "\"\r\n");
// section 2.3.1.3 ProjectModule
@@ -894,7 +898,8 @@ 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, NULL, 0);
+ sal_uInt8 nProjKey = VBAEncryption::calculateProjKey(aProjectID);
+ VBAEncryption aProtectionState(pData, 4, rStrm, NULL, nProjKey);
aProtectionState.write();
exportString(rStrm, "\"\r\n");
#else
@@ -907,7 +912,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, NULL, 0);
+ VBAEncryption aProjectPassword(pData, 1, rStrm, NULL, nProjKey);
aProjectPassword.write();
exportString(rStrm, "\"\r\n");
#else
@@ -920,7 +925,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, NULL, 0);
+ VBAEncryption aVisibilityState(pData, 1, rStrm, NULL, nProjKey);
aVisibilityState.write();
exportString(rStrm, "\"\r\n\r\n");
#else