Skip to content

Encryption: password preparation cites two obsolete RFCs — implement RFC 8265 OpaqueString or restate the gap #226

Open

Description

@Tim81

ISO 32000-2 §7.6.4.3 requires SASLprep normalisation of a password before the /R 5 and 6 key
derivation. This library deliberately does not apply it, and says so in three places —
PdfEncryptionSettings.cs:16-20 and :36-40, and StandardSecurityHandler.cs:12-16:

A full SASLprep implementation would require NFC normalisation and prohibited-character …

That documented gap is fine as far as it goes. What is new is what the normative reference has done
since
.

Both cited RFCs are obsolete

Found while mapping ISO 32000-2's normative-reference graph (#225), which flags them as obsolete.
Confirmed against the RFC Editor:

RFC Title Status
RFC 3454 Preparation of Internationalized Strings ("stringprep") obsoleted by RFC 7564
RFC 4013 SASLprep: Stringprep Profile for User Names and Passwords obsoleted by RFC 7613, in turn obsoleted by RFC 8265

So the standard PDF 2.0 normatively cites for password preparation was obsoleted, and its replacement
was obsoleted too. The live successor is RFC 8265, "Preparation, Enforcement, and Comparison of
Internationalized Strings Representing Usernames and Passwords" — specifically its OpaqueString
profile, which is the PRECIS framework's answer for passwords.

That materially changes the shape of the work. Implementing "SASLprep" literally means implementing a
withdrawn 2005 profile of a withdrawn 2002 framework. OpaqueString is both current and simpler:
width-mapping fullwidth/halfwidth characters, mapping non-ASCII space to U+0020, NFC normalisation,
and a FreeformClass membership check — rather than stringprep's bespoke tables.

Why it matters in practice

The gap is invisible for ASCII passwords, which is why it has cost nothing so far. It bites when a
password contains:

  • non-ASCII whitespace (ideographic space, non-breaking space) — mapped to U+0020 by OpaqueString,
    left alone by us;
  • characters with more than one Unicode representation — é as U+00E9 versus U+0065 U+0301. We hash
    the bytes as given, so a document encrypted by a conforming writer will not open with the same
    password typed on a system that normalises differently, and vice versa.

The failure is silent and looks like a wrong password. Given how much v2.2 was about exactly that
class of confusion (#211), a password that is correct but does not authenticate deserves better than
the current generic message.

RFC 7564, RFC 7613 and RFC 8265 are all now held, so this no longer has to settle for restating the
gap — Option 1 below can be implemented directly against the text.

What to decide

  1. Implement OpaqueString (RFC 8265) rather than SASLprep, and say in the doc comments that we
    implement the live successor to the obsolete profile ISO 32000-2 cites. NFC is available in the
    BCL (string.Normalize(NormalizationForm.FormC)) so the zero-runtime-dependency rule is safe; the
    work is the width-mapping and the FreeformClass check.
  2. Or keep the gap and update the wording: the three doc comments currently imply SASLprep is the
    current requirement. At minimum they should record that RFC 4013 is obsolete and name RFC 8265, so
    the next person does not go and implement the withdrawn profile.

Option 1 is the better answer if it comes with a decode-side fallback: on a failed authentication,
retry with the normalised form before reporting failure, the way the reader already falls back from
UTF-8 to PDFDocEncoding for /R ≤ 4 (PdfDocEncoding.cs:6-13). That turns a silent
wrong-password into a success without breaking any file that already works.

Test shape

Value-level, not "it round-trips": encrypt with a password containing a decomposed character and a
non-ASCII space, then assert the derived file key matches the one a conforming implementation
produces for the composed form. qpdf can generate the reference file.

Relates to

Activity

  1. added
    area/signing
    type/feature
    priority/P2
    needs-design
    on Aug 28, 2026
  2. Tim81 commented on Aug 29, 2026

    @Tim81
    OwnerAuthor

    Primary-source correction. This reverses the recommendation in the issue body.

    The body proposes implementing RFC 8265 OpaqueString instead of SASLprep, on the grounds that RFC
    3454 and RFC 4013 are obsolete. The obsolescence is real — the RFC Editor confirms it, and the
    PDF2NormRefs graph flags both.

    But ISO 32000-2:2020 addresses this directly. Clause 0.4, in the list of normative-reference
    changes:

    This document requires that RFC 3454 ("stringprep") and RFC 4013 ("SASLprep") continue to be used
    to maintain backward compatibility
    even though these RFCs are marked as obsolete by IETF.

    So the standard knows the RFCs are obsolete and requires them anyway, deliberately, for compatibility.

    Why the substitution would be a defect

    Password preparation feeds the /R 5 and 6 key derivation. OpaqueString and SASLprep do not agree on
    every input — the width mapping and the prohibited-character sets differ — so for some passwords the
    two produce different bytes and therefore different keys.

    A document written with OpaqueString preparation would then be unopenable by a conforming reader
    using the password the user typed, and a document written by a conforming writer would be unopenable by
    this library. That is an interoperability break affecting exactly the users who need non-ASCII
    passwords, which is the population this issue set out to serve.

    The corrected scope

    Implement SASLprep as ISO 32000-2 specifies it — RFC 4013 over RFC 3454: the mapping tables, NFKC
    normalisation, prohibited-output checks and bidirectional-string rules.

    Keep the RFCs obsolete status as context in the documentation, not as grounds to substitute. The
    existing comments at PdfEncryptionSettings.cs:16-20, :36-40 and StandardSecurityHandler.cs:12-16
    already document the gap honestly; they should be updated to say the standard requires the obsolete
    profile rather than implying a modern replacement is the right target.

    Worth keeping from the original filing

    The observation that "implementing SASLprep literally means implementing a withdrawn 2005 profile of a
    withdrawn 2002 framework" remains true, and is a fair thing to record in a comment next to the
    implementation. It is an argument for documenting the oddity, not for departing from it.

    Found during the ISO 32000-2 planning pass; see #225 for the wider inventory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/signingneeds-designpriority/P2type/feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions