class Net::IMAP::SASL::CramMD5Authenticator

CRAM-MD5” SASL 机制的验证器,在RFC2195中指定。 请参阅 Net::IMAP#authenticate

已弃用

CRAM-MD5 已经过时且不安全。它包含在此处是为了与现有服务器兼容。draft-ietf-sasl-crammd5-to-historic 建议使用 SCRAM-* 或受 TLS 保护的 PLAIN 代替。

此外,RFC8314 不鼓励使用明文,并建议所有流量都使用 TLS 1.2 或更高版本。使用 TLS,CRAM-MD5 没问题,但 PLAIN 也是如此。

公共类方法

new(user = nil, pass = nil, authcid: nil, username: nil, password: nil, secret: nil, warn_deprecation: true, **) 点击切换源代码
# File net-imap-0.5.4/lib/net/imap/sasl/cram_md5_authenticator.rb, line 17
def initialize(user = nil, pass = nil,
               authcid: nil, username: nil,
               password: nil, secret: nil,
               warn_deprecation: true,
               **)
  if warn_deprecation
    warn "WARNING: CRAM-MD5 mechanism is deprecated.", category: :deprecated
  end
  require "digest/md5"
  @user = authcid || username || user
  @password = password || secret || pass
  @done = false
end

公共实例方法

done?() 点击切换源代码
# File net-imap-0.5.4/lib/net/imap/sasl/cram_md5_authenticator.rb, line 40
def done?; @done end
initial_response?() 点击切换源代码
# File net-imap-0.5.4/lib/net/imap/sasl/cram_md5_authenticator.rb, line 31
def initial_response?; false end
process(challenge) 点击切换源代码
# File net-imap-0.5.4/lib/net/imap/sasl/cram_md5_authenticator.rb, line 33
def process(challenge)
  digest = hmac_md5(challenge, @password)
  return @user + " " + digest
ensure
  @done = true
end

私有实例方法

hmac_md5(text, key) 点击切换源代码
# File net-imap-0.5.4/lib/net/imap/sasl/cram_md5_authenticator.rb, line 44
def hmac_md5(text, key)
  if key.length > 64
    key = Digest::MD5.digest(key)
  end

  k_ipad = key + "\0" * (64 - key.length)
  k_opad = key + "\0" * (64 - key.length)
  for i in 0..63
    k_ipad[i] = (k_ipad[i].ord ^ 0x36).chr
    k_opad[i] = (k_opad[i].ord ^ 0x5c).chr
  end

  digest = Digest::MD5.digest(k_ipad + text)

  return Digest::MD5.hexdigest(k_opad + digest)
end