Upgrade to Pro — share decks privately, control downloads, hide ads and more …

caching_sha2_passwordのはなし

 caching_sha2_passwordのはなし

kubo ayumu

March 25, 2025
Tweet

More Decks by kubo ayumu

Other Decks in Technology

Transcript

  1. 前提 • ServerGreeting ◦ Initial Handshake packetの送信 ◦ default_authentication_pluginで設定されている認証プ ラグインを送信

    • LoginRequest ◦ Initial Handshake packetの応答 ◦ クライアント側で使用する認証プラグインを送信 ◦ その後サーバー側でmysql.userのpluginを確認
  2. mysql_native_passwordの仕様の話 • パスワードハッシュ(SHA-1)を用いたチャレンジ&レスポンス認 証 • ユーザ作成を行うと、mysql.userのauthentication_stringカラ ムにSHA1(SHA1(passwors))の結果が格納される mysql> create user

    kubo identified with 'mysql_native_password' by 'password'; Query OK, 0 rows affected (0.27 sec) mysql> select Host,User,plugin,authentication_string from mysql.user where User='kubo'; +------+------+-----------------------+-------------------------------------------+ | Host | User | plugin | authentication_string | +------+------+-----------------------+-------------------------------------------+ | % | kubo | mysql_native_password | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | +------+------+-----------------------+-------------------------------------------+ 1 row in set (0.03 sec)
  3. mysql_native_passwordの仕様の話 • サーバ側からクライアント側に20バイトのランダムデータが 送信され、クライアント側で以下の計算をしてサーバーに送 信 SHA1( password ) XOR SHA1(

    "20-bytes random data from server" <concat> SHA1( SHA1( password ) ) ) • サーバーはSHA1(SHA1( password ))とランダムデータの値 を知っているので、それらとクライアントから送られてきた計 算結果にXORとSHA1を作用させることで、パスワードハッ シュを照合
  4. sha256_passwordの仕様の話 • パスワードハッシュ方式(SHA-256)に基づいた認証 • salt付きでハッシュ化されるため、同じパスワードのユーザ作 成でも異なるauthentication_stringの値となる mysql> create user kubo1

    identified with 'sha256_password' by 'password'; Query OK, 0 rows affected (0.03 sec) mysql> create user kubo2 identified with 'sha256_password' by 'password'; Query OK, 0 rows affected (0.03 sec) mysql> select Host,User,plugin,SUBSTR(HEX(authentication_string), -10) from mysql.user where User in ('kubo1','kubo2'); +------+-------+-----------------+-----------------------------------------+ | Host | User | plugin | SUBSTR(HEX(authentication_string), -10) | +------+-------+-----------------+-----------------------------------------+ | % | kubo1 | sha256_password | 736D4A6132 | | % | kubo2 | sha256_password | 7631786841 | +------+-------+-----------------+-----------------------------------------+
  5. caching_sha2_passwordの仕様の話 • Fast authenticationではmysql_native_passwordのように まずサーバーからクライアントへランダムデータを送る • クライアントでは以下の計算結果をサーバーに送る XOR(SHA256(password), SHA256(SHA256(SHA256(password)), Nonce))

    • サーバー側では該当ユーザのパスワードハッシュの値が キャッシュ内にあるか確認 • そこでもし見つかれば、クライアントから送られてきた計算結 果にその値とランダムデータの値をXORとSHAを作用させる ことで、パスワードハッシュの照合
  6. 参考 • Protecting MySQL Passwords With the sha256_password Plugin •

    MySQL 8.0.4 : New Default Authentication Plugin : caching_sha2_password • Caching_sha2_password information