# Certificate Trust

---

# The Trust Store

_Peios / Using Peios / Certificate Trust_

> How trustd combines shipped roots with local trust decisions.

trustd supplies the machine's trusted certificate authorities. It combines
shipped roots with registry decisions, then publishes the effective set
through a local service and compatibility files.

A program with its own private trust store uses separate policy. Changing
the machine store does not establish that every application changed its
trust decisions.

## Seeing what is in force

`trust status` reports health, generation, root counts, and compatibility
output. `trust list` reports the effective roots served by trustd.

The generation identifies the published set. Programs holding a snapshot
can use it to detect a change. Health is `degraded` when reading,
composition, or compatibility output fails. It is not safe to infer successful
publication from the registry alone.

`trust list --distrusted` reads durable registry decisions. It does not prove
that the daemon has applied them. See
[Adding and Distrusting Certificates](/peios/using-peios/certificate-trust/adding-and-distrusting.md)
for changes and verification.

<!-- Preserve the published heading anchor. -->
<!-- lint-disable-next-line spelling -->
## Who can change it {#who-may-change-it}

The security descriptors on `Machine\System\Trust\Certificates` and its
subkeys control registry writes. SYSTEM and Administrators have write access
under the default policy; everyone can read. The `trust` command and library
use the caller's authority. They do not grant permission to change trust.

Reloading trustd has a separate control permission. A caller can have
permission to record a decision without permission to request a reload.
The daemon also watches for registry changes.

## Where trust policy comes from

| Input | Location | Updated by |
|---|---|---|
| Shipped roots | `/usr/share/ca-certificates/mozilla.crt` | Root-store package updates |
| Additions and distrusts | `Machine\System\Trust\Certificates` | Registry policy |

The package supplies certificates; the registry records decisions about
them. A distrust can exclude a shipped root without modifying the package.
An addition supplies a certificate that the shipped set does not contain.

A root's fingerprint identifies the certificate. Subject names alone do
not distinguish certificates reliably. Purpose metadata records the uses
for which an addition is trusted.

## What programs actually read

Native clients use `libtrust.so` to query or subscribe to
`/run/trustd/trust.sock`. A subscription publishes complete generations.
Applications must replace their own cached trust state when appropriate;
a notification does not itself invalidate an application's existing sessions.

Compatibility consumers read generated bundles or a hashed directory under
`/etc/ssl`. Those outputs contain roots permitted for `ServerAuth`.
They are derived from policy, so editing them does not make a lasting change.
See [The Compatibility Trust Files](/peios/using-peios/certificate-trust/the-compat-files.md).

Installing a root bundle alone does not compose or render the machine store.
Likewise, stopping trustd does not remove an existing rendered bundle or
invalidate a program's cached copy.

## Failure and recovery

If a complete configuration read or composition fails, trustd retains its
previous effective set and reports degraded health. Missing optional values
retain their documented defaults. An incomplete addition without a
`Certificate` value is skipped while it is being created.

Compatibility rendering happens after the effective socket set changes.
A rendering failure can leave different consumers using different sets.
Inspect the failure and verify both the service and the paths used by the
affected application. See
[When the Store Is
Degraded](/peios/using-peios/certificate-trust/adding-and-distrusting.md#when-the-store-is-degraded).

---

# Adding and Distrusting Certificates

_Peios / Using Peios / Certificate Trust_

> Record a trust decision and verify its effective result.

Add a certificate authority when the machine needs to trust an authority
outside the shipped set. Distrust a certificate to exclude it even if a
package or local addition supplies it.

## Before you start

- Install and start trustd and the `trust` command.
- Obtain write access to the relevant keys under
  `Machine\System\Trust\Certificates`.
- Verify the intended certificate's fingerprint through a trusted channel.
- Identify the applications affected by the change and how they obtain trust.

`trust(1)` owns command syntax. The regman entry for
`Machine\System\Trust\Certificates` owns the registry schema.

## In Security Policy

Use Security Policy's certificate views to inspect effective roots, additions,
and distrust decisions. Graphical changes use the same registry permissions
as `trust`. Verify the resulting store and affected applications after using
either interface.

## Trusting a certificate authority

1. Inspect `trust status` and `trust list` before making a change.
2. Obtain the intended certificate as a single PEM or DER file. The following
   example assumes it is saved as `corp-root.pem` in the current directory:

   ```sh
   trust add corp-ca corp-root.pem
   ```

3. Follow [Verify the Change](#verify-the-change).

The name identifies the local addition. The command rejects an invalid,
expired, or non-authority certificate before writing it. trustd validates
certificates again when composing the store.

To withdraw this named addition:

```sh
trust remove corp-ca
```

Removing an addition does not create a distrust decision. Another source
can still supply the same certificate.

### Purposes

An addition defaults to `ServerAuth`, used to validate TLS servers. Choose
other purposes only when intended. For example:

```sh
trust add corp-ca corp-root.pem --purposes ServerAuth,CodeSigning
```

Socket queries can filter by purpose. Compatibility bundles and hashed
files include only roots carrying `ServerAuth`. Applications using other
purposes must request and enforce the appropriate policy themselves.

## Distrusting a certificate authority

1. Find the intended certificate with `trust list` and inspect it with
   `trust show`. Compare the full SHA-256 fingerprint, not only its subject.
2. Run `trust distrust` with that fingerprint or its unambiguous prefix.
   Use `--reason` to record why it is being excluded; see `trust(1)`.
3. Check the durable decision with `trust list --distrusted`, then verify
   the effective result below.

A complete fingerprint can record a distrust before the machine has that
certificate. A later bundle or addition cannot make it trusted while the
distrust remains.

To remove a distrust, use `trust restore` with its fingerprint. Removing
the decision does not supply a certificate that is absent from both the
shipped bundle and local additions.

## Verify the change

1. Run `trust status`. Resolve degraded health using the procedure below.
2. Run `trust list`. For an addition, inspect its complete fingerprint,
   source, and purposes with `trust show`.
3. For a distrust, confirm that the root is absent from the effective set
   and that `trust list --distrusted` contains the decision.
4. Retest the affected application. If it caches trust, refresh that state
   using the application's documented procedure.

A registry write records intent. A socket query confirms the daemon's set.
Neither proves that a running application has discarded a cached root or
that compatibility rendering succeeded.

## Doing it from the registry

The `trust` command uses ordinary registry operations. A domain policy can
write the same keys; it does not need a separate trust mechanism.

When creating an addition manually, write `Certificate` last. trustd skips
an entry without that value so that the other metadata can be prepared
first. Use the regman schema rather than inferring value types from examples.

<!-- Preserve the published heading anchor. -->
<!-- lint-disable-next-line spelling -->
## Package-provided trust {#packages-may-offer-trust-never-take-it}

Package-provided trust decisions belong in inert registry seeds. Installing
files must not silently widen machine trust. Applying a seed is an explicit
image or administrative policy action.

A private application store is separate from the machine store. Its contents
and refresh behavior belong to that application's documentation.

## When the store is degraded

1. Read the error from `trust status` and preserve the failing operation or
   path for diagnosis.
2. Correct the cause. Repair a missing or invalid root bundle through its
   package. Correct an unreadable registry configuration or unintended
   distrust decision without restoring an intentionally excluded root.
3. If rendering failed, inspect the paths the affected application uses.
   Reported rendered paths can describe an earlier successful render; they
   are not a fresh inventory after failure. Do not edit generated files.
4. With trustd's control permission, run:

   ```sh
   trust reload
   trust status
   ```

5. Confirm healthy status, verify the intended change, and retest the
   application.

An authorized reload returns an error if refresh leaves degraded health.
The registry decision remains recorded. Service-manager reload uses SIGHUP;
its completion does not report the result of recomposition, so inspect
`trust status` afterward.

Skipped invalid certificates are reported separately from degraded health.
Read the warnings and correct the named entries before relying on them.

---

# Managing Certificate Trust in Security Policy

_Peios / Using Peios / Certificate Trust_

> Inspect a certificate before adding it to machine trust.

Security Policy manages the certificate authorities the machine accepts
and its explicit distrust entries. A trust change affects programs that
consume that machine policy, so inspect the certificate and its source
before accepting it.

## Before you start

You need permission to change `Machine\System\Trust`. Reloading trustd
uses its separate control permission. Obtain the certificate or fingerprint
through the verification process appropriate to the authority you trust.

## Inspect and change trust

1. Open **Security Policy** and select **Trusted** or **Distrusted**.
2. Inspect the issuer, validity, fingerprint, and trust purpose. To add a
   certificate, use **Add Certificate** and select its PEM or DER file.
3. Review the parsed certificate. The application rejects a non-authority
   certificate, an expired certificate, and conflicting existing trust or
   distrust entries.
4. Confirm only the intended trust, distrust, or removal operation. Read
   the result.

## Check the result

Verify the certificate in the effective list read from trustd. The window
follows changes made through other tools too. A stored entry alone does
not establish that every consuming program has refreshed its state.

**Settings** shows trustd's status, its reload operation, certificate-file
export settings, and permissions. **Signing Keys** displays code-signing
keys compiled into the kernel; this window cannot add or remove those
keys. See `gxwi-security-policy(1)` and `trust(1)`.

---

# Understanding Trust Status

_Peios / Using Peios / Certificate Trust_

> Distinguish stored trust decisions from effective and cached roots.

`trust` reads the effective store from trustd and records policy changes in
the registry. These are different views: a stored decision can exist before
the daemon or an application has applied it. `trust(1)` owns the command
reference, including arguments and exit statuses.

## Listing

`trust list` shows the effective roots. `trust list --distrusted` reads
durable
registry decisions. Compare both when checking a withdrawal.

`trust list --purpose ServerAuth` filters the service response by purpose.
It does not inspect rendered files. Healthy compatibility output uses the
same purpose filter, but a failed render can leave older files in place.

## Showing one root

`trust show` accepts a full fingerprint or unambiguous prefix from the
listing. An ambiguous prefix is refused. Inspect the full fingerprint,
source, and purposes before making a trust decision.

The `--pem` option emits only the certificate, suitable for export.
Exporting it does not change policy.

## Exit statuses

A command finding no matching root differs from a failed attempt to query
trustd. Scripts should check the exit status described in `trust(1)` rather
than treating every empty result as absence.

A successful registry write means the decision was recorded. Verify healthy
status and the effective store before treating it as applied. `trust reload`
returns failure when the refresh leaves degraded health.

## When a write is refused

`trust` has no additional authority to grant. Registry descriptors govern
changes, and trustd's control descriptor separately governs reload requests.
Have an authorized administrator perform the intended operation.

Editing generated certificate files is not a substitute for changing policy.
The next render replaces them, and other consumers can use the service
instead of those files.

## Reloading through the service manager

`svctl --wait reload trustd` sends SIGHUP. trustd processes it in its event
loop without replacing the main process. Repeated pending signals can be
combined into one refresh.

Inspect `trust status` afterward. Delivery of a service reload does not prove
that reading configuration, composing roots, or rendering files succeeded.

---

# The Compatibility Trust Files

_Peios / Using Peios / Certificate Trust_

> How trustd supplies file-based trust and what rendering failures mean.

trustd renders certificate files for programs that obtain machine trust from
a path. The files are derived output, not configuration. Change trust through
the registry or `trust`; manual edits are replaced on the next render.

## Three artifacts, because the ecosystem does not agree

| Path | Purpose |
|---|---|
| `/etc/ssl/certs/ca-certificates.crt` | Certificate bundle |
| `/etc/ssl/cert.pem` | Alternate bundle path |
| `/etc/ssl/certs/<subject-hash>.0` | Hashed certificate lookup |

Roots with the same subject hash use successive numeric suffixes. Updating
only a bundle would leave hashed lookups using stale roots, so trustd
rebuilds the certificate directory as well.

Only roots with `ServerAuth` are rendered. Purpose metadata is not embedded
as a substitute for application validation; each consumer still applies its
certificate rules.

## Publication and failure

The renderer prepares a replacement certificate directory and attempts an
atomic exchange. Where exchange is unavailable, it uses renames with rollback.
The fallback can temporarily leave the directory absent. A rollback failure
can require repair.

The directory and alternate bundle are separate operations, and the service
publishes its effective set before rendering. No single atomic switch covers
the socket and every file. A failure can therefore leave consumers observing
different generations.

Follow [degraded-store
recovery](/peios/using-peios/certificate-trust/adding-and-distrusting.md#when-the-store-is-degraded)
and check the actual paths used by the application. A previously reported
rendered path is not proof of its contents after a failed refresh.

## Turning them off

`Machine\System\Trust GenerateLinuxTrustFiles` selects whether trustd supplies
compatibility files. Its regman entry owns the value reference.

Turning file output off removes trust inputs from programs that require
those paths. Use that mode only when the installed applications use the
service or deliberately managed private stores. The socket continues serving.

Removal itself uses several filesystem operations and can fail partway.
A stored setting does not prove that all files were removed. Check service
health, the relevant paths, and application behavior after changing the mode.

To restore ordinary file output:

```sh
reg set Machine/System/Trust GenerateLinuxTrustFiles dword:1
trust reload
trust status
```

These operations require registry write access and trustd's control right.
Confirm healthy status and retest the application.

## Why a copy, when name resolution gets a pointer

A resolver configuration can name a service that answers later requests.
A certificate bundle has to contain the authorities itself. It cannot direct
a consumer to ask trustd instead, which is why file consumers need a rendered
copy and their own refresh behavior.

The effective roots are public, so generated files are readable by ordinary
programs. Changing the policy remains protected by registry permissions.
