crypto

package
v0.3.88 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentTLSConfig

func AgentTLSConfig(agentCertPEM, agentKeyPEM, caCertPEM []byte) (*tls.Config, error)

AgentTLSConfig creates a TLS config for the agent client. It presents the agent's client certificate and verifies the dashboard's server cert.

func CreateCACertificate

func CreateCACertificate(pub ed25519.PublicKey, priv ed25519.PrivateKey) ([]byte, error)

CreateCACertificate creates a self-signed CA certificate with the given key pair.

func CreateSignedCertificate

func CreateSignedCertificate(
	agentPub ed25519.PublicKey,
	caCert *x509.Certificate,
	caPriv ed25519.PrivateKey,
	commonName string,
) ([]byte, error)

CreateSignedCertificate creates a certificate signed by the CA for an agent.

func DashboardTLSConfig

func DashboardTLSConfig(ca *CA) (*tls.Config, error)

DashboardTLSConfig creates a TLS config for the dashboard server. It requires client certificates signed by the CA (mTLS). The server cert uses ECDSA P-256 for broad browser compatibility, while still being signed by the Ed25519 CA.

func DecodeCertPEM

func DecodeCertPEM(certPEM []byte) (*x509.Certificate, error)

DecodeCertPEM decodes a PEM-encoded certificate.

func DecodePrivateKeyPEM

func DecodePrivateKeyPEM(keyPEM []byte) (ed25519.PrivateKey, error)

DecodePrivateKeyPEM decodes a PEM-encoded PKCS8 private key.

func Decrypt

func Decrypt(ciphertext, key []byte) ([]byte, error)

Decrypt decrypts ciphertext that was encrypted with Encrypt. Expects the nonce prepended to the ciphertext.

func DeriveKey

func DeriveKey(masterSecret, salt, info []byte) ([]byte, error)

DeriveKey derives a 32-byte encryption key from a master secret using HKDF.

func EncodeCertPEM

func EncodeCertPEM(certDER []byte) []byte

EncodeCertPEM encodes a DER certificate to PEM format.

func EncodePrivateKeyPEM

func EncodePrivateKeyPEM(priv ed25519.PrivateKey) ([]byte, error)

EncodePrivateKeyPEM encodes an Ed25519 private key to PKCS8 PEM format.

func Encrypt

func Encrypt(plaintext, key []byte) ([]byte, error)

Encrypt encrypts plaintext using AES-256-GCM with a random nonce. The nonce is prepended to the ciphertext.

func GenerateEd25519KeyPair

func GenerateEd25519KeyPair() (ed25519.PublicKey, ed25519.PrivateKey, error)

GenerateEd25519KeyPair generates a new Ed25519 key pair.

Types

type CA

type CA struct {
	Certificate *x509.Certificate
	CertPEM     []byte
	PrivateKey  ed25519.PrivateKey
}

CA represents the certificate authority for the dashboard.

func LoadCAFromDir

func LoadCAFromDir(dir string, encryptionKey []byte) (*CA, error)

LoadCAFromDir loads a CA from a directory with an encrypted private key.

func NewCA

func NewCA() (*CA, error)

NewCA generates a new certificate authority with a fresh Ed25519 key pair.

func (*CA) IssueAgentCertificate

func (ca *CA) IssueAgentCertificate(agentPub ed25519.PublicKey, agentName string) (certPEM []byte, err error)

IssueAgentCertificate creates and signs a certificate for an agent.

func (*CA) SaveToDir

func (ca *CA) SaveToDir(dir string, encryptionKey []byte) error

SaveToDir saves the CA certificate and encrypted private key to a directory.

func (*CA) VerifyAgentCertificate

func (ca *CA) VerifyAgentCertificate(certPEM []byte) (*x509.Certificate, error)

VerifyAgentCertificate verifies that an agent certificate was signed by this CA.

Jump to

Keyboard shortcuts

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