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
Zig で TLS1.3 を実装している話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Naoki MATSUMOTO
October 07, 2023
Technology
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Zig で TLS1.3 を実装している話
Naoki MATSUMOTO
October 07, 2023
More Decks by Naoki MATSUMOTO
See All by Naoki MATSUMOTO
Rootless な環境における eBPF の活用
mt2naoki
4
980
Mewz on libkrun
mt2naoki
2
1k
詳解 bypass4netns: Rootless Containers Network の仕組みと高速化
mt2naoki
2
1.7k
QUIC の仕組み(Handshake)
mt2naoki
1
920
bypass4netns: Accelerating TCP/IP Communications in Rootless Containers
mt2naoki
0
320
Rootless コンテナはいいぞ
mt2naoki
4
1.3k
コンテナ技術における最新の研究動向
mt2naoki
15
12k
Efficient Container Image Updating in Low-bandwidth Networks with Delta Encoding
mt2naoki
0
1.8k
TLS 1.3 で学ぶ暗号技術
mt2naoki
0
620
Other Decks in Technology
See All in Technology
脆弱性対応、どこで線を引くか
rymiyamoto
1
390
LLMにもCAP定理があるという話
harukasakihara
0
380
小さく始める AI 活用推進 ― 日経電子版 Web チームの事例/nikkei-tech-talk47
nikkei_engineer_recruiting
0
270
2026TECHFRESH畢業分享會 - Lightning Talk - 打造精準高效的 MCP 設計模式與測試實務
line_developers_tw
PRO
0
1.1k
白金鉱業Meetup_Vol.24_「AIエージェントは分けるほど良い」は本当か? / Is it true that “the more you divide AI agents, the better”?
brainpadpr
1
390
LayerX コーポレートエンジニアリング室におけるサプライチェーンセキュリティへの取り組み / Supply Chain Security at LayerX Corporate Engineering
yuyatakeyama
2
550
2026TECHFRESH畢業分享會 - Lightning Talk - E起 See See : 電商推薦讀心術? 數據說了算
line_developers_tw
PRO
0
1.1k
Socrates × Looker 〜セマンティックレイヤーで進化するデータ分析エージェント〜
hanon52_
3
2.4k
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
350
人材育成分科会.pdf
_awache
4
260
スキルと MCP ツール、責務をどう分けるか? AI が迷わないインターフェース設計の戦略
cdataj
1
1.1k
あなたの知らないPDFのアクセシビリティ
lycorptech_jp
PRO
0
200
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
610
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
240
Typedesign – Prime Four
hannesfritz
42
3.1k
The Curious Case for Waylosing
cassininazir
1
390
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
First, design no harm
axbom
PRO
2
1.2k
Done Done
chrislema
186
16k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
270
How to train your dragon (web standard)
notwaldorf
97
6.7k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Evolving SEO for Evolving Search Engines
ryanjones
0
220
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Transcript
Zig で TLS1.3 を 実装している話 京都大学情報学研究科 松本直樹
Zig • シンプル • comptime によるコンパイル時最適化 • マルチプラットフォーム対応 • 組み込みも対象
TLS1.3 • TLS1.2 までの仕様を整理し、新しい TLS として策定(RFC8446) • 1-RTT フルハンドシェイク •
0-RTT Resumption 等
TLS1.3 のフルハンドシェイク • 結構シンプル
実装のポイント1: 鍵導出(Key Schedule) 1. PSKから初期シークレット導出 2. DHでシークレットを共有 3. メッセージのハッシュから ハンドシェイク用の鍵を導出
4. ハンドシェイク完了後、 アプリケーション用の鍵を導出 面倒!
実装のポイント1: 鍵導出(Key Schedule) • TLS1.3 の Test Vector がある(RFC8448) •
Step by Step で鍵導出の実装を検証できる
実装のポイント2: CertificateVerify • 証明書の秘密鍵でハンドシェイクのメッセージを署名 → サーバーが秘密鍵を保持しているか確認 • 実際のステップ 1. 証明書・秘密鍵を読み込む
2. Certificate を送信 3. メッセージのハッシュを生成 4. 署名 5. CertificateVerify を送信 • 簡単そう…?
実装のポイント2: CertificateVerify • Certificate, CertificateVerify に必要な機能 • X.509 証明書を読み込む →
そんなものはない • 秘密鍵を読み込む → そんなものはない • RSA or ECDSA で署名, 検証する • ecdsa_secp256r1_sha256 → ある • rsa_pss_rsae_sha256 → そんなものはない • rsa_pkcs1_sha256 → そんなものはない
いっぱい実装しよう • ASN.1(必要な部分のみ) • X.509(RFC 5280 Section 4.1. Basic Certificate
Fields) • 秘密鍵 • RSA(RFC 8017 Section A.1. RSA Key Representation) • EC(RFC 5915 Section 3. Elliptic Curve Private Key Format) • RSAでの署名,検証(RFC8017, PKCS#1) • RSA自体の実装(モンゴメリ冪乗法 等) • rsa_pss_rsae(Section 8.1. RSASSA-PSS) • MGF1も(Section B.2.1. MGF1) • rsa_pkcs1(Section 8.2. RSASSA-PKCS1-v1_5)
実装した結果 • Client • www.google.com につながった🎉 • Server • chrome
からの接続が可能🎉
GREASE • Chrome で一部のフィールドに無意味なランダムを挿入する → TLS 実装の堅牢化を意図
まとめ • Zig で TLS1.3 を実装した • 既存のWebサイト, ブラウザで接続できた •
TLS, PKI に関する知見が深まった • Zig に対する知見が深まった • たまによく SEGV する • Zig はいいぞ(まだまだ安定してないけど) • https://github.com/shiguredo/tls13-zig