Documentation
¶
Index ¶
- func CommonName(certPEM []byte) (string, error)
- func ExportDir(baseDir, instanceName, projectPath string) string
- func Fingerprint(certPEM []byte) (string, error)
- func FormatLocation(loc string) string
- func Label(projectPath, siteName string) string
- func ProjectID(projectPath string) string
- func StatePath() string
- type Entry
- type NSSStatus
- type Options
- type RevokeOutcome
- type SiteInput
- type SiteOutcome
- type State
- type Store
- type TrustInput
- type TrustResult
- type VerifyResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommonName ¶
CommonName returns the Subject CN of the first certificate in the PEM bytes.
func ExportDir ¶
ExportDir returns the per-project directory where exported cert and key files live. The directory is keyed by VM instance name (which defaults to the main site key) plus a short hash of the absolute project path so two forks of the same project don't collide.
func Fingerprint ¶
Fingerprint returns the hex-encoded SHA-256 fingerprint of the DER bytes of the first certificate in a PEM-encoded byte slice.
func FormatLocation ¶
FormatLocation maps an internal location identifier to a human-readable label suitable for CLI output. Internal forms like "nss:/Users/.../Library/Application Support/Firefox/Profiles/abc.default" become "Firefox (abc.default)".
func Label ¶
Label returns the label used to identify a site's cert in trust stores (macOS keychain via cert subject, NSS nicknames, Linux user CA filenames). Format: trellis-<projectID>-<site>.
Types ¶
type Entry ¶
type Entry struct {
Project string `json:"project"`
Site string `json:"site"`
Fingerprint string `json:"fingerprint"`
CommonName string `json:"common_name,omitempty"`
CertPath string `json:"cert_path"`
KeyPath string `json:"key_path,omitempty"`
Label string `json:"label"`
Locations []string `json:"locations"`
AddedAt time.Time `json:"added_at"`
}
Entry records what a `vm trust` invocation added so that a later `vm untrust` can reverse exactly the same set, even when the cert on disk has since changed.
type NSSStatus ¶
NSSStatus reports the outcome of the Firefox/NSS trust attempt so callers can decide whether to print install hints.
type Options ¶
type Options struct {
// TrustSystem (Linux) toggles writing to /usr/local/share/ca-certificates
// and running `sudo update-ca-certificates`. Off by default because it
// requires sudo.
TrustSystem bool
// DisableNSS skips Firefox NSS profile updates even when certutil is
// available. Mostly useful for tests.
DisableNSS bool
}
Options influence how Default constructs the platform store.
type RevokeOutcome ¶
RevokeOutcome is the per-site result of RevokeSite.
func RevokeSite ¶
func RevokeSite(store Store, state *State, project string, entry Entry) RevokeOutcome
RevokeSite removes one site's trust entry from the host stores and drops its exported cert+key files. State is updated in place on success; callers are responsible for State.Save() at the end of a batch.
type SiteInput ¶
type SiteInput struct {
Project string
Site string
InstanceName string
BaseDir string
CertPEM []byte
// KeyPEM, when non-empty, is written to <ExportDir>/<Site>.key with 0o600.
// When empty, any previously exported key file at that path is removed.
KeyPEM []byte
}
SiteInput describes a single site's cert (and optionally key) bytes that ApplySite should export to disk and add to the host's trust stores.
type SiteOutcome ¶
type SiteOutcome struct {
Site string
Verb string
Locations []string
NSS NSSStatus
KeyExported bool
Err error
ErrHint string
}
SiteOutcome is the per-site result of ApplySite. The cmd layer maps Verb to a one-line user-facing message and surfaces Err / ErrHint on failure.
func ApplySite ¶
func ApplySite(store Store, state *State, in SiteInput) SiteOutcome
ApplySite exports the cert and key (if provided) for a single site to the project's export dir, then trusts the cert in the host's stores. State is updated in place; callers are responsible for State.Save() at the end of a batch.
On a fingerprint match it verifies the live trust setting and re-trusts only if drift is detected. On a fingerprint change it removes the previous trust entries before adding the new one.
type State ¶
type State struct {
Entries []Entry `json:"entries"`
}
func (*State) EntriesForProject ¶
EntriesForProject returns entries belonging to a project, sorted by site.
type Store ¶
type Store interface {
// Trust adds the cert. Idempotent: re-running against an
// already-trusted cert should succeed without error.
Trust(input TrustInput) (TrustResult, error)
// Untrust removes the cert from the locations recorded at trust time.
// It returns the list of locations actually cleaned. Missing entries
// are skipped silently.
Untrust(input TrustInput, locations []string) ([]string, error)
// Verify classifies each recorded location as present, missing, or
// unknown. Used to detect drift between recorded state and reality
// (e.g. user manually deleted from keychain).
Verify(input TrustInput, locations []string) (VerifyResult, error)
}
Store applies trust changes for the cert across the platform's trust stores. Each implementation may write to multiple underlying stores (system keychain + NSS, etc.); TrustResult captures all of them so the caller can record state and surface NSS hints.
type TrustInput ¶
type TrustInput struct {
// CertPath is an absolute path to the PEM-encoded certificate already
// present on disk. Stores that need a file (e.g. macOS `security`,
// `certutil -i`) read it from here.
CertPath string
// CertPEM is the same content as the file at CertPath. Provided so
// callers don't have to re-read the file.
CertPEM []byte
// Fingerprint is the hex-encoded SHA-256 of the DER bytes; used as a
// stable identifier for state tracking and verification.
Fingerprint string
// Label is a human-readable name used for keychain entries and NSS
// nicknames, e.g. "trellis: example.com".
Label string
}
TrustInput describes a cert that should be added to the host's trust stores.
type TrustResult ¶
TrustResult bundles what a Trust call did across all underlying stores.
type VerifyResult ¶
VerifyResult classifies each recorded location as present, missing, or unknown. Unknown means the verifier couldn't determine the state (e.g. certutil isn't on PATH so NSS can't be queried) and should be treated as not-yet-broken so we don't accidentally re-trust and lose state.
func (VerifyResult) AllAccounted ¶
func (v VerifyResult) AllAccounted(locations []string) bool
AllAccounted reports whether every recorded location was either confirmed present or could not be checked. If anything is Missing, the caller should treat the entry as drifted and re-trust.