Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
caching_sha2_passwordのはなし
Search
kubo ayumu
March 25, 2025
Technology
2.8k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
caching_sha2_passwordのはなし
https://mysql.connpass.com/event/345603/
kubo ayumu
March 25, 2025
More Decks by kubo ayumu
See All by kubo ayumu
MariaDB Connector/C のcaching_sha2_passwordプラグインの仕様について
boro1234
0
1.3k
大テーブルと小テーブルのJOINのコスト計算の話
boro1234
5
2.1k
やさしいActiveRecordのDB接続のしくみ
boro1234
14
9.2k
テーブル定義変更の ガイドラインを作った話
boro1234
2
2k
正規化理論ことはじめ -数学的背景から理解する正規化の初手-
boro1234
1
1.2k
RDBおける候補キーを求めるためのアルゴリズム
boro1234
0
1.3k
CakePHPの内部実装 から理解するPSR-7
boro1234
0
1.6k
Other Decks in Technology
See All in Technology
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
Digitization部 紹介資料
sansan33
PRO
2
7.8k
ブラウザで変わるID連携(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
360
Distributed Transactions Under Fire: Building a Zero-Oversell Flash Sale Platform with Amazon Aurora DSQL
yama3133
1
110
500名弱規模の組織のPythonプロジェクト(dbt) をどう管理するか?
hiracky16
0
380
形式手法特論:Hyperproperty とモデル検査 #kernelvm / Kernel VM Study Tokyo 19th
ytaka23
1
890
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
20k
:syncing_time:
sksat
3
850
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
24k
IHV like なユースケースへのOpenID Connect 関連仕様の適用事例
optim
0
360
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
12
86k
hookで自作する Claude Code の「実況ボード」
shinyasaita
2
240
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
260
Into the Great Unknown - MozCon
thekraken
41
2.7k
It's Worth the Effort
3n
188
29k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Code Review Best Practice
trishagee
74
20k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
630
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
500
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
250
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Tell your own story through comics
letsgokoyo
1
1k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
WCS-LA-2024
lcolladotor
0
810
Transcript
caching_sha2_passwordの はなし MySQL30周年&ユーザ会25周年記念イベント @amamanamam
くぼ • DBREやってます • MySQL 8.0から仲良くなり始めました • ビールをよく飲みます • Xはこちら
◦ https://twitter.com/amamanamam
皆さん caching_sha2_password 移行の準備は できていますか?
ということで caching_sha2_password について簡単に まとめてきました
アジェンダ ・前提 ・mysql_native_passwordの仕様の話 ・sha256_passwordの仕様の話 ・caching_sha2_passwordの仕様の話
アジェンダ ・前提 ・mysql_native_passwordの仕様の話 ・sha256_passwordの仕様の話 ・caching_sha2_passwordの仕様の話
前提 • MySQL 8.0と8.4LTSでは caching_sha2_passwordがデフォルト • MySQL8.4LTSでは mysql_native_passwordが無効 • MySQL9.0
Innovation Releaseでは mysql_native_passwordが廃止
前提 • AuroraMySQL V3では mysql_native_passwordがデフォルト • AuroraMySQL V4(?)でやっと caching_sha2_passwordがデフォルトに なったりするかな...?
前提 https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_lifecycle.html
前提 • ServerGreeting ◦ Initial Handshake packetの送信 ◦ default_authentication_pluginで設定されている認証プ ラグインを送信
• LoginRequest ◦ Initial Handshake packetの応答 ◦ クライアント側で使用する認証プラグインを送信 ◦ その後サーバー側でmysql.userのpluginを確認
前提 • AuthSwitchRequest/Response ◦ ユーザの認証プラグインが期待されている認証プラグイ ンと異なった時に、使用すべき認証プラグインを送信
アジェンダ ・前提 ・mysql_native_passwordの仕様の話 ・sha256_passwordの仕様の話 ・caching_sha2_passwordの仕様の話
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)
mysql_native_passwordの仕様の話 • サーバ側からクライアント側に20バイトのランダムデータが 送信され、クライアント側で以下の計算をしてサーバーに送 信 SHA1( password ) XOR SHA1(
"20-bytes random data from server" <concat> SHA1( SHA1( password ) ) ) • サーバーはSHA1(SHA1( password ))とランダムデータの値 を知っているので、それらとクライアントから送られてきた計 算結果にXORとSHA1を作用させることで、パスワードハッ シュを照合
アジェンダ ・前提 ・mysql_native_passwordの仕様の話 ・sha256_passwordの仕様の話 ・caching_sha2_passwordの仕様の話
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 | +------+-------+-----------------+-----------------------------------------+
sha256_passwordの仕様の話 • パスワードをプレーンテキストで送る必要があるため、 SSL/TLSやRSA暗号鍵でのセキュアな接続を必要とす る
アジェンダ ・前提 ・mysql_native_passwordの仕様の話 ・sha256_passwordの仕様の話 ・caching_sha2_passwordの仕様の話
caching_sha2_passwordの仕様の話 • パスワードハッシュ方式(SHA-256)に基づいた認証 • クライアント・サーバー間のやり取りには以下の2つのフェー ズがある ◦ Fast authentication ◦
Complete authentication
caching_sha2_passwordの仕様の話 • Fast authenticationではmysql_native_passwordのように まずサーバーからクライアントへランダムデータを送る • クライアントでは以下の計算結果をサーバーに送る XOR(SHA256(password), SHA256(SHA256(SHA256(password)), Nonce))
• サーバー側では該当ユーザのパスワードハッシュの値が キャッシュ内にあるか確認 • そこでもし見つかれば、クライアントから送られてきた計算結 果にその値とランダムデータの値をXORとSHAを作用させる ことで、パスワードハッシュの照合
caching_sha2_passwordの仕様の話 • キャッシュ内に何も見つからなければComplete authenticationのフェーズに入る • Complete authenticationでは、sha256_passwordのように SSL/TLS接続もしくはRSA暗号化通信がなされた状況下で パスワードをそのまま受け取って照合を行う
caching_sha2_passwordの仕様の話 • キャッシュ内に何も見つからなければComplete authenticationのフェーズに入る • Complete authenticationでは、sha256_passwordのように SSL/TLS接続もしくはRSA暗号化通信がなされた状況下で パスワードをそのまま受け取って照合を行う
まとめ • caching_sha2_passwordはmysql_native_passwordと sha256_passwordを組み合わせたような認証プラグイン • 1回目の認証はsha256_passwordのようにセキュアな経路 を必要とする • 2回目以降はキャッシュ内のパスワードハッシュに基づいて mysql_native_passwordのような認証を行う
参考 • Protecting MySQL Passwords With the sha256_password Plugin •
MySQL 8.0.4 : New Default Authentication Plugin : caching_sha2_password • Caching_sha2_password information