Skip to content

Commit

Permalink
♻️ Use SASL::AuthenticationExchange internally
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Jun 30, 2024
1 parent 999e5ac commit 2ff4010
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
26 changes: 3 additions & 23 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion lib/net/imap/sasl/authentication_exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down

0 comments on commit 2ff4010

Please sign in to comment.