Documentation
¶
Overview ¶
Package ratls provides RA-TLS certificate verification for dstack TEE applications.
RA-TLS embeds TDX attestation quotes into X.509 certificate extensions. This package extracts and verifies those quotes, proving the certificate holder is running inside a genuine TEE.
Index ¶
Examples ¶
Constants ¶
const DefaultPCCSURL = "https://pccs.phala.network"
DefaultPCCSURL is the default PCCS server for collateral fetching.
Variables ¶
This section is empty.
Functions ¶
func TLSConfig ¶
TLSConfig returns a *tls.Config that verifies the server's RA-TLS certificate during the TLS handshake.
Standard CA chain verification is skipped because RA-TLS certificates are self-signed; trust is established through hardware attestation instead. TLSConfig alone does not authenticate the application, OS, or compose. Use WithVerify to compare verified measurements and boot-time events to trusted policy. Use VerifyResult.BootEvent rather than scanning events after system-ready. Do not replace the returned config's verification callbacks: both enforce RA-TLS, one for full handshakes and the other for resumed sessions.
Types ¶
type Option ¶
type Option func(*config)
Option configures RA-TLS verification.
func WithOnVerified ¶
func WithOnVerified(fn func(*VerifyResult)) Option
WithOnVerified sets a callback invoked after successful verification. Use this with TLSConfig to inspect the VerifyResult.
func WithPCCSURL ¶
WithPCCSURL sets the PCCS server URL for collateral fetching.
func WithVerify ¶ added in v0.6.0
func WithVerify(fn func(*VerifyResult) error) Option
WithVerify rejects an attested peer when fn returns an error. Use it to enforce the expected application, OS and compose identity. A nil function rejects verification rather than silently disabling policy.
type RuntimeEvent ¶ added in v0.6.0
type RuntimeEvent struct {
Event string `msgpack:"event"`
Payload msgpackBytes `msgpack:"payload"`
Version uint32 `msgpack:"version"`
}
RuntimeEvent is a measured dstack runtime event. Version 1 is the default.
type VerifyResult ¶
type VerifyResult struct {
// Report is the dcap-qvl verification report including TCB status and advisory IDs.
Report *dcap.VerifiedReport
// Quote is the parsed TDX quote structure with measurements and report data.
Quote *dcap.Quote
// RuntimeEvents are authenticated by replay against RTMR3, in order. Events
// after system-ready are app-controlled and untrusted for identity policy;
// use BootEvent for boot-time identity lookup.
RuntimeEvents []RuntimeEvent
}
VerifyResult contains the result of a successful RA-TLS verification.
func VerifyCert ¶
func VerifyCert(cert *x509.Certificate, opts ...Option) (*VerifyResult, error)
VerifyCert verifies that an X.509 certificate is a valid RA-TLS certificate.
It extracts the embedded TDX quote, verifies it via dcap-qvl, checks that the quote's report_data binds to the certificate's public key, validates TCB attributes (debug mode, signer), and replays RTMR3 from the event log. For versioned evidence it verifies the stack runtime events, not the separate platform event log or its advertised V2 digest preimages. Only dstack TDX is supported: gcp-tdx, nitro, sev-snp, and dstack-pod evidence are rejected. TLSConfig alone is not application authentication; use WithVerify to enforce trusted application, OS, and compose policy.
Example ¶
ExampleVerifyCert demonstrates verifying an RA-TLS certificate from a TLS connection.
package main
import (
"crypto/tls"
"fmt"
"github.com/Dstack-TEE/dstack/sdk/go/ratls"
)
func main() {
conn, err := tls.Dial("tcp", "myapp-8443s.phala.network:443", &tls.Config{
InsecureSkipVerify: true,
})
if err != nil {
panic(err)
}
defer conn.Close()
cert := conn.ConnectionState().PeerCertificates[0]
result, err := ratls.VerifyCert(cert)
if err != nil {
fmt.Printf("verification failed: %v\n", err)
return
}
fmt.Printf("verified: status=%s\n", result.Report.Status)
}
Output:
func (*VerifyResult) BootEvent ¶ added in v0.6.0
func (r *VerifyResult) BootEvent(name string) ([]byte, bool)
BootEvent returns the first matching boot-time event payload. Events at and after system-ready are excluded because the application can emit them.
func (*VerifyResult) BootEvents ¶ added in v0.6.0
func (r *VerifyResult) BootEvents(name string) [][]byte
BootEvents returns all matching boot-time event payloads in event order. Events at and after system-ready are excluded because the application can emit them.