3

I wanted to password-protect a PDF in Preview via the "Edit Permissions ..." dialog. I used a simple random password generator to create a reasonably secure password ... only to get it rejected with a "Password contains invalid characters" error message, repeatedly.

Screen shot of dialog, with error message

Through trial and error, I discovered that it actually doesn't like it when the password is too long. A 32-character password is fine, but a 33-character one produces this error.

This seems counter to many security recommendations, though. And arguably, the error message should tell you what's actually wrong; the current one is misleading. But I digress.

If there really are "illegal characters", which ones are they?

(I suppose it would be useful to understand whether the restrictions on allowed passwords are dictated by the actual PDF spec, or just an arbitrary bug which Apple could fix, but that's bonus points territory.)

I searched the Apple forums for any mention of this problem, but I seem to be the only one who is wondering about this. I also consulted Adobe's documentation for PDF Reader, but that doesn't mention any restrictions on allowable passwords, either.

This is on an up-to-date MacOS Monterey (12.5) installation.

7
  • Telling you what is actually wrong with a password would be leaking secrets about the password validation strategy
    – Peter M
    Aug 15, 2022 at 20:42
  • @PeterM How can I fix a password which is disallowed if the system doesn't tell me what's wrong with it? How does "password is too long" reveal anything secret?
    – tripleee
    Aug 16, 2022 at 5:45
  • By revealing "password too long", an attacker can incrementally shorten their test password word until that error disappears. This then allows them to set known limits when brute forcing the actual password - and hence saves them a lot of work.
    – Peter M
    Aug 16, 2022 at 12:23
  • 1
    This is the dialog for setting a password.
    – tripleee
    Aug 16, 2022 at 12:31
  • 1
    But then the error message could simply be changed to something like "password is not acceptable" to avoid providing false information.
    – tripleee
    Aug 16, 2022 at 12:33

1 Answer 1

5

Section 7.6 of the PDF standard (ISO 32000) covers encryption.

https://www.iso.org/obp/ui/#iso:std:iso:32000:-2:ed-2:v1:en
(Ironically, you have to pay for a copy of an open standard.)

Passwords in the 1.7 standard are stored as a 32-byte string of characters in the Latin-1 Unicode range. (See "PDFDocEncoding, Annex D" of the standard.)

There are extensions (in the 2.0 standard) that allow all Unicode characters in a 127-byte string. Note that some Unicode chars are multi-byte.

Not all PDF viewers can parse the 2.0 standard.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .