@supersdk/supercli 0.1.0-dev.1
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/api/consoleClient.js +132 -0
- package/dist/api/consoleClient.js.map +1 -0
- package/dist/auth/browserAuth.js +163 -0
- package/dist/auth/browserAuth.js.map +1 -0
- package/dist/auth/refresh.js +32 -0
- package/dist/auth/refresh.js.map +1 -0
- package/dist/cli.js +46 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/accounts.js +46 -0
- package/dist/commands/accounts.js.map +1 -0
- package/dist/commands/createApp.js +225 -0
- package/dist/commands/createApp.js.map +1 -0
- package/dist/commands/login.js +54 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.js +99 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/publishSite.js +361 -0
- package/dist/commands/publishSite.js.map +1 -0
- package/dist/commands/switchaccount.js +35 -0
- package/dist/commands/switchaccount.js.map +1 -0
- package/dist/commands/update.js +95 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/config/environments.js +53 -0
- package/dist/config/environments.js.map +1 -0
- package/dist/createApp/copyTemplate.js +237 -0
- package/dist/createApp/copyTemplate.js.map +1 -0
- package/dist/publish/orgResolve.js +30 -0
- package/dist/publish/orgResolve.js.map +1 -0
- package/dist/publish/responseClassifier.js +111 -0
- package/dist/publish/responseClassifier.js.map +1 -0
- package/dist/publish/siteClient.js +113 -0
- package/dist/publish/siteClient.js.map +1 -0
- package/dist/publish/siteConfig.js +190 -0
- package/dist/publish/siteConfig.js.map +1 -0
- package/dist/publish/siteZip.js +172 -0
- package/dist/publish/siteZip.js.map +1 -0
- package/dist/store/accountStore.js +236 -0
- package/dist/store/accountStore.js.map +1 -0
- package/dist/store/backends/encryptedFile.js +162 -0
- package/dist/store/backends/encryptedFile.js.map +1 -0
- package/dist/store/backends/osKeyring.js +283 -0
- package/dist/store/backends/osKeyring.js.map +1 -0
- package/dist/store/credentialStore.js +65 -0
- package/dist/store/credentialStore.js.map +1 -0
- package/dist/template/README.md +144 -0
- package/dist/template/android/.gitkeep +1 -0
- package/dist/template/android/app/build.gradle.kts +122 -0
- package/dist/template/android/app/src/main/AndroidManifest.xml +19 -0
- package/dist/template/android/app/src/main/java/com/supersdk/simple/MainActivity.java +17 -0
- package/dist/template/android/app/src/main/java/com/supersdk/simple/SimpleApplication.java +22 -0
- package/dist/template/android/app/src/test/java/com/supersdk/simple/AppNameResourceTest.java +19 -0
- package/dist/template/android/build.gradle.kts +3 -0
- package/dist/template/android/gradle/supersdk-config-reader.gradle +61 -0
- package/dist/template/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/dist/template/android/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/dist/template/android/gradle.properties +3 -0
- package/dist/template/android/gradlew +251 -0
- package/dist/template/android/settings.gradle.kts +25 -0
- package/dist/template/android/supersdk-default.config.json +17 -0
- package/dist/template/ios/MockSuperSDKPackage/Package.swift +15 -0
- package/dist/template/ios/MockSuperSDKPackage/Sources/SuperSDK/SuperSDK.swift +25 -0
- package/dist/template/ios/Resources/Info.plist +43 -0
- package/dist/template/ios/Sources/App/AppDelegate.swift +20 -0
- package/dist/template/ios/Sources/App/SceneDelegate.swift +14 -0
- package/dist/template/ios/Sources/App/SimpleSDKBootstrap.swift +7 -0
- package/dist/template/ios/Sources/App/SimpleSDKProbe.swift +26 -0
- package/dist/template/ios/Sources/App/SimpleSDKProvider.swift +4 -0
- package/dist/template/ios/Sources/App/SimpleViewController.swift +20 -0
- package/dist/template/ios/Tests/SimpleAppTests/SimpleSDKInitializationTests.swift +17 -0
- package/dist/template/ios/project.yml +67 -0
- package/dist/template/scripts/android_snapshot_canary.py +136 -0
- package/dist/template/scripts/build_android.sh +240 -0
- package/dist/template/scripts/build_ios.sh +261 -0
- package/dist/template/scripts/build_web.sh +12 -0
- package/dist/template/scripts/serve_web.py +51 -0
- package/dist/template/scripts/super_build_orchestrator.py +400 -0
- package/dist/template/scripts/supersdk_template.py +611 -0
- package/dist/template/scripts/web_host_validator.py +103 -0
- package/dist/template/scripts/web_package.py +202 -0
- package/dist/template/scripts/ws03_shared_schema_merge_guard.py +73 -0
- package/dist/template/super_build.sh +116 -0
- package/dist/template/supersdk.yaml +15 -0
- package/dist/template/web/src/css/style.css +83 -0
- package/dist/template/web/src/index.html +37 -0
- package/dist/template/web/src/js/app.js +99 -0
- package/dist/template/web/src/js/supersdk.js +1848 -0
- package/dist/template/web/src/js/supersdk.provenance.json +6 -0
- package/dist/update/channelResolver.js +183 -0
- package/dist/update/channelResolver.js.map +1 -0
- package/dist/update/installSafety.js +135 -0
- package/dist/update/installSafety.js.map +1 -0
- package/dist/util/fsAtomic.js +294 -0
- package/dist/util/fsAtomic.js.map +1 -0
- package/dist/util/log.js +55 -0
- package/dist/util/log.js.map +1 -0
- package/dist/util/origin.js +66 -0
- package/dist/util/origin.js.map +1 -0
- package/dist/util/prompt.js +113 -0
- package/dist/util/prompt.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.WrongPassphraseError = void 0;
|
|
37
|
+
exports.createEncryptedFileBackend = createEncryptedFileBackend;
|
|
38
|
+
// Opt-in credential fallback for systems with no OS credential service
|
|
39
|
+
// (headless Linux / WSL without secret-tool) — TECH.md D-1 decision B:
|
|
40
|
+
// AES-256-GCM with a scrypt-derived key, passphrase required on every use,
|
|
41
|
+
// never silently substituted for the OS backend (that gate lives in
|
|
42
|
+
// credentialStore.selectCredentialBackend, not here).
|
|
43
|
+
//
|
|
44
|
+
// Each account's secret is encrypted independently (own salt + iv + auth
|
|
45
|
+
// tag), so one account's corrupted/tampered vault entry cannot affect
|
|
46
|
+
// another's — TC-32. A GCM auth-tag mismatch (wrong passphrase OR tampered
|
|
47
|
+
// ciphertext) throws before any plaintext is returned — TC-30: no partial
|
|
48
|
+
// decryption, no plaintext residue.
|
|
49
|
+
const crypto = __importStar(require("node:crypto"));
|
|
50
|
+
const fs = __importStar(require("node:fs"));
|
|
51
|
+
const os = __importStar(require("node:os"));
|
|
52
|
+
const path = __importStar(require("node:path"));
|
|
53
|
+
const fsAtomic_1 = require("../../util/fsAtomic");
|
|
54
|
+
const SCRYPT_KEYLEN = 32;
|
|
55
|
+
// RFC 7914 "interactive" tier scrypt params — a passphrase is entered on
|
|
56
|
+
// every use, so this must stay fast enough not to be an annoyance while
|
|
57
|
+
// still being expensive to brute-force offline. N=2**14 needs ~16MiB, safely
|
|
58
|
+
// under Node's default scryptSync 32MiB maxmem (N=2**15 sits exactly at that
|
|
59
|
+
// cap and gets rejected).
|
|
60
|
+
const SCRYPT_PARAMS = { N: 2 ** 14, r: 8, p: 1 };
|
|
61
|
+
function vaultPath() {
|
|
62
|
+
const dir = process.env.SUPERCLI_HOME ?? path.join(os.homedir(), '.supersdk', 'cli');
|
|
63
|
+
return path.join(dir, 'vault.enc.json');
|
|
64
|
+
}
|
|
65
|
+
function emptyVault() {
|
|
66
|
+
return { version: 1, entries: {} };
|
|
67
|
+
}
|
|
68
|
+
function readVault() {
|
|
69
|
+
let raw;
|
|
70
|
+
try {
|
|
71
|
+
raw = fs.readFileSync(vaultPath(), 'utf8');
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
if (err.code === 'ENOENT')
|
|
75
|
+
return emptyVault();
|
|
76
|
+
return emptyVault();
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const parsed = JSON.parse(raw);
|
|
80
|
+
if (!parsed || typeof parsed !== 'object' || typeof parsed.entries !== 'object' || parsed.entries === null) {
|
|
81
|
+
return emptyVault();
|
|
82
|
+
}
|
|
83
|
+
return parsed;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return emptyVault();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function writeVault(vault) {
|
|
90
|
+
(0, fsAtomic_1.atomicWriteFileSync)(vaultPath(), JSON.stringify(vault, null, 2));
|
|
91
|
+
}
|
|
92
|
+
function deriveKey(passphrase, salt) {
|
|
93
|
+
return crypto.scryptSync(passphrase, salt, SCRYPT_KEYLEN, SCRYPT_PARAMS);
|
|
94
|
+
}
|
|
95
|
+
class WrongPassphraseError extends Error {
|
|
96
|
+
constructor() {
|
|
97
|
+
super('wrong passphrase, or the credential entry is corrupted');
|
|
98
|
+
this.name = 'WrongPassphraseError';
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.WrongPassphraseError = WrongPassphraseError;
|
|
102
|
+
function createEncryptedFileBackend(getPassphrase) {
|
|
103
|
+
return {
|
|
104
|
+
kind: 'encrypted-file',
|
|
105
|
+
isAvailable() {
|
|
106
|
+
// Pure Node crypto + local file — no OS dependency, always available.
|
|
107
|
+
return true;
|
|
108
|
+
},
|
|
109
|
+
get(accountKey) {
|
|
110
|
+
const vault = readVault();
|
|
111
|
+
const entry = vault.entries[accountKey];
|
|
112
|
+
if (!entry)
|
|
113
|
+
return null;
|
|
114
|
+
const passphrase = getPassphrase();
|
|
115
|
+
const salt = Buffer.from(entry.salt, 'base64');
|
|
116
|
+
const iv = Buffer.from(entry.iv, 'base64');
|
|
117
|
+
const tag = Buffer.from(entry.tag, 'base64');
|
|
118
|
+
const ciphertext = Buffer.from(entry.ciphertext, 'base64');
|
|
119
|
+
const key = deriveKey(passphrase, salt);
|
|
120
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
|
|
121
|
+
decipher.setAuthTag(tag);
|
|
122
|
+
try {
|
|
123
|
+
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
124
|
+
return JSON.parse(plaintext.toString('utf8'));
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// GCM tag verification failed before any plaintext was returned —
|
|
128
|
+
// fail closed, no partial content, no distinction between "wrong
|
|
129
|
+
// passphrase" and "corrupted ciphertext" is leaked to the caller.
|
|
130
|
+
throw new WrongPassphraseError();
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
set(accountKey, secret) {
|
|
134
|
+
const passphrase = getPassphrase();
|
|
135
|
+
const salt = crypto.randomBytes(16);
|
|
136
|
+
const iv = crypto.randomBytes(12);
|
|
137
|
+
const key = deriveKey(passphrase, salt);
|
|
138
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
|
|
139
|
+
const plaintext = Buffer.from(JSON.stringify(secret), 'utf8');
|
|
140
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
141
|
+
const tag = cipher.getAuthTag();
|
|
142
|
+
const vault = readVault();
|
|
143
|
+
vault.entries[accountKey] = {
|
|
144
|
+
salt: salt.toString('base64'),
|
|
145
|
+
iv: iv.toString('base64'),
|
|
146
|
+
tag: tag.toString('base64'),
|
|
147
|
+
ciphertext: ciphertext.toString('base64'),
|
|
148
|
+
};
|
|
149
|
+
writeVault(vault);
|
|
150
|
+
},
|
|
151
|
+
delete(accountKey) {
|
|
152
|
+
// Deleting never needs the passphrase — it only removes the entry, it
|
|
153
|
+
// does not need to decrypt it first.
|
|
154
|
+
const vault = readVault();
|
|
155
|
+
if (vault.entries[accountKey]) {
|
|
156
|
+
delete vault.entries[accountKey];
|
|
157
|
+
writeVault(vault);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=encryptedFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryptedFile.js","sourceRoot":"","sources":["../../../src/store/backends/encryptedFile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,gEA6DC;AAhJD,uEAAuE;AACvE,uEAAuE;AACvE,2EAA2E;AAC3E,oEAAoE;AACpE,sDAAsD;AACtD,EAAE;AACF,yEAAyE;AACzE,sEAAsE;AACtE,2EAA2E;AAC3E,0EAA0E;AAC1E,oCAAoC;AACpC,oDAAsC;AACtC,4CAA8B;AAC9B,4CAA8B;AAC9B,gDAAkC;AAClC,kDAA0D;AAe1D,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,yEAAyE;AACzE,wEAAwE;AACxE,6EAA6E;AAC7E,6EAA6E;A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BAC1B,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC7B,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBACzB,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC3B,UAAU,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;aAC1C,CAAC;YACF,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;QACD,MAAM,CAAC,UAAU;YACf,sEAAsE;YACtE,qCAAqC;YACrC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;YAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACjC,UAAU,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createOsKeyringBackend = createOsKeyringBackend;
|
|
37
|
+
// Default credential backend: shell out to the platform's system credential
|
|
38
|
+
// service. Zero native npm dependency, so `npm install -g @supersdk/supercli`
|
|
39
|
+
// never needs a compiler (AC-1/R4) — this was the explicit blueprint decision
|
|
40
|
+
// over keytar (unmaintained + node-gyp) and @napi-rs/keyring (prebuilt native,
|
|
41
|
+
// kept only as a fallback candidate if this proves unreliable in the field).
|
|
42
|
+
//
|
|
43
|
+
// Platform coverage (TECH.md §跨平台凭据后端候选对比):
|
|
44
|
+
// macOS -> /usr/bin/security (Keychain), generic password items
|
|
45
|
+
// Linux -> secret-tool (libsecret / Secret Service); commonly absent on
|
|
46
|
+
// headless systems, which is exactly the case isAvailable() must
|
|
47
|
+
// detect so credentialStore falls through to the encrypted-file
|
|
48
|
+
// opt-in instead of failing unhelpfully (TC-29)
|
|
49
|
+
// Windows -> Windows Credential Manager via advapi32 CredWrite/CredRead/
|
|
50
|
+
// CredDelete, invoked through a PowerShell P/Invoke script (no
|
|
51
|
+
// native npm module). NOTE: this path has been reviewed but not
|
|
52
|
+
// exercised against a real Windows machine in this change — see
|
|
53
|
+
// TECH.md residual risk table ("Windows 凭据后端未真机实证"); it
|
|
54
|
+
// is covered here only by mocked unit tests + code review, with
|
|
55
|
+
// real-machine verification deferred to the BL-006 window.
|
|
56
|
+
const node_child_process_1 = require("node:child_process");
|
|
57
|
+
const os = __importStar(require("node:os"));
|
|
58
|
+
const SERVICE = 'supersdk-cli';
|
|
59
|
+
function serialize(secret) {
|
|
60
|
+
return JSON.stringify(secret);
|
|
61
|
+
}
|
|
62
|
+
function deserialize(raw) {
|
|
63
|
+
const parsed = JSON.parse(raw);
|
|
64
|
+
if (typeof parsed.accessToken !== 'string' ||
|
|
65
|
+
typeof parsed.accessExpiresAt !== 'number' ||
|
|
66
|
+
typeof parsed.refreshToken !== 'string' ||
|
|
67
|
+
typeof parsed.refreshExpiresAt !== 'number') {
|
|
68
|
+
throw new Error('malformed credential payload read from OS keyring');
|
|
69
|
+
}
|
|
70
|
+
return parsed;
|
|
71
|
+
}
|
|
72
|
+
// ---- macOS: /usr/bin/security ----
|
|
73
|
+
function darwinBackend() {
|
|
74
|
+
return {
|
|
75
|
+
kind: 'os-keyring',
|
|
76
|
+
isAvailable() {
|
|
77
|
+
const probe = (0, node_child_process_1.spawnSync)('security', ['-h'], { stdio: 'ignore' });
|
|
78
|
+
return probe.error == null;
|
|
79
|
+
},
|
|
80
|
+
get(accountKey) {
|
|
81
|
+
const res = (0, node_child_process_1.spawnSync)('security', ['find-generic-password', '-a', accountKey, '-s', SERVICE, '-w'], {
|
|
82
|
+
encoding: 'utf8',
|
|
83
|
+
});
|
|
84
|
+
if (res.error || res.status !== 0 || !res.stdout)
|
|
85
|
+
return null;
|
|
86
|
+
return deserialize(res.stdout.trim());
|
|
87
|
+
},
|
|
88
|
+
set(accountKey, secret) {
|
|
89
|
+
// `security` has no stdin-based write path for generic passwords — the
|
|
90
|
+
// secret is necessarily an argv element of this OS helper process (not
|
|
91
|
+
// SuperCLI's own process argv, and never logged). This is the same
|
|
92
|
+
// approach used by e.g. git-credential-osxkeychain; documented residual.
|
|
93
|
+
const res = (0, node_child_process_1.spawnSync)('security', ['add-generic-password', '-a', accountKey, '-s', SERVICE, '-w', serialize(secret), '-U'], { stdio: 'ignore' });
|
|
94
|
+
if (res.error || res.status !== 0) {
|
|
95
|
+
throw new Error(`macOS Keychain write failed (exit ${res.status ?? 'spawn error'})`);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
delete(accountKey) {
|
|
99
|
+
// Best-effort: deleting an already-absent entry is not an error.
|
|
100
|
+
(0, node_child_process_1.spawnSync)('security', ['delete-generic-password', '-a', accountKey, '-s', SERVICE], { stdio: 'ignore' });
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// ---- Linux: secret-tool (libsecret) ----
|
|
105
|
+
function linuxBackend() {
|
|
106
|
+
return {
|
|
107
|
+
kind: 'os-keyring',
|
|
108
|
+
isAvailable() {
|
|
109
|
+
// secret-tool is frequently absent on headless/CI/WSL systems — that is
|
|
110
|
+
// precisely the case that must route to the encrypted-file opt-in
|
|
111
|
+
// fallback rather than fail with a confusing OS error (TC-29).
|
|
112
|
+
const probe = (0, node_child_process_1.spawnSync)('secret-tool', ['--version'], { stdio: 'ignore' });
|
|
113
|
+
return probe.error == null;
|
|
114
|
+
},
|
|
115
|
+
get(accountKey) {
|
|
116
|
+
const res = (0, node_child_process_1.spawnSync)('secret-tool', ['lookup', 'service', SERVICE, 'account', accountKey], {
|
|
117
|
+
encoding: 'utf8',
|
|
118
|
+
});
|
|
119
|
+
if (res.error || res.status !== 0 || !res.stdout)
|
|
120
|
+
return null;
|
|
121
|
+
return deserialize(res.stdout.trim());
|
|
122
|
+
},
|
|
123
|
+
set(accountKey, secret) {
|
|
124
|
+
// secret-tool reads the secret value from stdin, not argv — the
|
|
125
|
+
// preferred channel (never appears in any process's argv).
|
|
126
|
+
const res = (0, node_child_process_1.spawnSync)('secret-tool', ['store', '--label', `SuperSDK CLI (${accountKey})`, 'service', SERVICE, 'account', accountKey], { input: serialize(secret), encoding: 'utf8' });
|
|
127
|
+
if (res.error || res.status !== 0) {
|
|
128
|
+
throw new Error(`secret-tool write failed (exit ${res.status ?? 'spawn error'})`);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
delete(accountKey) {
|
|
132
|
+
(0, node_child_process_1.spawnSync)('secret-tool', ['clear', 'service', SERVICE, 'account', accountKey], { stdio: 'ignore' });
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// ---- Windows: Credential Manager via PowerShell P/Invoke ----
|
|
137
|
+
function psQuote(value) {
|
|
138
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
139
|
+
}
|
|
140
|
+
function credentialTarget(accountKey) {
|
|
141
|
+
return `${SERVICE}:${accountKey}`;
|
|
142
|
+
}
|
|
143
|
+
const WIN_CRED_TYPE_DEFINITION = `
|
|
144
|
+
if (-not ("SuperCliCred" -as [type])) {
|
|
145
|
+
Add-Type @"
|
|
146
|
+
using System;
|
|
147
|
+
using System.Runtime.InteropServices;
|
|
148
|
+
public static class SuperCliCred {
|
|
149
|
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
150
|
+
public struct CREDENTIAL {
|
|
151
|
+
public int Flags;
|
|
152
|
+
public int Type;
|
|
153
|
+
public IntPtr TargetName;
|
|
154
|
+
public IntPtr Comment;
|
|
155
|
+
public long LastWritten;
|
|
156
|
+
public int CredentialBlobSize;
|
|
157
|
+
public IntPtr CredentialBlob;
|
|
158
|
+
public int Persist;
|
|
159
|
+
public int AttributeCount;
|
|
160
|
+
public IntPtr Attributes;
|
|
161
|
+
public IntPtr TargetAlias;
|
|
162
|
+
public IntPtr UserName;
|
|
163
|
+
}
|
|
164
|
+
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
165
|
+
public static extern bool CredWriteW(ref CREDENTIAL credential, uint flags);
|
|
166
|
+
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
167
|
+
public static extern bool CredReadW(string target, int type, int reservedFlag, out IntPtr credentialPtr);
|
|
168
|
+
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
169
|
+
public static extern bool CredDeleteW(string target, int type, int flags);
|
|
170
|
+
[DllImport("advapi32.dll")]
|
|
171
|
+
public static extern void CredFree(IntPtr buffer);
|
|
172
|
+
}
|
|
173
|
+
"@
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
function winSetScript(accountKey) {
|
|
177
|
+
const targetLiteral = psQuote(credentialTarget(accountKey));
|
|
178
|
+
return `${WIN_CRED_TYPE_DEFINITION}
|
|
179
|
+
$secret = [Console]::In.ReadToEnd()
|
|
180
|
+
$bytes = [System.Text.Encoding]::Unicode.GetBytes($secret)
|
|
181
|
+
$blob = [Runtime.InteropServices.Marshal]::AllocHGlobal([Math]::Max($bytes.Length, 1))
|
|
182
|
+
try {
|
|
183
|
+
[Runtime.InteropServices.Marshal]::Copy($bytes, 0, $blob, $bytes.Length)
|
|
184
|
+
$targetPtr = [Runtime.InteropServices.Marshal]::StringToHGlobalUni(${targetLiteral})
|
|
185
|
+
try {
|
|
186
|
+
$cred = New-Object SuperCliCred+CREDENTIAL
|
|
187
|
+
$cred.Type = 1
|
|
188
|
+
$cred.TargetName = $targetPtr
|
|
189
|
+
$cred.CredentialBlobSize = $bytes.Length
|
|
190
|
+
$cred.CredentialBlob = $blob
|
|
191
|
+
$cred.Persist = 2
|
|
192
|
+
$ok = [SuperCliCred]::CredWriteW([ref]$cred, 0)
|
|
193
|
+
if (-not $ok) { Write-Error "CredWriteW failed"; exit 1 }
|
|
194
|
+
} finally {
|
|
195
|
+
[Runtime.InteropServices.Marshal]::FreeHGlobal($targetPtr)
|
|
196
|
+
}
|
|
197
|
+
} finally {
|
|
198
|
+
[Runtime.InteropServices.Marshal]::FreeHGlobal($blob)
|
|
199
|
+
}
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
function winGetScript(accountKey) {
|
|
203
|
+
const targetLiteral = psQuote(credentialTarget(accountKey));
|
|
204
|
+
return `${WIN_CRED_TYPE_DEFINITION}
|
|
205
|
+
$ptr = [IntPtr]::Zero
|
|
206
|
+
$ok = [SuperCliCred]::CredReadW(${targetLiteral}, 1, 0, [ref]$ptr)
|
|
207
|
+
if (-not $ok) { exit 2 }
|
|
208
|
+
try {
|
|
209
|
+
$cred = [Runtime.InteropServices.Marshal]::PtrToStructure($ptr, [type][SuperCliCred+CREDENTIAL])
|
|
210
|
+
$bytes = New-Object byte[] $cred.CredentialBlobSize
|
|
211
|
+
[Runtime.InteropServices.Marshal]::Copy($cred.CredentialBlob, $bytes, 0, $cred.CredentialBlobSize)
|
|
212
|
+
[Console]::Out.Write([System.Text.Encoding]::Unicode.GetString($bytes))
|
|
213
|
+
} finally {
|
|
214
|
+
[SuperCliCred]::CredFree($ptr)
|
|
215
|
+
}
|
|
216
|
+
`;
|
|
217
|
+
}
|
|
218
|
+
function winDeleteScript(accountKey) {
|
|
219
|
+
const targetLiteral = psQuote(credentialTarget(accountKey));
|
|
220
|
+
return `${WIN_CRED_TYPE_DEFINITION}
|
|
221
|
+
[SuperCliCred]::CredDeleteW(${targetLiteral}, 1, 0) | Out-Null
|
|
222
|
+
`;
|
|
223
|
+
}
|
|
224
|
+
function runPowerShellEncoded(script, stdinInput) {
|
|
225
|
+
// -EncodedCommand (Base64 UTF-16LE) sidesteps all -Command quoting/escaping
|
|
226
|
+
// hazards; the account key is embedded inside this opaque blob (never a
|
|
227
|
+
// separate argv element), and the secret itself is passed over stdin only.
|
|
228
|
+
const encoded = Buffer.from(script, 'utf16le').toString('base64');
|
|
229
|
+
return (0, node_child_process_1.spawnSync)('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', encoded], { input: stdinInput, encoding: 'utf8' });
|
|
230
|
+
}
|
|
231
|
+
function windowsBackend() {
|
|
232
|
+
return {
|
|
233
|
+
kind: 'os-keyring',
|
|
234
|
+
isAvailable() {
|
|
235
|
+
const probe = (0, node_child_process_1.spawnSync)('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', 'exit 0'], {
|
|
236
|
+
stdio: 'ignore',
|
|
237
|
+
});
|
|
238
|
+
return probe.error == null;
|
|
239
|
+
},
|
|
240
|
+
get(accountKey) {
|
|
241
|
+
const res = runPowerShellEncoded(winGetScript(accountKey));
|
|
242
|
+
if (res.error || res.status !== 0 || !res.stdout)
|
|
243
|
+
return null;
|
|
244
|
+
return deserialize(res.stdout);
|
|
245
|
+
},
|
|
246
|
+
set(accountKey, secret) {
|
|
247
|
+
const res = runPowerShellEncoded(winSetScript(accountKey), serialize(secret));
|
|
248
|
+
if (res.error || res.status !== 0) {
|
|
249
|
+
throw new Error(`Windows Credential Manager write failed: ${res.stderr || res.status || 'spawn error'}`);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
delete(accountKey) {
|
|
253
|
+
runPowerShellEncoded(winDeleteScript(accountKey));
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
function unsupportedBackend(platform) {
|
|
258
|
+
return {
|
|
259
|
+
kind: 'os-keyring',
|
|
260
|
+
isAvailable: () => false,
|
|
261
|
+
get: () => null,
|
|
262
|
+
set: () => {
|
|
263
|
+
throw new Error(`no OS keyring backend implemented for platform "${platform}"`);
|
|
264
|
+
},
|
|
265
|
+
delete: () => {
|
|
266
|
+
// Nothing to do — isAvailable() is false so this backend should never
|
|
267
|
+
// hold state in the first place.
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function createOsKeyringBackend(platform = os.platform()) {
|
|
272
|
+
switch (platform) {
|
|
273
|
+
case 'darwin':
|
|
274
|
+
return darwinBackend();
|
|
275
|
+
case 'linux':
|
|
276
|
+
return linuxBackend();
|
|
277
|
+
case 'win32':
|
|
278
|
+
return windowsBackend();
|
|
279
|
+
default:
|
|
280
|
+
return unsupportedBackend(platform);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
//# sourceMappingURL=osKeyring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osKeyring.js","sourceRoot":"","sources":["../../../src/store/backends/osKeyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwQA,wDAWC;AAnRD,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAC/E,6EAA6E;AAC7E,EAAE;AACF,4CAA4C;AAC5C,mEAAmE;AACnE,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAC5E,4DAA4D;AAC5D,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,oEAAoE;AACpE,4EAA4E;AAC5E,uEAAuE;AACvE,2DAA+C;AAC/C,4CAA8B;AAG9B,MAAM,OAAO,GAAG,cAAc,CAAC;AAE/B,SAAS,SAAS,CAAC,MAAwB;IACzC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAA8B,CAAC;IAC5D,IACE,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ;QACtC,OAAO,MAAM,CAAC,eAAe,KAAK,QAAQ;QAC1C,OAAO,MAAM,CAAC,YAAY,KAAK,QAAQ;QACvC,OAAO,MAAM,CAAC,gBAAgB,KAAK,QAAQ,EAC3C,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,MAA0B,CAAC;AACpC,CAAC;AAED,qCAAqC;AAErC,SAAS,aAAa;IACpB,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,WAAW;YACT,MAAM,KAAK,GAAG,IAAA,8BAAS,EAAC,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,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AAC,UAAU,CAAC,CAAC,CAAC;QACpD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK;QACxB,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI;QACf,GAAG,EAAE,GAAG,EAAE;YACR,MAAM,IAAI,KAAK,CAAC,mDAAmD,QAAQ,GAAG,CAAC,CAAC;QAClF,CAAC;QACD,MAAM,EAAE,GAAG,EAAE;YACX,sEAAsE;YACtE,iCAAiC;QACnC,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,sBAAsB,CAAC,WAA4B,EAAE,CAAC,QAAQ,EAAE;IAC9E,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,aAAa,EAAE,CAAC;QACzB,KAAK,OAAO;YACV,OAAO,YAAY,EAAE,CAAC;QACxB,KAAK,OAAO;YACV,OAAO,cAAc,EAAE,CAAC;QAC1B;YACE,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoCredentialBackendError = void 0;
|
|
4
|
+
exports.selectCredentialBackend = selectCredentialBackend;
|
|
5
|
+
exports.backendForAccount = backendForAccount;
|
|
6
|
+
// Credential (secret) storage abstraction (AC-8). Metadata lives in
|
|
7
|
+
// accountStore.ts; this module only ever touches token material, and only
|
|
8
|
+
// through one of two backends:
|
|
9
|
+
// - OS keyring (default): shells out to the platform's system credential
|
|
10
|
+
// service. Zero native npm dependency (TECH.md decision) — see backends/osKeyring.ts.
|
|
11
|
+
// - encrypted-file (opt-in only, D-1=B): AES-256-GCM + scrypt, passphrase
|
|
12
|
+
// required on every use, never silently substituted for the OS backend.
|
|
13
|
+
//
|
|
14
|
+
// The one invariant this module enforces end-to-end: if the OS keyring is
|
|
15
|
+
// unavailable and the caller has not explicitly opted in to the encrypted
|
|
16
|
+
// fallback, credential writes fail closed (NoCredentialBackendError) rather
|
|
17
|
+
// than ever falling back to a plaintext file (TC-29).
|
|
18
|
+
const osKeyring_1 = require("./backends/osKeyring");
|
|
19
|
+
const encryptedFile_1 = require("./backends/encryptedFile");
|
|
20
|
+
const log_1 = require("../util/log");
|
|
21
|
+
class NoCredentialBackendError extends Error {
|
|
22
|
+
constructor() {
|
|
23
|
+
super('no OS credential service is available on this system (e.g. headless Linux without secret-tool), ' +
|
|
24
|
+
'and the encrypted-file fallback is not enabled. Re-run with --credential-backend encrypted-file ' +
|
|
25
|
+
'to opt in to a passphrase-protected local vault. Refusing to write credentials in plaintext.');
|
|
26
|
+
this.name = 'NoCredentialBackendError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.NoCredentialBackendError = NoCredentialBackendError;
|
|
30
|
+
/**
|
|
31
|
+
* Resolves which backend a NEW login should use: OS keyring if available,
|
|
32
|
+
* otherwise the encrypted-file fallback ONLY if the caller opted in. Never
|
|
33
|
+
* degrades silently to plaintext (TC-29).
|
|
34
|
+
*/
|
|
35
|
+
function selectCredentialBackend(opts = {}) {
|
|
36
|
+
const osBackend = opts.osKeyringBackend ?? (0, osKeyring_1.createOsKeyringBackend)();
|
|
37
|
+
if (osBackend.isAvailable()) {
|
|
38
|
+
return osBackend;
|
|
39
|
+
}
|
|
40
|
+
if (opts.allowEncryptedFallback) {
|
|
41
|
+
if (!opts.passphraseProvider) {
|
|
42
|
+
throw new Error('encrypted-file backend requires a passphrase provider');
|
|
43
|
+
}
|
|
44
|
+
return opts.encryptedFileBackend ?? (0, encryptedFile_1.createEncryptedFileBackend)(opts.passphraseProvider);
|
|
45
|
+
}
|
|
46
|
+
log_1.log.error('no OS credential service available and encrypted fallback not enabled');
|
|
47
|
+
throw new NoCredentialBackendError();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the exact backend a KNOWN, already-saved account was stored under
|
|
51
|
+
* (accountStore.AccountRecord.backend), rather than re-running availability
|
|
52
|
+
* detection — used by logout/refresh/accounts so an account created under the
|
|
53
|
+
* encrypted-file backend is never accidentally probed against the OS keyring
|
|
54
|
+
* (which would just look like "no credential found").
|
|
55
|
+
*/
|
|
56
|
+
function backendForAccount(accountBackendKind, opts = {}) {
|
|
57
|
+
if (accountBackendKind === 'os-keyring') {
|
|
58
|
+
return opts.osKeyringBackend ?? (0, osKeyring_1.createOsKeyringBackend)();
|
|
59
|
+
}
|
|
60
|
+
if (!opts.passphraseProvider) {
|
|
61
|
+
throw new Error('encrypted-file backend requires a passphrase provider');
|
|
62
|
+
}
|
|
63
|
+
return opts.encryptedFileBackend ?? (0, encryptedFile_1.createEncryptedFileBackend)(opts.passphraseProvider);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=credentialStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentialStore.js","sourceRoot":"","sources":["../../src/store/credentialStore.ts"],"names":[],"mappings":";;;AA0DA,0DAaC;AASD,8CAeC;AA/FD,oEAAoE;AACpE,0EAA0E;AAC1E,+BAA+B;AAC/B,2EAA2E;AAC3E,0FAA0F;AAC1F,4EAA4E;AAC5E,4EAA4E;AAC5E,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,4EAA4E;AAC5E,sDAAsD;AACtD,oDAA8D;AAC9D,4DAA+F;AAC/F,qCAAkC;AAmBlC,MAAa,wBAAyB,SAAQ,KAAK;IACjD;QACE,KAAK,CACH,kGAAkG;YAChG,kGAAkG;YAClG,8FAA8F,CACjG,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AATD,4DASC;AAWD;;;;GAIG;AACH,SAAgB,uBAAuB,CAAC,OAA6B,EAAE;IACrE,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,IA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