Class: Mysql::Authenticator::Sha256Password

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql/authenticator/sha256_password.rb

Overview

sha256_password

Instance Method Summary collapse

Constructor Details

#initialize(protocol) ⇒ Sha256Password

Returns a new instance of Sha256Password.

Parameters:



8
9
10
# File 'lib/mysql/authenticator/sha256_password.rb', line 8

def initialize(protocol)
  @protocol = protocol
end

Instance Method Details

#authenticate(passwd, scramble) {|String| ... } ⇒ Mysql::Packet

Parameters:

  • passwd (String)
  • scramble (String)

Yields:

  • (String)

    hashed password

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mysql/authenticator/sha256_password.rb', line 21

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

#nameString

Returns:

  • (String)


13
14
15
# File 'lib/mysql/authenticator/sha256_password.rb', line 13

def name
  'sha256_password'
end