server

package
v0.2.1-rc.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package server runs MyOwnPKI (PHASE1 step 12): the admin listener with TLS, the public listener for CRLs and CA certificates, and the background jobs (audit delivery and checkpoints, CRL renewal, clean-ups).

The server starts sealed. It refuses to start before init and without the auth key. Shutting down seals the keyring – with a last checkpoint – within ShutdownBudget, before a container runtime sends SIGKILL.

Index

Constants

View Source
const ShutdownBudget = 8 * time.Second

ShutdownBudget: everything – requests, the last checkpoint, the seal – is done within this time. Docker and Podman send SIGKILL after 10 s (owner 2026-10-16).

Variables

View Source
var ErrNotInitialized = errors.New("this instance is not initialized – run myownpki init first")

ErrNotInitialized: serve before myownpki init.

Functions

func AdminCertFile

func AdminCertFile(cfg config.Config) string

AdminCertFile is the file of the certificate the admin listener serves: the operator's file or the bootstrap certificate. `myownpki healthcheck` pins it.

func Fingerprint

func Fingerprint(der []byte) string

Fingerprint is the SHA-256 of der as colon-separated upper-case hex.

Types

type CertInfo

type CertInfo struct {
	Source      string // "operator" or "bootstrap"
	Fingerprint string // SHA-256, colon-separated hex – as browsers show it
	NotAfter    time.Time
	DNSNames    []string
	IPs         []netip.Addr
	// Created: a new bootstrap certificate was made at this start (first
	// start, renewal or new names) – its fingerprint changed.
	Created bool
	Reason  string // why it was created
}

CertInfo describes the admin certificate for the log.

type Options

type Options struct {
	Config   config.Config
	Log      *slog.Logger
	Clock    clock.Clock // nil = clock.System
	Hostname string      // "" = os.Hostname
	Version  string
}

Options configure a server.

type Server

type Server struct {
	CertInfo CertInfo
	// contains filtered or unexported fields
}

Server is one running MyOwnPKI.

func Open

func Open(ctx context.Context, opt Options) (_ *Server, err error)

Open checks the data directory and prepares everything; nothing listens yet.

func (*Server) ACME added in v0.2.0

func (s *Server) ACME() *acme.Server

ACME is the ACME server, nil while ACME is off.

func (*Server) ACMEAddr added in v0.2.0

func (s *Server) ACMEAddr() string

ACMEAddr is "" when ACME is off; else the listener's address (tests use port 0).

func (*Server) AdminAddr

func (s *Server) AdminAddr() string

AdminAddr and PublicAddr are the bound addresses (tests use port 0).

func (*Server) Listen

func (s *Server) Listen(ctx context.Context) error

Listen opens both listeners. A warning goes out when the admin listener is reachable from other machines without an allowlist.

func (*Server) PublicAddr

func (s *Server) PublicAddr() string

PublicAddr is "" when the public listener is off.

func (*Server) Sealed

func (s *Server) Sealed() bool

Sealed reports the seal state.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve runs listeners and jobs until ctx ends, then shuts down within ShutdownBudget: no new connections, in-flight requests get a few seconds, then the seal with its last checkpoint, then the databases close.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops everything within ShutdownBudget.

func (*Server) Unseal

func (s *Server) Unseal(ctx context.Context, passphrase []byte, who keys.Who) error

Unseal unlocks the keyring (console at start; the API follows in step 13). A wrong passphrase leaves the server running sealed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL