Kaydet (Commit) e5f1bba2 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

add test for projkey generation

Change-Id: I42957abbdcf396830713d7ca4eb7539e6c110e11
üst 6970e2ba
......@@ -122,6 +122,8 @@ public:
void write();
static sal_uInt8 calculateProjKey(const OUString& rString);
private:
const sal_uInt8* mpData; // an array of bytes to be obfuscated
const sal_uInt16 mnLength; // the length of Data
......
......@@ -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()
{
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment