Skip to content

A20: Clear owned password hashing buffers - #2849

Merged
stevehu merged 1 commit into
masterfrom
fix/a20-hash-password-buffers-master
Nov 28, 2026
Merged

stevehu merged 1 commit into
masterfrom
fix/a20-hash-password-buffers-master

Conversation

@stevehu

@stevehu stevehu commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Clear the temporary password array and the PBEKeySpec copies in hashing and verification. Preserve the stored hash format and caller ownership of the verifier input.

All four focused HashUtil tests passed locally on master.

@sonarqubecloud

Copy link
Copy Markdown

@stevehu stevehu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code review (A20 password hashing buffers). One finding inline; the change is otherwise fine. The same comment applies to the master/2.x counterpart.

}
try {
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
byte[] hash = skf.generateSecret(spec).getEncoded();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[nit] The PBKDF2 SecretKey keeps a password copy that can't be destroyed. generateSecret(spec) returns a PBKDF2KeyImpl that holds its own clone of the password in passwd, plus an HMAC keyed with the password. spec.clearPassword() doesn't touch either one, and destroy() throws DestroyFailedException. Checked on JDK 25 via reflection: passwd still holds the password after clearPassword(). It's zeroed only when the Cleaner runs after GC. The same applies at line 163 in validatePassword.

Fix: record this as a provider-owned copy in the A20 assessment, or compute PBKDF2 with a Mac over bytes you own if this copy must be ruled out.

@stevehu
stevehu merged commit ab14cbd into master Nov 28, 2026
3 of 4 checks passed
@stevehu
stevehu deleted the fix/a20-hash-password-buffers-master branch November 28, 2026 01:31
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