Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions crates/dg/src/auth/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ async fn list(ctx: &Ctx) -> Result<()> {
/// id, so the words alone recover it. One identity update signed by the master key.
///
/// Only a master identity that carries its words can do this: the private half must be
/// recoverable, and `dg` keeps nothing but limited keys (an ENCRYPTION key is not one). Readers
/// (`git clone`, `dg`) need the key's private half in the identity they sign with: sign in with
/// the full identity for private repositories (`dg auth login --full-key`), or keep the words'
/// file, which now derives it.
/// recoverable. Readers (`git clone`, `dg`) need the key's private half in the key source they
/// sign with: `dg auth login` again stores it beside a limited key (QW2-004), and the words'
/// file now derives it.
async fn add_encryption(
ctx: &Ctx,
client: &forge_core::platform::PlatformClient,
Expand Down Expand Up @@ -214,7 +213,10 @@ async fn add_encryption(
"purpose": "ENCRYPTION",
"derived": true,
}),
|| println!("✓ added ENCRYPTION key #{added}; the recovery words re-derive it"),
|| {
println!("✓ added ENCRYPTION key #{added}; the recovery words re-derive it");
println!(" to use it from this computer: `dg auth login <identity file>` (or --mnemonic) stores it beside a limited key");
},
);
Ok(())
}
Expand Down Expand Up @@ -259,16 +261,17 @@ async fn add(ctx: &Ctx, args: &AddArgs) -> Result<()> {
ctx.confirm_or_cancel("Add the key?")?;
// The key this computer signs with now is replaced by default: otherwise it would stay live
// on chain with nothing holding it. `--replace` names another one; `--keep-current` keeps it.
let identity = client.fetch_signer(&master).await?;
let replace = match args.replace {
Some(id) => Some(id),
None if args.keep_current => None,
None => {
let identity = client.fetch_signer(&master).await?;
identity
.signing_key_id(&current, ctx.network())
.filter(|id| identity.is_limited_key(*id))
}
None => identity
.signing_key_id(&current, ctx.network())
.filter(|id| identity.is_limited_key(*id)),
};
// The encryption keys the key in use holds are kept too, whatever the master source holds.
let encryption =
super::encryption_to_store(ctx, &args.storage, &identity, &[&master, &current]);
let (id, stored) = super::register_and_store(
ctx,
&client,
Expand All @@ -277,8 +280,10 @@ async fn add(ctx: &Ctx, args: &AddArgs) -> Result<()> {
replace,
&checked,
args.storage.insecure_plaintext,
&encryption,
)
.await?;
let kept: Vec<u32> = encryption.iter().map(|k| k.id).collect();
super::store::set_default(ctx, &master.identity_id, &stored.source())?;
ctx.emit(
super::group::with_group_fields(
Expand All @@ -288,12 +293,14 @@ async fn add(ctx: &Ctx, args: &AddArgs) -> Result<()> {
"budgetCredits": spec.budget_credits,
"expiresAt": spec.expires_at_ms,
"storedAt": stored.describe(),
"encryptionKeyIds": kept,
"replacedKeyId": replace,
}),
Some(&checked),
),
|| {
println!("✓ limited key #{id} added; this computer now signs with it");
super::print_kept_encryption(&kept);
println!(" stored in {}", stored.describe());
if let Some(old) = replace {
println!(" key #{old} disabled");
Expand Down
Loading
Loading