Skip to content

Commit 86ccc2b

Browse files
committed
♻️ SASL LOGIN: Add "#done?" [🚧 WIP]
The client should raise an error if the command completes successfully but "done?" returns false. also moved to sasl dir and SASL module. move login login
1 parent 3a5b1d7 commit 86ccc2b

File tree

6 files changed

+67
-50
lines changed

6 files changed

+67
-50
lines changed

lib/net/imap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def starttls(options = {}, verify = true)
987987
#
988988
# For +DIGEST-MD5+ see SASL::DigestMD5Authenticator.
989989
#
990-
# For +LOGIN+, see LoginAuthenticator.
990+
# For +LOGIN+, see SASL::LoginAuthenticator.
991991
#
992992
# For +CRAM-MD5+, see SASL::CramMD5Authenticator.
993993
#

lib/net/imap/authenticators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ def authenticators
6767
require_relative "sasl/xoauth2_authenticator"
6868

6969
# deprecated
70-
require_relative "authenticators/login"
70+
require_relative "sasl/login_authenticator"
7171
require_relative "sasl/cram_md5_authenticator"
7272
require_relative "sasl/digest_md5_authenticator"

lib/net/imap/authenticators/login.rb

Lines changed: 0 additions & 46 deletions
This file was deleted.

lib/net/imap/sasl/authenticator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module SASL
3333
#
3434
# For +DIGEST-MD5+ see SASL::DigestMD5Authenticator.
3535
#
36-
# For +LOGIN+, see LoginAuthenticator.
36+
# For +LOGIN+, see SASL::LoginAuthenticator.
3737
#
3838
# For +CRAM-MD5+, see SASL::CramMD5Authenticator.
3939
#
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
module Net
4+
class IMAP < Protocol
5+
module SASL
6+
7+
# Authenticator for the "+LOGIN+" SASL mechanism. See Net::IMAP#authenticate.
8+
#
9+
# +LOGIN+ authentication sends the password in cleartext.
10+
# RFC3501[https://tools.ietf.org/html/rfc3501] encourages servers to disable
11+
# cleartext authentication until after TLS has been negotiated.
12+
# RFC8314[https://tools.ietf.org/html/rfc8314] recommends TLS version 1.2 or
13+
# greater be used for all traffic, and deprecate cleartext access ASAP. +LOGIN+
14+
# can be secured by TLS encryption.
15+
#
16+
# == Deprecated
17+
#
18+
# The {SASL mechanisms
19+
# registry}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
20+
# marks "LOGIN" as obsoleted in favor of "PLAIN". It is included here for
21+
# compatibility with existing servers. See
22+
# {draft-murchison-sasl-login}[https://www.iana.org/go/draft-murchison-sasl-login]
23+
# for both specification and deprecation.
24+
class LoginAuthenticator
25+
def process(data)
26+
case @state
27+
when STATE_USER
28+
@state = STATE_PASSWORD
29+
@user
30+
when STATE_PASSWORD
31+
@state = STATE_DONE
32+
@password
33+
when STATE_DONE
34+
raise ResponseParseError, data
35+
end
36+
end
37+
38+
def done?; @state == STATE_DONE end
39+
40+
private
41+
42+
STATE_USER = :USER
43+
STATE_PASSWORD = :PASSWORD
44+
STATE_DONE = :DONE
45+
46+
def initialize(user, password, warn_deprecation: true, **_ignored)
47+
if warn_deprecation
48+
warn "WARNING: LOGIN SASL mechanism is deprecated. Use PLAIN instead."
49+
end
50+
@user = user
51+
@password = password
52+
@state = STATE_USER
53+
end
54+
55+
Net::IMAP.add_authenticator "LOGIN", self
56+
end
57+
end
58+
59+
LoginAuthenticator = SASL::LoginAuthenticator # :nodoc:
60+
deprecate_constant :LoginAuthenticator
61+
62+
end
63+
end

test/net/imap/sasl/test_authenticators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def login(*args, warn_deprecation: false, **kwargs, &block)
9191
end
9292

9393
def test_login_authenticator_matches_mechanism
94-
assert_kind_of(Net::IMAP::LoginAuthenticator, login("n", "p"))
94+
assert_kind_of(Net::IMAP::SASL::LoginAuthenticator, login("n", "p"))
9595
end
9696

9797
def test_login_authenticator_deprecated

0 commit comments

Comments
 (0)