-
Notifications
You must be signed in to change notification settings - Fork 30
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
3 changed files
with
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "authenticator" | ||
|
||
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 < Authenticator | ||
|
||
# :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 | ||
# new {|propname, auth_ctx| propval } -> 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. | ||
# | ||
# ==== Properties | ||
# Only one property, 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. | ||
# | ||
# See Net::IMAP::SASL::Authenticator@Properties for a detailed | ||
# description of property assignment, lazy loading, and callbacks. | ||
def initialize(authzid_arg = nil, authzid: nil) | ||
super | ||
propinit :authzid, authzid, authzid_arg | ||
end | ||
|
||
property :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 | ||
|
||
private | ||
|
||
NULL = "\0" | ||
|
||
def propset(name, value) | ||
if name == :authzid && !value.nil? | ||
raise ArgumentError, "#{name} contains NULL" if value.include? NULL | ||
value = value.encode "UTF-8" | ||
unless value.valid_encoding? | ||
raise ArgumentError, "#{name} isn't valid UTF-8" | ||
end | ||
end | ||
super(name, value) | ||
end | ||
|
||
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