Class: Mysql::Authenticator::Sha256Password
- Inherits:
-
Object
- Object
- Mysql::Authenticator::Sha256Password
- Defined in:
- lib/mysql/authenticator/sha256_password.rb
Overview
sha256_password
Instance Method Summary collapse
- #authenticate(passwd, scramble) {|String| ... } ⇒ Mysql::Packet
-
#initialize(protocol) ⇒ Sha256Password
constructor
A new instance of Sha256Password.
- #name ⇒ String
Constructor Details
#initialize(protocol) ⇒ Sha256Password
Returns a new instance of Sha256Password.
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
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 |
#name ⇒ String
13 14 15 |
# File 'lib/mysql/authenticator/sha256_password.rb', line 13 def name 'sha256_password' end |