feat: support CRAM-MD5 authentication (RFC 2195)#11
Merged
Conversation
Advertise and accept AUTH CRAM-MD5 alongside PLAIN and LOGIN. The existing [[server.auth]] username/password credentials serve all three mechanisms, so no config changes are needed. - smtp: new AuthenticatingCramMd5 session state, challenge generation (<counter.nanos@hostname>, unique per session to prevent digest replay), and an on_auth_cram_md5 callback with a supports_cram_md5 capability gate so implementations that don't support the mechanism neither advertise it nor accept it (504 instead). - hedwig: verify the client digest by recomputing HMAC-MD5(password, challenge) from the stored password, compared in constant time. hmac and md-5 were already in the tree as transitive deps. - Harden the AUTH exchange for all mechanisms: cancellation with '*' (RFC 4954) and malformed base64/response data now get a 501 and return the session to Greeted instead of tearing down the connection. Verified end-to-end with Python smtplib forcing CRAM-MD5 against a live server: 235 on correct password, 535 on wrong, mail accepted after auth.
Deploying hedwig with
|
| Latest commit: |
328f02e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e6f58e2a.hedwig-1mq.pages.dev |
| Branch Preview URL: | https://feat-cram-md5-auth.hedwig-1mq.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
AUTH CRAM-MD5support alongside the existing PLAIN and LOGIN mechanisms. No config changes needed — the existing[[server.auth]]username/password credentials serve all three mechanisms, since CRAM-MD5 verification just recomputes the HMAC from the stored plaintext password. The mechanism is negotiated per-connection by the client, so there is no per-credentialauth_typeknob.smtp crate
AuthCramMd5/AuthCramMd5Responsecommands andAuthenticatingCramMd5(challenge)session state.<counter.nanos@hostname>, using the configurable hostname from feat: make inbound SMTP greeting/EHLO hostname configurable #9). The atomic counter + timestamp guarantees per-session uniqueness — which is what blocks digest replay — without adding a rand dependency.on_auth_cram_md5(username, challenge, digest)trait callback plus asupports_cram_md5()capability gate (both defaulted, non-breaking): implementations that don't opt in neither advertise CRAM-MD5 in EHLO nor accept it (504instead).hedwig
on_auth_cram_md5recomputesHMAC-MD5(password, challenge)and compares digests in constant time. Lowercase hex per the RFC; uppercase tolerated.hmacandmd-5added as direct deps — both were already in the tree transitively.AUTH exchange hardening (all mechanisms)
*(RFC 4954 §4) now gets501and returns the session toGreetedinstead of tearing down the connection.501instead of a connection-killing internal error. Both flaws pre-existed in the PLAIN/LOGIN paths and are fixed uniformly.Note
CRAM-MD5 is a legacy-client compatibility feature, not a security upgrade: it avoids sending the password in cleartext, but MD5-based challenge-response is obsolete and PLAIN over TLS remains the stronger option.
Testing
535, cancellation, malformed responses,504when the callback doesn't support the mechanism, recovery after malformedAUTH PLAIN.smtplibforcing CRAM-MD5:235on correct password,535on wrong, mail accepted after auth.