From 2ff4010632787bca54265505ee0c007868510564 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=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 9cdd6621..ddd76788 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -1339,29 +1339,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 eb4ad2c0..6f5fc99b 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: use with more clients, to verify the API can accommodate them. #