@xenosystem/agent-cli 0.5.114 → 0.5.116
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/cli.js +1 -1
- package/dist/index.js +1918 -1906
- package/dist/metafile-esm.json +1 -1
- package/dist/sdk-build-identity.json +17 -17
- package/node_modules/@xeno-corporation/account/README.md +32 -1
- package/node_modules/@xeno-corporation/account/dist/node.d.mts +52 -1
- package/node_modules/@xeno-corporation/account/dist/node.d.ts +52 -1
- package/node_modules/@xeno-corporation/account/dist/node.js +580 -6
- package/node_modules/@xeno-corporation/account/dist/node.js.map +1 -1
- package/node_modules/@xeno-corporation/account/dist/node.mjs +573 -0
- package/node_modules/@xeno-corporation/account/dist/node.mjs.map +1 -1
- package/node_modules/@xeno-corporation/account/package.json +1 -1
- package/package.json +3 -3
|
@@ -31,11 +31,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/node.ts
|
|
32
32
|
var node_exports = {};
|
|
33
33
|
__export(node_exports, {
|
|
34
|
+
createLinuxAccountHost: () => createLinuxAccountHost,
|
|
34
35
|
createNodeDpopSigner: () => createNodeDpopSigner,
|
|
35
36
|
createWindowsAccountHost: () => createWindowsAccountHost
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(node_exports);
|
|
38
|
-
var
|
|
39
|
+
var import_node_crypto3 = __toESM(require("crypto"));
|
|
39
40
|
|
|
40
41
|
// src/dpop.ts
|
|
41
42
|
function normalizeDpopHtu(value) {
|
|
@@ -657,6 +658,578 @@ var WindowsHostRpc = class WindowsHostRpc2 {
|
|
|
657
658
|
}
|
|
658
659
|
};
|
|
659
660
|
|
|
661
|
+
// src/linux-host.ts
|
|
662
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
663
|
+
var import_node_child_process2 = require("child_process");
|
|
664
|
+
var import_node_crypto2 = require("crypto");
|
|
665
|
+
var import_node_fs = require("fs");
|
|
666
|
+
var import_node_path2 = require("path");
|
|
667
|
+
var import_node_os = require("os");
|
|
668
|
+
var VALUE_PREFIX = "xa1:";
|
|
669
|
+
var MAX_VALUE_BYTES = 2560;
|
|
670
|
+
var MAX_KEY_BYTES = 1024;
|
|
671
|
+
function refused2() {
|
|
672
|
+
return new AccountError({
|
|
673
|
+
code: "UNREACHABLE",
|
|
674
|
+
message: "Linux account host authority is unavailable",
|
|
675
|
+
retryable: false
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
__name(refused2, "refused");
|
|
679
|
+
async function createLinuxAccountHost(options) {
|
|
680
|
+
if (process.platform !== "linux") throw refused2();
|
|
681
|
+
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
682
|
+
const tool = findSecretTool();
|
|
683
|
+
return openLinuxAccountHost(options, {
|
|
684
|
+
secretTool: tool ? secretToolRunner(tool, timeoutMs) : null,
|
|
685
|
+
lockDirectory: runtimeLockDirectory()
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
__name(createLinuxAccountHost, "createLinuxAccountHost");
|
|
689
|
+
async function openLinuxAccountHost(options, deps) {
|
|
690
|
+
const clientId = options.clientId, namespace = options.namespace ?? clientId;
|
|
691
|
+
const timeoutMs = options.timeoutMs ?? 15e3, waitMs = options.lockTimeoutMs ?? 5e3;
|
|
692
|
+
const transactionTimeoutMs = options.transactionTimeoutMs ?? timeoutMs;
|
|
693
|
+
if (typeof clientId !== "string" || typeof namespace !== "string" || !/^xeno-[a-z0-9][a-z0-9-]{0,63}$/.test(clientId) || !/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/.test(namespace) || !Number.isSafeInteger(timeoutMs) || timeoutMs < 1e3 || timeoutMs > 12e4 || !Number.isSafeInteger(waitMs) || waitMs < 1 || waitMs > 1e4 || !Number.isSafeInteger(transactionTimeoutMs) || transactionTimeoutMs < 100 || transactionTimeoutMs > 12e4 || options.createKey !== void 0 && typeof options.createKey !== "boolean") throw refused2();
|
|
694
|
+
const identity = (0, import_node_crypto2.createHash)("sha256").update(`xeno/account/linux-host/1\0${namespace}\0${clientId}`).digest("hex");
|
|
695
|
+
const keyName = `Xeno.Account.${identity}`;
|
|
696
|
+
const refreshKey = `xeno.account/${clientId}/refresh`;
|
|
697
|
+
const keyring = deps.secretTool ? new Keyring(deps.secretTool, identity, clientId) : null;
|
|
698
|
+
let custody, privateKey, publicJwk;
|
|
699
|
+
let persistent;
|
|
700
|
+
const stored = keyring ? await keyring.read("dpop-key").catch(() => void 0) : void 0;
|
|
701
|
+
if (typeof stored === "string") {
|
|
702
|
+
({ privateKey, publicJwk } = parsePrivateJwk(stored));
|
|
703
|
+
persistent = true;
|
|
704
|
+
custody = {
|
|
705
|
+
kind: "linux-secret-service+software-key",
|
|
706
|
+
hardwareBacked: false,
|
|
707
|
+
nonExportable: false,
|
|
708
|
+
persistent: true,
|
|
709
|
+
createdKey: false,
|
|
710
|
+
keyName
|
|
711
|
+
};
|
|
712
|
+
} else {
|
|
713
|
+
if (options.createKey !== true) throw refused2();
|
|
714
|
+
const generated = (0, import_node_crypto2.generateKeyPairSync)("ec", {
|
|
715
|
+
namedCurve: "P-256"
|
|
716
|
+
});
|
|
717
|
+
const jwk = JSON.stringify(generated.privateKey.export({
|
|
718
|
+
format: "jwk"
|
|
719
|
+
}));
|
|
720
|
+
({ privateKey, publicJwk } = parsePrivateJwk(jwk));
|
|
721
|
+
if (keyring && stored === null && await keyring.works()) {
|
|
722
|
+
if (await keyring.read("refresh") !== null || await keyring.read("pending") !== null) throw refused2();
|
|
723
|
+
await keyring.write("dpop-key", jwk);
|
|
724
|
+
persistent = true;
|
|
725
|
+
custody = {
|
|
726
|
+
kind: "linux-secret-service+software-key",
|
|
727
|
+
hardwareBacked: false,
|
|
728
|
+
nonExportable: false,
|
|
729
|
+
persistent: true,
|
|
730
|
+
createdKey: true,
|
|
731
|
+
keyName
|
|
732
|
+
};
|
|
733
|
+
} else {
|
|
734
|
+
persistent = false;
|
|
735
|
+
custody = {
|
|
736
|
+
kind: "linux-session-memory+software-key",
|
|
737
|
+
hardwareBacked: false,
|
|
738
|
+
nonExportable: false,
|
|
739
|
+
persistent: false,
|
|
740
|
+
createdKey: true,
|
|
741
|
+
keyName
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const jkt = (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify({
|
|
746
|
+
crv: publicJwk.crv,
|
|
747
|
+
kty: publicJwk.kty,
|
|
748
|
+
x: publicJwk.x,
|
|
749
|
+
y: publicJwk.y
|
|
750
|
+
})).digest("base64url");
|
|
751
|
+
const memory = /* @__PURE__ */ new Map();
|
|
752
|
+
const lock = persistent ? new ProcessLock(deps.lockDirectory, identity) : null;
|
|
753
|
+
const context = new import_node_async_hooks2.AsyncLocalStorage();
|
|
754
|
+
let tail = Promise.resolve(), locks = 0, closed = false, closing = false, failed = false;
|
|
755
|
+
const current = /* @__PURE__ */ __name(() => {
|
|
756
|
+
if (closed || closing || failed) throw refused2();
|
|
757
|
+
}, "current");
|
|
758
|
+
const itemOf = /* @__PURE__ */ __name((key) => {
|
|
759
|
+
current();
|
|
760
|
+
if (key === refreshKey) return "refresh";
|
|
761
|
+
if (key === `${refreshKey}/pending`) return "pending";
|
|
762
|
+
throw refused2();
|
|
763
|
+
}, "itemOf");
|
|
764
|
+
const exclusive = /* @__PURE__ */ __name(async (key, work) => {
|
|
765
|
+
itemOf(key);
|
|
766
|
+
if (context.getStore() || locks >= 64) throw refused2();
|
|
767
|
+
locks++;
|
|
768
|
+
const prior = tail;
|
|
769
|
+
let release;
|
|
770
|
+
tail = new Promise((resolve) => {
|
|
771
|
+
release = resolve;
|
|
772
|
+
});
|
|
773
|
+
await prior;
|
|
774
|
+
const lease = {
|
|
775
|
+
id: (0, import_node_crypto2.randomUUID)(),
|
|
776
|
+
active: true
|
|
777
|
+
};
|
|
778
|
+
let acquired = false;
|
|
779
|
+
try {
|
|
780
|
+
current();
|
|
781
|
+
if (lock) {
|
|
782
|
+
await lock.acquire(waitMs);
|
|
783
|
+
acquired = true;
|
|
784
|
+
}
|
|
785
|
+
let timer;
|
|
786
|
+
try {
|
|
787
|
+
return await Promise.race([
|
|
788
|
+
context.run(lease, work),
|
|
789
|
+
new Promise((_resolve, reject) => {
|
|
790
|
+
timer = setTimeout(() => {
|
|
791
|
+
lease.active = false;
|
|
792
|
+
failed = true;
|
|
793
|
+
reject(refused2());
|
|
794
|
+
}, transactionTimeoutMs);
|
|
795
|
+
})
|
|
796
|
+
]);
|
|
797
|
+
} finally {
|
|
798
|
+
if (timer) clearTimeout(timer);
|
|
799
|
+
}
|
|
800
|
+
} finally {
|
|
801
|
+
lease.active = false;
|
|
802
|
+
try {
|
|
803
|
+
if (acquired && lock && !lock.release()) failed = true;
|
|
804
|
+
} finally {
|
|
805
|
+
locks--;
|
|
806
|
+
release();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}, "exclusive");
|
|
810
|
+
const storage = /* @__PURE__ */ __name(async (key, operation) => {
|
|
811
|
+
const item = itemOf(key);
|
|
812
|
+
const lease = context.getStore();
|
|
813
|
+
if (lease) {
|
|
814
|
+
if (!lease.active) throw refused2();
|
|
815
|
+
try {
|
|
816
|
+
return await operation(item);
|
|
817
|
+
} catch {
|
|
818
|
+
if (persistent) failed = true;
|
|
819
|
+
throw refused2();
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
return exclusive(refreshKey, () => storage(key, operation));
|
|
823
|
+
}, "storage");
|
|
824
|
+
const store = {
|
|
825
|
+
withExclusive: exclusive,
|
|
826
|
+
async get(key) {
|
|
827
|
+
return storage(key, async (item) => {
|
|
828
|
+
if (!keyring || !persistent) return memory.get(item) ?? null;
|
|
829
|
+
const value = await keyring.read(item);
|
|
830
|
+
if (value !== null && typeof value !== "string") throw refused2();
|
|
831
|
+
return value;
|
|
832
|
+
});
|
|
833
|
+
},
|
|
834
|
+
async set(key, text) {
|
|
835
|
+
if (typeof text !== "string" || Buffer.byteLength(text, "utf8") > MAX_VALUE_BYTES) throw refused2();
|
|
836
|
+
await storage(key, async (item) => {
|
|
837
|
+
if (!keyring || !persistent) {
|
|
838
|
+
memory.set(item, text);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
await keyring.write(item, text);
|
|
842
|
+
});
|
|
843
|
+
},
|
|
844
|
+
async delete(key) {
|
|
845
|
+
await storage(key, async (item) => {
|
|
846
|
+
if (!keyring || !persistent) {
|
|
847
|
+
memory.delete(item);
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
await keyring.remove(item);
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
const dpopSigner = {
|
|
855
|
+
jkt,
|
|
856
|
+
async createProof(args) {
|
|
857
|
+
current();
|
|
858
|
+
if (!args || typeof args.method !== "string" || typeof args.url !== "string" || args.url.length > 8192 || args.accessToken !== void 0 && (typeof args.accessToken !== "string" || args.accessToken.length > 16384 || !/^[\x21-\x7e]+$/.test(args.accessToken)) || args.nonce !== void 0 && (typeof args.nonce !== "string" || args.nonce.length > 4096 || /[\r\n]/.test(args.nonce))) throw refused2();
|
|
859
|
+
const method = args.method.toUpperCase();
|
|
860
|
+
let url;
|
|
861
|
+
try {
|
|
862
|
+
url = new URL(args.url);
|
|
863
|
+
} catch {
|
|
864
|
+
throw refused2();
|
|
865
|
+
}
|
|
866
|
+
if (!/^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS)$/.test(method) || url.username || url.password || url.protocol !== "https:") throw refused2();
|
|
867
|
+
const header = {
|
|
868
|
+
alg: "ES256",
|
|
869
|
+
typ: "dpop+jwt",
|
|
870
|
+
jwk: publicJwk
|
|
871
|
+
};
|
|
872
|
+
const claims = {
|
|
873
|
+
jti: (0, import_node_crypto2.randomUUID)(),
|
|
874
|
+
htm: method,
|
|
875
|
+
htu: normalizeDpopHtu(args.url),
|
|
876
|
+
iat: Math.floor(Date.now() / 1e3),
|
|
877
|
+
...args.accessToken ? {
|
|
878
|
+
ath: (0, import_node_crypto2.createHash)("sha256").update(args.accessToken).digest("base64url")
|
|
879
|
+
} : {},
|
|
880
|
+
...args.nonce ? {
|
|
881
|
+
nonce: args.nonce
|
|
882
|
+
} : {}
|
|
883
|
+
};
|
|
884
|
+
const a = Buffer.from(JSON.stringify(header)).toString("base64url"), b = Buffer.from(JSON.stringify(claims)).toString("base64url");
|
|
885
|
+
const signature = (0, import_node_crypto2.sign)("sha256", Buffer.from(`${a}.${b}`), {
|
|
886
|
+
key: privateKey,
|
|
887
|
+
dsaEncoding: "ieee-p1363"
|
|
888
|
+
});
|
|
889
|
+
if (signature.length !== 64) throw refused2();
|
|
890
|
+
return `${a}.${b}.${signature.toString("base64url")}`;
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
return {
|
|
894
|
+
store,
|
|
895
|
+
dpopSigner,
|
|
896
|
+
custody,
|
|
897
|
+
async close(input = {}) {
|
|
898
|
+
if (closed) return;
|
|
899
|
+
if (closing || locks || input.deleteCreatedKey && !custody.createdKey) throw refused2();
|
|
900
|
+
closing = true;
|
|
901
|
+
try {
|
|
902
|
+
if (input.deleteCreatedKey && keyring && persistent) await keyring.remove("dpop-key");
|
|
903
|
+
memory.clear();
|
|
904
|
+
closed = true;
|
|
905
|
+
} catch {
|
|
906
|
+
throw refused2();
|
|
907
|
+
} finally {
|
|
908
|
+
closing = false;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
__name(openLinuxAccountHost, "openLinuxAccountHost");
|
|
914
|
+
function parsePrivateJwk(text) {
|
|
915
|
+
if (Buffer.byteLength(text, "utf8") > MAX_KEY_BYTES) throw refused2();
|
|
916
|
+
let jwk;
|
|
917
|
+
try {
|
|
918
|
+
jwk = JSON.parse(text);
|
|
919
|
+
} catch {
|
|
920
|
+
throw refused2();
|
|
921
|
+
}
|
|
922
|
+
if (jwk.kty !== "EC" || jwk.crv !== "P-256" || typeof jwk.x !== "string" || typeof jwk.y !== "string" || typeof jwk.d !== "string") throw refused2();
|
|
923
|
+
try {
|
|
924
|
+
const privateKey = (0, import_node_crypto2.createPrivateKey)({
|
|
925
|
+
key: jwk,
|
|
926
|
+
format: "jwk"
|
|
927
|
+
});
|
|
928
|
+
return {
|
|
929
|
+
privateKey,
|
|
930
|
+
publicJwk: {
|
|
931
|
+
kty: "EC",
|
|
932
|
+
crv: "P-256",
|
|
933
|
+
x: jwk.x,
|
|
934
|
+
y: jwk.y
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
} catch {
|
|
938
|
+
throw refused2();
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
__name(parsePrivateJwk, "parsePrivateJwk");
|
|
942
|
+
var Keyring = class Keyring2 {
|
|
943
|
+
static {
|
|
944
|
+
__name(this, "Keyring");
|
|
945
|
+
}
|
|
946
|
+
run;
|
|
947
|
+
identity;
|
|
948
|
+
clientId;
|
|
949
|
+
constructor(run, identity, clientId) {
|
|
950
|
+
this.run = run;
|
|
951
|
+
this.identity = identity;
|
|
952
|
+
this.clientId = clientId;
|
|
953
|
+
}
|
|
954
|
+
attributes(item) {
|
|
955
|
+
return [
|
|
956
|
+
"xeno-account",
|
|
957
|
+
this.identity,
|
|
958
|
+
"item",
|
|
959
|
+
item
|
|
960
|
+
];
|
|
961
|
+
}
|
|
962
|
+
/** `null` = no such item; throws when the keyring itself did not answer. */
|
|
963
|
+
async read(item) {
|
|
964
|
+
const result = await this.run([
|
|
965
|
+
"lookup",
|
|
966
|
+
...this.attributes(item)
|
|
967
|
+
]);
|
|
968
|
+
if (result.code === 1 && !result.stdout && !result.stderr.trim()) return null;
|
|
969
|
+
if (result.code !== 0) throw refused2();
|
|
970
|
+
const raw = result.stdout.replace(/\n$/, "");
|
|
971
|
+
if (!raw.startsWith(VALUE_PREFIX)) throw refused2();
|
|
972
|
+
const bytes = Buffer.from(raw.slice(VALUE_PREFIX.length), "base64");
|
|
973
|
+
try {
|
|
974
|
+
return new TextDecoder("utf-8", {
|
|
975
|
+
fatal: true
|
|
976
|
+
}).decode(bytes);
|
|
977
|
+
} catch {
|
|
978
|
+
throw refused2();
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
async write(item, value) {
|
|
982
|
+
const encoded = VALUE_PREFIX + Buffer.from(value, "utf8").toString("base64");
|
|
983
|
+
const result = await this.run([
|
|
984
|
+
"store",
|
|
985
|
+
`--label=XENO account ${this.clientId} (${item})`,
|
|
986
|
+
...this.attributes(item)
|
|
987
|
+
], encoded);
|
|
988
|
+
if (result.code !== 0 || await this.read(item) !== value) throw refused2();
|
|
989
|
+
}
|
|
990
|
+
async remove(item) {
|
|
991
|
+
await this.run([
|
|
992
|
+
"clear",
|
|
993
|
+
...this.attributes(item)
|
|
994
|
+
]);
|
|
995
|
+
if (await this.read(item) !== null) throw refused2();
|
|
996
|
+
}
|
|
997
|
+
/** Proves the keyring stores, returns and clears a value before anything is committed to it. */
|
|
998
|
+
async works() {
|
|
999
|
+
const probe = `probe-${(0, import_node_crypto2.randomUUID)()}`;
|
|
1000
|
+
try {
|
|
1001
|
+
await this.write("probe", probe);
|
|
1002
|
+
await this.remove("probe");
|
|
1003
|
+
return true;
|
|
1004
|
+
} catch {
|
|
1005
|
+
try {
|
|
1006
|
+
await this.run([
|
|
1007
|
+
"clear",
|
|
1008
|
+
...this.attributes("probe")
|
|
1009
|
+
]);
|
|
1010
|
+
} catch {
|
|
1011
|
+
}
|
|
1012
|
+
return false;
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
function findSecretTool() {
|
|
1017
|
+
for (const directory of (process.env.PATH ?? "").split(import_node_path2.delimiter)) {
|
|
1018
|
+
if (!directory || !(0, import_node_path2.isAbsolute)(directory)) continue;
|
|
1019
|
+
const candidate = (0, import_node_path2.join)(directory, "secret-tool");
|
|
1020
|
+
try {
|
|
1021
|
+
if ((0, import_node_fs.statSync)(candidate).isFile()) return candidate;
|
|
1022
|
+
} catch {
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return null;
|
|
1026
|
+
}
|
|
1027
|
+
__name(findSecretTool, "findSecretTool");
|
|
1028
|
+
function secretToolRunner(executable, timeoutMs) {
|
|
1029
|
+
const allowed = [
|
|
1030
|
+
"PATH",
|
|
1031
|
+
"HOME",
|
|
1032
|
+
"USER",
|
|
1033
|
+
"LOGNAME",
|
|
1034
|
+
"DBUS_SESSION_BUS_ADDRESS",
|
|
1035
|
+
"XDG_RUNTIME_DIR",
|
|
1036
|
+
"DISPLAY",
|
|
1037
|
+
"WAYLAND_DISPLAY",
|
|
1038
|
+
"XAUTHORITY"
|
|
1039
|
+
];
|
|
1040
|
+
const env = {
|
|
1041
|
+
LC_ALL: "C"
|
|
1042
|
+
};
|
|
1043
|
+
for (const name of allowed) {
|
|
1044
|
+
const value = process.env[name];
|
|
1045
|
+
if (value) env[name] = value;
|
|
1046
|
+
}
|
|
1047
|
+
return (args, input) => new Promise((resolve, reject) => {
|
|
1048
|
+
const child = (0, import_node_child_process2.spawn)(executable, args, {
|
|
1049
|
+
stdio: [
|
|
1050
|
+
"pipe",
|
|
1051
|
+
"pipe",
|
|
1052
|
+
"pipe"
|
|
1053
|
+
],
|
|
1054
|
+
env,
|
|
1055
|
+
windowsHide: true
|
|
1056
|
+
});
|
|
1057
|
+
let stdout = "", stderr = "", settled = false;
|
|
1058
|
+
const finish = /* @__PURE__ */ __name((fn) => {
|
|
1059
|
+
if (!settled) {
|
|
1060
|
+
settled = true;
|
|
1061
|
+
clearTimeout(timer);
|
|
1062
|
+
fn();
|
|
1063
|
+
}
|
|
1064
|
+
}, "finish");
|
|
1065
|
+
const timer = setTimeout(() => {
|
|
1066
|
+
child.kill("SIGKILL");
|
|
1067
|
+
finish(() => reject(refused2()));
|
|
1068
|
+
}, timeoutMs);
|
|
1069
|
+
child.stdout.setEncoding("utf8").on("data", (chunk) => {
|
|
1070
|
+
stdout += chunk;
|
|
1071
|
+
if (stdout.length > 16384) {
|
|
1072
|
+
child.kill("SIGKILL");
|
|
1073
|
+
finish(() => reject(refused2()));
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
child.stderr.setEncoding("utf8").on("data", (chunk) => {
|
|
1077
|
+
stderr += chunk;
|
|
1078
|
+
if (stderr.length > 16384) stderr = stderr.slice(-16384);
|
|
1079
|
+
});
|
|
1080
|
+
child.once("error", () => finish(() => reject(refused2())));
|
|
1081
|
+
child.once("close", (code) => finish(() => resolve({
|
|
1082
|
+
code,
|
|
1083
|
+
stdout,
|
|
1084
|
+
stderr
|
|
1085
|
+
})));
|
|
1086
|
+
child.stdin.on("error", () => {
|
|
1087
|
+
});
|
|
1088
|
+
child.stdin.end(input ?? "");
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
__name(secretToolRunner, "secretToolRunner");
|
|
1092
|
+
function runtimeLockDirectory() {
|
|
1093
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
1094
|
+
const runtime = process.env.XDG_RUNTIME_DIR;
|
|
1095
|
+
if (runtime && (0, import_node_path2.isAbsolute)(runtime)) return (0, import_node_path2.join)(runtime, "xeno", "account");
|
|
1096
|
+
return (0, import_node_path2.join)((0, import_node_os.tmpdir)(), `xeno-account-${uid}`);
|
|
1097
|
+
}
|
|
1098
|
+
__name(runtimeLockDirectory, "runtimeLockDirectory");
|
|
1099
|
+
function privateDirectory(path) {
|
|
1100
|
+
(0, import_node_fs.mkdirSync)(path, {
|
|
1101
|
+
recursive: true,
|
|
1102
|
+
mode: 448
|
|
1103
|
+
});
|
|
1104
|
+
const stat = (0, import_node_fs.lstatSync)(path);
|
|
1105
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
1106
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || uid !== void 0 && stat.uid !== uid || process.platform !== "win32" && (stat.mode & 63) !== 0) throw refused2();
|
|
1107
|
+
}
|
|
1108
|
+
__name(privateDirectory, "privateDirectory");
|
|
1109
|
+
function readBootId() {
|
|
1110
|
+
try {
|
|
1111
|
+
return (0, import_node_fs.readFileSync)("/proc/sys/kernel/random/boot_id", "utf8").trim() || void 0;
|
|
1112
|
+
} catch {
|
|
1113
|
+
return void 0;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
__name(readBootId, "readBootId");
|
|
1117
|
+
function readStartTime(pid) {
|
|
1118
|
+
try {
|
|
1119
|
+
const stat = (0, import_node_fs.readFileSync)(`/proc/${pid}/stat`, "utf8");
|
|
1120
|
+
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
1121
|
+
} catch {
|
|
1122
|
+
return void 0;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
__name(readStartTime, "readStartTime");
|
|
1126
|
+
var ProcessLock = class ProcessLock2 {
|
|
1127
|
+
static {
|
|
1128
|
+
__name(this, "ProcessLock");
|
|
1129
|
+
}
|
|
1130
|
+
directory;
|
|
1131
|
+
path;
|
|
1132
|
+
token = null;
|
|
1133
|
+
constructor(directory, identity) {
|
|
1134
|
+
this.directory = directory;
|
|
1135
|
+
this.path = (0, import_node_path2.join)(directory, `${identity}.lock`);
|
|
1136
|
+
}
|
|
1137
|
+
async acquire(waitMs) {
|
|
1138
|
+
if (this.token) throw refused2();
|
|
1139
|
+
privateDirectory(this.directory);
|
|
1140
|
+
const deadline = Date.now() + waitMs;
|
|
1141
|
+
const token = (0, import_node_crypto2.randomUUID)();
|
|
1142
|
+
const record = {
|
|
1143
|
+
v: 1,
|
|
1144
|
+
token,
|
|
1145
|
+
pid: process.pid,
|
|
1146
|
+
host: (0, import_node_os.hostname)(),
|
|
1147
|
+
boot: readBootId(),
|
|
1148
|
+
start: readStartTime(process.pid)
|
|
1149
|
+
};
|
|
1150
|
+
for (; ; ) {
|
|
1151
|
+
try {
|
|
1152
|
+
const fd = (0, import_node_fs.openSync)(this.path, "wx", 384);
|
|
1153
|
+
try {
|
|
1154
|
+
(0, import_node_fs.writeSync)(fd, JSON.stringify(record));
|
|
1155
|
+
(0, import_node_fs.fsyncSync)(fd);
|
|
1156
|
+
} finally {
|
|
1157
|
+
(0, import_node_fs.closeSync)(fd);
|
|
1158
|
+
}
|
|
1159
|
+
this.token = token;
|
|
1160
|
+
return;
|
|
1161
|
+
} catch (error) {
|
|
1162
|
+
if (error.code !== "EEXIST") throw refused2();
|
|
1163
|
+
}
|
|
1164
|
+
this.breakIfGone();
|
|
1165
|
+
if (Date.now() >= deadline) throw refused2();
|
|
1166
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
/** False when this process no longer held the lock it took, so its transaction was not exclusive. */
|
|
1170
|
+
release() {
|
|
1171
|
+
const token = this.token;
|
|
1172
|
+
this.token = null;
|
|
1173
|
+
if (!token) return false;
|
|
1174
|
+
const holder = this.readHolder(this.path);
|
|
1175
|
+
if (holder?.token !== token) return false;
|
|
1176
|
+
try {
|
|
1177
|
+
(0, import_node_fs.unlinkSync)(this.path);
|
|
1178
|
+
return true;
|
|
1179
|
+
} catch {
|
|
1180
|
+
return false;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
readHolder(path) {
|
|
1184
|
+
try {
|
|
1185
|
+
const value = JSON.parse((0, import_node_fs.readFileSync)(path, "utf8"));
|
|
1186
|
+
return value && value.v === 1 && typeof value.token === "string" && Number.isSafeInteger(value.pid) && typeof value.host === "string" ? value : null;
|
|
1187
|
+
} catch (error) {
|
|
1188
|
+
return error.code === "ENOENT" ? void 0 : null;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
gone(holder) {
|
|
1192
|
+
if (holder === null) {
|
|
1193
|
+
try {
|
|
1194
|
+
return Date.now() - (0, import_node_fs.statSync)(this.path).mtimeMs > 3e4;
|
|
1195
|
+
} catch {
|
|
1196
|
+
return false;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (holder.host !== (0, import_node_os.hostname)()) return false;
|
|
1200
|
+
const boot = readBootId();
|
|
1201
|
+
if (boot && holder.boot && boot !== holder.boot) return true;
|
|
1202
|
+
try {
|
|
1203
|
+
process.kill(holder.pid, 0);
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
return error.code === "ESRCH";
|
|
1206
|
+
}
|
|
1207
|
+
const start = readStartTime(holder.pid);
|
|
1208
|
+
return Boolean(start && holder.start && start !== holder.start);
|
|
1209
|
+
}
|
|
1210
|
+
breakIfGone() {
|
|
1211
|
+
const holder = this.readHolder(this.path);
|
|
1212
|
+
if (holder === void 0 || !this.gone(holder)) return;
|
|
1213
|
+
const moved = `${this.path}.stale-${(0, import_node_crypto2.randomUUID)()}`;
|
|
1214
|
+
try {
|
|
1215
|
+
(0, import_node_fs.renameSync)(this.path, moved);
|
|
1216
|
+
} catch {
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
const removed = this.readHolder(moved);
|
|
1220
|
+
if (holder !== null && removed?.token !== holder.token) {
|
|
1221
|
+
try {
|
|
1222
|
+
(0, import_node_fs.linkSync)(moved, this.path);
|
|
1223
|
+
} catch {
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
try {
|
|
1227
|
+
(0, import_node_fs.unlinkSync)(moved);
|
|
1228
|
+
} catch {
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
|
|
660
1233
|
// src/node.ts
|
|
661
1234
|
function createNodeDpopSigner(input) {
|
|
662
1235
|
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
@@ -670,13 +1243,13 @@ function createNodeDpopSigner(input) {
|
|
|
670
1243
|
x: privateJwk.x,
|
|
671
1244
|
y: privateJwk.y
|
|
672
1245
|
};
|
|
673
|
-
const jkt =
|
|
1246
|
+
const jkt = import_node_crypto3.default.createHash("sha256").update(JSON.stringify({
|
|
674
1247
|
crv: "P-256",
|
|
675
1248
|
kty: "EC",
|
|
676
1249
|
x: privateJwk.x,
|
|
677
1250
|
y: privateJwk.y
|
|
678
1251
|
})).digest("base64url");
|
|
679
|
-
const key =
|
|
1252
|
+
const key = import_node_crypto3.default.createPrivateKey({
|
|
680
1253
|
key: privateJwk,
|
|
681
1254
|
format: "jwk"
|
|
682
1255
|
});
|
|
@@ -689,16 +1262,16 @@ function createNodeDpopSigner(input) {
|
|
|
689
1262
|
jwk: publicJwk
|
|
690
1263
|
};
|
|
691
1264
|
const claims = {
|
|
692
|
-
jti:
|
|
1265
|
+
jti: import_node_crypto3.default.randomUUID(),
|
|
693
1266
|
htm: args.method.toUpperCase(),
|
|
694
1267
|
htu: normalizeDpopHtu(args.url),
|
|
695
1268
|
iat: Math.floor(Date.now() / 1e3)
|
|
696
1269
|
};
|
|
697
|
-
if (args.accessToken) claims.ath =
|
|
1270
|
+
if (args.accessToken) claims.ath = import_node_crypto3.default.createHash("sha256").update(args.accessToken).digest("base64url");
|
|
698
1271
|
if (args.nonce) claims.nonce = args.nonce;
|
|
699
1272
|
const a = Buffer.from(JSON.stringify(header)).toString("base64url");
|
|
700
1273
|
const b = Buffer.from(JSON.stringify(claims)).toString("base64url");
|
|
701
|
-
const signature =
|
|
1274
|
+
const signature = import_node_crypto3.default.sign("sha256", Buffer.from(`${a}.${b}`), {
|
|
702
1275
|
key,
|
|
703
1276
|
dsaEncoding: "ieee-p1363"
|
|
704
1277
|
}).toString("base64url");
|
|
@@ -709,6 +1282,7 @@ function createNodeDpopSigner(input) {
|
|
|
709
1282
|
__name(createNodeDpopSigner, "createNodeDpopSigner");
|
|
710
1283
|
// Annotate the CommonJS export names for ESM import in node:
|
|
711
1284
|
0 && (module.exports = {
|
|
1285
|
+
createLinuxAccountHost,
|
|
712
1286
|
createNodeDpopSigner,
|
|
713
1287
|
createWindowsAccountHost
|
|
714
1288
|
});
|