@mp-lb/forum-cli 0.1.50 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +568 -21
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2103,7 +2103,7 @@ var prepareCheckoutIgnore = async ({
|
|
|
2103
2103
|
// src/index.ts
|
|
2104
2104
|
import { realpathSync, watch as watch2 } from "fs";
|
|
2105
2105
|
import path27 from "path";
|
|
2106
|
-
import { lstat as lstat6, mkdir as mkdir7, readFile as
|
|
2106
|
+
import { lstat as lstat6, mkdir as mkdir7, readFile as readFile11, rm as rm8, writeFile as writeFile6 } from "fs/promises";
|
|
2107
2107
|
import { createInterface as createInterface2 } from "readline/promises";
|
|
2108
2108
|
import { pathToFileURL } from "url";
|
|
2109
2109
|
|
|
@@ -17450,6 +17450,244 @@ var decryptTextForUser = async ({
|
|
|
17450
17450
|
// ../../packages/encryption/src/keyBinding/formatEncryptionFingerprint.ts
|
|
17451
17451
|
var formatEncryptionFingerprint = (fingerprint) => (fingerprint.toUpperCase().match(/.{1,4}/g) ?? []).join(" ");
|
|
17452
17452
|
|
|
17453
|
+
// ../../packages/encryption/src/rekey/resolveKeepFingerprint.ts
|
|
17454
|
+
var resolveKeepFingerprint = (recipientId, candidate) => encryptionFingerprintSchema.safeParse(recipientId).success ? recipientId : candidate.trustedFingerprint ?? null;
|
|
17455
|
+
|
|
17456
|
+
// ../../packages/encryption/src/rekey/planRecipientRekey.ts
|
|
17457
|
+
var planRecipientRekey = ({
|
|
17458
|
+
candidates,
|
|
17459
|
+
recipients,
|
|
17460
|
+
reissueRecipientIds = [],
|
|
17461
|
+
removeRecipientIds = []
|
|
17462
|
+
}) => {
|
|
17463
|
+
const known = new Set(recipients.map((recipient) => recipient.recipientId));
|
|
17464
|
+
for (const recipientId of [...removeRecipientIds, ...reissueRecipientIds]) {
|
|
17465
|
+
if (!known.has(recipientId)) {
|
|
17466
|
+
throw new Error(`Unknown encryption recipient: ${recipientId}`);
|
|
17467
|
+
}
|
|
17468
|
+
}
|
|
17469
|
+
const removed = new Set(removeRecipientIds);
|
|
17470
|
+
const reissued = new Set(reissueRecipientIds);
|
|
17471
|
+
for (const recipientId of removed) {
|
|
17472
|
+
if (reissued.has(recipientId)) {
|
|
17473
|
+
throw new Error(
|
|
17474
|
+
`Recipient ${recipientId} cannot be both removed and reissued.`
|
|
17475
|
+
);
|
|
17476
|
+
}
|
|
17477
|
+
}
|
|
17478
|
+
const candidateById = new Map(
|
|
17479
|
+
candidates.map((candidate) => [candidate.userEncryption.keyId, candidate])
|
|
17480
|
+
);
|
|
17481
|
+
const plan = [];
|
|
17482
|
+
const issues = [];
|
|
17483
|
+
for (const recipient of recipients) {
|
|
17484
|
+
const { label, recipientId } = recipient;
|
|
17485
|
+
if (removed.has(recipientId)) {
|
|
17486
|
+
plan.push({ action: "remove", recipientId });
|
|
17487
|
+
continue;
|
|
17488
|
+
}
|
|
17489
|
+
if (reissued.has(recipientId)) {
|
|
17490
|
+
plan.push({ action: "reissue", recipientId });
|
|
17491
|
+
continue;
|
|
17492
|
+
}
|
|
17493
|
+
const candidate = candidateById.get(recipientId);
|
|
17494
|
+
if (candidate) {
|
|
17495
|
+
const expectedFingerprint = resolveKeepFingerprint(
|
|
17496
|
+
recipientId,
|
|
17497
|
+
candidate
|
|
17498
|
+
);
|
|
17499
|
+
if (expectedFingerprint) {
|
|
17500
|
+
plan.push({
|
|
17501
|
+
action: "keep",
|
|
17502
|
+
expectedFingerprint,
|
|
17503
|
+
recipientId,
|
|
17504
|
+
userEncryption: candidate.userEncryption
|
|
17505
|
+
});
|
|
17506
|
+
} else {
|
|
17507
|
+
issues.push({
|
|
17508
|
+
...label ? { label } : {},
|
|
17509
|
+
reason: "public_key_unverified",
|
|
17510
|
+
recipientId
|
|
17511
|
+
});
|
|
17512
|
+
}
|
|
17513
|
+
continue;
|
|
17514
|
+
}
|
|
17515
|
+
issues.push({
|
|
17516
|
+
...label ? { label } : {},
|
|
17517
|
+
reason: recipient.wrappedDataKey.cipher === publicKeyCipher ? "public_key_unavailable" : "secret_not_retained",
|
|
17518
|
+
recipientId
|
|
17519
|
+
});
|
|
17520
|
+
}
|
|
17521
|
+
return { issues, plan };
|
|
17522
|
+
};
|
|
17523
|
+
|
|
17524
|
+
// ../../packages/encryption/src/rekey/assertCompleteRekeyPlan.ts
|
|
17525
|
+
var assertCompleteRekeyPlan = ({
|
|
17526
|
+
actorKeyId,
|
|
17527
|
+
plan,
|
|
17528
|
+
recipients
|
|
17529
|
+
}) => {
|
|
17530
|
+
const current = new Set(recipients.map((recipient) => recipient.recipientId));
|
|
17531
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17532
|
+
for (const entry of plan) {
|
|
17533
|
+
if (!current.has(entry.recipientId)) {
|
|
17534
|
+
throw new Error(`Unknown encryption recipient: ${entry.recipientId}`);
|
|
17535
|
+
}
|
|
17536
|
+
if (seen.has(entry.recipientId)) {
|
|
17537
|
+
throw new Error(
|
|
17538
|
+
`Recipient ${entry.recipientId} appears more than once in the rekey plan.`
|
|
17539
|
+
);
|
|
17540
|
+
}
|
|
17541
|
+
seen.add(entry.recipientId);
|
|
17542
|
+
if (entry.action === "keep" && entry.userEncryption.keyId !== entry.recipientId) {
|
|
17543
|
+
throw new Error(
|
|
17544
|
+
`Recipient ${entry.recipientId} cannot be kept under a different public key.`
|
|
17545
|
+
);
|
|
17546
|
+
}
|
|
17547
|
+
}
|
|
17548
|
+
const missing = [...current].filter((recipientId) => !seen.has(recipientId));
|
|
17549
|
+
if (missing.length) {
|
|
17550
|
+
throw new Error(
|
|
17551
|
+
`Rekey plan does not say what to do with recipient(s): ${missing.join(", ")}`
|
|
17552
|
+
);
|
|
17553
|
+
}
|
|
17554
|
+
if (!plan.some(
|
|
17555
|
+
(entry) => entry.action === "keep" && entry.recipientId === actorKeyId
|
|
17556
|
+
)) {
|
|
17557
|
+
throw new Error(
|
|
17558
|
+
"Rekey must keep your own access, otherwise nobody could save later versions."
|
|
17559
|
+
);
|
|
17560
|
+
}
|
|
17561
|
+
};
|
|
17562
|
+
|
|
17563
|
+
// ../../packages/encryption/src/rekey/generateFileKey.ts
|
|
17564
|
+
var generateFileKey = async () => crypto.subtle.generateKey({ length: 256, name: encryptedFileCipher }, true, [
|
|
17565
|
+
"decrypt",
|
|
17566
|
+
"encrypt"
|
|
17567
|
+
]);
|
|
17568
|
+
|
|
17569
|
+
// ../../packages/encryption/src/rekey/rekeyEncryptedPlainText.ts
|
|
17570
|
+
var keyBytes = async (key) => new Uint8Array(await crypto.subtle.exportKey("raw", key));
|
|
17571
|
+
var sameBytes = (left, right) => left.length === right.length && left.every((byte, i) => byte === right[i]);
|
|
17572
|
+
var rekeyEncryptedPlainText = async ({
|
|
17573
|
+
actorKeyId,
|
|
17574
|
+
actorUserKey,
|
|
17575
|
+
encryptedText,
|
|
17576
|
+
fileKey,
|
|
17577
|
+
plan,
|
|
17578
|
+
workspaceAccess
|
|
17579
|
+
}) => {
|
|
17580
|
+
const payload = parseEncryptedPlainTextPayload(encryptedText);
|
|
17581
|
+
assertCompleteRekeyPlan({ actorKeyId, plan, recipients: payload.recipients });
|
|
17582
|
+
const plaintext = await decryptPlainTextWithFileKey({
|
|
17583
|
+
encryptedText,
|
|
17584
|
+
fileKey
|
|
17585
|
+
});
|
|
17586
|
+
const nextFileKey = await generateFileKey();
|
|
17587
|
+
if (sameBytes(await keyBytes(fileKey), await keyBytes(nextFileKey))) {
|
|
17588
|
+
throw new Error("Rekey produced the same file key; refusing to continue.");
|
|
17589
|
+
}
|
|
17590
|
+
const byId = new Map(
|
|
17591
|
+
payload.recipients.map((recipient) => [recipient.recipientId, recipient])
|
|
17592
|
+
);
|
|
17593
|
+
const recipients = [];
|
|
17594
|
+
const issuedSecrets = [];
|
|
17595
|
+
const removedRecipientIds = [];
|
|
17596
|
+
for (const entry of plan) {
|
|
17597
|
+
const previous = byId.get(entry.recipientId);
|
|
17598
|
+
if (entry.action === "remove") {
|
|
17599
|
+
removedRecipientIds.push(entry.recipientId);
|
|
17600
|
+
continue;
|
|
17601
|
+
}
|
|
17602
|
+
if (entry.action === "keep") {
|
|
17603
|
+
recipients.push(
|
|
17604
|
+
await createUserRecipientGrant({
|
|
17605
|
+
expectedFingerprint: entry.expectedFingerprint,
|
|
17606
|
+
fileKey: nextFileKey,
|
|
17607
|
+
label: previous.label,
|
|
17608
|
+
userEncryption: entry.userEncryption
|
|
17609
|
+
})
|
|
17610
|
+
);
|
|
17611
|
+
continue;
|
|
17612
|
+
}
|
|
17613
|
+
const label = previous.label ?? entry.recipientId;
|
|
17614
|
+
const grant = await createExternalRecipientGrant({
|
|
17615
|
+
fileKey: nextFileKey,
|
|
17616
|
+
name: label
|
|
17617
|
+
});
|
|
17618
|
+
recipients.push(grant.recipient);
|
|
17619
|
+
issuedSecrets.push({
|
|
17620
|
+
label,
|
|
17621
|
+
previousRecipientId: entry.recipientId,
|
|
17622
|
+
recipientId: grant.recipient.recipientId,
|
|
17623
|
+
secret: grant.secret
|
|
17624
|
+
});
|
|
17625
|
+
}
|
|
17626
|
+
const actorFileKey = await unwrapFileKey({
|
|
17627
|
+
recipients,
|
|
17628
|
+
recipientId: actorKeyId,
|
|
17629
|
+
userKey: actorUserKey
|
|
17630
|
+
}).catch(() => null);
|
|
17631
|
+
if (!actorFileKey || !sameBytes(await keyBytes(actorFileKey), await keyBytes(nextFileKey))) {
|
|
17632
|
+
throw new Error(
|
|
17633
|
+
"Your new grant does not open with your unlocked key; refusing to rekey."
|
|
17634
|
+
);
|
|
17635
|
+
}
|
|
17636
|
+
const nextWorkspaceAccess = workspaceAccess ?? payload.workspaceAccess ?? "personal";
|
|
17637
|
+
const nextEncryptedText = await encryptPlainTextWithFileKey({
|
|
17638
|
+
fileKey: nextFileKey,
|
|
17639
|
+
plaintext,
|
|
17640
|
+
recipients,
|
|
17641
|
+
version: currentEncryptedFileVersion,
|
|
17642
|
+
workspaceAccess: nextWorkspaceAccess
|
|
17643
|
+
});
|
|
17644
|
+
const verified = await decryptPlainTextWithFileKey({
|
|
17645
|
+
encryptedText: nextEncryptedText,
|
|
17646
|
+
fileKey: nextFileKey
|
|
17647
|
+
});
|
|
17648
|
+
if (verified !== plaintext) {
|
|
17649
|
+
throw new Error("Rekeyed file did not round-trip; refusing to write.");
|
|
17650
|
+
}
|
|
17651
|
+
return {
|
|
17652
|
+
encryptedText: nextEncryptedText,
|
|
17653
|
+
encryption: {
|
|
17654
|
+
kind: "encrypted-file",
|
|
17655
|
+
recipients,
|
|
17656
|
+
version: currentEncryptedFileVersion,
|
|
17657
|
+
workspaceAccess: nextWorkspaceAccess
|
|
17658
|
+
},
|
|
17659
|
+
fileKey: nextFileKey,
|
|
17660
|
+
issuedSecrets,
|
|
17661
|
+
removedRecipientIds
|
|
17662
|
+
};
|
|
17663
|
+
};
|
|
17664
|
+
|
|
17665
|
+
// ../../packages/encryption/src/parseUserRecipientLabel.ts
|
|
17666
|
+
var userRecipientLabelPrefix = "user:";
|
|
17667
|
+
var parseUserRecipientLabel = (label) => {
|
|
17668
|
+
if (!label?.startsWith(userRecipientLabelPrefix)) {
|
|
17669
|
+
return null;
|
|
17670
|
+
}
|
|
17671
|
+
const value = label.slice(userRecipientLabelPrefix.length);
|
|
17672
|
+
const separatorIndex = value.indexOf(":");
|
|
17673
|
+
if (separatorIndex === -1) {
|
|
17674
|
+
return { displayName: null, userId: value };
|
|
17675
|
+
}
|
|
17676
|
+
const userId = value.slice(0, separatorIndex);
|
|
17677
|
+
const encodedDisplayName = value.slice(separatorIndex + 1);
|
|
17678
|
+
if (!encodedDisplayName) {
|
|
17679
|
+
return { displayName: null, userId };
|
|
17680
|
+
}
|
|
17681
|
+
try {
|
|
17682
|
+
return {
|
|
17683
|
+
displayName: decodeURIComponent(encodedDisplayName),
|
|
17684
|
+
userId
|
|
17685
|
+
};
|
|
17686
|
+
} catch {
|
|
17687
|
+
return { displayName: encodedDisplayName, userId };
|
|
17688
|
+
}
|
|
17689
|
+
};
|
|
17690
|
+
|
|
17453
17691
|
// ../../packages/core/src/fileTypes.ts
|
|
17454
17692
|
var textStorageClass = "text";
|
|
17455
17693
|
var binaryStorageClass = "binary";
|
|
@@ -31790,6 +32028,10 @@ var createStoreClient = ({
|
|
|
31790
32028
|
listSkillFolders: (input) => call("skills.folders", () => trpc.skills.folders.query(input)),
|
|
31791
32029
|
readSkill: (input) => call("skills.read", () => trpc.skills.read.query(input)),
|
|
31792
32030
|
readUserPreferences: () => call("userPreferences.read", () => trpc.userPreferences.read.query({})),
|
|
32031
|
+
readPublicEncryptionKeys: (input) => call(
|
|
32032
|
+
"userPreferences.readPublicEncryptionKeys",
|
|
32033
|
+
() => trpc.userPreferences.readPublicEncryptionKeys.query(input)
|
|
32034
|
+
),
|
|
31793
32035
|
upsertUserPreferences: (input) => call(
|
|
31794
32036
|
"userPreferences.upsert",
|
|
31795
32037
|
() => trpc.userPreferences.upsert.mutate(input)
|
|
@@ -33179,21 +33421,191 @@ var decryptTextForRecipientSecret = async (encryptedText, secretArg) => {
|
|
|
33179
33421
|
}
|
|
33180
33422
|
};
|
|
33181
33423
|
|
|
33424
|
+
// src/describeRekeyIssues.ts
|
|
33425
|
+
var reasonText = {
|
|
33426
|
+
public_key_unavailable: "their current public encryption key is unavailable, so the new file key cannot be wrapped for them",
|
|
33427
|
+
public_key_unverified: "their legacy encryption key has no fingerprint you have verified, so the new file key will not be wrapped for them (verify their key in the web app first)",
|
|
33428
|
+
secret_not_retained: "its secret is not stored by Forum, so it cannot be carried onto a new file key"
|
|
33429
|
+
};
|
|
33430
|
+
var describeRekeyIssues = (issues) => [
|
|
33431
|
+
"Rekeying would not preserve every remaining recipient:",
|
|
33432
|
+
...issues.map(
|
|
33433
|
+
(issue2) => ` - ${issue2.label ?? issue2.recipientId} (${issue2.recipientId}): ${reasonText[issue2.reason]}.`
|
|
33434
|
+
),
|
|
33435
|
+
"Decide for each one: pass --reissue <label-or-id> to mint a new secret (external recipients only) or --remove <label-or-id> to revoke it. Nothing was changed."
|
|
33436
|
+
].join("\n");
|
|
33437
|
+
|
|
33438
|
+
// src/resolveRecipientPublicKeys.ts
|
|
33439
|
+
var resolveRecipientPublicKeys = async ({
|
|
33440
|
+
actor,
|
|
33441
|
+
lookupPublicKeys,
|
|
33442
|
+
recipients
|
|
33443
|
+
}) => {
|
|
33444
|
+
const userIds = [
|
|
33445
|
+
...new Set(
|
|
33446
|
+
recipients.filter((recipient) => recipient.recipientId !== actor.keyId).map((recipient) => parseUserRecipientLabel(recipient.label)?.userId).filter((userId) => Boolean(userId))
|
|
33447
|
+
)
|
|
33448
|
+
];
|
|
33449
|
+
const others = userIds.length ? await lookupPublicKeys(userIds) : [];
|
|
33450
|
+
const actorKey = actor.version === 3 ? { keyId: actor.keyId, publicKey: actor.publicKey, version: 3 } : { keyId: actor.keyId, publicKey: actor.publicKey, version: 2 };
|
|
33451
|
+
return [
|
|
33452
|
+
{
|
|
33453
|
+
trustedFingerprint: await verifyUserEncryptionPublicKey(actorKey),
|
|
33454
|
+
userEncryption: actorKey
|
|
33455
|
+
},
|
|
33456
|
+
...others.flatMap(
|
|
33457
|
+
(entry) => entry.encryption ? [
|
|
33458
|
+
{
|
|
33459
|
+
...entry.trustedFingerprint ? { trustedFingerprint: entry.trustedFingerprint } : {},
|
|
33460
|
+
userEncryption: entry.encryption
|
|
33461
|
+
}
|
|
33462
|
+
] : []
|
|
33463
|
+
)
|
|
33464
|
+
];
|
|
33465
|
+
};
|
|
33466
|
+
|
|
33467
|
+
// src/resolveRecipientSelectors.ts
|
|
33468
|
+
var resolveRecipientSelectors = ({
|
|
33469
|
+
recipients,
|
|
33470
|
+
selectors
|
|
33471
|
+
}) => selectors.map((selector) => {
|
|
33472
|
+
const byId = recipients.find(
|
|
33473
|
+
(recipient) => recipient.recipientId === selector
|
|
33474
|
+
);
|
|
33475
|
+
if (byId) {
|
|
33476
|
+
return byId.recipientId;
|
|
33477
|
+
}
|
|
33478
|
+
const byLabel = recipients.filter(
|
|
33479
|
+
(recipient) => recipient.label === selector
|
|
33480
|
+
);
|
|
33481
|
+
if (byLabel.length === 1) {
|
|
33482
|
+
return byLabel[0].recipientId;
|
|
33483
|
+
}
|
|
33484
|
+
if (byLabel.length > 1) {
|
|
33485
|
+
throw new Error(
|
|
33486
|
+
`Several recipients are labelled "${selector}"; select one by recipient id: ${byLabel.map((recipient) => recipient.recipientId).join(", ")}`
|
|
33487
|
+
);
|
|
33488
|
+
}
|
|
33489
|
+
throw new Error(`No recipient matches "${selector}".`);
|
|
33490
|
+
});
|
|
33491
|
+
|
|
33492
|
+
// src/rekeyEncryptedTextForUser.ts
|
|
33493
|
+
var rekeyEncryptedTextForUser = async ({
|
|
33494
|
+
encryptedText,
|
|
33495
|
+
lookupPublicKeys,
|
|
33496
|
+
password,
|
|
33497
|
+
reissue,
|
|
33498
|
+
remove,
|
|
33499
|
+
userEncryption
|
|
33500
|
+
}) => {
|
|
33501
|
+
if (userEncryption.version === 1) {
|
|
33502
|
+
throw new Error(
|
|
33503
|
+
"Legacy encryption must be migrated before rekeying (run `fm encryption migrate`)."
|
|
33504
|
+
);
|
|
33505
|
+
}
|
|
33506
|
+
const { recipients } = parseEncryptedPlainTextPayload(encryptedText);
|
|
33507
|
+
if (!findEncryptionRecipient({
|
|
33508
|
+
recipients,
|
|
33509
|
+
recipientId: userEncryption.keyId
|
|
33510
|
+
})) {
|
|
33511
|
+
throw new Error(
|
|
33512
|
+
"You are not a recipient of this file, so its key cannot be unwrapped."
|
|
33513
|
+
);
|
|
33514
|
+
}
|
|
33515
|
+
const removeRecipientIds = resolveRecipientSelectors({
|
|
33516
|
+
recipients,
|
|
33517
|
+
selectors: remove
|
|
33518
|
+
});
|
|
33519
|
+
const reissueRecipientIds = resolveRecipientSelectors({
|
|
33520
|
+
recipients,
|
|
33521
|
+
selectors: reissue
|
|
33522
|
+
});
|
|
33523
|
+
const userKey = await unlockUserEncryption({
|
|
33524
|
+
metadata: userEncryption,
|
|
33525
|
+
password
|
|
33526
|
+
});
|
|
33527
|
+
const fileKey = await unwrapFileKey({
|
|
33528
|
+
recipients,
|
|
33529
|
+
recipientId: userEncryption.keyId,
|
|
33530
|
+
userKey
|
|
33531
|
+
});
|
|
33532
|
+
const candidates = await resolveRecipientPublicKeys({
|
|
33533
|
+
actor: userEncryption,
|
|
33534
|
+
lookupPublicKeys,
|
|
33535
|
+
recipients
|
|
33536
|
+
});
|
|
33537
|
+
const { issues, plan } = planRecipientRekey({
|
|
33538
|
+
candidates,
|
|
33539
|
+
recipients,
|
|
33540
|
+
reissueRecipientIds,
|
|
33541
|
+
removeRecipientIds
|
|
33542
|
+
});
|
|
33543
|
+
if (issues.length) {
|
|
33544
|
+
throw new Error(describeRekeyIssues(issues));
|
|
33545
|
+
}
|
|
33546
|
+
const result = await rekeyEncryptedPlainText({
|
|
33547
|
+
actorKeyId: userEncryption.keyId,
|
|
33548
|
+
actorUserKey: userKey,
|
|
33549
|
+
encryptedText,
|
|
33550
|
+
fileKey,
|
|
33551
|
+
plan
|
|
33552
|
+
});
|
|
33553
|
+
return {
|
|
33554
|
+
encryptedText: result.encryptedText,
|
|
33555
|
+
issuedSecrets: result.issuedSecrets,
|
|
33556
|
+
removedRecipientIds: result.removedRecipientIds
|
|
33557
|
+
};
|
|
33558
|
+
};
|
|
33559
|
+
|
|
33182
33560
|
// src/addExternalRecipient.ts
|
|
33183
33561
|
var addExternalRecipientToEncryptedText = async ({
|
|
33184
33562
|
encryptedText,
|
|
33185
33563
|
force,
|
|
33564
|
+
lookupPublicKeys,
|
|
33186
33565
|
name,
|
|
33187
33566
|
password,
|
|
33567
|
+
reissue = [],
|
|
33568
|
+
remove = [],
|
|
33188
33569
|
userEncryption
|
|
33189
33570
|
}) => {
|
|
33190
33571
|
const payload = parseEncryptedPlainTextPayload(encryptedText);
|
|
33191
|
-
const
|
|
33572
|
+
const duplicates = payload.recipients.filter(
|
|
33192
33573
|
(recipient2) => recipient2.label === name
|
|
33193
33574
|
);
|
|
33194
|
-
if (
|
|
33575
|
+
if (duplicates.length && !force) {
|
|
33195
33576
|
throw new Error(
|
|
33196
|
-
`A recipient named "${name}" already exists in this file. Pass --force to replace it.`
|
|
33577
|
+
`A recipient named "${name}" already exists in this file. Pass --force to replace it; this rekeys the file so the old secret cannot read future versions.`
|
|
33578
|
+
);
|
|
33579
|
+
}
|
|
33580
|
+
if (duplicates.length) {
|
|
33581
|
+
const [replaced, ...extraDuplicates] = duplicates.map(
|
|
33582
|
+
(recipient2) => recipient2.recipientId
|
|
33583
|
+
);
|
|
33584
|
+
const result = await rekeyEncryptedTextForUser({
|
|
33585
|
+
encryptedText,
|
|
33586
|
+
lookupPublicKeys,
|
|
33587
|
+
password,
|
|
33588
|
+
reissue: [replaced, ...reissue],
|
|
33589
|
+
remove: [...extraDuplicates, ...remove],
|
|
33590
|
+
userEncryption
|
|
33591
|
+
});
|
|
33592
|
+
const replacement = result.issuedSecrets.find(
|
|
33593
|
+
(issued) => issued.previousRecipientId === replaced
|
|
33594
|
+
);
|
|
33595
|
+
return {
|
|
33596
|
+
encryptedText: result.encryptedText,
|
|
33597
|
+
otherIssuedSecrets: result.issuedSecrets.filter(
|
|
33598
|
+
(issued) => issued !== replacement
|
|
33599
|
+
),
|
|
33600
|
+
rekeyed: true,
|
|
33601
|
+
recipientId: replacement.recipientId,
|
|
33602
|
+
removedRecipientIds: result.removedRecipientIds,
|
|
33603
|
+
secret: replacement.secret
|
|
33604
|
+
};
|
|
33605
|
+
}
|
|
33606
|
+
if (remove.length || reissue.length) {
|
|
33607
|
+
throw new Error(
|
|
33608
|
+
"--remove/--reissue only apply when replacing a recipient with --force; use `fm encrypt-rekey` to revoke recipients."
|
|
33197
33609
|
);
|
|
33198
33610
|
}
|
|
33199
33611
|
const userKey = await unlockUserEncryption({
|
|
@@ -33209,13 +33621,15 @@ var addExternalRecipientToEncryptedText = async ({
|
|
|
33209
33621
|
fileKey,
|
|
33210
33622
|
name
|
|
33211
33623
|
});
|
|
33212
|
-
const retained = force ? payload.recipients.filter((existing) => existing.label !== name) : payload.recipients;
|
|
33213
33624
|
return {
|
|
33214
33625
|
encryptedText: updateEncryptedPlainTextRecipients({
|
|
33215
33626
|
encryptedText,
|
|
33216
|
-
recipients: [...
|
|
33627
|
+
recipients: [...payload.recipients, recipient]
|
|
33217
33628
|
}),
|
|
33629
|
+
otherIssuedSecrets: [],
|
|
33630
|
+
rekeyed: false,
|
|
33218
33631
|
recipientId: recipient.recipientId,
|
|
33632
|
+
removedRecipientIds: [],
|
|
33219
33633
|
secret
|
|
33220
33634
|
};
|
|
33221
33635
|
};
|
|
@@ -33423,9 +33837,25 @@ var runEncryptionIdentityCommand = async ({
|
|
|
33423
33837
|
);
|
|
33424
33838
|
};
|
|
33425
33839
|
|
|
33840
|
+
// src/writeTextFileIfUnchanged.ts
|
|
33841
|
+
import { readFile as readFile9 } from "fs/promises";
|
|
33842
|
+
var writeTextFileIfUnchanged = async ({
|
|
33843
|
+
expectedText,
|
|
33844
|
+
filePath,
|
|
33845
|
+
text
|
|
33846
|
+
}) => {
|
|
33847
|
+
const current = await readFile9(filePath, "utf8");
|
|
33848
|
+
if (current !== expectedText) {
|
|
33849
|
+
throw new Error(
|
|
33850
|
+
`${filePath} changed while this command was running; nothing was written. Re-run against the latest version.`
|
|
33851
|
+
);
|
|
33852
|
+
}
|
|
33853
|
+
await atomicWriteTextFile(filePath, text);
|
|
33854
|
+
};
|
|
33855
|
+
|
|
33426
33856
|
// src/openInEditor.ts
|
|
33427
33857
|
import { spawn } from "child_process";
|
|
33428
|
-
import { mkdtemp as mkdtemp2, readFile as
|
|
33858
|
+
import { mkdtemp as mkdtemp2, readFile as readFile10, rm as rm7, writeFile as writeFile5 } from "fs/promises";
|
|
33429
33859
|
import { tmpdir } from "os";
|
|
33430
33860
|
import path26 from "path";
|
|
33431
33861
|
var openInEditor = async (currentText, { extension = "" } = {}) => {
|
|
@@ -33446,7 +33876,7 @@ var openInEditor = async (currentText, { extension = "" } = {}) => {
|
|
|
33446
33876
|
if (exitCode !== 0) {
|
|
33447
33877
|
return null;
|
|
33448
33878
|
}
|
|
33449
|
-
return await
|
|
33879
|
+
return await readFile10(tempPath, "utf8");
|
|
33450
33880
|
} finally {
|
|
33451
33881
|
await rm7(dir, { force: true, recursive: true }).catch(() => {
|
|
33452
33882
|
});
|
|
@@ -33535,7 +33965,7 @@ var standaloneIncludeId = (paragraph) => {
|
|
|
33535
33965
|
var textContent = (file2) => file2?.content && "text" in file2.content ? file2.content.text : null;
|
|
33536
33966
|
var compileMarkdown = async ({
|
|
33537
33967
|
entry,
|
|
33538
|
-
readFile:
|
|
33968
|
+
readFile: readFile12,
|
|
33539
33969
|
optional: optional2,
|
|
33540
33970
|
limits = {}
|
|
33541
33971
|
}) => {
|
|
@@ -33579,7 +34009,7 @@ var compileMarkdown = async ({
|
|
|
33579
34009
|
throw new Error(`Include cycle: ${[...chain, id].join(" -> ")}`);
|
|
33580
34010
|
let target;
|
|
33581
34011
|
try {
|
|
33582
|
-
target = await
|
|
34012
|
+
target = await readFile12(id);
|
|
33583
34013
|
} catch (error51) {
|
|
33584
34014
|
if (optional2) {
|
|
33585
34015
|
warnings.push(`Omitted unreadable include ${id} from ${label}.`);
|
|
@@ -33658,7 +34088,8 @@ Usage:
|
|
|
33658
34088
|
fm hash <filePath> [--store <storeId>] [--token <jwt>] [--local]
|
|
33659
34089
|
fm encrypt (<text>|--file|-f <localPath>) [--password <password>] [--token <jwt>]
|
|
33660
34090
|
fm decrypt (<encrypted-json>|--file|-f <localPath>) [--secret <recipient-secret>] [--password <password>] [--token <jwt>]
|
|
33661
|
-
fm encrypt-add-recipient (<encrypted-json>|--file|-f <localPath>) --name <recipient-name> [--force] [--json] [--password <password>] [--token <jwt>]
|
|
34091
|
+
fm encrypt-add-recipient (<encrypted-json>|--file|-f <localPath>) --name <recipient-name> [--force [--reissue <label-or-id>]... [--remove <label-or-id>]...] [--json] [--password <password>] [--token <jwt>]
|
|
34092
|
+
fm encrypt-rekey (<encrypted-json>|--file|-f <localPath>) [--remove <label-or-id>]... [--reissue <label-or-id>]... [--json] [--password <password>] [--token <jwt>]
|
|
33662
34093
|
fm edit (<localPath>|--file|-f <localPath>) [--password <password>] [--token <jwt>]
|
|
33663
34094
|
fm query <filename-or-path> [-s <storeIds>] [--token <jwt>]
|
|
33664
34095
|
fm q <filename-or-path> [-s <storeIds>] [--token <jwt>]
|
|
@@ -33738,7 +34169,9 @@ Encryption:
|
|
|
33738
34169
|
Provide your encryption password interactively, via --password, or via DOCTRINE_ENCRYPTION_PASSWORD.
|
|
33739
34170
|
To decrypt as an external recipient (no account/login), pass --secret <recipient-secret> or set DOCTRINE_RECIPIENT_SECRET.
|
|
33740
34171
|
encrypt-add-recipient grants a new external recipient (you must already be a recipient) and prints its doctrine-recipient-v1_ secret once \u2014 hand it to CI; with --file the secret is the only stdout line so SECRET=$(fm encrypt-add-recipient \u2026) captures it.
|
|
33741
|
-
|
|
34172
|
+
encrypt-add-recipient --force replaces a same-name recipient by REKEYING the file (new file key, plaintext re-encrypted): the old secret cannot read the new or later versions. Remaining Forum users are kept by public key; other external recipients need --reissue (new secret) or --remove.
|
|
34173
|
+
encrypt-rekey revokes recipients (--remove) and/or reissues external secrets (--reissue) under a new file key. It refuses to drop anyone not named. Revocation covers future versions only \u2014 not earlier versions, backups, or already-copied plaintext/credentials.
|
|
34174
|
+
edit opens an encrypted file's plaintext in $EDITOR (fallback vi) and re-encrypts in place on save, keeping the SAME data key and recipients (unlike encrypt, which rotates the key and drops external recipients). Sync/commit afterward; run fm push for store-synced projects. Editing is not revocation: use encrypt-rekey to cut off a recipient.
|
|
33742
34175
|
API:
|
|
33743
34176
|
Uses ${DEFAULT_API_BASE_URL} by default. Set DOCTRINE_API_URL for local development.
|
|
33744
34177
|
Output:
|
|
@@ -33747,7 +34180,7 @@ Output:
|
|
|
33747
34180
|
`;
|
|
33748
34181
|
var readCliVersion = async () => {
|
|
33749
34182
|
const packageJson = JSON.parse(
|
|
33750
|
-
await
|
|
34183
|
+
await readFile11(new URL("../package.json", import.meta.url), "utf8")
|
|
33751
34184
|
);
|
|
33752
34185
|
return typeof packageJson.version === "string" ? packageJson.version : "unknown";
|
|
33753
34186
|
};
|
|
@@ -33798,6 +34231,8 @@ var parseArgs = (argv) => {
|
|
|
33798
34231
|
let encryptionPassword = null;
|
|
33799
34232
|
let recipientSecret = null;
|
|
33800
34233
|
let recipientName = null;
|
|
34234
|
+
const removeRecipients = [];
|
|
34235
|
+
const reissueRecipients = [];
|
|
33801
34236
|
let syncPath = null;
|
|
33802
34237
|
let syncTarget = null;
|
|
33803
34238
|
let pathsFile = null;
|
|
@@ -33895,6 +34330,23 @@ var parseArgs = (argv) => {
|
|
|
33895
34330
|
recipientName = current.slice("--name=".length);
|
|
33896
34331
|
continue;
|
|
33897
34332
|
}
|
|
34333
|
+
if (current === "--remove" || current === "--reissue") {
|
|
34334
|
+
if (next) {
|
|
34335
|
+
(current === "--remove" ? removeRecipients : reissueRecipients).push(
|
|
34336
|
+
next
|
|
34337
|
+
);
|
|
34338
|
+
}
|
|
34339
|
+
index += 1;
|
|
34340
|
+
continue;
|
|
34341
|
+
}
|
|
34342
|
+
if (current.startsWith("--remove=")) {
|
|
34343
|
+
removeRecipients.push(current.slice("--remove=".length));
|
|
34344
|
+
continue;
|
|
34345
|
+
}
|
|
34346
|
+
if (current.startsWith("--reissue=")) {
|
|
34347
|
+
reissueRecipients.push(current.slice("--reissue=".length));
|
|
34348
|
+
continue;
|
|
34349
|
+
}
|
|
33898
34350
|
if (current === "--ref") {
|
|
33899
34351
|
if (!next) {
|
|
33900
34352
|
throw new Error(
|
|
@@ -34037,6 +34489,8 @@ var parseArgs = (argv) => {
|
|
|
34037
34489
|
encryptionPassword,
|
|
34038
34490
|
recipientSecret,
|
|
34039
34491
|
recipientName,
|
|
34492
|
+
removeRecipients,
|
|
34493
|
+
reissueRecipients,
|
|
34040
34494
|
syncPath,
|
|
34041
34495
|
syncTarget,
|
|
34042
34496
|
pathsFile,
|
|
@@ -34537,7 +34991,7 @@ var readWriteTextInput = async (inlineText, inputFilePath) => {
|
|
|
34537
34991
|
throw new Error("Provide either inline text or --file, not both.");
|
|
34538
34992
|
}
|
|
34539
34993
|
if (inputFilePath) {
|
|
34540
|
-
return
|
|
34994
|
+
return readFile11(inputFilePath, "utf8");
|
|
34541
34995
|
}
|
|
34542
34996
|
return inlineText ?? null;
|
|
34543
34997
|
};
|
|
@@ -34847,7 +35301,7 @@ var diffRemoteFiles = async ({
|
|
|
34847
35301
|
storeRef
|
|
34848
35302
|
}) => {
|
|
34849
35303
|
const leftText = await readRemoteTextFile(leftPath, storeRef, client);
|
|
34850
|
-
const rightText = localRight ? await
|
|
35304
|
+
const rightText = localRight ? await readFile11(path27.resolve(rightPath), "utf8") : await readRemoteTextFile(rightPath, storeRef, client);
|
|
34851
35305
|
return buildUnifiedDiff({
|
|
34852
35306
|
leftLabel: leftPath,
|
|
34853
35307
|
leftText,
|
|
@@ -35128,7 +35582,7 @@ var runEditCommand = async (rest, parsed, client) => {
|
|
|
35128
35582
|
`Usage: ${commandNames} edit (<localPath>|--file|-f <localPath>) [--password <password>] [--token <jwt>]`
|
|
35129
35583
|
);
|
|
35130
35584
|
}
|
|
35131
|
-
const encryptedText = await
|
|
35585
|
+
const encryptedText = await readFile11(filePath, "utf8");
|
|
35132
35586
|
const [password, userEncryption] = await Promise.all([
|
|
35133
35587
|
readEncryptionPassword(parsed),
|
|
35134
35588
|
readUserEncryption(client)
|
|
@@ -35143,7 +35597,11 @@ var runEditCommand = async (rest, parsed, client) => {
|
|
|
35143
35597
|
renderWarning("No changes; nothing written.");
|
|
35144
35598
|
return;
|
|
35145
35599
|
}
|
|
35146
|
-
await
|
|
35600
|
+
await writeTextFileIfUnchanged({
|
|
35601
|
+
expectedText: encryptedText,
|
|
35602
|
+
filePath,
|
|
35603
|
+
text: result.encryptedText
|
|
35604
|
+
});
|
|
35147
35605
|
renderOutput(
|
|
35148
35606
|
`Updated ${filePath}. Run \`${commandNames} push\` (and commit) for store-synced projects.`
|
|
35149
35607
|
);
|
|
@@ -35164,7 +35622,7 @@ var runRecipientSecretDecryptCommand = async (rest, parsed) => {
|
|
|
35164
35622
|
};
|
|
35165
35623
|
var runEncryptAddRecipientCommand = async (rest, parsed, client) => {
|
|
35166
35624
|
const name = parsed.recipientName?.trim();
|
|
35167
|
-
const usage2 = `Usage: ${commandNames} encrypt-add-recipient (<encrypted-json>|--file <localPath>) --name <recipient-name> [--force] [--json]`;
|
|
35625
|
+
const usage2 = `Usage: ${commandNames} encrypt-add-recipient (<encrypted-json>|--file <localPath>) --name <recipient-name> [--force [--reissue <label-or-id>]... [--remove <label-or-id>]...] [--json]`;
|
|
35168
35626
|
if (!name) {
|
|
35169
35627
|
throw new Error(usage2);
|
|
35170
35628
|
}
|
|
@@ -35182,24 +35640,38 @@ var runEncryptAddRecipientCommand = async (rest, parsed, client) => {
|
|
|
35182
35640
|
const result = await addExternalRecipientToEncryptedText({
|
|
35183
35641
|
encryptedText,
|
|
35184
35642
|
force: parsed.force,
|
|
35643
|
+
lookupPublicKeys: createPublicKeyLookup(client),
|
|
35185
35644
|
name,
|
|
35186
35645
|
password,
|
|
35646
|
+
reissue: parsed.reissueRecipients,
|
|
35647
|
+
remove: parsed.removeRecipients,
|
|
35187
35648
|
userEncryption: userEncryption.userEncryption
|
|
35188
35649
|
});
|
|
35189
35650
|
if (parsed.inputFilePath) {
|
|
35190
|
-
await
|
|
35651
|
+
await writeTextFileIfUnchanged({
|
|
35652
|
+
expectedText: encryptedText,
|
|
35653
|
+
filePath: parsed.inputFilePath,
|
|
35654
|
+
text: result.encryptedText
|
|
35655
|
+
});
|
|
35191
35656
|
}
|
|
35192
35657
|
if (parsed.json) {
|
|
35193
35658
|
renderOutput({
|
|
35194
35659
|
name,
|
|
35195
35660
|
recipientId: result.recipientId,
|
|
35661
|
+
rekeyed: result.rekeyed,
|
|
35662
|
+
removedRecipientIds: result.removedRecipientIds,
|
|
35663
|
+
reissued: result.otherIssuedSecrets,
|
|
35196
35664
|
secret: result.secret,
|
|
35197
35665
|
...parsed.inputFilePath ? {} : { ciphertext: result.encryptedText }
|
|
35198
35666
|
});
|
|
35199
35667
|
return;
|
|
35200
35668
|
}
|
|
35669
|
+
if (result.rekeyed) {
|
|
35670
|
+
renderWarning(rekeyNotice(result.removedRecipientIds));
|
|
35671
|
+
}
|
|
35672
|
+
renderIssuedSecretsToStderr(result.otherIssuedSecrets);
|
|
35201
35673
|
renderWarning(
|
|
35202
|
-
|
|
35674
|
+
`${result.rekeyed ? "Replaced" : "Added"} recipient "${name}". Recipient secret (shown once \u2014 hand to CI):`
|
|
35203
35675
|
);
|
|
35204
35676
|
if (parsed.inputFilePath) {
|
|
35205
35677
|
process.stdout.write(`${result.secret}
|
|
@@ -35210,8 +35682,79 @@ var runEncryptAddRecipientCommand = async (rest, parsed, client) => {
|
|
|
35210
35682
|
`);
|
|
35211
35683
|
renderOutput(result.encryptedText);
|
|
35212
35684
|
};
|
|
35685
|
+
var createPublicKeyLookup = (client) => async (userIds) => {
|
|
35686
|
+
const [keys, preferences] = await Promise.all([
|
|
35687
|
+
client.readPublicEncryptionKeys({ userIds }),
|
|
35688
|
+
client.readUserPreferences()
|
|
35689
|
+
]);
|
|
35690
|
+
const trustedKeys = preferences.encryptionTrustedKeys ?? {};
|
|
35691
|
+
return keys.map((entry) => ({
|
|
35692
|
+
encryption: entry.encryption,
|
|
35693
|
+
...trustedKeys[entry.userId] ? { trustedFingerprint: trustedKeys[entry.userId].fingerprint } : {},
|
|
35694
|
+
userId: entry.userId
|
|
35695
|
+
}));
|
|
35696
|
+
};
|
|
35697
|
+
var rekeyNotice = (removedRecipientIds) => [
|
|
35698
|
+
"Rekeyed: the file now uses a new file key.",
|
|
35699
|
+
removedRecipientIds.length ? `Revoked recipients: ${removedRecipientIds.join(", ")}.` : null,
|
|
35700
|
+
"Old secrets and wrappers cannot read this or later versions. They can still read earlier versions and backups, and anything already decrypted or copied; rotate the underlying credentials at their providers if that matters."
|
|
35701
|
+
].filter(Boolean).join(" ");
|
|
35702
|
+
var renderIssuedSecretsToStderr = (issued) => {
|
|
35703
|
+
if (!issued.length) {
|
|
35704
|
+
return;
|
|
35705
|
+
}
|
|
35706
|
+
renderWarning(
|
|
35707
|
+
"Reissued recipient secrets (shown once \u2014 previous secrets no longer read new versions):"
|
|
35708
|
+
);
|
|
35709
|
+
for (const entry of issued) {
|
|
35710
|
+
process.stderr.write(`${entry.label} ${entry.secret}
|
|
35711
|
+
`);
|
|
35712
|
+
}
|
|
35713
|
+
};
|
|
35714
|
+
var runEncryptRekeyCommand = async (rest, parsed, client) => {
|
|
35715
|
+
const usage2 = `Usage: ${commandNames} encrypt-rekey (<encrypted-json>|--file <localPath>) [--remove <label-or-id>]... [--reissue <label-or-id>]... [--json]`;
|
|
35716
|
+
const encryptedText = await readCommandTextInput(
|
|
35717
|
+
rest.length ? rest.join(" ") : void 0,
|
|
35718
|
+
parsed.inputFilePath
|
|
35719
|
+
);
|
|
35720
|
+
if (encryptedText === null) {
|
|
35721
|
+
throw new Error(usage2);
|
|
35722
|
+
}
|
|
35723
|
+
const [password, userEncryption] = await Promise.all([
|
|
35724
|
+
readEncryptionPassword(parsed),
|
|
35725
|
+
readUserEncryption(client)
|
|
35726
|
+
]);
|
|
35727
|
+
const result = await rekeyEncryptedTextForUser({
|
|
35728
|
+
encryptedText,
|
|
35729
|
+
lookupPublicKeys: createPublicKeyLookup(client),
|
|
35730
|
+
password,
|
|
35731
|
+
reissue: parsed.reissueRecipients,
|
|
35732
|
+
remove: parsed.removeRecipients,
|
|
35733
|
+
userEncryption: userEncryption.userEncryption
|
|
35734
|
+
});
|
|
35735
|
+
if (parsed.inputFilePath) {
|
|
35736
|
+
await writeTextFileIfUnchanged({
|
|
35737
|
+
expectedText: encryptedText,
|
|
35738
|
+
filePath: parsed.inputFilePath,
|
|
35739
|
+
text: result.encryptedText
|
|
35740
|
+
});
|
|
35741
|
+
}
|
|
35742
|
+
if (parsed.json) {
|
|
35743
|
+
renderOutput({
|
|
35744
|
+
reissued: result.issuedSecrets,
|
|
35745
|
+
removedRecipientIds: result.removedRecipientIds,
|
|
35746
|
+
...parsed.inputFilePath ? {} : { ciphertext: result.encryptedText }
|
|
35747
|
+
});
|
|
35748
|
+
return;
|
|
35749
|
+
}
|
|
35750
|
+
renderWarning(rekeyNotice(result.removedRecipientIds));
|
|
35751
|
+
renderIssuedSecretsToStderr(result.issuedSecrets);
|
|
35752
|
+
renderOutput(
|
|
35753
|
+
parsed.inputFilePath ? `Updated ${parsed.inputFilePath}. Run \`${commandNames} push\` (and commit) for store-synced projects.` : result.encryptedText
|
|
35754
|
+
);
|
|
35755
|
+
};
|
|
35213
35756
|
var defaultEncryptionMigrationBackupPath = () => path27.resolve(process.cwd(), "doctrine-encryption-migration.json");
|
|
35214
|
-
var readEncryptionMigrationBackup = async (backupPath) => JSON.parse(await
|
|
35757
|
+
var readEncryptionMigrationBackup = async (backupPath) => JSON.parse(await readFile11(backupPath, "utf8"));
|
|
35215
35758
|
var writeEncryptionMigrationBackup = async (backupPath, backup) => {
|
|
35216
35759
|
await mkdir7(path27.dirname(backupPath), { recursive: true });
|
|
35217
35760
|
await writeFile6(backupPath, `${JSON.stringify(backup, null, 2)}
|
|
@@ -38333,6 +38876,10 @@ var main = async (argv = process.argv.slice(2)) => {
|
|
|
38333
38876
|
await runEncryptCommand(rest, parsed, client);
|
|
38334
38877
|
return;
|
|
38335
38878
|
}
|
|
38879
|
+
if (command === "encrypt-rekey") {
|
|
38880
|
+
await runEncryptRekeyCommand(rest, parsed, client);
|
|
38881
|
+
return;
|
|
38882
|
+
}
|
|
38336
38883
|
if (command === "encrypt-add-recipient") {
|
|
38337
38884
|
await runEncryptAddRecipientCommand(rest, parsed, client);
|
|
38338
38885
|
return;
|