Skip to content

Accept unpadded base64 in Olm message bodies - #9

Merged
TroyHernandez merged 2 commits into
mainfrom
fix-olm-base64-padding
Oct 8, 2026
Merged

TroyHernandez merged 2 commits into
mainfrom
fix-olm-base64-padding

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

What

Decode Olm message bodies with a padding-indifferent base64 engine so both padded (libolm) and unpadded (vodozemac) bodies open.

Why

mxc_olm_create_inbound() and mxc_olm_decrypt() decoded the Olm message body with base64 0.22 STANDARD, whose default decode padding mode is RequireCanonical. vodozemac (matrix-dart-sdk 10.x, Element, modern FluffyChat) emits Olm bodies unpadded, so every inbound body whose length was not a multiple of 4 was rejected (prekey body is not valid base64 / olm body is not valid base64) and silently dropped. This blocked inbound Olm from modern clients generally, and surfaced as MatrixRTC call encryption keys never decrypting (one-way audio only).

Change

  • B64 is now a GeneralPurpose engine on the STANDARD alphabet with DecodePaddingMode::Indifferent. Both decode sites (create_inbound, decrypt) accept padded and unpadded; encoding stays canonical (padded), which peers already accept. vodozemac's own from_base64 calls (megolm, keys, signatures) were already tolerant, so only the two raw-body decodes needed the change.
  • Regression test in test_olm.R: builds real Olm bodies, strips their padding to mimic vodozemac, and confirms create_inbound and decrypt both open them (and that padded bodies still work), stepping plaintext length across AES-CBC block boundaries so a genuinely padded body is exercised.

Verification

Isolated-library build clean; full tinytest suite green including the new regression. Confirmed live: two-way MatrixRTC audio with a FluffyChat fork once tiny ran this build.

libolm padded Olm message bodies; vodozemac (matrix-dart-sdk 10.x,
Element) emits them unpadded, so the canonical-padding base64 decoder
rejected every inbound body whose length was not a multiple of 4
("prekey body is not valid base64" / "olm body is not valid base64"),
dropping it. Decode with DecodePaddingMode::Indifferent so
mxc_olm_create_inbound and mxc_olm_decrypt accept both padded and unpadded
bodies; encoding stays padded, which peers already accept. Restores inbound
Olm from vodozemac peers, including MatrixRTC call encryption keys.
@TroyHernandez
TroyHernandez merged commit cdc3888 into main Oct 8, 2026
4 checks passed
@TroyHernandez
TroyHernandez deleted the fix-olm-base64-padding branch October 8, 2026 12:38
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.

1 participant