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
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
980
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
640
Other Decks in Technology
See All in Technology
SmartHR Engineering Team Deck
smarthr
1
3.4k
MIXIで活躍できるエンジニアを 若手社員目線で考えてみる
mixi_engineers
PRO
0
130
dbt in Microsoft Fabric
ryomaru0825
0
150
【GCC2026】鉄拳8でのVFX開発事例
bandainamcostudios
PRO
0
260
Flutter × BLE Centralを自前Pluginで実装する設計パターン - MethodChannel / EventChannelで作る双方向ブリッジの実践 / Building Custom Flutter BLE Central Plugins: Bidirectional Bridging with Method & Event Channels
bitkey
PRO
0
230
型落ちシンクライアント端末のPoEモジュールを自作したかった話
logica0419
0
320
AI開発に用いられるHPC技術について
gpuunite_official
0
250
トークンマネジメントでAIにとって働きやすい環境を実現する
hikaruegashira
0
140
8bit CPU 2026
koba789
6
2.6k
地震情報アプリを作ってみた
yama3133
1
110
Oracle MCP Servers Explained
thatjeffsmith
0
410
35分でわかるEffective Platform Engineering
nwiizo
5
600
Featured
See All Featured
The Curious Case for Waylosing
cassininazir
1
480
Why Our Code Smells
bkeepers
PRO
340
58k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
480
How to Talk to Developers About Accessibility
jct
2
520
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Amusing Abliteration
ianozsvald
1
260
Building Adaptive Systems
keathley
44
3.2k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
480
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.4k
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