@@ -23,6 +23,11 @@ def self.instances
2323 # rubocop:enable Layout/LineLength
2424 @max_user_connections , @max_connections_per_hour , @max_queries_per_hour , @max_updates_per_hour , ssl_type , ssl_cipher ,
2525 x509_issuer , x509_subject , @password , @plugin , @authentication_string = mysql_caller ( query , 'regular' ) . chomp . split ( %r{\t } )
26+
27+ if @plugin == 'caching_sha2_password'
28+ @password = mysql_caller ( "SELECT CONCAT('0x',HEX('#{ @password } '))" , 'regular' ) . chomp
29+ end
30+
2631 @tls_options = parse_tls_options ( ssl_type , ssl_cipher , x509_issuer , x509_subject )
2732 if ( newer_than ( 'mariadb' => '10.1.21' ) && ( @plugin == 'ed25519' || @plugin == 'mysql_native_password' ) ) ||
2833 ( newer_than ( 'mariadb' => '10.2.16' ) && older_than ( 'mariadb' => '10.2.19' ) ) ||
@@ -76,6 +81,8 @@ def create
7681 if !plugin . nil?
7782 if password_hash . nil?
7883 self . class . mysql_caller ( "CREATE USER '#{ merged_name } ' IDENTIFIED WITH '#{ plugin } '" , 'system' )
84+ elsif plugin . eql? "caching_sha2_password"
85+ self . class . mysql_caller ( "CREATE USER '#{ merged_name } ' IDENTIFIED WITH '#{ plugin } ' AS X'#{ password_hash [ 2 ..-1 ] } '" , 'system' )
7986 else
8087 self . class . mysql_caller ( "CREATE USER '#{ merged_name } ' IDENTIFIED WITH '#{ plugin } ' AS '#{ password_hash } '" , 'system' )
8188 end
@@ -159,9 +166,11 @@ def password_hash=(string)
159166 end
160167 self . class . mysql_caller ( sql , 'system' )
161168 elsif !mysqld_version . nil? && newer_than ( 'mysql' => '5.7.6' , 'percona' => '5.7.6' , 'mariadb' => '10.2.0' )
162- raise ArgumentError , _ ( 'Only mysql_native_password (*ABCD...XXX) hashes are supported.' ) unless %r{^\* |^$} . match? ( string )
169+ raise ArgumentError , _ ( 'Only mysql_native_password (*ABCD...XXX) or caching_sha2_password (0x1234ABC...XXX) hashes are supported.' ) unless %r{^\* |^$} . match? ( string ) || %r{0x[A-F0-9]+ $}. match? ( string )
163170
164- self . class . mysql_caller ( "ALTER USER #{ merged_name } IDENTIFIED WITH mysql_native_password AS '#{ string } '" , 'system' )
171+ sql = "ALTER USER #{ merged_name } IDENTIFIED WITH"
172+ plugin == 'caching_sha2_password' ? sql += " '#{ plugin } ' AS X'#{ @resource [ :password_hash ] [ 2 ..-1 ] } '" : sql += " 'mysql_native_password' AS '#{ @resource [ :password_hash ] } '"
173+ self . class . mysql_caller ( sql , 'system' )
165174 else
166175 # default ... if mysqld_version does not work
167176 self . class . mysql_caller ( "SET PASSWORD FOR #{ merged_name } = '#{ string } '" , 'system' )
0 commit comments