Skip to content

Commit

Permalink
✨ Add very basic SASL-IR support to #authenticate [🚧 WIP]
Browse files Browse the repository at this point in the history
WIP: No tests, so it's probably broken.
And I'd like the default `:sasl_ir` value to be configurable.
  • Loading branch information
nevans committed Jul 26, 2023
1 parent b8f2986 commit 04ba19a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1053,14 +1053,22 @@ def starttls(options = {}, verify = true)
# If the TaggedResponse to #authenticate includes updated capabilities, they
# will be cached.
#
def authenticate(mechanism, ...)
authenticator = self.class.authenticator(mechanism, ...)
send_command("AUTHENTICATE", mechanism) do |resp|
def authenticate(mechanism, *creds, sasl_ir: false, **props, &callback)
authenticator = self.class.authenticator(mechanism,
*creds,
**props,
&callback)
cmdargs = ["AUTHENTICATE", mechanism]
sasl_ir = capable?("SASL-IR") if [nil, :auto].include?(sasl_ir)
if sasl_ir && SASL.initial_response?(authenticator)
response = authenticator.process(nil)
cmdargs << [response].pack("m0")
end
send_command(*cmdargs) do |resp|
if resp.instance_of?(ContinuationRequest)
data = authenticator.process(resp.data.text.unpack("m")[0])
s = [data].pack("m0")
send_string_data(s)
put_string(CRLF)
challenge = resp.data.text.unpack1("m")
response = authenticator.process(challenge)
send_string_data([response].pack("m0") + CRLF)
end
end
.tap { @capabilities = capabilities_from_resp_code _1 }
Expand Down
4 changes: 4 additions & 0 deletions lib/net/imap/sasl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def saslprep(string, **opts)
Net::IMAP::StringPrep::SASLprep.saslprep(string, **opts)
end

def initial_response?(mechanism)
mechanism.respond_to?(:initial_response?) && mechanism.initial_response?
end

end
end

Expand Down

0 comments on commit 04ba19a

Please sign in to comment.