@@ -23,6 +23,11 @@ def self.instances
23
23
# rubocop:enable Layout/LineLength
24
24
@max_user_connections , @max_connections_per_hour , @max_queries_per_hour , @max_updates_per_hour , ssl_type , ssl_cipher ,
25
25
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
+
26
31
@tls_options = parse_tls_options ( ssl_type , ssl_cipher , x509_issuer , x509_subject )
27
32
if ( newer_than ( 'mariadb' => '10.1.21' ) && ( @plugin == 'ed25519' || @plugin == 'mysql_native_password' ) ) ||
28
33
( newer_than ( 'mariadb' => '10.2.16' ) && older_than ( 'mariadb' => '10.2.19' ) ) ||
@@ -76,6 +81,8 @@ def create
76
81
if !plugin . nil?
77
82
if password_hash . nil?
78
83
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' )
79
86
else
80
87
self . class . mysql_caller ( "CREATE USER '#{ merged_name } ' IDENTIFIED WITH '#{ plugin } ' AS '#{ password_hash } '" , 'system' )
81
88
end
@@ -159,9 +166,11 @@ def password_hash=(string)
159
166
end
160
167
self . class . mysql_caller ( sql , 'system' )
161
168
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 )
163
170
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' )
165
174
else
166
175
# default ... if mysqld_version does not work
167
176
self . class . mysql_caller ( "SET PASSWORD FOR #{ merged_name } = '#{ string } '" , 'system' )
0 commit comments