Skip to content

OF-3257: Guard against timing attacks in ScramSha1SaslServer#3289

Merged
guusdk merged 7 commits intoigniterealtime:mainfrom
guusdk:OF-3257_ScramSha1-constant-time
May 5, 2026
Merged

OF-3257: Guard against timing attacks in ScramSha1SaslServer#3289
guusdk merged 7 commits intoigniterealtime:mainfrom
guusdk:OF-3257_ScramSha1-constant-time

Conversation

@guusdk
Copy link
Copy Markdown
Member

@guusdk guusdk commented Apr 23, 2026

This PR improves the resilience of the SCRAM-SHA-1 SASL implementation against timing-based side-channel attacks.

The changes focus on ensuring more consistent execution paths during authentication, particularly when handling non-existing users or missing credentials. Instead of short-circuiting, equivalent work is performed using substitute values to better align timing characteristics.

For detailed implementation specifics, see the individual commit messages.

@guusdk
Copy link
Copy Markdown
Member Author

guusdk commented Apr 23, 2026

There is some overlap between the implementations in these two PRs:

Notably, the introduction of the same system property. Both PRs should introduce an exact duplicate. This, however, could trigger a merge conflict.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Openfire’s SCRAM-SHA-1 SASL server implementation against timing-based side-channel attacks by avoiding early exits when credentials are missing, and by using constant-time comparisons for key material.

Changes:

  • Introduces a new encrypted system property used to derive deterministic “fake” SCRAM keys for non-existing users.
  • Updates SCRAM authentication to always compute equivalent HMAC work and to use MessageDigest.isEqual for constant-time key comparison.
  • Adds unit tests to validate determinism and variability of the generated fake keys, plus i18n strings for the new system property.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

File Description
xmppserver/src/main/java/org/jivesoftware/openfire/sasl/ScramSha1SaslServer.java Adds server secret property + fake key generation and uses constant-time key comparison in SCRAM verification.
xmppserver/src/test/java/org/jivesoftware/openfire/sasl/ScramSha1SaslServerFakeKeyTest.java Adds tests validating fake key behavior (determinism, variance by username/secret, expected length).
i18n/src/main/resources/openfire_i18n.properties Adds system property description for the new SCRAM fake-key secret.
i18n/src/main/resources/openfire_i18n_nl.properties Adds Dutch translation for the new system property description.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread xmppserver/src/main/java/org/jivesoftware/openfire/sasl/ScramSha1SaslServer.java Outdated
Comment thread xmppserver/src/main/java/org/jivesoftware/openfire/sasl/ScramSha1SaslServer.java Outdated
Comment thread xmppserver/src/main/java/org/jivesoftware/openfire/sasl/ScramSha1SaslServer.java Outdated
Comment thread xmppserver/src/main/java/org/jivesoftware/openfire/sasl/ScramSha1SaslServer.java Outdated
Comment thread i18n/src/main/resources/openfire_i18n.properties Outdated
Comment thread i18n/src/main/resources/openfire_i18n_nl.properties Outdated
@guusdk
Copy link
Copy Markdown
Member Author

guusdk commented Apr 24, 2026

#3289 and #3288 are a bit messy, as they both introduce a few snippets of code that are duplicated between the two. I've then applied (the same) modifications to that duplicated code (in each PR). Apologies for the mess this created.

guusdk added 7 commits April 27, 2026 08:39
… fake keys

When storedKey or serverKey are missing, generate deterministic fake values derived from a server-side secret and the username. This ensures that authentication follows the same execution path regardless of user existence, reducing susceptibility to timing attacks.

Includes unit tests to verify determinism and key separation.
…AM-SHA-1(-PLUS) SASL server

Previously, the comparison of the expected and received channel binding payloads in ScramSha1SaslServer used Arrays.equals, which is not guaranteed to operate in constant time. This could potentially leak information about the channel binding data through timing side-channels.

This change replaces Arrays.equals with MessageDigest.isEqual, ensuring that the comparison is performed in constant time. This strengthens the implementation against timing attacks, aligns with secure coding best practices, and provides defense-in-depth for sensitive authentication operations.
…EXISTENT_USERS

The previous method for one-time initialization of the SERVER_SECRET_NONEXISTENT_USERS property (which depended on a static initializer block) proved to be fragile.

In this commit, initialization happens in a getter that should be used instead of directly accessing the property.
@guusdk guusdk force-pushed the OF-3257_ScramSha1-constant-time branch from 268b31a to e0527c3 Compare April 27, 2026 06:43
@guusdk
Copy link
Copy Markdown
Member Author

guusdk commented Apr 27, 2026

I have rebased this on Main now that #3288 was merged there.

@guusdk guusdk merged commit d9f966f into igniterealtime:main May 5, 2026
53 of 62 checks passed
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.

3 participants