modus
Menu
On this page

The entry unlock

The source src/modules/system/unlock built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.

The unlock of a named principal: the process that keeps the record of a named principal in its private store, and asks for its passphrase in its window.

A principal is a key pair: an Ed25519 key, to sign grants, and an X25519 key, to unlock documents. Its record is the file "principal" of the store of this process: its name, its two public keys, and its two secret keys sealed with ChaCha20-Poly1305 under a key that Argon2id derives from the passphrase and a salt (src/library/modus/principals). A wrong passphrase gives another key, and the seal does not open: no passphrase and no hash of it is kept or compared.

The root service starts this process at boot. With no file it stops at once: the machine runs as principal 0 only, with no unlock. With a file it gives the public part of the record to the root service and asks for the passphrase; when the seal opens, it tells the root service, which starts the session of the principal, and it stops. With that command it gives the root service one key: the key of the tag of the disk grant table of the principal, which keyed BLAKE2b gives from the secret unlock key. The secret keys are then erased. The root service starts it again after a lock. To create a principal, the root service starts it with a name: the passphrase is typed two times, the keys are made from the generator of the process, and the session starts.

The passphrase shows as dots. On a machine with the TPM service and Secure Boot on, the file of a new principal has the form sealed by the TPM : the TPM releases a secret only to the system of the seal and to the authorization value that the passphrase gives, and counts each wrong passphrase; the secret and the passphrase together open the keys. A recovery key, shown one time at the creation, opens a copy of the keys when the TPM refuses or when the passphrase is lost; a new passphrase then seals them again. With no TPM service, or with Secure Boot off, the keys are sealed under the passphrase alone: the strength of that file is the strength of the passphrase against Argon2id with 19 MiB and 2 passes, on a copy of the disk.

It also keeps the record of the machine key, the object "machine" of its store, in one of three forms :

  • the machine key, 32 random bytes, sealed under the machine passphrase. With the TPM service and Secure Boot on, the TPM seals it with the passphrase, as the keys of a named principal: the TPM counts each wrong machine passphrase, another system opens nothing with the right one, and a recovery key, shown one time, opens a copy. Else the passphrase alone seals it. With either record, and when the root service does not hold the key yet, it asks for the machine passphrase first. The root service starts it with the mode Unlock_Mode.Set_Machine_Passphrase after machine_passphrase();
  • the machine key sealed by the TPM service to PCR 7 and PCR 11, with a copy under a recovery key. At each start the TPM releases the key with no typing; when it refuses (another system, another machine, no TPM), the window asks for the recovery key, and the key is sealed again to the system that runs. The root service starts it with the mode Unlock_Mode.Seal_Machine_Key after machine_seal(): the window shows the recovery key one time.

When a record gives the machine key, it gives the root service the key of the tag of the disk grant table of principal 0, which the machine key gives, and erases the other keys: the root service then needs no key that opens a seal.

What it is for. It separates who holds the machine (principal 0) from a named principal whose processes run in a session of their own, with stores of their own. It is the only process that the root service believes when it says that a passphrase opened a seal.

Start: the root service starts it; no line of the console does.

  • At boot, two times on a machine with a TPM service and a data disk: first before the start policy, with no window, to unseal the machine key (Unlock_Mode.Machine_Key_Without_Window), then as a row of the start list; and again after lock() in the console.
  • With a name, after principal_create("alice") in the console: the window asks for the passphrase two times.
  • During a session, after passphrase_change() or recovery_key_change() in a console of the session: the window asks for the current passphrase, then for the new one, or shows the new recovery key.

A lock stops it, whatever its mode: no window that a session asked for outlives the session.

Grants, as the root service gives them:

  • Store: its private store, which holds the file "principal".
  • Principals: a ring to the root service for Principal_Record, Principal_Unlock, Machine_Key and Principal_Change_End only. No other process can send these commands, so no other process can start a session or give the key of a disk grant table.
  • Tpm: the ring and the region of the TPM service, when the system is measured into a TPM: Seal, Unseal, and the read and the write of the TPM pins of its record and its file (modus:contract/tpm_service, pins.odin).
  • Versions_Erase: the storage service lets it end the versions of the objects of its own store, with zeros over their blocks (erase_versions). No other process has it.

What a reader sees: a window with the name of the principal and the passphrase as dots; Enter tries it, Backspace removes one byte, Escape clears it. The log has, for example:

  • unlock: principal 1 "alice" is locked: its passphrase opens its session;
  • unlock: the passphrase of principal 1 "alice" opens its seal; ...;
  • unlock: the passphrase of principal 1 "alice" is wrong: ...;
  • unlock: the machine passphrase opens the machine key; ...;
  • unlock: the TPM releases the machine key: the system is the system of the seal; ....

What it does not prove: the secret keys sign and decrypt nothing yet; the unlock key only gives the key of the tag of the disk grant table. With the file under the passphrase alone, a wrong passphrase costs one derivation of Argon2id, and nothing counts or slows the tries.

The design:.

See: Principals, Principals: The keys sealed by the TPM, Principals: A change of the passphrase, Principals: The unlock and the lock

unlock module with an entry

Hash
09ffba8cb301c7e19ddb4123bcfdb89abb7d8ab1a403d1e1a1ef15ae2d39b760
Size
856843 bytes
Exports
0
Imports
2
Imported by
0
License
MIT

The unlock of a named principal: the process that keeps the record of a named principal in its private store, and asks for its passphrase in its window

FactValue
KindModules with an entry
Sourcesrc/modules/system/unlock
Boot imageyes: in the boot image, 856843 bytes in this build
Build settings
  • DRAWING_THROUGH_MODULE=true
Imports
Imported bynone

Neighbours

What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.

Exports

ExportWhat it does
entry()The entry of unlock: it reads or creates the record of a named principal, asks for the passphrase, and stops when the session starts

entry

entry()

The entry of unlock: it reads or creates the record of a named principal, asks for the passphrase, and stops when the session starts.

The entry takes its random generator, opens the ring to the root service and its private store; with no ring it stops with Refused, with no store with Failed. A mode word that names no mode, and a request that the machine cannot take (a record that exists already or cannot be read, no TPM service, Secure Boot off, a refused name), stop it with Refused. Then:

  • Create (the context value VALUE_MODE is Unlock_Mode.Create_Principal): it checks the name of the new principal and asks for a passphrase of 8 bytes at least.
  • Set the machine passphrase (Unlock_Mode.Set_Machine_Passphrase): with no record "machine", it asks for a passphrase two times, makes the machine key, seals it, and gives the root service the key of the tag. With the TPM service and Secure Boot on, the TPM seals the key with the passphrase, and the window shows a recovery key until Enter, before the record is written.
  • Seal the machine key (Unlock_Mode.Seal_Machine_Key): with the TPM service and no record "machine", it makes the machine key and a recovery key, has the TPM service seal the key, and shows the recovery key until Enter; then it writes the record and gives the root service the key of the tag. Each window that shows a new recovery key writes its record or its file only after Enter: a stop before it (a lock, a close) leaves the disk as it was.
  • Change the passphrase (Unlock_Mode.Change_Passphrase) or make a new recovery key (Unlock_Mode.New_Recovery_Key) of the principal whose session runs: it reads the file, asks for the current passphrase, which opens the keys as an unlock does, then for the new passphrase two times, or shows the new recovery key until Enter. Enter with nothing ends the change. A file that cannot take the change (a new recovery key for the form under the passphrase alone, no TPM service for the form sealed by the TPM, a new seal with Secure Boot off) stops it with Refused before its window opens.
  • Unlock: it reads the file "principal", and the record "machine" unless the mode is Unlock_Mode.Unlock_Machine_Key_Held. With a record under a machine passphrase it asks for the machine passphrase first; when the TPM seals the key with it and refuses for another cause than a wrong passphrase, it asks for the recovery key, then for a new machine passphrase that the TPM seals the key again with. With a record sealed by the TPM it asks the TPM service for the key, and asks for the recovery key only when the TPM refuses; after a recovery it seals the key again to the system that runs. When the file or the record opened, and after each write of a new secret, it asks the store to erase their versions, so an old secret opens no version of them. Enter with nothing skips either. With no record to ask for and no file it writes "unlock: no named principal: the machine runs as principal 0, with no unlock" and stops with Done. A file that does not decode stops it with Refused; a record that the root service refuses, with Failed.

It reserves the memory of Argon2id (about 19 MiB), opens its window, and reads keys until the passphrase opens the seal and the root service starts the session. It then stops with Done. A wrong passphrase keeps the window open.

See: The erase of the versions of an object in the repository

Form
The entry of the module: one parameter, an address, fixed by the contract.
Source
src/modules/system/unlock/main.odin:2776

Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).

What the root service gives it

WhatValueAs the root service says
GrantsThe records of the named principals in its private store, the passphrase in its window, the commands of the principals, and the ring of the TPM service, which seals the machine key to the measure of the system. It erases the versions of the file of a principal after a change of a secret, so an old secret opens no version. See: Principals, Storage: The erase of versions
Other terms of its start grant setnone
Budget that it asks for
  • working memory pages 6119
  • pages of its threads 72
  • pages of the pictures of its window 732
  • pages of the module and its imports from the files of the build
  • processes 1
  • threads 1
The blocks of Argon2id, 19 MiB (4864 pages) (src/library/modus/principals, DERIVATION_MEMORY_PAGES), and the rest: 5765 pages. And the glyph memory of the copy of the text rendering of the drawing module, which draws its text: 354 pages (display.TEXT_MEMORY_PAGES). 5765 + 354 = 6119.

The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).

Principal_Record type of the package root

Principal_Record :: struct {...}

A type with no comment in its source.

src/modules/system/root/principals.odin:38