@rogatio/cli 6.16.1 → 6.16.2
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/node/index.js +44 -16
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -22681,6 +22681,18 @@ async function readPreviousRogatioCa(caCertFile) {
|
|
|
22681
22681
|
return void 0;
|
|
22682
22682
|
}
|
|
22683
22683
|
}
|
|
22684
|
+
async function assertReadableIfRegular(path2, snapshot2) {
|
|
22685
|
+
if (snapshot2 !== void 0) return;
|
|
22686
|
+
try {
|
|
22687
|
+
const info = await lstat(path2);
|
|
22688
|
+
if (!info.isFile()) return;
|
|
22689
|
+
} catch {
|
|
22690
|
+
return;
|
|
22691
|
+
}
|
|
22692
|
+
throw new TrustError("trust.write-failed", "CA file could not be read", [
|
|
22693
|
+
"trust.write-failed"
|
|
22694
|
+
]);
|
|
22695
|
+
}
|
|
22684
22696
|
async function discardPreviousCa(caPreviousCertFile) {
|
|
22685
22697
|
try {
|
|
22686
22698
|
await rm(caPreviousCertFile, { force: true });
|
|
@@ -22732,6 +22744,9 @@ function createRequestBodyTrustController(options = {}) {
|
|
|
22732
22744
|
let reusedExisting = false;
|
|
22733
22745
|
let previousKeyPem;
|
|
22734
22746
|
let previousPubPem;
|
|
22747
|
+
let replacedKey = false;
|
|
22748
|
+
let replacedPub = false;
|
|
22749
|
+
let replacedCert = false;
|
|
22735
22750
|
const caCertFile = join2(
|
|
22736
22751
|
installRoot,
|
|
22737
22752
|
options.caCertFileName ?? ".rogatio-ca.crt"
|
|
@@ -22838,32 +22853,35 @@ function createRequestBodyTrustController(options = {}) {
|
|
|
22838
22853
|
console.error("[rogatio] previous CA trust anchor was not removed");
|
|
22839
22854
|
}
|
|
22840
22855
|
}
|
|
22841
|
-
async function
|
|
22842
|
-
await rm(caKeyFile, { force: true });
|
|
22843
|
-
await rm(caPubFile, { force: true });
|
|
22844
|
-
await rm(caCertFile, { force: true });
|
|
22856
|
+
async function removeReplacedCaFiles() {
|
|
22857
|
+
if (replacedKey) await rm(caKeyFile, { force: true });
|
|
22858
|
+
if (replacedPub) await rm(caPubFile, { force: true });
|
|
22859
|
+
if (replacedCert) await rm(caCertFile, { force: true });
|
|
22860
|
+
}
|
|
22861
|
+
async function restoreOrDrop(path2, snapshot2, replaced, mode) {
|
|
22862
|
+
if (snapshot2 !== void 0) {
|
|
22863
|
+
await writeFileAtomic(path2, snapshot2, mode);
|
|
22864
|
+
return;
|
|
22865
|
+
}
|
|
22866
|
+
if (replaced) await rm(path2, { force: true });
|
|
22845
22867
|
}
|
|
22846
22868
|
async function rollbackReplacedCa() {
|
|
22847
22869
|
if (reusedExisting) return;
|
|
22848
22870
|
if (!replacingPrevious) {
|
|
22849
|
-
await
|
|
22871
|
+
await removeReplacedCaFiles();
|
|
22850
22872
|
return;
|
|
22851
22873
|
}
|
|
22852
22874
|
const saved = await readPreviousRogatioCa(caPreviousCertFile);
|
|
22853
22875
|
const live = await readPreviousRogatioCa(caCertFile);
|
|
22854
22876
|
const copyKept = rememberedFingerprint !== void 0 && saved?.fingerprint === rememberedFingerprint;
|
|
22855
22877
|
const liveDiffers = live?.fingerprint !== rememberedFingerprint;
|
|
22856
|
-
if (copyKept && liveDiffers) {
|
|
22857
|
-
await
|
|
22878
|
+
if (copyKept && replacedCert && liveDiffers) {
|
|
22879
|
+
await removeReplacedCaFiles();
|
|
22858
22880
|
return;
|
|
22859
22881
|
}
|
|
22860
|
-
if (copyKept && !
|
|
22861
|
-
|
|
22862
|
-
|
|
22863
|
-
}
|
|
22864
|
-
if (previousPubPem !== void 0) {
|
|
22865
|
-
await writeFileAtomic(caPubFile, previousPubPem);
|
|
22866
|
-
}
|
|
22882
|
+
if (copyKept && !replacedCert) {
|
|
22883
|
+
await restoreOrDrop(caKeyFile, previousKeyPem, replacedKey, 384);
|
|
22884
|
+
await restoreOrDrop(caPubFile, previousPubPem, replacedPub);
|
|
22867
22885
|
}
|
|
22868
22886
|
}
|
|
22869
22887
|
async function runCaTrust() {
|
|
@@ -22881,12 +22899,21 @@ function createRequestBodyTrustController(options = {}) {
|
|
|
22881
22899
|
reusedExisting = false;
|
|
22882
22900
|
previousKeyPem = void 0;
|
|
22883
22901
|
previousPubPem = void 0;
|
|
22902
|
+
replacedKey = false;
|
|
22903
|
+
replacedPub = false;
|
|
22904
|
+
replacedCert = false;
|
|
22884
22905
|
const reusable = await reusableCaMaterial();
|
|
22885
22906
|
reusedExisting = reusable;
|
|
22886
22907
|
const liveAnchor = await readPreviousRogatioCa(caCertFile);
|
|
22887
22908
|
const siblingAnchor = await readPreviousRogatioCa(caPreviousCertFile);
|
|
22888
22909
|
let preserved;
|
|
22889
22910
|
if (!reusable) {
|
|
22911
|
+
const rawCert = await readNoFollowRegularFile(caCertFile);
|
|
22912
|
+
previousKeyPem = await readNoFollowRegularFile(caKeyFile);
|
|
22913
|
+
previousPubPem = await readNoFollowRegularFile(caPubFile);
|
|
22914
|
+
await assertReadableIfRegular(caCertFile, rawCert);
|
|
22915
|
+
await assertReadableIfRegular(caKeyFile, previousKeyPem);
|
|
22916
|
+
await assertReadableIfRegular(caPubFile, previousPubPem);
|
|
22890
22917
|
replacingPrevious = liveAnchor !== void 0 || siblingAnchor !== void 0;
|
|
22891
22918
|
const { privateKey } = generateCaKeyPair(TRUST_LIMITS.caKeyBits);
|
|
22892
22919
|
const certResult = await createCertificate(
|
|
@@ -22914,11 +22941,12 @@ function createRequestBodyTrustController(options = {}) {
|
|
|
22914
22941
|
} else if (siblingAnchor) {
|
|
22915
22942
|
await discardPreviousCa(caPreviousCertFile);
|
|
22916
22943
|
}
|
|
22917
|
-
previousKeyPem = await readNoFollowRegularFile(caKeyFile);
|
|
22918
|
-
previousPubPem = await readNoFollowRegularFile(caPubFile);
|
|
22919
22944
|
await writeFileAtomic(caKeyFile, certResult.keyPem, 384);
|
|
22945
|
+
replacedKey = true;
|
|
22920
22946
|
await writeFileAtomic(caPubFile, certResult.certPem);
|
|
22947
|
+
replacedPub = true;
|
|
22921
22948
|
await writeFileAtomic(caCertFile, certResult.certPem);
|
|
22949
|
+
replacedCert = true;
|
|
22922
22950
|
}
|
|
22923
22951
|
let installedNew = false;
|
|
22924
22952
|
if (caTrustInstaller && !installerCalled) {
|
package/package.json
CHANGED