1
1
# frozen_string_literal: true
2
2
3
3
# Authenticator for the "+PLAIN+" SASL mechanism, specified in
4
- # RFC4616 [https://tools.ietf.org/html/rfc4616]. See Net::IMAP#authenticate.
4
+ # RFC-4616 [https://tools.ietf.org/html/rfc4616]. See Net::IMAP#authenticate.
5
5
#
6
6
# +PLAIN+ authentication sends the password in cleartext.
7
- # RFC3501 [https://tools.ietf.org/html/rfc3501] encourages servers to disable
7
+ # RFC-3501 [https://tools.ietf.org/html/rfc3501] encourages servers to disable
8
8
# cleartext authentication until after TLS has been negotiated.
9
- # RFC8314 [https://tools.ietf.org/html/rfc8314] recommends TLS version 1.2 or
9
+ # RFC-8314 [https://tools.ietf.org/html/rfc8314] recommends TLS version 1.2 or
10
10
# greater be used for all traffic, and deprecate cleartext access ASAP. +PLAIN+
11
11
# can be secured by TLS encryption.
12
12
class Net ::IMAP ::SASL ::PlainAuthenticator
13
+
13
14
NULL = -"\0 " . b
14
15
private_constant :NULL
15
16
16
- # +username+ is the authentication identity, the identity whose +password+ is
17
- # used. +username+ is referred to as +authcid+ by
18
- # RFC4616[https://tools.ietf.org/html/rfc4616].
17
+ # Authentication identity: the identity that matches the #password.
18
+ #
19
+ # RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
20
+ # this to +authcid+.
21
+ attr_reader :username
22
+
23
+ # A password or passphrase that matches the #username.
24
+ attr_reader :password
25
+
26
+ # Authorization identity: an identity to act as or on behalf of. The identity
27
+ # form is application protocol specific. If not provided or left blank, the
28
+ # server derives an authorization identity from the authentication identity.
29
+ # The server is responsible for verifying the client's credentials and
30
+ # verifying that the identity it associates with the client's authentication
31
+ # identity is allowed to act as (or on behalf of) the authorization identity.
19
32
#
20
- # +authzid+ is the authorization identity (identity to act as). It can
21
- # usually be left blank. When +authzid+ is left blank (nil or empty string)
22
- # the server will derive an identity from the credentials and use that as the
23
- # authorization identity.
33
+ # For example, an administrator or superuser might take on another role:
34
+ #
35
+ # imap.authenticate "PLAIN", "root", passwd, authzid: "user"
36
+ #
37
+ attr_reader :authzid
38
+
39
+ # :call-seq:
40
+ # new(username, password, authzid: nil) -> authenticator
41
+ #
42
+ # Creates an Authenticator for the "+PLAIN+" SASL mechanism.
43
+ #
44
+ # Called by Net::IMAP#authenticate and similar methods on other clients.
45
+ #
46
+ # === Parameters
47
+ #
48
+ # * #username ― Identity whose +password+ is used.
49
+ # * #password ― Password or passphrase associated with this username+.
50
+ # * #authzid ― Alternate identity to act as or on behalf of. Optional.
51
+ #
52
+ # See attribute documentation for more details.
24
53
def initialize ( username , password , authzid : nil )
25
54
raise ArgumentError , "username contains NULL" if username &.include? ( NULL )
26
55
raise ArgumentError , "password contains NULL" if password &.include? ( NULL )
@@ -30,8 +59,13 @@ def initialize(username, password, authzid: nil)
30
59
@authzid = authzid
31
60
end
32
61
62
+ # :call-seq:
63
+ # initial_response? -> true
64
+ #
65
+ # +PLAIN+ can send an initial client response.
33
66
def initial_response? ; true end
34
67
68
+ # Responds with the client's credentials.
35
69
def process ( data )
36
70
return "#@authzid \0 #@username \0 #@password "
37
71
end
0 commit comments