Skip to content

Use HMAC-SHA256 for cache passwords over MD5#877

Open
Firstyear wants to merge 1 commit intocyrusimap:masterfrom
Firstyear:20250807-hmac-sha256
Open

Use HMAC-SHA256 for cache passwords over MD5#877
Firstyear wants to merge 1 commit intocyrusimap:masterfrom
Firstyear:20250807-hmac-sha256

Conversation

@Firstyear
Copy link

Currently the password cache uses MD5 for password caching in the mmapped cache file. This is not cryptographically secure.

This changes the algorithm to HMAC-SHA256. While other password verification algorithms are considered cryptographically superior (such as argon2id) in this case we want to maintain the cache's high performance, while improving the security of cached passwords.

To achieve this, the HMAC key itself is ephemeral and only ever stored in memory. This means that per invocation of saslauthd the HMAC key will be randomised. This results in the cache mmap file being effectively useless to an attacker who manages to steal the cache as they lack the HMAC key to attempt to validate or bruteforce any cached password.

This also means that if saslauthd crashes, the key material to access the cache is lost, effectively invalidating all records in that cache.

If an attacker were able to access the HMAC key in memory, then we can pretty safely assume that the attacker can also access plaintext password material making the need to access the key irrelevant.

As a result, this change improves security of cached passwords without a significant loss of performance in the cache's operation.

@Firstyear Firstyear force-pushed the 20250807-hmac-sha256 branch from 63b507f to 3fd55b7 Compare August 7, 2025 04:00
Currently the password cache uses MD5 for password caching in the
mmapped cache file. This is not cryptographically secure.

This changes the algorithm to HMAC-SHA256. While other password
verification algorithms are considered cryptographically superior
(such as argon2id) in this case we want to maintain the cache's
high performance, while improving the security of cached passwords.

To achieve this, the HMAC key itself is ephemeral and only ever
stored in memory. This means that per invocation of saslauthd
the HMAC key will be randomised. This results in the cache mmap
file being effectively useless to an attacker who manages to
steal the cache as they lack the HMAC key to attempt to validate
or bruteforce any cached password.

This also means that if saslauthd crashes, the key material to
access the cache is lost, effectively invalidating all records
in that cache.

If an attacker were able to access the HMAC key in memory, then we
can pretty safely assume that the attacker can also access plaintext
password material making the need to access the key irrelevant.

As a result, this change improves security of cached passwords
without a significant loss of performance in the cache's operation.

Signed-off-by: William <william@blackhats.net.au>
@Firstyear Firstyear force-pushed the 20250807-hmac-sha256 branch from 3fd55b7 to 6eb8eab Compare August 7, 2025 04:23
@Neustradamus
Copy link
Contributor

@hyc, @quanah: Have you seen this PR?

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.

2 participants