Documentation
¶
Overview ¶
Package cfapi is the Cloudflare WARP registration client and the importer for wgcf profiles. It is used by the panel: one address registers every node, and the agent stays free of the uTLS stack. Nothing here runs by itself: every call to Cloudflare is an explicit call of Register, Fetch or Delete, which the panel makes only on the owner's click (or the opt-in auto re-registration).
The constants a registration request is built from changed twice in 2026 and broke every client each time (Cloudflare answers HTTP 429 to a request that does not look like the Android app: API version in the path, User-Agent, CF-Client-Version and the TLS ClientHello). They are Params, data the panel stores and the owner can change, not code. The ClientHello is chosen by name (TLSSpecID) from a registry.
The request format, headers and the uTLS ClientHello are taken from wgcf v2.3.0 (MIT, see tls.go for the notice). Tests talk only to a fake API server (NewTLS test server through Client.BaseURL and Client.RootCAs); the live service is never contacted from the test suite.
Index ¶
Constants ¶
const ( // BaseURL is the registration API. BaseURL = "https://api.cloudflareclient.com" // TOSURL is the terms page the UI links next to the register button. TOSURL = "https://www.cloudflare.com/application/terms/" )
Variables ¶
This section is empty.
Functions ¶
func GenerateKey ¶
GenerateKey makes a WireGuard key pair (base64): a clamped X25519 private key and its public key.
func IsNotFound ¶
IsNotFound reports an HTTP 404 (registration unknown or already deleted).
func IsRateLimited ¶
IsRateLimited reports an HTTP 429: Cloudflare dislikes the caller (TLS fingerprint, headers, too many registrations from one address). The remedy is to import a wgcf profile, not to hammer.
func RegisterTLSSpec ¶
func RegisterTLSSpec(id string, spec func() *utls.ClientHelloSpec)
RegisterTLSSpec adds a named ClientHello (for the day Cloudflare changes what it accepts and the owner ships a new one without waiting for a release). An existing name is replaced.
Types ¶
type APIError ¶
type APIError struct {
Status int
// Body is the first bytes of the answer (Cloudflare error JSON; it carries no secrets).
Body string
}
APIError is a non-200 answer of the API.
type Account ¶
type Account struct {
ID string
Token Secret // Bearer secret for Fetch/Delete; empty for an imported profile without wgcf-account.toml
License Secret
AccountType string // "free" | "plus" | ""
ClientID string // base64, 3 bytes: the source of Reserved
PrivateKey Secret // base64 X25519
PeerPublicKey string
EndpointHost string // "engage.cloudflareclient.com:2408": informational, never dialed
EndpointV4 string
EndpointV6 string
Ports []uint16
AddressV4 string // "172.16.0.2/32"
AddressV6 string // "" = none
MTU uint16
Reserved []byte // 0 or 3 bytes
}
Account is a WARP device account in the forms the panel stores and the agent's WarpSpec needs. Endpoints are IP literals without a port; addresses carry their prefix length.
func ParseWgcf ¶
ParseWgcf builds an Account from the text of wgcf-profile.conf (required) and, when given, wgcf-account.toml (adds the device id, the access token and the license key, which enable Fetch and Delete; the client id, and so the "reserved" bytes, are then read with Fetch). An endpoint that is a host name stays in EndpointHost with empty EndpointV4/V6: the caller resolves it once (ResolveEndpoint) and stores the literal. Errors never contain key material.
func (*Account) ResolveEndpoint ¶
func (a *Account) ResolveEndpoint(ctx context.Context, lookup func(ctx context.Context, host string) ([]netip.Addr, error), withV6 bool) error
ResolveEndpoint turns a host-name endpoint into IP literals once, through lookup (the panel's resolver): the IPv4 address is taken, and the IPv6 one only when withV6 is set (new accounts often have no working IPv6). A profile whose endpoint already was a literal is left alone.
type Client ¶
type Client struct {
Params Params
// BaseURL overrides BaseURL (tests).
BaseURL string
// RootCAs verifies the server certificate; nil = system roots. Tests put their server's CA here.
RootCAs *x509.CertPool
// Timeout for one call, dial and handshake included (30 s).
Timeout time.Duration
// Rand is the key source (crypto/rand).
Rand io.Reader
}
Client talks to the API. The zero value is usable (defaults, the real base URL).
func (*Client) Delete ¶
Delete removes our registration at Cloudflare (DELETE /reg/{id}); the token is required.
func (*Client) Fetch ¶
Fetch reads the registration again (GET /reg/{id}): endpoint, addresses and client id may have changed. It creates nothing. privateKey is the account's own key (Cloudflare never returns it); it is copied into the result.
type Params ¶
type Params struct {
// APIVersion is the path segment before /reg ("v0a5641").
APIVersion string
// UserAgent and CFClientVersion imitate the Android app.
UserAgent string
CFClientVersion string
// TLSSpecID names the uTLS ClientHello ("wgcf_v2.3.0"), see TLSSpecIDs.
TLSSpecID string
}
Params are the registration constants. Empty fields fall back to Defaults.
func (Params) Validate ¶
Validate rejects values that cannot go into a URL or a header, or name an unknown ClientHello.
func (Params) WithDefaults ¶
WithDefaults fills empty fields from Defaults.
type Secret ¶
type Secret string
Secret is a string that prints as [REDACTED] everywhere it is formatted or logged; Reveal returns the value.