class Mysql::Authenticator::Sha256Password
Public Class Methods
new(protocol)
click to toggle source
@param protocol [Mysql::Protocol]
# File lib/mysql/authenticator/sha256_password.rb, line 7 def initialize(protocol) @protocol = protocol end
Public Instance Methods
authenticate(passwd, scramble) { |passwd| ... }
click to toggle source
@param passwd [String] @param scramble [String] @yield [String] hashed password @return [Mysql::Packet]
# File lib/mysql/authenticator/sha256_password.rb, line 20 def authenticate(passwd, scramble) if @protocol.client_flags & CLIENT_SSL != 0 yield passwd+"\0" return @protocol.read end yield "\x01" # request public key pkt = @protocol.read data = pkt.to_s if data[0] == "\x01" pkt.utiny # skip pubkey = pkt.to_s hash = (passwd+"\0").unpack("C*").zip(scramble.unpack("C*")).map{|a, b| a ^ b}.pack("C*") enc = OpenSSL::PKey::RSA.new(pubkey).public_encrypt(hash, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING) @protocol.write enc pkt = @protocol.read end return pkt end
name()
click to toggle source
@return [String]
# File lib/mysql/authenticator/sha256_password.rb, line 12 def name 'sha256_password' end