Skip to content

Commit

Permalink
💩🚧 More complete SASL error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Sep 26, 2023
1 parent 82fe814 commit 31f36d9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,28 @@ def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
response = authenticator.process(nil)
cmdargs << sasl_encode_ir(response)
end
result = send_command(*cmdargs) do |resp|
if resp.instance_of?(ContinuationRequest)
challenge = sasl_decode resp.data.text
response = sasl_encode authenticator.process challenge
put_string(response + CRLF)
begin
error = false
result = send_command(*cmdargs) do |resp|
if resp.instance_of?(ContinuationRequest)
unless error
begin
challenge = sasl_decode resp.data.text
response = sasl_encode authenticator.process(challenge)
rescue DataFormatError, ResponseParseError, SASL::Error => error
end
end
put_string(error ? "*\r\n" : response + CRLF)
end
end
rescue ResponseError => ex
ex.cause ||= error if error
raise
end
unless SASL.done?(authenticator)
if error
logout!
raise error
elsif !SASL.done?(authenticator)
logout!
raise SASL::AuthenticationFailed, "authentication ended prematurely"
end
Expand Down

0 comments on commit 31f36d9

Please sign in to comment.