Recover after a lost key

Recover after a lost key

This guide replaces the key of a ward that has lost every key it held. The ward's guardians approve an update that installs a new key. The lost key is not needed.

Background

An update needs a proof from every key it installs, and either one current key or guardians per policy.recovery (REQ-7-6). If the ward still holds one of its keys, that key approves the update and no guardian is needed. An identity can list up to 8 keys (REQ-6-1), so a second key kept apart from the first turns a lost key into an ordinary rotation. If the ward holds no key and has no guardian, nothing can recover it.

policy.recovery defaults to "majority" (REQ-6-11). With two or more guardians, any setting other than "any" needs at least two approvals (REQ-6-8).

Before you need it: name a guardian

A guardian is an identity named in the ward's guardians (Section 3). It can be an identity you control yourself, such as one whose key you keep offline and use for nothing else.

  1. Create the guardian with a self-held key:

    did-guardian create alice-cold --registrar example.com
    

    Do not use register for this. register creates an identity whose key the registrar holds.

  2. Add it as the ward's guardian. If the ward has a self-held key and no guardians yet:

    did-guardian guardian add did:guardian:example.com:alice did:guardian:example.com:alice-cold --ward-key <alice-key-label> --guardian-key example.com:alice-cold
    

    You can also name the guardian when you create the ward, with create alice --registrar example.com --guardian <did> --guardian-key <label>. A ward whose key the registrar holds adds a guardian with guardian adopt and guardian confirm-adopt. Both steps need a login session, so that guardian must also have a registrar-held key.

What you need

  • The ward's DID, for example did:guardian:example.com:alice.
  • Enough guardians to meet the ward's policy.recovery.
  • For each guardian, either its key saved locally or its login secret on the ward's registrar.

Recover with one guardian key

Use this when one approval is enough: the ward has one guardian, or its policy.recovery is "any". The guardian's key must be saved locally.

  1. Preview the operation:

    did-guardian guardian recover did:guardian:example.com:alice did:guardian:example.com:bob --guardian-key bob
    

    The command prints the signed update and does not submit it. The new key in a preview is a throwaway and is not saved.

  2. Submit it:

    did-guardian guardian recover did:guardian:example.com:alice did:guardian:example.com:bob --guardian-key bob --submit
    

    The command generates a new key and saves it on your machine as <ward-did>-recovered-<timestamp>. It prints the label and the public key. To install a key you already hold, pass --new-key <label>.

  3. Check the result. The command prints Submitted and accepted. If it prints Rejected: and exits with status 1, the policy needs more approvals. Follow Recover a self-held ward with several guardians.

  4. Give the new key to the ward over a secure channel. It is now the ward's only key.

Recover a ward whose key the registrar holds

Use this when the registrar holds the ward's key. The registrar generates the ward's new key and keeps holding it, so the ward keeps its account (REQ-10-13). Each guardian signs through its own login session.

  1. Log in as a guardian:

    did-guardian login did:guardian:example.com:bob --login-secret <bob's secret>
    
  2. Start the recovery:

    did-guardian guardian recover did:guardian:example.com:alice did:guardian:example.com:bob --held
    

    If this one approval meets policy.recovery, the command prints:

    Finalized -- did:guardian:example.com:alice has a new, registrar-generated key.
    
    New login secret for did:guardian:example.com:alice (shown once -- copy it now and pass it to the owner out of band):
    <secret>
    

    Otherwise it prints a pending id. A ward has at most one open recovery of this kind. Starting a new one replaces the old one.

  3. Have each other required guardian log in as itself and sign:

    did-guardian login did:guardian:example.com:carol --login-secret <carol's secret>
    did-guardian operation sign <pending-id> --registrar example.com --held
    

    A guardian with a local key signs with --key <label> instead of --held. The command checks the proposal against the ward's log, shows the operation, and asks for confirmation. The guardian whose signature completes the recovery receives the new login secret.

  4. Pass the new login secret to the ward over a secure channel.

Recover a self-held ward with several guardians

Use this when the ward held its own key and the policy needs more than one approval, or when a guardian's key is held by a registrar. Do not run key take-custody on a guardian to get a local key. Taking custody replaces the guardian's key, and the ward's entry still names the old one, so the registrar rejects that guardian's approvals until the entry is updated (Section 12).

  1. Generate the new key for the ward:

    did-guardian key generate alice-recovered
    
  2. Write the update to a file, without proof. Set keys to the new public key. Copy services and alsoKnownAs from the ward's current state. Set prev to the hash of the last operation in the ward's log. If any guardian holds a local key, the preview from Recover with one guardian key prints this body: run it with --new-key alice-recovered and remove proof.

    1{
    2  "type": "update",
    3  "keys": ["<new public key>"],
    4  "services": [],
    5  "alsoKnownAs": [],
    6  "prev": "<hash of the last operation>"
    7}
    
  3. Propose it, signed by the new key:

    did-guardian operation propose did:guardian:example.com:alice --file update.json --key alice-recovered
    

    The command prints a pending id. The proposal expires after 7 days.

  4. Have each guardian sign. A guardian with a local key runs did-guardian operation sign <pending-id> --registrar example.com --key bob. A guardian whose key the registrar holds logs in and runs the same command with --held in place of --key bob.

  5. When enough guardians have signed, the registrar accepts the operation, and the CLI prints Finalized and accepted. To check progress, run did-guardian operation status <pending-id> --registrar example.com.

  6. Give the alice-recovered key to the ward over a secure channel.

Login sessions after a recovery

Accepting an update that changes keys ends every session of the ward on its registrar and invalidates its login secret. If the registrar holds the ward's key, it issues a new login secret in the same step and returns it once, to the request that completed the operation. The CLI prints it. When the ward next logs in, the account dashboard asks it to set a password, and the issued secret stops working once it does.

If the key was stolen

Whoever holds a stolen key can act as the identity until the guardians replace the key (Section 12). Operations already accepted stay in the log and cannot be undone.

The registrar accepts one operation for each prev (REQ-10-8). The holder of the stolen key can keep submitting operations, so a recovery prepared against an older prev is rejected. If that happens, prepare the recovery again against the current log and collect the approvals again. This delays recovery for as long as the holder keeps submitting.

After recovering

  • The ward's guardians, successor and policy do not change. guardian recover copies services and alsoKnownAs forward unchanged (REQ-7-11).
  • Confirm the result with did-guardian resolve did:guardian:example.com:alice.
  • Add a second key or a second guardian so the next lost key needs less help.