用 Zig 编写的 QUIC TLS 1.3 实现,严格遵守 RFC 8446 (TLS 1.3) 和 RFC 9001 (QUIC-TLS)。
| 方面 | 信息 |
|---|---|
| API 稳定性 | 生产就绪 |
| Zig 版本 | 0.16.0 |
| 平台 | Linux、macOS、Windows |
在 Ed25519 和 RSA-2048 证书配置上已验证了小于 2 毫秒的握手目标。secp256r1 (P-256) 工作负载当前每次握手运行 2–3 毫秒,原因是上游 Zig stdlib 的限制(PERF-229)。完整决策记录见 ADR-0002。
✅ 符合 RFC - 实现 TLS 1.3 (RFC 8446) 和 QUIC-TLS (RFC 9001) ✅ 零依赖 - 仅使用 Zig 标准库 ✅ 互操作性测试 - 与 BoringSSL 和 OpenSSL 的一致性测试 ✅ QUIC 原生 - 专为 QUIC 集成设计,无传统记录层 ✅ 测试充分 - 551 个单元测试 + RFC 测试向量 + 449 个一致性测试
# Build and test everything
make
# Or manually
zig build
zig build test
该项目同时使用 Makefile 和 build.zig 以提供灵活性:
# Build and run all tests (default)
make
# Build only
make build
# Run specific test suites
make test-unit # Unit tests
make test-vectors # RFC 8446/9001 test vectors
make test-conformance # BoringSSL/OpenSSL conformance (requires libssl-dev)
# Development workflow
make dev # Format + check + unit tests
make clean # Clean build artifacts
make help # Show all available targets
# Build the library
zig build
# Run all tests
zig build test
# Run specific test suites
zig build test-vectors
zig build test-conformance # Requires OpenSSL dev libraries
# With optimizations
zig build -Doptimize=ReleaseFast
Build Summary: All steps succeeded; 1000 tests passed ✅
全面的测试覆盖:
总计:1000 个测试,确保 RFC 合规性、密码学等价性和生产就绪性
src/
├── lib.zig # Main library entry point
├── tls13/ # TLS 1.3 handshake state machine (modularized)
├── tls13_full.zig # Full TLS 1.3 message parsing
├── key_schedule.zig # HKDF-based key derivation
├── record.zig # Record layer & AEAD operations
├── x509.zig # Certificate parsing & validation
├── sig.zig # Signature verification
├── asn1.zig # ASN.1 DER decoder
├── alert.zig # TLS alert protocol
├── entropy.zig # Fail-closed RNG helper (SEC-074)
├── zero_rtt.zig # 0-RTT support
└── quic_*.zig # QUIC integration interfaces
tests/
├── rfc8446_vectors.zig # RFC test vectors
├── boringssl_conformance.zig # BoringSSL parity tests
└── openssl_conformance.zig # OpenSSL conformance tests
const std = @import("std");
const tls = @import("ztls");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
// Configure TLS context
const config = tls.Config{
.allocator = gpa.allocator(),
.role = .client,
.supported_cipher_suites = &.{.TLS_AES_128_GCM_SHA256},
.supported_groups = &.{.x25519},
.alpn_protocols = &.{"h3"},
};
// Set up callbacks
const callbacks = tls.Callbacks{
.on_secret_available = mySecretCallback,
.on_handshake_complete = myHandshakeCallback,
};
// Initialize TLS context
var ctx = try tls.Context.init(config, callbacks);
defer ctx.deinit();
// Process incoming CRYPTO frames from QUIC
try ctx.processCrypto(crypto_data);
}
std.crypto.kdf.hkdf 的 HKDF 密钥派生该项目包含全面的一致性测试,以确保与行业标准 TLS 实现的兼容性:
运行一致性测试:
# Install OpenSSL development libraries first
make install-deps # Auto-detects your OS
# Run conformance tests
make test-conformance
ztls 附带一个可选的 OpenTelemetry 接口。当设置 -Dwith_otel=true 构建标志时,库会在每次 TLS 握手时精确发出一个跨度(跨度名称:"TLS handshake"),并在完成时附加以下语义约定属性:
tls.role -- "client" 或 "server"tls.protocol.version -- "1.3"(一直为 ztls)tls.cipher_suite -- 协商的密码(例如 TLS_AES_128_GCM_SHA256)network.protocol.name -- "tls"# Default build: no otel symbols, zero overhead.
zig build test
# Enabled build: one span per handshake, exported via the OTLP
# defaults (http://localhost:4318) or whatever OTEL_* env vars
# specify.
zig build test -Dwith_otel=true
该接口通过惰性依赖进行门控,因此只有在启用该标志时才会拉取 otel 包。想要安装 TracerProvider 的应用程序入口代码应调用 ztls.observability_init.Otel.init 然后调用 installGlobals();完整的宿主应用程序引导请参阅上游 otel 集成配方(otel/docs/integration/RECIPE.md)。
# Quick development iteration
make dev
# Format code
make fmt
# or
zig fmt src/ tests/
# Check syntax
make check
# Clean build
make clean build
添加特性时:
Apache-2.0 许可证 - 详见 LICENSE。
使用 Zig 0.16.0 构建 | TLS 1.3 | QUIC 原生 | 符合 RFC