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

Crypto Policy

Single-page view · as markdown

How Crypto Policy Works

Peios / Using Peios / Crypto Policy

Peios applies one crypto policy to every program on the machine that uses libpcrypto or libpssl, its libraries with OpenSSL's API. The policy decides which algorithms a program can use, records the use of weak ones, and lets named programs keep using an algorithm that they need and that the policy would otherwise refuse.

The policy is configured under Machine\System\Cryptography. cryptod, the crypto policy service, publishes it as a file that the libraries read, and records what programs report of their weak cryptography.

Grades #

Each use of cryptography is graded as an entry: an algorithm and the operation it's used for, such as md5.hmac for HMAC-MD5 or md5.digest for an MD5 digest. The same algorithm can have different grades for different operations. MD5 is broken as a digest, but HMAC-MD5 has no practical attack.

Grades run from U to A:

GradeMeaning
UPractically broken, or forbidden by current standards
DNo practical break, but under 112-bit security or deprecated
C112-bit security
B128-bit security
A192-bit security or more

Separately, each entry records whether FIPS 140-3 approves it. FIPS approval isn't a grade: FIPS approves some entries below A, such as HMAC-SHA-1, and doesn't approve some A-grade ones.

/usr/share/peios-crypto/algorithms.tsv lists every entry, with its grade and whether FIPS approves it.

A few entries are on the floor: they're refused under every policy, and no exception can allow them. The floor holds ciphers and TLS suites that encrypt nothing, the 40-bit export-grade RC2 cipher, RSA keys and Diffie-Hellman parameters under 1024 bits, and ECDSA signing with a fixed nonce, which gives away the private key.

Thresholds #

The policy has two thresholds:

  • Reject: entries below this grade are refused. By default it's U, so only the floor is refused.
  • Warn: entries below this grade are allowed, but their use is recorded. By default it's C, so the use of anything graded U or D is recorded.

Each can also apply to every entry FIPS doesn't approve, whatever its grade. Turning that on for Reject doesn't make the machine operate in a FIPS-approved mode, because the libraries' module isn't validated.

A refused call fails as if the algorithm weren't supported. A few low-level functions can't report failure, such as SHA256 and MD5_Init, so a program that calls one for a refused entry ends. Before raising the Reject threshold, find out what would stop working: see Configuring Crypto Policy.

Exceptions #

An exception lets particular programs use particular entries: a RADIUS server that must use HMAC-MD5 because the protocol requires it, for example. Each exception is a key under Machine\System\Cryptography\Exceptions, named Owner.Purpose, such as Radius.PacketAuth. It names the entries it allows, and has a security descriptor, ProgramSecurity, granting the programs that can use it.

Packages add the exceptions their software needs when they install, and remove them when they uninstall.

Important

An exception applies to a program, not to whoever it's acting for. ProgramSecurity is checked against each process's primary token, the identity the program runs as. Impersonation is ignored. This is unusual on Peios, where access is normally decided by whose behalf a thread is acting on.

An exception answers "which software needs this algorithm". If it followed impersonation, a service would lose its exception while it served a client, and a client could weaken a service's cryptography.

Grant a service's own SID, S-1-5-80-..., to except one service. A user or group SID is accepted, but it excepts every program that runs as that user or group, including ones that don't need the algorithm.

An exception allows an entry the Reject threshold refuses only while Exceptions\AllowExceptionsToReject is 1, its default. When it's 0, exceptions only stop warnings. An exception never allows an entry on the floor.

When changes apply #

cryptod publishes the policy when it starts, and again a moment after Machine\System\Cryptography changes. Each process reads the policy once, at its first use of the libraries, and keeps it for as long as it runs.

So a change applies to processes started after it's published. A service that's already running keeps the policy it started with until it's restarted. Exceptions work the same way, so a service doesn't lose one partway through a request.

cryptod also keeps a copy of the policy that survives a reboot. A process that starts before cryptod reads that copy. A process uses Peios's built-in defaults only on a machine where cryptod has never run, or if it can't use either copy.

What's recorded #

The libraries report to cryptod, and cryptod records each report as an event:

  • cryptod.algorithm.warned: a process's first use of each entry below the Warn threshold.
  • cryptod.exception.used: a process's first use of each exception, whether or not the exception warns. An audit can always find the weak cryptography in use.
  • cryptod.policy.failed: a policy cryptod couldn't publish as written, or one a process couldn't use.
  • cryptod.policy.applied: each policy cryptod publishes.

Each process reports each use once, so the records show which programs use what without one for every call. A process is named by the identity and process ID the kernel recorded when it connected to cryptod.

cryptod also keeps a summary of what's been used, and by whom, since it started. See the cryptod reference.

When something is wrong #

cryptod checks the policy when it publishes it:

  • If a setting such as a threshold can't be read, cryptod keeps the policy it last published, and records cryptod.policy.failed. Falling back to defaults could loosen a policy an administrator had tightened.
  • If an exception can't apply as written, cryptod drops that exception alone, so it allows nothing, publishes the rest, and records why. A misspelled entry, such as md5.hmca, is the usual cause.

A process uses a copy of the policy only if SYSTEM or cryptod owns it and nobody else can change it. Otherwise it uses the next copy, or the defaults, and reports it.

Limits #

  • A process that starts before cryptod is listening can't report, so its first uses aren't recorded. It still applies the policy.
  • A report is attributed to the identity of the reporting thread when it connected. A thread that was impersonating a user then is recorded as that user. The process ID still identifies the process.
  • A process that replaces its primary token keeps the exceptions of the token it started with.
  • Policy is applied to programs that use libpcrypto and libpssl. A program with cryptography of its own, or a statically linked copy of another library, is outside it.

Configuring Crypto Policy

Peios / Using Peios / Crypto Policy

Tighten the crypto policy in steps: find what would stop working, give the services that need a weak algorithm an exception, then raise the threshold. Check the result after each change.

The regman entry for Machine\System\Cryptography owns the complete configuration reference. evman cryptod describes the records cryptod writes.

Before you start #

  • Check that cryptod is running: svctl status cryptod.
  • Obtain write access to Machine\System\Cryptography. SYSTEM and Administrators have it.
  • Obtain read access to cryptod's events in eventd.
  • Allow time for the machine to run its normal workload under the current policy, so that the records show everything it uses.

Find the weak cryptography in use #

  1. List the programs that used an entry below the Warn threshold:

    evctl 'EVENTS cryptod.algorithm.warned SINCE 7d ago'
    

    Each record names the entry, its grade, and the process that used it.

  2. List the uses of a grade that a new threshold would refuse. For example, before refusing everything below C:

    evctl 'EVENTS cryptod.algorithm.warned SINCE 7d ago WHERE object.crypto-algorithm.grade == "U"'
    evctl 'EVENTS cryptod.algorithm.warned SINCE 7d ago WHERE object.crypto-algorithm.grade == "D"'
    
  3. List the exceptions in use, and by which programs:

    evctl 'EVENTS cryptod.exception.used SINCE 7d ago'
    

Every program in these results would fail to use its entry under the new threshold, unless it has an exception. A program that calls a low-level digest function, such as SHA256 or MD5_Init, for a refused entry ends.

Let a service keep an algorithm #

Give an exception to a service that must keep using an entry, such as a RADIUS server that needs HMAC-MD5. Grant it to the service's own SID, so that no other program gets it.

  1. Find the service's SID. Read its main process ID from svctl status <service>, then list that process's token groups:

    token groups --pid <pid>
    

    The service SID is the group that begins S-1-5-80-.

  2. Create the exception, named for its owner and purpose. This one allows HMAC-MD5 for one service:

    reg set -p Machine/System/Cryptography/Exceptions/Example.LegacyRadius \
        Algorithms multi:md5.hmac
    reg set Machine/System/Cryptography/Exceptions/Example.LegacyRadius \
        ProgramSecurity 'sz:O:SYG:SYD:(A;;0x1;;;S-1-5-80-<service SID>)'
    

    Name each entry as an algorithm and an operation. md5.hmac doesn't allow md5.digest. The descriptor needs an owner, O:SY here, as an access check refuses one without, and a DACL granting the Use right, 0x1.

  3. Check that cryptod published it, and didn't drop it:

    evctl 'EVENTS cryptod.policy.* SINCE 10m ago'
    

    A cryptod.policy.failed record naming the exception says why it was dropped. A dropped exception allows nothing.

  4. Restart the service, so that it reads the new policy:

    svctl restart <service>
    

Raise the reject threshold #

  1. Set the lowest grade the policy allows. This refuses everything graded U or D:

    reg set Machine/System/Cryptography/Reject MinimumGrade sz:C
    
  2. Check that cryptod published the policy, as above. If a cryptod.policy.failed record says a setting is invalid, cryptod kept the previous policy: correct the value and check again.

  3. Restart the services that should take up the new policy. Processes started from now on use it; running ones keep the policy they started with.

To refuse everything FIPS 140-3 doesn't approve, whatever its grade, set Reject\FIPS to 1:

reg set Machine/System/Cryptography/Reject FIPS dword:1

Check the result #

Watch for refusals and new warnings after the change:

evctl 'EVENTS cryptod.* SINCE 1h ago'

A program refused an algorithm reports an error from its own calls, such as a failed TLS handshake with an insufficient_security alert. If a service stops working, give it an exception or lower the threshold, then restart it.

To undo a change, set the value back, or delete it to return to Peios's default, then restart the affected services:

reg del Machine/System/Cryptography/Reject MinimumGrade

cryptod Reference

Peios / Using Peios / Crypto Policy

cryptod compiles Machine\System\Cryptography into the policy file that libpcrypto reads, and records what processes report of their weak cryptography. Its configuration is documented by regman, and its records by evman.

Service #

PropertyValue
Servicecryptod
Program/usr/sbin/cryptod
IdentityService: its own SID, S-1-5-80-2691053820-547492864-353945177-641201782-1210658655
PrivilegesSeChangeNotifyPrivilege, SeAuditPrivilege
ReadinessNotify, once it has published the policy and is listening
Event rootcryptod

cryptod must run as its own service SID. Processes trust a policy copy only if SYSTEM or that SID owns it, and a file cryptod writes is owned by its token's user.

Files and sockets #

PathWhat it is
/run/cryptod/policyThe current policy
/var/state/cryptod/policyThe policy kept across reboots, for processes that start before cryptod
/run/cryptod/reportWhere processes report, a SOCK_SEQPACKET socket everyone can connect to
/run/cryptod/postureWhere the posture is served, a SOCK_STREAM socket for SYSTEM and Administrators
/usr/share/peios-crypto/algorithms.tsvEvery graded entry, which cryptod checks policies against

A process reads /run/cryptod/policy, then /var/state/cryptod/policy, then uses Peios's defaults: refuse only the floor, warn below C, FIPS ignored, exceptions allowed to override refusal. It moves to the next if a copy is absent or can't be used, and reports why.

cryptod writes each copy whole: to a new file beside it, which it gives the copy's descriptor, then renames over the copy. Each copy's descriptor is protected, grants full access to SYSTEM and cryptod, and grants reading to Everyone, S-1-15-2-1 and S-1-15-2-2, so that confined applications can read it too. Both directories grant the same readers traversal.

algorithms.tsv has one line per entry: its identifier, its grade or floor, and 1 or 0 for whether FIPS 140-3 approves it, separated by tabs. cryptod doesn't start without it.

Trusting a copy #

A process uses a copy only if its descriptor shows that nobody but SYSTEM and cryptod could have written it:

  • Its owner is SYSTEM or cryptod's SID.
  • It has a DACL. A copy with none lets everyone change it.
  • No entry of the DACL grants anyone else a right that could change the file: writing or appending data, writing extended attributes or attributes, deleting it, changing its descriptor or owner, or a generic or maximum-allowed right that includes them. Entries that deny, and entries that only pass to children, are ignored.

The check fails closed. A descriptor over 4 KiB, or an entry granting CREATOR OWNER a right to change the file, is refused as insecure, even where it would be harmless. A process that refuses a copy reports copy-insecure.

The policy file #

The file is version 1 of a binary format, at most 1 MiB less one byte. Integers are big-endian. A process reads the whole file before using any of it, and refuses a file of another version.

FieldSizeMeaning
Magic8 bytesPEIOSCPL
Version21
Reject below1A grade: 0 for U, then 1 to 4 for D to A
Warn below1A grade, as above
Flags10x01 reject non-FIPS, 0x02 warn non-FIPS, 0x04 exceptions can override refusal
Exception count2The number of exceptions that follow

Each exception follows in turn:

FieldSizeMeaning
Name1-byte length, then the nameOwner.Purpose
Flags10x01 warn about its use
ProgramSecurity2-byte length, then the descriptorA self-relative security descriptor
Entry count2The number of entries that follow
Entrieseach a 1-byte length, then the identifierSuch as md5.hmac

cryptod resolves Exceptions\Enabled, WarnByDefault and WarnAlways as it compiles, so the file holds only what applies. It leaves out exceptions it dropped. A process ignores an entry it doesn't grade, and any entry on the floor.

Reports #

A process connects to /run/cryptod/report, sends one datagram, and closes. It doesn't wait, and doesn't retry: a report that can't be sent is lost. A datagram has four fields:

FieldSizeMeaning
Kind11 warned, 2 exception used, 3 policy copy unusable
Problem1For kind 3, why; otherwise 0
Entry1-byte length, then the identifierFor kinds 1 and 2; otherwise empty
Exception1-byte length, then the nameFor kind 2; otherwise empty

The problems are 1 unreadable, 2 insecure, 3 malformed, 4 an unknown version, and 5 the process's token unreadable.

cryptod takes the sender's identity from the connection: the user of the token the kernel captured at connect, and the process ID. Nothing in the datagram names the sender. cryptod discards a datagram that libpcrypto couldn't have sent, such as one naming an entry it doesn't grade.

Rates #

cryptod relays at most 512 reports at once from each user, then 8 a second. It writes its records at up to 80 a second, below the lowest rate KMES allows a process without SeTcbPrivilege, and queues up to 4096 records when more arrive. A full queue drops its oldest standard record to make room, and turns a record away only when everything it holds is essential. The posture counts what's turned away.

Posture #

Connecting to /run/cryptod/posture returns one MessagePack map, then the connection closes. It describes the policy in force, and what's been used since cryptod started:

KeyValue
policyThe thresholds, flags, and exceptions in force; dropped, the exceptions dropped and why; defaults; and last-failure, a compile that failed since, or nil
fipsrequested; approved-mode, always false while the module isn't validated; reasons; and exceptions-admitting-non-fips
useOne map per user SID: the exceptions it used, by entry, and the entries it was warned about, each with a count of reports
turned-awayCounts of reports rate-limited, unattributed, and invalid, and overflow: what didn't fit the queue or a table

The posture is held in memory, so it starts again when cryptod restarts. Its tables are bounded, at 4096 users and 256 exceptions each.

Peios Learn — documentation for Peios software.

Built with Trail.