Skip to content

Use 32 random bytes as the owner password when none is given - #1816

Closed
andreasrosdal wants to merge 1 commit into
LibrePDF:masterfrom
andreasrosdal:random-owner-password
Closed

andreasrosdal wants to merge 1 commit into
LibrePDF:masterfrom
andreasrosdal:random-owner-password

Conversation

@andreasrosdal

Copy link
Copy Markdown
Contributor

Summary

When a document is encrypted with a user password and no owner password (null or empty), PdfEncryption.setupAllKeys made one up: the MD5 hash of a random document ID (16 bytes). It now uses 32 bytes from SecureRandom:

  • 32 bytes is the full length of a padded password for RC4 and AES-128, and gives 256 bits of entropy for AES-256 (R6), matching the key size.
  • MD5 is no longer used to create the password.
  • Nobody knows the generated password, so nobody can open the document with full permissions. Behaviour is otherwise unchanged.

API changes

None. The new PdfEncryption.createRandomOwnerPassword() is package-private.

Tests

RandomOwnerPasswordTest checks the password length and that it differs each time. For RC4-40, RC4-128, AES-128 and AES-256 it checks that the user can read the document without owner permissions and that an empty owner password is replaced too. It also checks that an owner password that is given still gives full permissions. The full openpdf-core suite passes and checkstyle:check is clean.

🤖 Generated with Claude Code

A document encrypted with a user password and without an owner password
got the MD5 hash of a random document ID as its owner password. It now
gets 32 bytes from SecureRandom, the full length of a padded password and
of an AES-256 key, and MD5 is no longer used to create it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 medium

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
BestPractice 1 medium

View in Codacy

🟢 Metrics 5 complexity · 0 duplication

Metric Results
Complexity 5
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

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