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
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Zig で TLS1.3 を実装している話
Search
Naoki MATSUMOTO
October 07, 2023
Technology
280
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
1k
Mewz on libkrun
mt2naoki
2
1.2k
詳解 bypass4netns: Rootless Containers Network の仕組みと高速化
mt2naoki
2
2k
QUIC の仕組み(Handshake)
mt2naoki
1
1k
bypass4netns: Accelerating TCP/IP Communications in Rootless Containers
mt2naoki
0
340
Rootless コンテナはいいぞ
mt2naoki
4
1.4k
コンテナ技術における最新の研究動向
mt2naoki
15
12k
Efficient Container Image Updating in Low-bandwidth Networks with Delta Encoding
mt2naoki
0
1.9k
TLS 1.3 で学ぶ暗号技術
mt2naoki
0
650
Other Decks in Technology
See All in Technology
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
610
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
220
現場に行くだけでは足りない——プロダクトエンジニアが業務の流れを捉える観点と、その鍛え方
takumiengineering
0
350
Claude Code本って、 読む必要あるの?
oikon48
1
240
KPIだけでは評価できないプロダクトが考えるべき Evalsという第二の評価系 / Beyond KPIs: Evals as a Second Evaluation Framework for Products #PdEConf
aki_iinuma
4
3.8k
20260903 Tokyo Jazug Night #62 | Azure エンジニアよ、 その環境は本当にセキュアか?
olivia_0707
1
640
AIで開発は速くなったのに、なぜ現場は楽にならないのか 〜あなたの組織のボトルネックを突き止めるワークショップ〜
jacopen
1
290
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1k
リージョンの壁を越える、 ちょっと変わったAWSサービスの話
falken
PRO
0
280
【視聴者参加型!】AWSセキュリティアンチパターンクイズ
syoshie
0
460
作品が生態系になった ─ Mini Tokyo 3D から世界へ
nagix
0
140
From Vanilla Kubernetes to a Batteries-Included Platform: Developer Experience at 1,300+ Clusters
yosshi_
0
640
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Making Projects Easy
brettharned
120
6.7k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Utilizing Notion as your number one productivity tool
mfonobong
4
580
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
430
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
520
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
650
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
970
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