Skip to content

Added AES-128 and RC4 up to 128 bits on PDFProtectionTrait#36

Merged
alphp merged 4 commits into
fawno:masterfrom
erikn69:patch-12
May 5, 2026
Merged

Added AES-128 and RC4 up to 128 bits on PDFProtectionTrait#36
alphp merged 4 commits into
fawno:masterfrom
erikn69:patch-12

Conversation

@erikn69
Copy link
Copy Markdown
Contributor

@erikn69 erikn69 commented May 4, 2026

the original author initiated this process: klemenv/FPDF_Protection/fpdf_protection.php,
but it hasn't been published; it seems to be working correctly.

// examples
$pdf->SetProtection(['print'], 'user123', 'admin123', 'AES', 128);
$pdf->SetProtection(['print'], 'user123', 'admin123', 'RC4', 40);
$pdf->SetProtection(['print'], 'user123', 'admin123', 'RC4', 128);

@erikn69 erikn69 force-pushed the patch-12 branch 2 times, most recently from 182ecf1 to 6df7bcf Compare May 4, 2026 18:29
@alphp
Copy link
Copy Markdown
Member

alphp commented May 4, 2026

This Trait causes an invalid stream ending Exception in tests on GitHub Actions:

1) Fawno\FPDF\Tests\Scripts\PDFProtectionTraitTest::testPDFProtectionTrait
Exception: invalid stream ending
/app/vendor/ddn/sapp/src/PDFObjectParser.php:361
/app/vendor/ddn/sapp/src/PDFObjectParser.php:451
/app/vendor/ddn/sapp/src/PDFObjectParser.php:150
/app/vendor/ddn/sapp/src/PDFUtilFnc.php:559
/app/vendor/ddn/sapp/src/PDFUtilFnc.php:470
/app/vendor/ddn/sapp/src/PDFDoc.php:255
/app/vendor/ddn/sapp/src/PDFDoc.php:749
/app/vendor/ddn/sapp/src/PDFDoc.php:793
/app/vendor/ddn/sapp/src/PDFDoc.php:918
/app/tests/TestCase.php:51
/app/tests/TestCase.php:67
/app/tests/TestCase.php:60
/app/tests/Scripts/PDFProtectionTraitTest.php:24

This error predates this PR.

@erikn69
Copy link
Copy Markdown
Contributor Author

erikn69 commented May 4, 2026

Look at erikn69@f23fbd8
A simpler commit unrelated to this gives the same error;
I couldn't find the problem, but it only happens in github actions, on localhost:

root@e5a720beb1af:/var/www/github/FPDF-1# ./vendor/bin/phpunit
PHPUnit 12.5.24 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.0
Configuration: /var/www/github/FPDF-1/phpunit.xml

.....................                                             21 / 21 (100%)

Time: 00:01.042, Memory: 18.00 MB

OK (21 tests, 74 assertions)

Maybe
dealfonso/sapp/src/PDFDoc.php#L158-L160

@alphp
Copy link
Copy Markdown
Member

alphp commented May 4, 2026

Rebase, I marked affected tests as incomplete.

@erikn69
Copy link
Copy Markdown
Contributor Author

erikn69 commented May 5, 2026

Rebase, I marked affected tests as incomplete.

Revert 8c1dda9
The real problem: it's not validated whether the algorithm exists. RC-40 is unsafe and has been removed from current versions of OpenSSL. I did add a validation to ensure it uses fallback if the algorithm doesn't exist.

@alphp
Copy link
Copy Markdown
Member

alphp commented May 5, 2026

Revert 8c1dda9 The real problem: it's not validated whether the algorithm exists. RC-40 is unsafe and has been removed from current versions of OpenSSL. Add validation to ensure it uses fallback if the algorithm doesn't exist.

Now I understand why the tests don't fail on my systems. For work reasons, I have OpenSSL's legacy algorithms enabled.

@erikn69
Copy link
Copy Markdown
Contributor Author

erikn69 commented May 5, 2026

I have OpenSSL's legacy algorithms enabled.

Me too

@alphp
Copy link
Copy Markdown
Member

alphp commented May 5, 2026

I tried encryption using AES and it seems that something breaks.
File "example/test.php":

	// PDFProtection
	$pdf->SetProtection(['print'], 'user', 'admin', 'AES');

Result:
example.pdf

PS: It seems to be a problem with the viewer; I tested it with the built-in Chrome and Firefox viewers and the generated file displays correctly.

@alphp alphp merged commit 879f784 into fawno:master May 5, 2026
4 checks passed
@erikn69 erikn69 deleted the patch-12 branch May 7, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants