Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios

Certificate Authority

Single-page view · as markdown

The Certificate Authority

Peios / Using Peios / Certificate Authority

A Peios machine can run its own certificate authority: pkid, a service that issues X.509 certificates for the machines, services, and people on your network, such as a server's TLS certificate or the certificate a phone signs in to Wi-Fi with. If you have run an enterprise certificate authority, the pieces will be familiar: CAs, templates that describe each kind of certificate, and requests that are issued at once or held for an officer.

You manage pkid with the pki command, or with the Certificate Authority window: open Certificate Authority from the launcher, or run pki --window. pkid decides every request by the access token of whoever sent it, so pki and the window can do exactly what you can, and nothing more. The window asks pkid and the Registry what you may change, offers only that, and shows the rest read-only with the reason. Someone who may only request certificates sees the authorities they can request from and their own requests and certificates.

How a certificate is issued #

A certificate starts as a request: a public key and the names it is for, signed with the matching private key to prove the requester holds it. The request names a CA and a template, and pkid checks it in this order:

  1. The CA. The requester needs the Request right in the CA's security descriptor.
  2. The template. The requester needs the Enroll right in the template's descriptor, and the request has to fit the template: the kinds of key and name it allows.
  3. Each name. The requester needs the right to request every name in the certificate, from the name trees.

A request that passes is issued at once, or held for an officer of the CA to approve, when the template or a name asks for approval. A request that fails any check is refused, with the reasons. pkid records every request and decision in its database, with who made it.

The template decides everything else about the certificate: its purposes, key usages, and lifetime. A requester can't change any of it, so the template, not the request, is what an administrator reviews.

CAs #

A CA is a key and a certificate that signs other certificates. Most networks have two tiers:

  • A root signs its own certificate. Every device that is to trust your certificates adds the root's certificate to its trust store once.
  • An issuing CA below the root signs the certificates people and machines use. Its certificate is signed by the root.

Two tiers let you keep the root's key away from the network. pkid keeps a CA's key in one of two places:

  • pkid's store, readable by pkid's service account alone. A CA whose key is here issues unattended, as an issuing CA does.
  • A sealed file, protected by a passphrase, such as on removable media. pkid never keeps such a key open: every operation that signs with it asks for the passphrase. A root's key belongs here, and the media can stay in a drawer until the root next signs something.

A CA can also be signed by a CA elsewhere, or sign a subordinate CA that runs elsewhere, so pkid can fit below or above an existing hierarchy.

Templates #

A template describes one kind of certificate: what it is for, how long it lasts, which keys and names a request can contain, and whether every request waits for approval. A CA issues only from the templates it is given.

pki setup adds two templates:

  • Server, for TLS servers named by host name. Its certificates last 90 days.
  • Device, for client authentication, such as EAP-TLS on Wi-Fi, for devices and people named by user principal name or email address. Its certificates last a year.

Both let any authenticated principal enroll. Enrolling grants nothing by itself: the names decide.

Names #

The name trees decide who can request certificates for which names. There are two trees, one of host names, such as radius.lab.home, and one of principal names, such as alice@home. Each name can have its own security descriptor and its own owner, and names below it inherit its descriptor's inheritable entries, so a grant on lab.home covers every name under it.

Three rights apply to a name:

  • Request issues certificates for the name without approval.
  • Request with approval holds them for an officer.
  • Wildcard also permits the name's wildcard form, such as *.lab.home.

A name's owner is the principal it belongs to, such as the RADIUS server's account for radius.lab.home. The roots of both trees grant Request to PRINCIPAL SELF, which matches a name's owner, so every owner can request its own names, and Administrators can request any. Nobody else can request anything until you grant it. A certificate whose names all belong to one owner carries the owner's SID, so services that accept it for sign-in can match it to the account rather than to a name that only looks the same.

Rights on a CA #

Each CA's descriptor grants four rights:

  • Read shows every request and certificate. Without it, a caller sees only its own.
  • Request lets a caller submit requests.
  • Officer approves and denies held requests and revokes certificates. An officer can never approve a request it submitted itself.
  • Manage changes the CA, signs subordinate CAs, and exports its key.

By default, Authenticated Users can request, and Administrators and SYSTEM hold every right. pkid(8) describes each right and descriptor.

Who can create and import CAs is a descriptor of its own, which grants Manage to Administrators and SYSTEM by default. pki ca creators shows and sets it, as does Who Can Add Authorities on the Certificate Authority window's overview.

Revocation #

A certificate can be revoked before it expires, such as when its key is exposed. Each CA publishes a certificate revocation list (CRL) of what it has revoked, which pki-httpd serves over HTTP at an address written into every certificate the CA issues, so that software checking a certificate can find out. pkid renews the list of a CA whose key it keeps; an offline root's list is renewed by hand, with its passphrase. Publishing Revocation Lists explains how.

Where it is kept #

The configuration, the templates, names, and CAs, is in the Registry under Machine\Software\Pki, which regman documents value by value. pkid takes a change up as soon as it is written, but only as a whole: while any part of the configuration is invalid, pkid issues nothing and says why in its pkid.configuration.loaded event. pki checks each change by the same rules before it writes it.

Requests, certificates, and revocations are in pkid's database. pki(8) documents every command, and pkid(8) the service.

Setting Up a Certificate Authority

Peios / Using Peios / Certificate Authority

Set up a certificate authority when the machines and people on your network need certificates you issue yourself. When you finish, you have a root CA whose key is kept off the machine and an issuing CA that issues server and device certificates unattended.

Before you start #

  • Sign in as a member of Administrators.
  • Make sure the pki package is installed. It doesn't start pkid or pki-httpd: they start once you set the machine up.
  • Have removable media mounted for the root's key, such as /media/usb.
  • Choose a passphrase of at least 15 characters for the root's key, and somewhere safe to keep it. Without the passphrase, the root can never sign again.

Prepare the machine #

Run pki setup once:

pki setup

It creates pkid's state directories under /var/state/pki and adds the default configuration under Machine\Software\Pki: the Server and Device templates and the roots of the name trees. Then it has pkid, and pki-httpd, which publishes revocation lists, start at boot, and starts them. It only adds what is missing, so running it again changes nothing you have set.

In the Certificate Authority window, the overview offers Set Up to an administrator until the machine is prepared.

Create the root #

  1. Create the root, with its key sealed in a file on the removable media:

    pki ca create "Home Root" --root --key-file /media/usb/home-root.key \
      --crl http://pki.home/crl/home-root.crl
    

    pki asks for the key's passphrase twice. pkid makes the key and the root's certificate, an RSA-4096 one that lasts 10 years. --crl is the address where the root's revocation list will be published, and goes into the certificates the root signs; see Publishing Revocation Lists.

  2. Publish the root's first revocation list while its key is to hand:

    pki ca publish-crl "Home Root"
    
  3. Write the root's certificate to a file, to give to the devices that are to trust it:

    pki ca show "Home Root" --out home-root.pem
    

Create the issuing CA #

  1. Create the issuing CA, signed by the root, issuing from both templates:

    pki ca create "Home Issuing" --issuer "Home Root" \
      --template Server --template Device \
      --crl http://pki.home/crl/home-issuing.crl
    

    pki asks for the root key's passphrase, since the root signs the new CA's certificate. The issuing CA's key goes in pkid's store, so it issues without a passphrase, and its certificate lasts 5 years. pkid publishes its revocation lists itself.

  2. Unmount the removable media and store it safely. The root is needed again to sign another CA, and to renew its revocation list, which lasts 180 days.

Check the result #

List the CAs:

pki ca list

Both CAs are listed, each with the state issuing. pki ca show "Home Issuing" shows the issuing CA in full, including the templates it issues from and its certificate's SHA-256 fingerprint.

Distribute the root #

Every device that is to trust your certificates needs home-root.pem in its trust store. Check its SHA-256 fingerprint against pki ca show "Home Root" when you install it. On a Peios machine, add it as described in Adding and Distrusting Certificates.

Keep a copy of the issuing CA's key #

A key in pkid's store can't leave it unless the CA was created with --exportable. To be able to restore the issuing CA on another machine, add --exportable when you create it, then export its key, sealed under a new passphrase:

pki ca export-key "Home Issuing" home-issuing.key

pki ca import restores it from the file and the CA's certificate.

Have a CA elsewhere sign your CA #

If your network already has a CA, make pkid's CA its subordinate instead of a root. --offline writes a request for that CA to sign:

pki ca create "Home Issuing" --offline home-issuing.csr

Once the other CA has signed it, install the certificate it returns:

pki ca install "Home Issuing" home-issuing.pem

The CA issues nothing until its certificate is installed.

Use the Certificate Authority window #

Add an Authority in the window's sidebar makes each kind of CA these steps make: a Root Authority, one Under an Authority Here, one Signed by an Authority Elsewhere, or one imported from a backup with Import From a Backup. Its Key Storage is the Certificate Service's store, or a Sealed File with a passphrase. A CA's page has Export Key, Sign a Subordinate Request, and, while it waits for its certificate, Save Request… and Install Certificate…. Only someone with the right to create CAs sees Add an Authority.

Controlling Who Can Request Certificates

Peios / Using Peios / Certificate Authority

Change who can request certificates when the defaults don't fit: a server that is to request its own certificate, a group that is to request names under a domain, or a kind of certificate that needs an officer's approval.

By default, a name's owner can request certificates for it, Administrators can request any name, and nobody else can request anything.

Before you start #

  • Sign in as a member of Administrators. The name and template commands write the Registry under Machine\Software\Pki, which only Administrators can change.
  • Run pki setup first, as described in Setting Up a Certificate Authority.

Let a principal request its own name #

Make the principal the name's owner, by its SID:

pki name set-owner radius.lab.home S-1-5-21-1-2-3-1105

The roots of the name trees grant Request to PRINCIPAL SELF, which matches a name's owner, so the owner can now request certificates for radius.lab.home without approval. Ownership covers exactly that name, not the names below it, and certificates for the name carry the owner's SID.

Never make a broad group, such as Users, an owner: every member could then request certificates for the name. pki warns if you do.

Let every account request its own principal name #

Rather than set an owner for each person's principal name, let the accounts on this machine own theirs. List the domains this machine speaks for:

pki name domains --set home

Now alice@home, with no owner of its own, belongs to the account alice: Alice can request certificates for it, such as for signing in to Wi-Fi, and they carry her account's SID. Nobody else can request it, as PRINCIPAL SELF matches only its owner. Only the account's name is used, which only an administrator can change, and a domain not listed is never looked up, so list only your own. An owner you set with set-owner still wins.

Let a group request names under a domain #

Give lab.home a descriptor that grants the group Request with approval (0x2), marked to inherit (CI) so it covers every name below:

pki name set-security lab.home "D:(A;CI;0x2;;;AU)"

Here AU is Authenticated Users. Their requests for names under lab.home now wait for an officer of the CA. pki adds the entries lab.home inherits from above, so Administrators and owners keep the rights the root gave them.

A tree's root, . or @, inherits nothing, so its descriptor replaces the shipped one whole. pki warns if a new root descriptor leaves Administrators unable to request the names in the tree, or owners unable to request their own.

Prefer Request with approval for groups. Request (0x1) issues without anyone looking, so granting it to a broad group lets every member obtain certificates for those names; pki warns when you grant it. Wildcard (0x4) also permits names such as *.lab.home.

To undo the change and let lab.home inherit again:

pki name set-security lab.home --inherit

Hold every certificate of a kind for approval #

Set a template's issuance to approval, and every request under it waits for an officer, whatever the names allow:

pki template set Server --issuance approval

Add a kind of certificate #

Create a template from a copy of another and change what differs, such as a server template whose certificates last 30 days:

pki template create "Short Server" --from Server --lifetime 30 \
  --renewal-window 10

pki refuses a template pkid wouldn't load, such as one whose renewal window isn't shorter than its lifetime. Then let a CA issue from it. --template replaces the CA's list, so give every template it is to keep:

pki ca set "Home Issuing" --template Server --template Device \
  --template "Short Server"

A template's enrollment descriptor decides who can use it at all; --enroll-security changes it.

Use the Certificate Authority window #

The window's Templates and Names pages make the same changes. Who Can Request opens the permissions editor on a template's or a name's descriptor; for a name, it shows the entries it inherits from the name above it. A name's page sets its Owner, by account name, and Inherit Again… drops its own permissions. Principal Domains is at the top of Names. Each control appears only where your permissions in the Registry let you change it.

Check the result #

Show a name to see its owner, its descriptor, and where the descriptor comes from:

pki name show www.lab.home

www.lab.home has no settings of its own, so its descriptor is inherited from lab.home. pki name list lists the names with settings of their own, and pki template show Server shows a template and the CAs that issue from it.

Requesting a Certificate

Peios / Using Peios / Certificate Authority

Request a certificate when a server, a service, or a device needs one from your CA. You can send a request that other software made, or have pki make the key and package the result for a device to import.

Before you start #

  • Find the CA's name and the template to use. pki ca list lists the CAs you have rights at, and pki ca show lists the templates a CA issues from.
  • Make sure you can request the names the certificate is to carry, as described in Controlling Who Can Request Certificates.

Certify a request you made #

Software that keeps its own key, such as a web server, makes the request itself, in PEM or DER. Submit it under a template the CA offers:

pki request submit "Home Issuing" Server www.csr --out www.pem

If the CA issues the certificate, pki writes it to www.pem. If the request is held for approval, pki prints its number instead. Once an officer approves it, collect the certificate:

pki cert get "Home Issuing" 42 --out www.pem

Make a key and certificate for a device #

Phones, laptops, and other devices import a key and its certificates as one PKCS #12 file. pki enroll makes the key on this machine, asks the CA to certify it, and writes the file:

pki enroll "Home Issuing" Device --upn alice@home --out alice.p12

pki asks for a passphrase of at least 15 characters, which protects the file and is asked for again when it is imported. pkid sees only the request, never the key. The file holds the key, the certificate, and the CA certificates above it that you can see on this pkid, so a device that imports it can present the chain.

Name the certificate with --dns for a host name, --email for an email address, or --upn for a user principal name, which EAP-TLS sign-in to Wi-Fi uses. Each can be repeated.

The file is encrypted with AES-256, as OpenSSL 3 writes by default, and OpenSSL 3 imports it. Apple systems older than iOS 18 and macOS 15 are reported to refuse it.

When the request is held #

The key exists nowhere but on this machine, so a held request can't lose it: pki seals the key under the same passphrase in a file beside the one it would have written, here alice.p12.key, and prints the command that finishes the job. Once an officer approves request 42, run:

pki enroll "Home Issuing" --request 42 --key alice.p12.key --out alice.p12

Delete alice.p12.key once the device has imported the file.

Request a certificate with the Certificate Authority window #

  1. Open Certificate Authority from the launcher, and choose Request a Certificate in the sidebar.
  2. Choose the Authority and the Template. Only those you may request from are offered.
  3. Type the names the certificate is for, separated by commas.
  4. Leave Key set to Make a Key Here to have the window make the key and save it with its certificates as a PKCS #12 file. Choose Save To and a Password of at least 15 characters. To certify a request other software made, set Key to Use My Own Request and choose the request file instead.
  5. Choose Request Certificate.

If the request is held for approval, the window keeps the key sealed beside the file and remembers the request. Once an officer approves it, the overview says the certificate is ready: open the request, choose Save…, and type the file's password.

Check the result #

List the CA's certificates:

pki cert list "Home Issuing"

The new certificate is listed with the state valid, its serial number, and when it expires. pki cert show with the serial number shows it in full.

Approving and Revoking Certificates

Peios / Using Peios / Certificate Authority

Approve and revoke certificates when a CA holds requests for an officer, or when a certificate's key is lost or its holder leaves. These are an officer's tasks: they need the Officer right in the CA's descriptor, which Administrators hold by default.

Before you start #

  • Sign in as an officer of the CA.

pki ca show "Home Issuing" lists your rights at the CA under Your access.

Make someone an officer #

Officers are named in the CA's descriptor. Someone with Manage CA at the CA can change it. To let the group Lab Officers approve and revoke, while everyone signed in can still request and Administrators keep every right:

pki ca set-security "Home Issuing" "D:(A;;0x2;;;AU)(A;;0x5;;;S-1-5-21-1-2-3-1105)(A;;0xf;;;BA)(A;;0xf;;;SY)"

In the Certificate Authority window, open the CA's page and choose Edit… under Permissions, which opens the permissions editor with these rights by name.

The descriptor replaces the one the CA had, so include every grant it should keep. Grant 0x4 (Issue and Manage Certificates) and 0x8 (Manage CA) only to people you trust to issue any certificate. pki warns you if the descriptor lets a broad group approve or manage, or leaves you without Manage CA. pki(8) lists the rights.

Approve or deny held requests #

  1. List the requests waiting for an officer:

    pki request list "Home Issuing" --status pending
    

    Each is listed with its number, template, when it was submitted, and the names it asks for.

  2. Look at a request in full, including who submitted it and why it was held:

    pki request show "Home Issuing" 42
    
  3. Approve it, which issues the certificate:

    pki request approve "Home Issuing" 42
    

    Or deny it, recording why:

    pki request deny "Home Issuing" 42 --reason "not a lab machine"
    

You can't approve a request you submitted yourself; another officer has to. pkid checks an approved request again as its requester, so approving it issues only what the requester was allowed to ask for, whatever the officer's own rights.

The requester then collects the certificate, as described in Requesting a Certificate.

With the Certificate Authority window #

Open Requests. Requests waiting for an officer are listed first, each with Approve and Details. Deny… on a request's page asks for an optional reason. The window shows your own requests without these, with why: another officer has to decide them.

Revoke a certificate #

  1. Find the certificate's serial number:

    pki cert list "Home Issuing"
    
  2. Revoke it, with the reason, such as key-compromise for a key that was exposed or superseded for one that was replaced:

    pki cert revoke "Home Issuing" 4f1a09 --reason key-compromise
    

A revocation can't be undone. pkid records it with its reason, the time, and the officer who made it. pki(8) lists every reason.

In the Certificate Authority window, open the certificate from Certificates and choose Revoke…, then the reason.

Software learns of the revocation from the CA's revocation list. pkid publishes a new list at once for a CA whose key it keeps. For a CA whose key is in a sealed file, pki reminds you to publish one with pki ca publish-crl, as described in Publishing Revocation Lists.

Check the result #

Show the certificate:

pki cert show "Home Issuing" 4f1a09

Its state is revoked, with when, why, and by whom. A request you approved or denied leaves the list that pki request list "Home Issuing" --status pending prints.

Publishing Revocation Lists

Peios / Using Peios / Certificate Authority

Publish revocation lists so that software checking a certificate can find out whether it was revoked. Each CA signs a certificate revocation list (CRL) naming the certificates it has revoked, and pki-httpd serves it over HTTP at the address the CA writes into every certificate it issues.

A revocation has no effect on software that never fetches the list, and software that does fetch it rejects every certificate below a CA whose list has expired. So a CA needs both an address that will keep working and a list that is kept current.

Before you start #

  • Sign in as a member of Administrators.
  • Choose a host name for the address that will outlive this machine, such as pki.home, and make it resolve to this machine. The address is written into each certificate when it is issued, so changing it later leaves every certificate already issued pointing at the old one.
  • Make sure the pkid and pki-httpd services are installed, and run pki setup, which reserves TCP port 80 for pki-httpd.

Give each CA an address #

  1. Give a CA its address when you create it, with --crl:

    pki ca create "Home Root" --root --key-file /media/usb/home-root.key \
      --crl http://pki.home/crl/home-root.crl
    pki ca create "Home Issuing" --issuer "Home Root" \
      --template Server --template Device \
      --crl http://pki.home/crl/home-issuing.crl
    

    The root's address goes into the certificates the root signs, so the issuing CA's certificate carries it, and the issuing CA's address goes into the certificates it issues.

  2. For a CA that exists already, set its address with ca set. Only certificates issued afterward carry it:

    pki ca set "Home Issuing" --crl http://pki.home/crl/home-issuing.crl
    

pki-httpd serves each list at the path of its address, so http://pki.home/crl/home-issuing.crl is served as /crl/home-issuing.crl. Use letters, digits, ., -, _, and ~ in each part of the path.

Keep each list current #

A CA whose key pkid keeps, such as the issuing CA, looks after its own list: pkid signs a new one after every revocation and at half each list's lifetime, which is 7 days unless you change it.

A CA whose key is in a sealed file, such as an offline root, can sign only with its passphrase, so you renew its list by hand. Its lists last 180 days.

  1. Mount the media holding the root's key.

  2. Sign and publish a new list:

    pki ca publish-crl "Home Root"
    

    pki asks for the root key's passphrase.

Do this after the root revokes anything, and well before its list expires: pki ca list flags a list that expires within 30 days, and pkid emits a pkid.crl.expiring event each day until it is renewed.

To change how long a CA's lists last:

pki ca set "Home Root" --crl-lifetime 365

In the Certificate Authority window, a CA's page shows its latest list and when it expires, and Publish Now signs a new one, asking for the key's passphrase if it is sealed. The overview lists each list that is due or has expired.

Check the result #

List the CAs and when their lists expire:

pki ca list

Then fetch a list from another machine, such as with curl, and check it names the CA:

curl -o home-issuing.crl http://pki.home/crl/home-issuing.crl
openssl crl -inform DER -in home-issuing.crl -noout -issuer -nextupdate

Serve on another port #

If another service already serves port 80, pki setup warns that the port is reserved for it. Choose another port for pki-httpd, such as 8080, and reserve it:

pki setup --http-port 8080

Restart pki-httpd, and give each CA an address with that port, such as http://pki.home:8080/crl/home-issuing.crl. In the Certificate Authority window, change Revocation List Port on the overview, which restarts pki-httpd for you. pki-httpd(8) describes the service.

Peios Learn — documentation for Peios software.

Built with Trail.