Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New AES-256 encryption #872

Merged
merged 12 commits into from Aug 2, 2023
Merged

New AES-256 encryption #872

merged 12 commits into from Aug 2, 2023

Conversation

andersonhc
Copy link
Collaborator

@andersonhc andersonhc commented Jul 28, 2023

This PR is implementing a new encryption method - AES 256.
AES 256 was introduced in PDF 2.0. The new algorithm got rid of all weak hashes, specially MD5, making the new method much stronger than all the old methods.
This PR is also fixing encryption of annotation strings.
The documentation was updated and the new test should cover all the changes.

Checklist:

  • The GitHub pipeline is OK (green),
    meaning that both pylint (static code analyzer) and black (code formatter) are happy with the changes of this PR.

  • A unit test is covering the code added / modified by this PR

  • This PR is ready to be merged

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

fix annotation encryption
@andersonhc andersonhc requested a review from Lucas-C as a code owner July 28, 2023 12:55
@Lucas-C
Copy link
Member

Lucas-C commented Jul 28, 2023

Nice addition, thank you @andersonhc!

Pylint is complaining on a few points:

fpdf/encryption.py:226:12: R1714: Consider merging these comparisons with 'in' by using 'self.encryption_method in (EncryptionMethod.AES_128, EncryptionMethod.AES_256)'. Use a set instead if elements are hashable. (consider-using-in)
fpdf/encryption.py:338:12: C0501: `for` loop could be `any(fun(char) for char in string)` (consider-using-any-or-all)
fpdf/encryption.py:420:8: W0622: Redefining built-in 'round' (redefined-builtin)
fpdf/encryption.py:412:4: R6301: Method could be a function (no-self-use)

.banditrc.yml Show resolved Hide resolved
fpdf/encryption.py Outdated Show resolved Hide resolved
fpdf/encryption.py Outdated Show resolved Hide resolved
fpdf/encryption.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Patch coverage: 92.35% and project coverage change: -0.17% ⚠️

Comparison is base (95b43fb) 93.39% compared to head (ad70c82) 93.22%.
Report is 3 commits behind head on master.

❗ Current head ad70c82 differs from pull request most recent head 525a7d5. Consider uploading reports for the commit 525a7d5 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #872      +/-   ##
==========================================
- Coverage   93.39%   93.22%   -0.17%     
==========================================
  Files          27       27              
  Lines        7388     7679     +291     
  Branches     1333     1395      +62     
==========================================
+ Hits         6900     7159     +259     
- Misses        307      328      +21     
- Partials      181      192      +11     
Files Changed Coverage Δ
fpdf/fpdf.py 92.55% <70.83%> (-0.42%) ⬇️
fpdf/graphics_state.py 98.76% <83.33%> (-0.60%) ⬇️
fpdf/fonts.py 92.30% <91.36%> (-3.46%) ⬇️
fpdf/deprecation.py 96.77% <93.75%> (-3.23%) ⬇️
fpdf/encryption.py 95.53% <94.00%> (-0.77%) ⬇️
fpdf/line_break.py 98.07% <94.66%> (-1.11%) ⬇️
fpdf/annotations.py 98.63% <100.00%> (ø)
fpdf/enums.py 98.00% <100.00%> (+<0.01%) ⬆️
fpdf/html.py 93.13% <100.00%> (+0.01%) ⬆️
fpdf/output.py 97.18% <100.00%> (-0.05%) ⬇️
... and 2 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

fpdf/encryption.py Outdated Show resolved Hide resolved
@Lucas-C
Copy link
Member

Lucas-C commented Aug 2, 2023

OK, there is just a remaining question about a potential extra unit test.

I let you tell me if you think it's useless, or add it to the PR,
and then I'll be happy to merge it!

@Lucas-C Lucas-C merged commit 40e3b91 into py-pdf:master Aug 2, 2023
11 checks passed
@Lucas-C
Copy link
Member

Lucas-C commented Aug 2, 2023

Merged! Thank you @andersonhc 👍

@andersonhc andersonhc deleted the encryption branch October 14, 2023 01:17
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.

None yet

2 participants