-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# frozen_string_literal: true | ||
|
||
module Net | ||
class IMAP < Protocol | ||
module SASL | ||
|
||
# Authenticator for the "+EXTERNAL+" SASL mechanism, as specified by | ||
# RFC-4422[https://tools.ietf.org/html/rfc4422]. See | ||
# Net::IMAP#authenticate. | ||
# | ||
# The EXTERNAL mechanism requests that the server use client credentials | ||
# established external to SASL, for example by TLS certificate or IPsec. | ||
# | ||
class ExternalAuthenticator | ||
|
||
# :call-seq: | ||
# initial_response? -> true | ||
# | ||
# +EXTERNAL+ can send an initial client response. | ||
def initial_response?; true end | ||
|
||
## | ||
# :call-seq: | ||
# new -> authenticator | ||
# new(authzid, **) -> authenticator | ||
# new(authzid:, **) -> authenticator | ||
# | ||
# Creates an Authenticator for the "+EXTERNAL+" SASL mechanism, as | ||
# specified in RFC-4422[https://tools.ietf.org/html/rfc4422]. To use | ||
# this, see Net::IMAP#authenticate or your client's authentication | ||
# method. | ||
# | ||
# ==== Configuration parameters | ||
# Only one parameter, which is optional: | ||
# | ||
# * #authzid -- the identity to act as. Leave blank to use the identity | ||
# associated with the client's credentials. | ||
# | ||
# May be sent as a positional argument or as a keyword argument. | ||
# | ||
def initialize(authzid_arg = nil, authzid: nil) | ||
@authzid = authzid || authzid_arg | ||
[authzid, authzid_arg].compact.count <= 1 or | ||
raise ArgumentError, "conflicting values for authzid" | ||
if @authzid | ||
raise ArgumentError, "contains NULL" if @authzid.include? NULL | ||
@authzid = @authzid.encode "UTF-8" | ||
@authzid.valid_encoding? or raise ArgumentError, "not valid UTF-8" | ||
end | ||
end | ||
|
||
attr_reader :authzid | ||
|
||
def process(_) | ||
return "" if authzid.nil? | ||
if /\u0000/u.match?(authzid) # also validates UTF8 encoding | ||
raise DataFormatError, "authzid contains NULL" | ||
end | ||
authzid.encode "UTF-8" | ||
end | ||
|
||
def authzid=(value) | ||
raise ArgumentError, "contains NULL" if value.include? NULL | ||
value = value.encode "UTF-8" | ||
value.valid_encoding? or raise ArgumentError, "not valid UTF-8" | ||
super(value) | ||
end | ||
|
||
private | ||
|
||
NULL = "\0" | ||
private_constant :NULL | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters