From a5a5ba95fc15965a7570107c82c719b359ac02d2 Mon Sep 17 00:00:00 2001 From: nick evans Date: Sun, 15 Sep 2024 22:52:23 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Use=20SASL::Authentication?= =?UTF-8?q?Exchange=20internally?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/net/imap.rb | 26 +++----------------- lib/net/imap/sasl/authentication_exchange.rb | 3 ++- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index e1ce6300..83807f00 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -1333,29 +1333,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: config.sasl_ir, - **props, &callback) - mechanism = SASL::Authenticators.normalize_name(mechanism) - 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(*args, sasl_ir: config.sasl_ir, **props, &callback) + sasl_adapter.authenticate(*args, sasl_ir: sasl_ir, **props, &callback) + .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] diff --git a/lib/net/imap/sasl/authentication_exchange.rb b/lib/net/imap/sasl/authentication_exchange.rb index 9a6de0dc..98bfcf37 100644 --- a/lib/net/imap/sasl/authentication_exchange.rb +++ b/lib/net/imap/sasl/authentication_exchange.rb @@ -4,7 +4,8 @@ module Net class IMAP module SASL - # This API is *experimental*, and may change. + # AuthenticationExchange is used internally by Net::IMAP#authenticate. + # But the API is still *experimental*, and may change. # # TODO: catch exceptions in #process and send #cancel_response. # TODO: raise an error if the command succeeds after being canceled.