pki

package
v0.1.0-alpha.1 Latest Latest
Warning

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

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

Documentation

Overview

Package pki is the small certificate authority of the hub. It signs the client certificates of enrolled agents and the certificate the hub shows them, and gives the agents what they need to trust the hub without a public certificate: they pin the fingerprint of the CA.

Index

Constants

View Source
const (

	// ClientValidity is how long the certificate of an agent is valid. There is
	// no renewal yet, so it is long; revocation does not depend on it.
	ClientValidity = 5 * 365 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func Fingerprint

func Fingerprint(der []byte) string

Fingerprint returns "sha256:" and the hex SHA-256 of a DER certificate.

func NewAgentKey

func NewAgentKey() (*ecdsa.PrivateKey, []byte, error)

NewAgentKey makes the key pair of an agent and the certificate request to send to the hub. The key stays on the agent.

func ParseFingerprint

func ParseFingerprint(s string) (string, error)

ParseFingerprint accepts a fingerprint written as "sha256:<hex>" or plain hex, with optional colons, in any case, and returns the canonical form.

func PinnedClientTLS

func PinnedClientTLS(fingerprint string, cert *tls.Certificate) (*tls.Config, error)

PinnedClientTLS is the TLS configuration of an agent. It trusts a hub if the certificate it presents is signed by a CA with the given fingerprint, and ignores the host name: the pinned CA only signs the certificates of one hub, so the name adds nothing, and the hub may be reached by any address. cert may be nil, which is the case for enrollment.

Types

type CA

type CA struct {
	// contains filtered or unexported fields
}

CA is the hub's certificate authority.

func LoadOrCreate

func LoadOrCreate(dir string, now time.Time) (*CA, error)

LoadOrCreate loads the CA stored in dir (ca.crt and ca.key), or creates it when neither file exists. The key is readable by the owner only.

func (*CA) CertDER

func (ca *CA) CertDER() []byte

CertDER is the certificate of the CA.

func (*CA) Fingerprint

func (ca *CA) Fingerprint() string

Fingerprint is what an agent pins to trust this hub, as "sha256:" followed by 64 hex digits.

func (*CA) ServerCertificate

func (ca *CA) ServerCertificate(now time.Time, hosts ...string) (tls.Certificate, error)

ServerCertificate issues a fresh certificate for the hub's agent listener, valid for the given host names or addresses. It is not stored: a new one is made at every start. The chain includes the CA, so agents that only know the fingerprint can find what they pin.

func (*CA) ServerTLS

func (ca *CA) ServerTLS(cert tls.Certificate) *tls.Config

ServerTLS is the TLS configuration of the agent listener. A client certificate is not required, because enrollment happens before an agent has one, but a certificate that is presented must be signed by this CA. The services decide which calls need an identity (see ClientIdentity).

func (*CA) SignClient

func (ca *CA) SignClient(csrDER []byte, agentID string, now time.Time) (certDER []byte, serialHex string, err error)

SignClient issues the client certificate of an agent from a certificate request. The subject of the request is ignored; the certificate is made for agentID. It returns the certificate (DER) and its serial number in hex.

type Identity

type Identity struct {
	AgentID string
	Serial  string // hex
}

Identity is a verified client certificate.

func ClientIdentity

func ClientIdentity(state tls.ConnectionState) (Identity, bool)

ClientIdentity returns the identity from the state of a TLS connection, or false if the client presented no verified certificate.

Jump to

Keyboard shortcuts

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