Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
caching_sha2_passwordのはなし
Search
kubo ayumu
March 25, 2025
Technology
2.9k
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.2k
やさしいActiveRecordのDB接続のしくみ
boro1234
14
9.3k
テーブル定義変更の ガイドラインを作った話
boro1234
2
2.1k
正規化理論ことはじめ -数学的背景から理解する正規化の初手-
boro1234
1
1.2k
RDBおける候補キーを求めるためのアルゴリズム
boro1234
0
1.3k
CakePHPの内部実装 から理解するPSR-7
boro1234
0
1.7k
Other Decks in Technology
See All in Technology
フィンテック養成勉強会#68
finengine
0
170
Metadata - Section 1: HTML Basics
mohab1
0
130
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
160
データエンジニアの次の戦場は "プロセスエンジニアリング"
sansantech
PRO
1
120
その Valkey 使いこなしていますか?
onk
PRO
5
1.6k
Gemini Intelligence 入門 ― AppFunctions と Gemini Nano
takuroabe
0
320
AI × アーキテクト 第1・2章|生成AIの課題とアーキテクトの素養
daidaidai
0
190
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
460
CloudWatch Logsのコスト最適化:どこまでAIに任せてどこから人間が承認すべきか
yama3133
0
120
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
210
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
220
Persisting Massive Data with Rails ~Designing for 60 billion rows, and fighting the bottlenecks~ Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
0
750
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
610
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
890
Bash Introduction
62gerente
615
220k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
New Earth Scene 8
popppiees
4
2.7k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
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