From 2a55ec3bda6eaea356e23deca8f39a41a7c2b02d Mon Sep 17 00:00:00 2001 From: nick evans Date: Wed, 27 Sep 2023 16:50:52 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Use=20experimental=20SASL:?= =?UTF-8?q?:ClientAdapter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ Adds `registry` option to `#authenticate`. This allows authenticator lookup and creation to be overridden, rather than be forced to depend on global defaults. --- lib/net/imap.rb | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index ade8f95ee..5e16bc1db 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -1157,6 +1157,8 @@ def starttls(**options) # +sasl_ir+ allows or disallows sending an "initial response" (see the # +SASL-IR+ capability, below). # + # Override +registry+ to use a custom SASL::Authenticators registry. + # # All other arguments are forwarded to the registered SASL authenticator for # the requested mechanism. The documentation for each individual # mechanism must be consulted for its specific parameters. @@ -1251,27 +1253,9 @@ def starttls(**options) # Previously cached #capabilities will be cleared when this method # completes. If the TaggedResponse to #authenticate includes updated # capabilities, they will be cached. - def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback) - mechanism = mechanism.to_s.tr("_", "-").upcase - authenticator = SASL.authenticator(mechanism, *creds, **props, &callback) - cmdargs = ["AUTHENTICATE", mechanism] - if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) && - authenticator.respond_to?(:initial_response?) && - authenticator.initial_response? - response = authenticator.process(nil) - cmdargs << (response.empty? ? "=" : [response].pack("m0")) - end - result = send_command_with_continuations(*cmdargs) {|data| - challenge = data.unpack1("m") - response = authenticator.process challenge - [response].pack("m0") - } - if authenticator.respond_to?(:done?) && !authenticator.done? - logout! - raise SASL::AuthenticationIncomplete, result - end - @capabilities = capabilities_from_resp_code result - result + def authenticate(...) + sasl_adapter.authenticate(...) + .tap { @capabilities = capabilities_from_resp_code _1 } end # Sends a {LOGIN command [IMAP4rev1 §6.2.3]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.2.3]