Documentation
¶
Overview ¶
Package generate provides functions for generating cryptographic credentials used in cheburbox server configurations.
Index ¶
- func BuildInbound(in config.Inbound, creds InboundCredentials) (option.Inbound, error)
- func BuildOutbound(out config.Outbound) (option.Outbound, error)
- func BuildOutboundWithState(out config.Outbound, state *ServerState, opts ...OutboundBuildOption) (option.Outbound, error)
- func CertNeedsRegeneration(cert *x509.Certificate, serverName string) bool
- func ComputePinSHA256(certPEM []byte) (string, error)
- func ConvertDNS(cfg config.DNS) (*option.DNSOptions, error)
- func ConvertRoute(route *config.Route) (*option.RouteOptions, error)
- func DerivePublicKey(privateKeyBase64 string) (string, error)
- func GeneratePassword() (string, error)
- func GenerateSelfSignedCert(serverName string) ([]byte, ed25519.PrivateKey, error)
- func GenerateSelfSignedCertPEM(serverName string) ([]byte, []byte, error)
- func GenerateShortID() (string, error)
- func GenerateUUID() (string, error)
- func GenerateX25519KeyPair() (string, string, error)
- func ReadCertFiles(certPath string, keyPath string) ([]byte, []byte, error)
- func WriteCertFiles(certPath string, keyPath string, certPEM []byte, keyPEM []byte) error
- type Edge
- type FileOutput
- type GenerateConfig
- type GenerateResult
- func GenerateAll(projectRoot string, jpath string, genCfg GenerateConfig) ([]GenerateResult, error)
- func GenerateServer(dir string, cfg config.Config, genCfg GenerateConfig) (GenerateResult, error)
- func GenerateServers(projectRoot string, jpath string, serverName string, genCfg GenerateConfig) ([]GenerateResult, error)
- type Graph
- type InboundCredentials
- type OutboundBuildOption
- type RealityKeys
- type ServerState
- func (s *ServerState) EnsureUser(server string, tag string, userName string) error
- func (s *ServerState) GetEndpoint(server string) (string, bool)
- func (s *ServerState) GetInboundCredentials(server string, tag string) (InboundCredentials, bool)
- func (s *ServerState) GetInboundType(server string, tag string) (string, bool)
- func (s *ServerState) GetListenPort(server string, tag string) (uint16, bool)
- func (s *ServerState) GetPinSHA256(server string, tag string) (string, bool)
- func (s *ServerState) StoreEndpoint(server string, endpoint string)
- func (s *ServerState) StoreInboundCredentials(server string, tag string, creds InboundCredentials)
- func (s *ServerState) StoreInboundType(server string, tag string, inboundType string)
- func (s *ServerState) StoreListenPort(server string, tag string, port uint16)
- func (s *ServerState) StorePinSHA256(server string, tag string, pin string)
- type UserCreds
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildInbound ¶
BuildInbound converts a cheburbox Inbound config and resolved credentials into a sing-box Inbound option.
func BuildOutbound ¶
BuildOutbound converts a cheburbox Outbound to a sing-box option.Outbound.
func BuildOutboundWithState ¶
func BuildOutboundWithState( out config.Outbound, state *ServerState, opts ...OutboundBuildOption, ) (option.Outbound, error)
BuildOutboundWithState converts a cheburbox Outbound to a sing-box option.Outbound using the provided ServerState for cross-server credential resolution.
func CertNeedsRegeneration ¶
func CertNeedsRegeneration(cert *x509.Certificate, serverName string) bool
func ComputePinSHA256 ¶
ComputePinSHA256 computes the SHA-256 pin of a PEM-encoded certificate's public key.
func ConvertDNS ¶
func ConvertDNS(cfg config.DNS) (*option.DNSOptions, error)
ConvertDNS converts cheburbox DNS configuration to sing-box DNSOptions.
func ConvertRoute ¶
func ConvertRoute(route *config.Route) (*option.RouteOptions, error)
ConvertRoute converts cheburbox route configuration to sing-box RouteOptions. Returns an empty RouteOptions if route is nil.
func DerivePublicKey ¶
func GeneratePassword ¶
GeneratePassword returns a base64-encoded 24-byte random password.
func GenerateSelfSignedCert ¶
func GenerateSelfSignedCert(serverName string) ([]byte, ed25519.PrivateKey, error)
GenerateSelfSignedCert creates a self-signed certificate and Ed25519 private key for the given server name, returning the DER-encoded certificate and the typed private key.
func GenerateSelfSignedCertPEM ¶
GenerateSelfSignedCertPEM creates a self-signed certificate and private key for the given server name, returning PEM-encoded certificate and PKCS#8 private key.
func GenerateShortID ¶
GenerateShortID returns a hex-encoded 8-byte random short identifier.
func GenerateUUID ¶
GenerateUUID returns a random UUIDv4 string.
func GenerateX25519KeyPair ¶
GenerateX25519KeyPair generates an X25519 key pair and returns the private and public keys as base64-encoded strings.
func ReadCertFiles ¶
ReadCertFiles reads PEM-encoded certificate and key from the given paths. Returns nil values without error if files do not exist.
Types ¶
type FileOutput ¶
FileOutput represents a generated file with its relative path and content.
type GenerateConfig ¶
GenerateConfig controls server generation behavior.
type GenerateResult ¶
type GenerateResult struct {
Server string
Files []FileOutput
}
GenerateResult holds the generated server name and output files.
func GenerateAll ¶
func GenerateAll(projectRoot string, jpath string, genCfg GenerateConfig) ([]GenerateResult, error)
GenerateAll discovers all servers in the project, builds a dependency graph, topologically sorts them, and generates configs in order with shared state for cross-server credential resolution. Uses two-pass generation to handle cross-server user provisioning.
func GenerateServer ¶
func GenerateServer(dir string, cfg config.Config, genCfg GenerateConfig) (GenerateResult, error)
GenerateServer generates a complete sing-box configuration for a server.
func GenerateServers ¶
func GenerateServers( projectRoot string, jpath string, serverName string, genCfg GenerateConfig, ) ([]GenerateResult, error)
GenerateServers generates configs for the specified server and its transitive dependencies.
type Graph ¶
Graph represents a directed graph of server dependencies.
func BuildGraph ¶
BuildGraph constructs a dependency graph from a set of server configurations. Each outbound with a non-empty Server field creates an edge from the owning server to the target. Returns an error for self-references, unknown server references, or dependency cycles.
func (*Graph) TopologicalSort ¶
TopologicalSort returns servers in dependency order: servers with no dependencies come first. Returns an error if a cycle is detected.
type InboundCredentials ¶
type InboundCredentials struct {
Users map[string]UserCreds
Reality *RealityKeys
ObfsPassword string
ServerName string
ALPN []string
}
InboundCredentials holds resolved credentials for building inbound options.
type OutboundBuildOption ¶
type OutboundBuildOption func(*outboundBuildConfig)
OutboundBuildOption configures outbound building behavior.
func WithDefaultUser ¶
func WithDefaultUser(user string) OutboundBuildOption
WithDefaultUser sets a fallback user for cross-server outbounds when no explicit user is specified in the config.
type RealityKeys ¶
RealityKeys holds generated reality key pair and short IDs.
type ServerState ¶
type ServerState struct {
// contains filtered or unexported fields
}
ServerState holds per-server state for credentials, pin-SHA256, endpoints, inbound types, and listen ports.
func NewServerState ¶
func NewServerState() *ServerState
NewServerState creates an empty ServerState ready for use.
func (*ServerState) EnsureUser ¶
func (s *ServerState) EnsureUser(server string, tag string, userName string) error
EnsureUser adds a user with generated credentials to an existing inbound. If the user already exists, their credentials are preserved.
func (*ServerState) GetEndpoint ¶
func (s *ServerState) GetEndpoint(server string) (string, bool)
GetEndpoint retrieves the public endpoint address for a server.
func (*ServerState) GetInboundCredentials ¶
func (s *ServerState) GetInboundCredentials(server string, tag string) (InboundCredentials, bool)
GetInboundCredentials retrieves credentials for a server's inbound.
func (*ServerState) GetInboundType ¶
func (s *ServerState) GetInboundType(server string, tag string) (string, bool)
GetInboundType retrieves the inbound protocol type for a server's inbound.
func (*ServerState) GetListenPort ¶
func (s *ServerState) GetListenPort(server string, tag string) (uint16, bool)
GetListenPort retrieves the listen port for a server's inbound.
func (*ServerState) GetPinSHA256 ¶
func (s *ServerState) GetPinSHA256(server string, tag string) (string, bool)
GetPinSHA256 retrieves the TLS pin-SHA256 fingerprint for a server's inbound.
func (*ServerState) StoreEndpoint ¶
func (s *ServerState) StoreEndpoint(server string, endpoint string)
StoreEndpoint saves the public endpoint address for a server.
func (*ServerState) StoreInboundCredentials ¶
func (s *ServerState) StoreInboundCredentials(server string, tag string, creds InboundCredentials)
StoreInboundCredentials saves credentials for a server's inbound.
func (*ServerState) StoreInboundType ¶
func (s *ServerState) StoreInboundType(server string, tag string, inboundType string)
StoreInboundType saves the inbound protocol type for a server's inbound.
func (*ServerState) StoreListenPort ¶
func (s *ServerState) StoreListenPort(server string, tag string, port uint16)
StoreListenPort saves the listen port for a server's inbound.
func (*ServerState) StorePinSHA256 ¶
func (s *ServerState) StorePinSHA256(server string, tag string, pin string)
StorePinSHA256 saves the TLS pin-SHA256 fingerprint for a server's inbound.