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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
AIで社員の自主発信に広報目線を組み込む
_mossann_t
0
140
品質と信頼性を地続きにする
grimoh
2
950
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
Making AI Agents Safe and Fast- Jev, Obsidian, and the Meta-Harness
x5gtrn
PRO
0
120
Goodbye ShellScript, Hello File-based App
shunsock
0
790
AI 時代のスタートアップエコシステ厶から考究する技術的負債との向き合い方
m3m0r7
PRO
3
2.6k
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
20k
絵ではじめるKubernetesセキュリティ
aoi1
4
700
事業課題から技術的負債に向き合う
sansantech
PRO
2
2.3k
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
30
19k
株式会社シーエーシー エンジニア向け会社紹介資料
cac
0
57k
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.6k
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Site-Speed That Sticks
csswizardry
13
1.5k
RailsConf 2023
tenderlove
30
1.6k
GitHub's CSS Performance
jonrohan
1033
470k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
The Limits of Empathy - UXLibs8
cassininazir
1
690
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
570
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
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