On Fri, 2014-03-07 at 15:01 +0100, zyx wrote:
> I'll test the functionality during the weekend, the most at the beginning
> of the next week, and let you know.

        Hello,
I created a little test program for the encryption (see the attached
test.cpp), which is testing all encryption algorithms. Your patch works
as you said, it fixes AESv2 decryption and keeps the AESv3 unchanged
(still broken). There is one change in behaviour, it exists with an
exception for AESv3:
        
        PoDoFo encounter an error. Error: 8 ePdfError_InternalLogic
                Error Description: An internal error occurred.
                Callstack:
                #0 Error Source: .../src/base/PdfEncrypt.cpp:1314
                        Information: Error AES-decryption data final

instead of failing silently, which is better in my opinion.

This doesn't seem to fix decrypt of an AcroForm elements, but that might
not be related to your changes at all (it didn't work even before).

In any case, I committed your patch to trunk as revision 1583:
http://sourceforge.net/p/podofo/code/1583

        Thanks and bye,
        zyx

-- 
http://www.litePDF.cz                                 i...@litepdf.cz
/* g++ -g -O0 test.cpp -o test -L/data/develop/dila/podofo/build-trunk/src -rdynamic -lpodofo -lfontconfig -lz -lcrypto -ljpeg -lpthread -lfreetype -lpng -lz -lcrypto -ljpeg -lpthread -lfreetype -lpng -lidn -Wl,-rpath,/data/develop/dila/podofo/build-trunk/src -I/data/develop/dila/podofo/build-trunk -I/data/develop/dila/podofo/podofo-trunk -I/data/develop/dila/podofo/podofo-trunk/src -I/usr/include/freetype2    -std=c++98 -Wall -Woverloaded-virtual -Wswitch-enum -Wcast-qual -Wwrite-strings -Wredundant-decls -Wreorder -W -fvisibility=hidden -DPODOFO_HAVE_GCC_SYMBOL_VISIBILITY && ./test */

#include <stdio.h>
#include "podofo.h"

using namespace PoDoFo;

static void drawPage(PdfMemDocument *memDocument)
{
	PODOFO_RAISE_LOGIC_IF (!memDocument, "!memDocument");

	PdfFont *pFont;
	PdfPage *pPage;
	PdfPainter painter;

	pPage = memDocument->CreatePage(PdfPage::CreateStandardPageSize(ePdfPageSize_A4));
	PODOFO_RAISE_LOGIC_IF (!pPage, "!pPage");

	painter.SetPage(pPage);

	pFont = memDocument->CreateFont("Helvetica");
	PODOFO_RAISE_LOGIC_IF (!pFont, "!pFont");

	pFont->SetFontSize(18.0);

	painter.SetFont(pFont);

	painter.DrawText(56.69, pPage->GetPageSize().GetHeight() - 56.69, "Hello World! Encrypted");
	painter.FinishPage();
}

static void testEnctyption(PdfEncrypt::EPdfEncryptAlgorithm algo, PdfEncrypt::EPdfKeyLength keyLength, const char *pFileName)
{
	PdfEncrypt *encrypt;

	if (pFileName)
		printf("Testing %s:\n", pFileName);

	encrypt = PdfEncrypt::CreatePdfEncrypt("user", "owner", 0, algo, keyLength);
	PODOFO_RAISE_LOGIC_IF (!encrypt, "!encrypt");

	PdfMemDocument *memDocument = new PdfMemDocument();
	PODOFO_RAISE_LOGIC_IF (!memDocument, "!memDocument");

	memDocument->SetEncrypted(*encrypt);

	delete encrypt;

	PdfInfo *info = memDocument->GetInfo();
	PODOFO_RAISE_LOGIC_IF (!info, "!info");

	info->SetProducer("test");

	drawPage(memDocument);

	PdfRefCountedBuffer *buffer = new PdfRefCountedBuffer();
	PODOFO_RAISE_LOGIC_IF (!buffer, "!buffer");

	PdfOutputDevice outputDevice(buffer);
	memDocument->Write(&outputDevice);

	delete memDocument;

	if (pFileName) {
		FILE *f = fopen(pFileName, "wb");
		PODOFO_RAISE_LOGIC_IF (!f, "!f");

		fwrite(buffer->GetBuffer(), buffer->GetSize(), 1, f);
		fclose(f);
	}

	memDocument = new PdfMemDocument();
	PODOFO_RAISE_LOGIC_IF (!memDocument, "!memDocument (2)");

	PdfRefCountedInputDevice inputDevice(buffer->GetBuffer(), buffer->GetSize());
	try {
		memDocument->Load(inputDevice);
	} catch (const PdfError &error) {
		if (error.GetError() == ePdfError_InvalidPassword) {
			memDocument->SetPassword("user");
		} else {
			throw;
		}
	}

	info = memDocument->GetInfo();
	PODOFO_RAISE_LOGIC_IF (!info, "!info");

	if (info->GetProducer().GetStringUtf8() != "test") {
		fprintf(stderr, "   Producer not set as expected 'test', but '%s' instead\n", info->GetProducer().GetString());
	} else {
		printf("   OK\n");
	}

	delete memDocument;
	delete buffer;
}

int main(void)
{
	PdfError::EnableLogging(false);

	try {
		testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_RC4V1, PdfEncrypt::ePdfKeyLength_40, "rc4v1.pdf");
		testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_RC4V2, PdfEncrypt::ePdfKeyLength_128, "rc4v2.pdf");
		testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_AESV2, PdfEncrypt::ePdfKeyLength_128, "aesv2.pdf");
		testEnctyption(PdfEncrypt::ePdfEncryptAlgorithm_AESV3, PdfEncrypt::ePdfKeyLength_256, "aesv3.pdf");
	} catch (const PdfError &error) {
		fprintf (stderr, "Failed with error:\n");
		error.PrintErrorMsg();
	}

	return 0;
}
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to