Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SASLprep. Code generated & tested with RFC3454 #64

Merged
merged 1 commit into from
Oct 31, 2022
Merged

Conversation

nevans
Copy link
Collaborator

@nevans nevans commented Sep 30, 2022

RFC-4422 recommends that mechanisms SHOULD prepare simple usernames and passwords with SASLprep. And SASLprep is required by the SCRAM-* mechanisms, which will be added in a future PR.

SASLprep is also recommended for the PLAIN SASL mechanism and for the ACL IMAP extension but—in both cases—string preparation is done by the server, at its own discretion.

SASLprep has been officially obsoleted by PRECIS. I don't believe any IMAP RFCs have allowed replacing SASLprep with PRECIS yet. In contrast, RFC-7622 updates XMPP to require PRECIS. (See RFC-8265 for more info on PRECIS, and Section 6 for migration considerations.)

Rather than create a fully generic StringPrep superclass or function, the SASLprep profile is optimized. Just enough of the generic StringPrep algorithm has been implemented to provide more detailed errors for prohibited strings. Future PRs can expand it as needed, to implement other profiles. In particular, the trace StringPrep profile is a requirement for clients using the ANONYMOUS mechanism.

Many other StringPrep implementations store the tables as an array of ranges and loop over every character in the input. But using Regexp is simpler and much faster, especially where the tables closely match Unicode character classes (benchmarks are included). Some StringPrep tables use Regexps that are generated from the RFC-3454 appendices. Manually written regular expressions are used in cases where there is a close match between Unicode character classes and the SASLprep tables. All regexps are tested against the RFC tables with every valid codepoint, to verify they aren't broken if their character classes are changed by new versions of Unicode.

Additionally:

  • Added rake rfcs to download many IMAP-related RFCs, for convenience.
  • The new code is namespaced under Net::IMAP::SASL. We could move the authenticators there too. If SASL funcionality is ever extracted to another gem, we can use: Net::IMAP::SASL = Net::SASL for backward compatibility.

RFC-4422 recommends that mechanisms SHOULD prepare simple usernames and
passwords with SASLprep.  And SASLprep is required by the `SCRAM-*`
mechanisms, which will be added in a future PR.

SASLprep is also recommended for the `PLAIN` SASL mechanism and for the
`ACL` IMAP extension but—in both cases—string preparation is done by the
*server*, at its own discretion.

SASLprep has been officially obsoleted by PRECIS.  I don't believe any
IMAP RFCs have allowed replacing SASLprep with PRECIS yet.  In contrast,
RFC-7622 updates XMPP to require PRECIS.  (See RFC-8265 for more info on
PRECIS, and Section 6 for migration considerations.)

Rather than create a fully generic StringPrep superclass or function,
the SASLprep profile is optimized.  Just enough of the generic
StringPrep algorithm has been implemented to provide more detailed
errors for prohibited strings.  Future PRs can expand it as needed, to
implement other profiles.  In particular, the `trace` StringPrep profile
is a requirement for clients using the `ANONYMOUS` mechanism.

Many other StringPrep implementations store the tables as an array of
ranges and loop over every character in the input.  But using Regexp is
simpler and much faster, especially where the tables closely match
Unicode character classes (benchmarks are included).  Some StringPrep
tables use Regexps that are generated from the RFC-3454 appendices.
Manually written regular expressions are used in cases where there is a
close match between Unicode character classes and the SASLprep tables.
All regexps are tested against the RFC tables with every valid
codepoint, to verify they aren't broken if their character classes are
changed by new versions of Unicode.

Additionally:

* Added `rake rfcs` to download many IMAP-related RFCs, for convenience.
* The new code is namespaced under `Net::IMAP::SASL`.  We could move the
  authenticators there too.  If SASL funcionality is ever extracted to
  another gem, we can use: `Net::IMAP::SASL = Net::SASL` for backward
  compatibility.
Copy link
Member

@shugo shugo left a comment

Choose a reason for hiding this comment

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

It looks fine. Thank you!

@nevans
Copy link
Collaborator Author

nevans commented Oct 31, 2022

SHA-* PR should be submitted this week. 😉

@nevans nevans merged commit 11757d8 into master Oct 31, 2022
@nevans nevans deleted the saslprep branch October 31, 2022 18:22
@nevans nevans added the SASL 🔒 Authentication and authentication mechanisms label Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SASL 🔒 Authentication and authentication mechanisms
Development

Successfully merging this pull request may close these issues.

2 participants