@kardalum/plugin-sdk 0.17.0 → 0.19.0
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/CHANGELOG.md +109 -0
- package/README.md +4 -3
- package/dist/assets/asset-picker.d.ts +11 -0
- package/dist/assets/asset-picker.js +109 -0
- package/dist/assets/asset-tree.d.ts +30 -0
- package/dist/assets/asset-tree.js +150 -0
- package/dist/built-in-editor-ids.d.ts +1 -0
- package/dist/built-in-editor-ids.js +20 -0
- package/dist/built-in-serializers.js +1 -1
- package/dist/built-in-settings-schemas.d.ts +2 -0
- package/dist/built-in-settings-schemas.js +31 -4
- package/dist/built-in-value-schemas.js +3 -0
- package/dist/built-ins.js +20 -11
- package/dist/capabilities.js +5 -0
- package/dist/data-type-plugin.d.ts +2 -2
- package/dist/datatype-validation.d.ts +2 -2
- package/dist/datatype-validation.js +20 -6
- package/dist/datatypes-entry.d.ts +1 -0
- package/dist/datatypes-entry.js +1 -0
- package/dist/define-plugin.d.ts +4 -4
- package/dist/define-plugin.js +5 -5
- package/dist/entitlement-entry.d.ts +3 -2
- package/dist/entitlement-entry.js +13 -1
- package/dist/entitlement-gate.d.ts +18 -0
- package/dist/entitlement-gate.js +95 -21
- package/dist/entitlement-plan.d.ts +21 -0
- package/dist/entitlement-plan.js +26 -0
- package/dist/entitlement-types.d.ts +21 -4
- package/dist/entitlement.d.ts +29 -1
- package/dist/entitlement.js +39 -0
- package/dist/grid-arrow-step.d.ts +7 -0
- package/dist/grid-arrow-step.js +20 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +11 -12
- package/dist/manifest-entry.d.ts +4 -0
- package/dist/manifest-entry.js +4 -0
- package/dist/manifest-schema.d.ts +5 -1
- package/dist/manifest-schema.js +14 -2
- package/dist/manifest.d.ts +21 -1
- package/dist/media/media-picker.js +34 -34
- package/dist/notify.d.ts +17 -0
- package/dist/notify.js +17 -0
- package/dist/plugin-context.js +3 -3
- package/dist/register-built-ins.js +6 -6
- package/dist/registry.js +1 -1
- package/dist/richtext/block-panel.js +19 -20
- package/dist/richtext/extensions.js +17 -8
- package/dist/richtext/insert-menu.js +4 -4
- package/dist/richtext/kardalum-block.js +17 -17
- package/dist/richtext/style-listbox.js +2 -2
- package/dist/richtext/text-style-class.js +1 -1
- package/dist/richtext-html-entry.d.ts +35 -0
- package/dist/richtext-html-entry.js +73 -0
- package/dist/simple-storage-value-provider.js +3 -3
- package/dist/structured-storage-types.d.ts +12 -1
- package/dist/structured-storage-types.js +2 -2
- package/dist/tailwind.js +10 -3
- package/dist/tokens/tailwind-theme.css +176 -0
- package/dist/tokens/tokens.css +1 -0
- package/dist/tokens/tokens.json +2 -1
- package/dist/ui-entry.js +3 -3
- package/dist/vendor-check.d.ts +39 -0
- package/dist/vendor-check.js +79 -0
- package/dist/vendor-entry.d.ts +3 -0
- package/dist/vendor-entry.js +9 -0
- package/dist/vendor-service.d.ts +20 -0
- package/dist/vendor-service.js +20 -0
- package/dist/views/asset-view.d.ts +6 -0
- package/dist/views/asset-view.js +55 -0
- package/dist/views/content-list-settings-view.js +1 -1
- package/dist/views/content-list-view.js +1 -1
- package/dist/views/date-range-view.js +5 -5
- package/dist/views/html-code-editor.js +2 -3
- package/dist/views/html-view.js +7 -7
- package/dist/views/image-view.js +5 -5
- package/dist/views/rich-text-view.js +33 -32
- package/node_modules/@kardalum/api-schemas/README.md +1 -1
- package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +17 -15
- package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.d.ts +21 -0
- package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.js +42 -0
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +10 -3
- package/node_modules/@kardalum/api-schemas/dist/auth.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.d.ts +36 -0
- package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.js +46 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +13 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +30 -9
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -3
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +12 -6
- package/node_modules/@kardalum/api-schemas/dist/core-actions.js +11 -6
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +50 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +26 -6
- package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +6 -3
- package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.d.ts +11 -0
- package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.js +28 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +90 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +56 -6
- package/node_modules/@kardalum/api-schemas/dist/document-type.schema.js +8 -8
- package/node_modules/@kardalum/api-schemas/dist/home.schema.d.ts +130 -0
- package/node_modules/@kardalum/api-schemas/dist/home.schema.js +87 -0
- package/node_modules/@kardalum/api-schemas/dist/index.d.ts +48 -19
- package/node_modules/@kardalum/api-schemas/dist/index.js +34 -12
- package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.d.ts +7 -0
- package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.js +9 -0
- package/node_modules/@kardalum/api-schemas/dist/listing-categories.schema.d.ts +46 -0
- package/node_modules/@kardalum/api-schemas/dist/listing-categories.schema.js +52 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +162 -1
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +144 -9
- package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.d.ts +17 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.js +16 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +26 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +15 -9
- package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +10 -0
- package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +4 -4
- package/node_modules/@kardalum/api-schemas/dist/media.schema.js +5 -5
- package/node_modules/@kardalum/api-schemas/dist/news.schema.d.ts +93 -0
- package/node_modules/@kardalum/api-schemas/dist/news.schema.js +86 -0
- package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +13 -0
- package/node_modules/@kardalum/api-schemas/dist/notification.schema.d.ts +410 -0
- package/node_modules/@kardalum/api-schemas/dist/notification.schema.js +193 -0
- package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.d.ts +86 -0
- package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.js +92 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +7 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +7 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.js +1 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +251 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +196 -31
- package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.d.ts +19 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.js +33 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.js +3 -3
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +10 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +24 -4
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +5 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +23 -20
- package/node_modules/@kardalum/api-schemas/dist/render-editing.js +4 -4
- package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.d.ts +83 -0
- package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.js +73 -0
- package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.d.ts +207 -0
- package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.js +147 -0
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +11 -0
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -8
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +14 -0
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +7 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +3 -3
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +10 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +27 -12
- package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +7 -0
- package/node_modules/@kardalum/api-schemas/dist/template.schema.js +22 -10
- package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.d.ts +1 -1
- package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +6 -1
- package/node_modules/@kardalum/api-schemas/dist/uuid.schema.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/uuid.schema.js +4 -0
- package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.d.ts +88 -0
- package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.js +100 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +13 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +5 -0
- package/node_modules/@kardalum/design-tokens/README.md +1 -1
- package/node_modules/@kardalum/design-tokens/dist/build-css.d.ts +1 -1
- package/node_modules/@kardalum/design-tokens/dist/build-css.js +2 -2
- package/node_modules/@kardalum/design-tokens/dist/build-theme-css.d.ts +16 -0
- package/node_modules/@kardalum/design-tokens/dist/build-theme-css.js +76 -0
- package/node_modules/@kardalum/design-tokens/dist/generate.js +4 -1
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.css +176 -0
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -1
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +3 -3
- package/node_modules/@kardalum/design-tokens/dist/theme-css.d.ts +2 -2
- package/node_modules/@kardalum/design-tokens/dist/theme-css.js +2 -2
- package/node_modules/@kardalum/design-tokens/dist/theme-types.d.ts +2 -2
- package/node_modules/@kardalum/design-tokens/dist/themes/dark.d.ts +3 -3
- package/node_modules/@kardalum/design-tokens/dist/themes/dark.js +3 -3
- package/node_modules/@kardalum/design-tokens/dist/themes/light.d.ts +1 -1
- package/node_modules/@kardalum/design-tokens/dist/themes/light.js +1 -1
- package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.d.ts +3 -3
- package/node_modules/@kardalum/design-tokens/dist/tokens.js +6 -5
- package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
- package/node_modules/@kardalum/design-tokens/dist/types.d.ts +2 -1
- package/node_modules/@kardalum/design-tokens/dist/types.js +1 -1
- package/node_modules/@kardalum/design-tokens/package.json +6 -3
- package/node_modules/@kardalum/plugin-package/README.md +1 -1
- package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +4 -4
- package/node_modules/@kardalum/plugin-package/dist/capabilities.js +54 -6
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +1 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +18 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +1 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +1 -1
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +9 -4
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +58 -1
- package/node_modules/@kardalum/plugin-package/dist/envelope.d.ts +2 -2
- package/node_modules/@kardalum/plugin-package/dist/envelope.js +2 -2
- package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +3 -3
- package/node_modules/@kardalum/plugin-package/dist/extract.js +10 -10
- package/node_modules/@kardalum/plugin-package/dist/hash.d.ts +1 -1
- package/node_modules/@kardalum/plugin-package/dist/hash.js +1 -1
- package/node_modules/@kardalum/plugin-package/dist/index.d.ts +4 -2
- package/node_modules/@kardalum/plugin-package/dist/index.js +3 -1
- package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +56 -19
- package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +119 -25
- package/node_modules/@kardalum/plugin-package/dist/package-contract.d.ts +2 -2
- package/node_modules/@kardalum/plugin-package/dist/package-contract.js +5 -5
- package/node_modules/@kardalum/plugin-package/dist/types.d.ts +1 -1
- package/node_modules/@kardalum/plugin-package/dist/vendor-token.d.ts +24 -0
- package/node_modules/@kardalum/plugin-package/dist/vendor-token.js +118 -0
- package/node_modules/@kardalum/ui/README.md +1 -1
- package/node_modules/@kardalum/ui/dist/components/alert-dialog.d.ts +1 -1
- package/node_modules/@kardalum/ui/dist/components/alert-dialog.js +8 -3
- package/node_modules/@kardalum/ui/dist/components/badge.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/button.js +2 -2
- package/node_modules/@kardalum/ui/dist/components/checkbox.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/dialog.d.ts +1 -1
- package/node_modules/@kardalum/ui/dist/components/dialog.js +52 -4
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.d.ts +5 -1
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +20 -7
- package/node_modules/@kardalum/ui/dist/components/empty-state.d.ts +4 -4
- package/node_modules/@kardalum/ui/dist/components/input.js +6 -1
- package/node_modules/@kardalum/ui/dist/components/popover-panel.d.ts +4 -0
- package/node_modules/@kardalum/ui/dist/components/popover-panel.js +13 -0
- package/node_modules/@kardalum/ui/dist/components/property-field.js +3 -3
- package/node_modules/@kardalum/ui/dist/components/sheet.d.ts +1 -1
- package/node_modules/@kardalum/ui/dist/components/sheet.js +15 -9
- package/node_modules/@kardalum/ui/dist/components/skeleton.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/switch.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/tab-strip.d.ts +3 -3
- package/node_modules/@kardalum/ui/dist/components/tab-strip.js +1 -1
- package/node_modules/@kardalum/ui/dist/components/toast.js +4 -3
- package/node_modules/@kardalum/ui/dist/components/tooltip.d.ts +27 -0
- package/node_modules/@kardalum/ui/dist/components/tooltip.js +82 -0
- package/node_modules/@kardalum/ui/dist/components/truncated-text.d.ts +11 -0
- package/node_modules/@kardalum/ui/dist/components/truncated-text.js +94 -0
- package/node_modules/@kardalum/ui/dist/components/use-toast.js +2 -2
- package/node_modules/@kardalum/ui/dist/index.d.ts +4 -1
- package/node_modules/@kardalum/ui/dist/index.js +4 -1
- package/node_modules/@kardalum/ui/dist/lib/menu-host.d.ts +5 -0
- package/node_modules/@kardalum/ui/dist/lib/menu-host.js +17 -0
- package/node_modules/@kardalum/ui/package.json +8 -6
- package/package.json +21 -7
|
@@ -81,7 +81,7 @@ function nameViolation(path) {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
/** Pure gate over one entry's (path, type, declaredSize). Returns the
|
|
84
|
-
* violation message or null. Exported for direct unit testing
|
|
84
|
+
* violation message or null. Exported for direct unit testing: a
|
|
85
85
|
* well-formed writer can't produce hostile names, but attackers hand-craft
|
|
86
86
|
* archives directly. The path rules are nameViolation's: what a Linux
|
|
87
87
|
* extraction and a Windows or macOS one would read as different files is
|
|
@@ -91,7 +91,7 @@ function nameViolation(path) {
|
|
|
91
91
|
* "OldFile" and "ContiguousFile" are accepted alongside "File" for
|
|
92
92
|
* historical (tar-era) compatibility with entries this gate has always
|
|
93
93
|
* allowed; the ZIP reader below only ever derives "File" or "Directory"
|
|
94
|
-
* for an entry, so those two never occur in practice post-migration
|
|
94
|
+
* for an entry, so those two never occur in practice post-migration: the
|
|
95
95
|
* allow-list simply isn't narrowed, since narrowing it wouldn't change zip
|
|
96
96
|
* behavior and would only risk breaking direct callers of this exported
|
|
97
97
|
* function. */
|
|
@@ -233,7 +233,7 @@ export function createEntryGate() {
|
|
|
233
233
|
return { ok: false, reason: pathRefusal };
|
|
234
234
|
totalBytes += entry.uncompressedSize;
|
|
235
235
|
if (totalBytes > MAX_TOTAL_BYTES)
|
|
236
|
-
return { ok: false, reason: `archive expands beyond the ${MAX_TOTAL_BYTES / 1024 / 1024}
|
|
236
|
+
return { ok: false, reason: `archive expands beyond the ${MAX_TOTAL_BYTES / 1024 / 1024} MiB limit` };
|
|
237
237
|
return { ok: true, name, isDirectory };
|
|
238
238
|
};
|
|
239
239
|
}
|
|
@@ -268,14 +268,14 @@ export function plannedEntryRefusal(entries) {
|
|
|
268
268
|
* written to disk incrementally as the archive streams in, so anything
|
|
269
269
|
* admitted before the violation was detected is already sitting under
|
|
270
270
|
* `targetDir`. Callers MUST treat `{ ok: false }` as fatal and delete
|
|
271
|
-
* `targetDir` themselves
|
|
271
|
+
* `targetDir` themselves. This function does not roll back a partial
|
|
272
272
|
* extraction.
|
|
273
273
|
*/
|
|
274
274
|
export function extractArtifact(archivePath, targetDir) {
|
|
275
275
|
return new Promise((resolve) => {
|
|
276
276
|
// Guards resolve() against firing twice (e.g. a stray 'readEntry'
|
|
277
|
-
// continuation racing an already-settled violation). Harmless
|
|
278
|
-
// Promise settlement is idempotent regardless
|
|
277
|
+
// continuation racing an already-settled violation). Harmless:
|
|
278
|
+
// Promise settlement is idempotent regardless, but noted since it's
|
|
279
279
|
// not load-bearing for the contract, just defensive.
|
|
280
280
|
let settled = false;
|
|
281
281
|
const settle = (value) => {
|
|
@@ -292,7 +292,7 @@ export function extractArtifact(archivePath, targetDir) {
|
|
|
292
292
|
return;
|
|
293
293
|
}
|
|
294
294
|
const resolvedTargetDir = resolvePath(targetDir);
|
|
295
|
-
// decodeStrings: false
|
|
295
|
+
// decodeStrings: false: yauzl's own string decoding path runs its own
|
|
296
296
|
// absolute-path/".."/backslash filename validation before ever emitting
|
|
297
297
|
// an 'entry' event, and rejects by emitting 'error' on the whole
|
|
298
298
|
// zipfile with its own message text. That would make yauzl's built-in
|
|
@@ -308,7 +308,7 @@ export function extractArtifact(archivePath, targetDir) {
|
|
|
308
308
|
}
|
|
309
309
|
// Fast upfront rejection: ZIP's central directory declares its entry
|
|
310
310
|
// count in the end-of-central-directory record, read during open()
|
|
311
|
-
// itself
|
|
311
|
+
// itself, unlike tar's PAX/meta-entry bypass, there is no way for a
|
|
312
312
|
// zip to hide entries from this count (yauzl only ever iterates
|
|
313
313
|
// exactly this many central directory records). Checking it here
|
|
314
314
|
// means a too-many-entries archive is rejected before writing a
|
|
@@ -342,7 +342,7 @@ export function extractArtifact(archivePath, targetDir) {
|
|
|
342
342
|
// This is an assertion, not a second gate: entryViolation (inside the
|
|
343
343
|
// gate) already rejects a leading "/" or "\\", a drive letter, and any
|
|
344
344
|
// ".." segment, so resolving fileName against targetDir can never
|
|
345
|
-
// land outside it
|
|
345
|
+
// land outside it: this branch must be unreachable. It stays
|
|
346
346
|
// because it is a two-line check against the one failure mode
|
|
347
347
|
// (zip-slip) that would actually write files outside targetDir, so
|
|
348
348
|
// the cost of keeping it is negligible next to what a silent
|
|
@@ -352,7 +352,7 @@ export function extractArtifact(archivePath, targetDir) {
|
|
|
352
352
|
fail(`unsafe entry path ${quoteEntryName(fileName)}`);
|
|
353
353
|
return;
|
|
354
354
|
}
|
|
355
|
-
// The filesystem calls below can throw
|
|
355
|
+
// The filesystem calls below can throw, most concretely EEXIST
|
|
356
356
|
// from mkdirSync when a hostile or malformed archive declares a
|
|
357
357
|
// file entry and a directory entry at the same path (e.g. "a" then
|
|
358
358
|
// "a/b", or a directory entry "a/" arriving after a file "a"). An
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** One definition of "the artifact's hash" for signer and verifier alike
|
|
1
|
+
/** One definition of "the artifact's hash" for signer and verifier alike:
|
|
2
2
|
* the same value S126 records as PluginVersion.artifactSha256. */
|
|
3
3
|
export declare function hashBuffer(buffer: Buffer): string;
|
|
4
4
|
export declare function hashArchive(path: string): Promise<string>;
|
|
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { createReadStream } from "node:fs";
|
|
3
3
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
/** One definition of "the artifact's hash" for signer and verifier alike
|
|
5
|
+
/** One definition of "the artifact's hash" for signer and verifier alike:
|
|
6
6
|
* the same value S126 records as PluginVersion.artifactSha256. */
|
|
7
7
|
export function hashBuffer(buffer) {
|
|
8
8
|
return createHash("sha256").update(buffer).digest("hex");
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export type { PackageSignatureSidecar, SignatureEnvelope, TrustedKey, VerifyFailureReason, VerifyResult, } from "./types.js";
|
|
2
2
|
export { VERIFY_FAILURE_REASONS } from "./types.js";
|
|
3
3
|
export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope, verifyEnvelope, } from "./envelope.js";
|
|
4
|
-
export type { LicenseChallenge, LicenseVerdictEnvelope, LicenseVerdictResult, LicenseVerdictSignatureResult, SignedLicenseVerdict, TamperKind, } from "./license-verdict.js";
|
|
5
|
-
export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
|
|
4
|
+
export type { LicenseChallenge, LicenseTermState, LicenseVerdictEnvelope, LicenseVerdictResult, LicenseVerdictSignatureResult, LicenseVerdictTerm, SignedLicenseVerdict, TamperKind, } from "./license-verdict.js";
|
|
5
|
+
export { canonicalizeLicenseVerdict, canonicalizeLicenseVerdictTerm, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_TERM_STATES, LICENSE_VERDICT_DETAIL_MAX, LICENSE_VERDICT_PLAN_ID_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, signLicenseVerdictWithTerm, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
|
|
6
|
+
export { VENDOR_TOKEN_LEEWAY_SECONDS, VENDOR_TOKEN_SIGNING_PREFIX, signVendorToken, verifyVendorToken } from "./vendor-token.js";
|
|
7
|
+
export type { VendorTokenFailure, VendorTokenVerifyResult } from "./vendor-token.js";
|
|
6
8
|
export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
|
|
7
9
|
export type { AdmittedEntry, PlannedEntry } from "./extract.js";
|
|
8
10
|
export { createEntryGate, createPathKeyGate, decodeEntryName, ENTRY_NAME_MAX, ENTRY_SEGMENTS_MAX, entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES, normalizeEntryName, plannedEntryRefusal, } from "./extract.js";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { VERIFY_FAILURE_REASONS } from "./types.js";
|
|
2
2
|
export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope, verifyEnvelope, } from "./envelope.js";
|
|
3
|
-
export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
|
|
3
|
+
export { canonicalizeLicenseVerdict, canonicalizeLicenseVerdictTerm, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_TERM_STATES, LICENSE_VERDICT_DETAIL_MAX, LICENSE_VERDICT_PLAN_ID_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, signLicenseVerdictWithTerm, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
|
|
4
|
+
// S320: the vendor token (spec 3a).
|
|
5
|
+
export { VENDOR_TOKEN_LEEWAY_SECONDS, VENDOR_TOKEN_SIGNING_PREFIX, signVendorToken, verifyVendorToken } from "./vendor-token.js";
|
|
4
6
|
export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
|
|
5
7
|
export { createEntryGate, createPathKeyGate, decodeEntryName, ENTRY_NAME_MAX, ENTRY_SEGMENTS_MAX, entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES, normalizeEntryName, plannedEntryRefusal, } from "./extract.js";
|
|
6
8
|
export { EXCLUDED_NAMES, createShippedLookup, isExcludedSegment, walkShipped, whyNotShipped } from "./shipped-files.js";
|
|
@@ -5,7 +5,7 @@ import type { TrustedKey } from "./types.js";
|
|
|
5
5
|
* makes a fake licence server unable to produce one the CMS accepts. A
|
|
6
6
|
* captured verdict is not a durable unlock: `nonce` (bound per request via
|
|
7
7
|
* a `LicenseChallenge`) is what actually prevents replay, since a
|
|
8
|
-
* verifier's own clock cannot be trusted to bound freshness
|
|
8
|
+
* verifier's own clock cannot be trusted to bound freshness; see
|
|
9
9
|
* `createLicenseChallenge`'s doc comment below. */
|
|
10
10
|
export interface LicenseVerdictEnvelope {
|
|
11
11
|
v: 1;
|
|
@@ -16,7 +16,7 @@ export interface LicenseVerdictEnvelope {
|
|
|
16
16
|
* on "the field names happen to differ" rather than being a property of
|
|
17
17
|
* the design. */
|
|
18
18
|
typ: "license-verdict";
|
|
19
|
-
/** First 16 hex of sha256(raw public key)
|
|
19
|
+
/** First 16 hex of sha256(raw public key): derived, never assigned. */
|
|
20
20
|
keyId: string;
|
|
21
21
|
/** sha256 of the licence key. The key itself never travels in a verdict:
|
|
22
22
|
* a captured verdict must not be a working credential. */
|
|
@@ -29,12 +29,12 @@ export interface LicenseVerdictEnvelope {
|
|
|
29
29
|
* trustworthy input to a check meant to defeat the CMS: the process
|
|
30
30
|
* being verified runs on the customer's machine, and they can capture a
|
|
31
31
|
* single genuine "valid" verdict once, then replay it forever by
|
|
32
|
-
* running the process under a clock pinned near `issuedAt
|
|
32
|
+
* running the process under a clock pinned near `issuedAt`: no source
|
|
33
33
|
* edit, survives updates, shareable as a recipe. No time-based check can
|
|
34
34
|
* close that, however tight the window. A fresh unpredictable nonce
|
|
35
35
|
* chosen by the verifier and checked for an exact match closes it,
|
|
36
36
|
* because a captured verdict cannot answer a challenge it never saw. Do
|
|
37
|
-
* not remove this as "covered by issuedAt"
|
|
37
|
+
* not remove this as "covered by issuedAt": it is the only check here a
|
|
38
38
|
* replay cannot pass. */
|
|
39
39
|
nonce: string;
|
|
40
40
|
status: "valid" | "invalid" | "revoked";
|
|
@@ -53,6 +53,15 @@ export interface LicenseVerdictEnvelope {
|
|
|
53
53
|
* signed before this field existed still verifies. At most
|
|
54
54
|
* LICENSE_VERDICT_DETAIL_MAX characters. */
|
|
55
55
|
detail?: string;
|
|
56
|
+
/** S317: the key of the plan the licence holds. Covered by
|
|
57
|
+
* `termSignature` only, never by `signature`, so a verifier built before
|
|
58
|
+
* S317 checks the bytes it always did and ignores this field. The
|
|
59
|
+
* validation route keeps it absent on a verdict that is not `valid`; the
|
|
60
|
+
* verifiers do not check that. */
|
|
61
|
+
planId?: string;
|
|
62
|
+
/** S317: the licence's term, covered by `termSignature` like `planId`. A
|
|
63
|
+
* verdict without it reads as plan unknown, term active. */
|
|
64
|
+
term?: LicenseVerdictTerm;
|
|
56
65
|
}
|
|
57
66
|
/** The longest `detail` a verdict may carry. */
|
|
58
67
|
export declare const LICENSE_VERDICT_DETAIL_MAX = 500;
|
|
@@ -60,22 +69,42 @@ export declare const LICENSE_VERDICT_DETAIL_MAX = 500;
|
|
|
60
69
|
* another licence's (or version's) delivery, a package the marketplace never
|
|
61
70
|
* delivered, or the right delivery changed on disk since its first report. */
|
|
62
71
|
export type TamperKind = "foreign-package" | "sideloaded" | "modified-on-disk";
|
|
72
|
+
/** A licence's term on the marketplace (S317; the states of S315 section 4):
|
|
73
|
+
* `active` (paid, or a free or one-time plan), `renewing` (the renewal is
|
|
74
|
+
* being charged), `past_due` (the renewal failed; 14 days of grace),
|
|
75
|
+
* `lapsed` (grace ended unpaid, or a cancelled term ended). */
|
|
76
|
+
export type LicenseTermState = "active" | "renewing" | "past_due" | "lapsed";
|
|
77
|
+
export declare const LICENSE_TERM_STATES: readonly LicenseTermState[];
|
|
78
|
+
/** The term a verdict carries. `endsAt` is the end of the term paid for
|
|
79
|
+
* (null for a free or one-time plan); `renewalAmountCents` the next charge
|
|
80
|
+
* in USD cents (null when nothing renews); `cancelAtPeriodEnd` true for a
|
|
81
|
+
* term the buyer cancelled. */
|
|
82
|
+
export interface LicenseVerdictTerm {
|
|
83
|
+
state: LicenseTermState;
|
|
84
|
+
endsAt: string | null;
|
|
85
|
+
renewalAmountCents: number | null;
|
|
86
|
+
cancelAtPeriodEnd: boolean;
|
|
87
|
+
}
|
|
88
|
+
/** The longest plan key a verdict carries. */
|
|
89
|
+
export declare const LICENSE_VERDICT_PLAN_ID_MAX = 64;
|
|
63
90
|
export interface SignedLicenseVerdict {
|
|
64
91
|
envelope: LicenseVerdictEnvelope;
|
|
65
92
|
signature: string;
|
|
93
|
+
/** S317: base64 Ed25519 over canonicalizeLicenseVerdictTerm; present only when the envelope carries planId or term. */
|
|
94
|
+
termSignature?: string;
|
|
66
95
|
}
|
|
67
96
|
/**
|
|
68
97
|
* A `LicenseChallenge` is the only way to obtain a nonce, and the only
|
|
69
98
|
* shape `verifyLicenseVerdict` accepts in place of a separately-typed
|
|
70
99
|
* "expected subject". Folding subject and nonce into one object the module
|
|
71
|
-
* itself produces means they can never disagree
|
|
100
|
+
* itself produces means they can never disagree: there is no way to hand
|
|
72
101
|
* `verifyLicenseVerdict` a nonce that was not the one generated for this
|
|
73
102
|
* exact subject.
|
|
74
103
|
*
|
|
75
104
|
* A challenge is single-use: `verifyLicenseVerdict` consumes it on first
|
|
76
105
|
* use (success or failure) and returns `"challenge-reused"` on any second
|
|
77
106
|
* use of the same object. A caller that needs to retry a validation round
|
|
78
|
-
* trip must call `createLicenseChallenge` again
|
|
107
|
+
* trip must call `createLicenseChallenge` again: a retry is a new
|
|
79
108
|
* question, and asking it again with the same nonce is exactly the
|
|
80
109
|
* caller-side mistake (caching one nonce and reusing it across requests)
|
|
81
110
|
* that collapses replay protection back to "one captured verdict unlocks
|
|
@@ -88,17 +117,17 @@ export interface LicenseChallenge {
|
|
|
88
117
|
readonly domain: string;
|
|
89
118
|
/** Hex-encoded, at least 16 random bytes. Exposed only so the caller can
|
|
90
119
|
* transmit it to the marketplace alongside the rest of the validation
|
|
91
|
-
* request
|
|
120
|
+
* request; it plays no other role on the caller's side. */
|
|
92
121
|
readonly nonce: string;
|
|
93
122
|
}
|
|
94
123
|
/** Verification authenticates a signed envelope; it does not decide
|
|
95
124
|
* whether to unlock anything. `"licensed"` is the only branch that should
|
|
96
125
|
* ever lead to unlocking a plugin. `"unlicensed"` means the marketplace
|
|
97
126
|
* gave an authentic, fresh, correctly subject-bound answer and that answer
|
|
98
|
-
* says no (`invalid` or `revoked`)
|
|
127
|
+
* says no (`invalid` or `revoked`): a real verdict, safe to show the
|
|
99
128
|
* user. `"unverifiable"` means no answer this caller can trust was
|
|
100
129
|
* obtained at all (malformed input, an untrusted or forged signature, a
|
|
101
|
-
* verdict for a different subject, a stale or reused challenge)
|
|
130
|
+
* verdict for a different subject, a stale or reused challenge). The
|
|
102
131
|
* caller must treat this exactly like an unreachable licence server and
|
|
103
132
|
* change nothing, never as a soft "no". There is no boolean here to
|
|
104
133
|
* misread: unlike a `{ ok: boolean }` shape, `if (result.ok) unlock()`
|
|
@@ -116,7 +145,7 @@ export type LicenseVerdictResult = {
|
|
|
116
145
|
verdict: "unverifiable";
|
|
117
146
|
reason: "malformed" | "untrusted-key" | "bad-signature" | "subject-mismatch" | "stale" | "challenge-reused";
|
|
118
147
|
};
|
|
119
|
-
/** A cheap SECONDARY bound only
|
|
148
|
+
/** A cheap SECONDARY bound only. The nonce (see `createLicenseChallenge`'s
|
|
120
149
|
* doc comment) is what actually stops replay, and it does so completely:
|
|
121
150
|
* a captured verdict cannot answer a challenge it never saw, regardless of
|
|
122
151
|
* how wide this window is. This check exists purely to reject an obviously
|
|
@@ -125,8 +154,8 @@ export type LicenseVerdictResult = {
|
|
|
125
154
|
* always be defeated by controlling `now`.
|
|
126
155
|
*
|
|
127
156
|
* Widened from 5 minutes to 24 hours (S209 criticals fix): a five-minute
|
|
128
|
-
* window bought no real security
|
|
129
|
-
* was guarding
|
|
157
|
+
* window bought no real security (the nonce already closes the gap this
|
|
158
|
+
* was guarding) but it did fail a paying customer's install outright the
|
|
130
159
|
* moment their clock drifted more than five minutes from real time (a
|
|
131
160
|
* sleeping Docker VM, an un-NTP'd VPS), turning `verifyLicenseVerdict` into
|
|
132
161
|
* `unverifiable: stale` and the whole install into a failure with no
|
|
@@ -140,14 +169,14 @@ export declare const MAX_VERDICT_AGE_MS: number;
|
|
|
140
169
|
export declare const ENTITLEMENT_MAX_AGE_MS: number;
|
|
141
170
|
export declare function hashLicenseKey(key: string): string;
|
|
142
171
|
/** Starts a licence validation round trip. Returns a challenge carrying
|
|
143
|
-
* both the subject being validated and a freshly generated nonce
|
|
172
|
+
* both the subject being validated and a freshly generated nonce. The
|
|
144
173
|
* caller sends the whole thing (or at least its `nonce`) to the
|
|
145
174
|
* marketplace, which echoes the nonce into the signed envelope it
|
|
146
175
|
* produces. The caller then passes this same challenge to
|
|
147
176
|
* `verifyLicenseVerdict`, so the subject and the nonce it gets checked
|
|
148
177
|
* against can never come from two different places and drift apart.
|
|
149
178
|
*
|
|
150
|
-
* Each challenge verifies at most once
|
|
179
|
+
* Each challenge verifies at most once; see `LicenseChallenge`'s doc
|
|
151
180
|
* comment. Call this again for every new validation attempt; do not cache
|
|
152
181
|
* or reuse a challenge (or its nonce) across requests. */
|
|
153
182
|
export declare function createLicenseChallenge(subject: {
|
|
@@ -155,14 +184,22 @@ export declare function createLicenseChallenge(subject: {
|
|
|
155
184
|
pluginId: string;
|
|
156
185
|
domain: string;
|
|
157
186
|
}): LicenseChallenge;
|
|
158
|
-
/** Explicit field order, exactly like canonicalizeEnvelope
|
|
187
|
+
/** Explicit field order, exactly like canonicalizeEnvelope, never
|
|
159
188
|
* JSON.stringify of the object itself, whose key order is not guaranteed
|
|
160
|
-
* across producers.
|
|
161
|
-
* when present, so an envelope without them produces exactly the bytes it
|
|
162
|
-
* did before the fields existed (pinned by a test): old signatures keep
|
|
163
|
-
* verifying. */
|
|
189
|
+
* across producers. What `signature` covers: unchanged since S284b. */
|
|
164
190
|
export declare function canonicalizeLicenseVerdict(envelope: LicenseVerdictEnvelope): Buffer;
|
|
191
|
+
/** S317: what `termSignature` covers: the version 1 fields, then `planId`
|
|
192
|
+
* and `term` always (null when absent), in this order. These bytes always
|
|
193
|
+
* hold a `planId` key, which the version 1 bytes never do, so neither
|
|
194
|
+
* signature can stand in for the other. */
|
|
195
|
+
export declare function canonicalizeLicenseVerdictTerm(envelope: LicenseVerdictEnvelope): Buffer;
|
|
165
196
|
export declare function signLicenseVerdict(envelope: LicenseVerdictEnvelope, privateKeyBase64: string): string;
|
|
197
|
+
/** S317: what the marketplace's validation route returns. `signature` is
|
|
198
|
+
* signLicenseVerdict's, byte for byte (Ed25519 is deterministic), so every
|
|
199
|
+
* verifier built before S317 accepts it; `termSignature` is added only when
|
|
200
|
+
* the envelope carries a plan or a term. Throws RangeError for a malformed
|
|
201
|
+
* plan or term: the marketplace never signs one. */
|
|
202
|
+
export declare function signLicenseVerdictWithTerm(envelope: LicenseVerdictEnvelope, privateKeyBase64: string): SignedLicenseVerdict;
|
|
166
203
|
export type LicenseVerdictSignatureResult = {
|
|
167
204
|
ok: true;
|
|
168
205
|
envelope: LicenseVerdictEnvelope;
|
|
@@ -3,7 +3,10 @@ import { deriveKeyId } from "./envelope.js";
|
|
|
3
3
|
/** The longest `detail` a verdict may carry. */
|
|
4
4
|
export const LICENSE_VERDICT_DETAIL_MAX = 500;
|
|
5
5
|
const TAMPER_KINDS = ["foreign-package", "sideloaded", "modified-on-disk"];
|
|
6
|
-
|
|
6
|
+
export const LICENSE_TERM_STATES = ["active", "renewing", "past_due", "lapsed"];
|
|
7
|
+
/** The longest plan key a verdict carries. */
|
|
8
|
+
export const LICENSE_VERDICT_PLAN_ID_MAX = 64;
|
|
9
|
+
/** A cheap SECONDARY bound only. The nonce (see `createLicenseChallenge`'s
|
|
7
10
|
* doc comment) is what actually stops replay, and it does so completely:
|
|
8
11
|
* a captured verdict cannot answer a challenge it never saw, regardless of
|
|
9
12
|
* how wide this window is. This check exists purely to reject an obviously
|
|
@@ -12,8 +15,8 @@ const TAMPER_KINDS = ["foreign-package", "sideloaded", "modified-on-disk"];
|
|
|
12
15
|
* always be defeated by controlling `now`.
|
|
13
16
|
*
|
|
14
17
|
* Widened from 5 minutes to 24 hours (S209 criticals fix): a five-minute
|
|
15
|
-
* window bought no real security
|
|
16
|
-
* was guarding
|
|
18
|
+
* window bought no real security (the nonce already closes the gap this
|
|
19
|
+
* was guarding) but it did fail a paying customer's install outright the
|
|
17
20
|
* moment their clock drifted more than five minutes from real time (a
|
|
18
21
|
* sleeping Docker VM, an un-NTP'd VPS), turning `verifyLicenseVerdict` into
|
|
19
22
|
* `unverifiable: stale` and the whole install into a failure with no
|
|
@@ -35,14 +38,14 @@ export function hashLicenseKey(key) {
|
|
|
35
38
|
* challenge used, unused, or forge a fresh-looking one. */
|
|
36
39
|
const consumedChallenges = new WeakSet();
|
|
37
40
|
/** Starts a licence validation round trip. Returns a challenge carrying
|
|
38
|
-
* both the subject being validated and a freshly generated nonce
|
|
41
|
+
* both the subject being validated and a freshly generated nonce. The
|
|
39
42
|
* caller sends the whole thing (or at least its `nonce`) to the
|
|
40
43
|
* marketplace, which echoes the nonce into the signed envelope it
|
|
41
44
|
* produces. The caller then passes this same challenge to
|
|
42
45
|
* `verifyLicenseVerdict`, so the subject and the nonce it gets checked
|
|
43
46
|
* against can never come from two different places and drift apart.
|
|
44
47
|
*
|
|
45
|
-
* Each challenge verifies at most once
|
|
48
|
+
* Each challenge verifies at most once; see `LicenseChallenge`'s doc
|
|
46
49
|
* comment. Call this again for every new validation attempt; do not cache
|
|
47
50
|
* or reuse a challenge (or its nonce) across requests. */
|
|
48
51
|
export function createLicenseChallenge(subject) {
|
|
@@ -53,14 +56,12 @@ export function createLicenseChallenge(subject) {
|
|
|
53
56
|
nonce: randomBytes(16).toString("hex"),
|
|
54
57
|
});
|
|
55
58
|
}
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export function canonicalizeLicenseVerdict(envelope) {
|
|
63
|
-
return Buffer.from(JSON.stringify({
|
|
59
|
+
/** The version 1 fields in their signed order. `tamper` and then `detail`
|
|
60
|
+
* are appended only when present, so an envelope without them produces
|
|
61
|
+
* exactly the bytes it did before they existed (pinned by a test). `planId`
|
|
62
|
+
* and `term` are never part of these bytes (S317, plan P1). */
|
|
63
|
+
function canonicalFields(envelope) {
|
|
64
|
+
return {
|
|
64
65
|
v: envelope.v,
|
|
65
66
|
alg: envelope.alg,
|
|
66
67
|
typ: envelope.typ,
|
|
@@ -74,12 +75,79 @@ export function canonicalizeLicenseVerdict(envelope) {
|
|
|
74
75
|
issuedAt: envelope.issuedAt,
|
|
75
76
|
...(envelope.tamper !== undefined ? { tamper: envelope.tamper } : {}),
|
|
76
77
|
...(envelope.detail !== undefined ? { detail: envelope.detail } : {}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Explicit field order, exactly like canonicalizeEnvelope, never
|
|
81
|
+
* JSON.stringify of the object itself, whose key order is not guaranteed
|
|
82
|
+
* across producers. What `signature` covers: unchanged since S284b. */
|
|
83
|
+
export function canonicalizeLicenseVerdict(envelope) {
|
|
84
|
+
return Buffer.from(JSON.stringify(canonicalFields(envelope)), "utf8");
|
|
85
|
+
}
|
|
86
|
+
/** S317: what `termSignature` covers: the version 1 fields, then `planId`
|
|
87
|
+
* and `term` always (null when absent), in this order. These bytes always
|
|
88
|
+
* hold a `planId` key, which the version 1 bytes never do, so neither
|
|
89
|
+
* signature can stand in for the other. */
|
|
90
|
+
export function canonicalizeLicenseVerdictTerm(envelope) {
|
|
91
|
+
const term = envelope.term;
|
|
92
|
+
return Buffer.from(JSON.stringify({
|
|
93
|
+
...canonicalFields(envelope),
|
|
94
|
+
planId: envelope.planId ?? null,
|
|
95
|
+
term: term === undefined
|
|
96
|
+
? null
|
|
97
|
+
: { state: term.state, endsAt: term.endsAt, renewalAmountCents: term.renewalAmountCents, cancelAtPeriodEnd: term.cancelAtPeriodEnd },
|
|
77
98
|
}), "utf8");
|
|
78
99
|
}
|
|
100
|
+
/** S319 (S317 rider): an instant exactly as `toISOString` writes it, so a
|
|
101
|
+
* term end has one spelling and the bytes a signature covers are the bytes
|
|
102
|
+
* every verifier reads. */
|
|
103
|
+
function isCanonicalInstant(value) {
|
|
104
|
+
const time = Date.parse(value);
|
|
105
|
+
return Number.isFinite(time) && new Date(time).toISOString() === value;
|
|
106
|
+
}
|
|
107
|
+
function isTerm(value) {
|
|
108
|
+
if (typeof value !== "object" || value === null)
|
|
109
|
+
return false;
|
|
110
|
+
const t = value;
|
|
111
|
+
return (typeof t.state === "string" &&
|
|
112
|
+
LICENSE_TERM_STATES.includes(t.state) &&
|
|
113
|
+
(t.endsAt === null || (typeof t.endsAt === "string" && isCanonicalInstant(t.endsAt))) &&
|
|
114
|
+
// S319 (S317 rider): a whole number of cents a JSON reader keeps exactly,
|
|
115
|
+
// never negative, and never -0 (which JSON writes as 0, so the signed
|
|
116
|
+
// bytes and the signer's value would disagree).
|
|
117
|
+
(t.renewalAmountCents === null ||
|
|
118
|
+
(typeof t.renewalAmountCents === "number" &&
|
|
119
|
+
Number.isSafeInteger(t.renewalAmountCents) &&
|
|
120
|
+
!Object.is(t.renewalAmountCents, -0) &&
|
|
121
|
+
t.renewalAmountCents >= 0)) &&
|
|
122
|
+
typeof t.cancelAtPeriodEnd === "boolean");
|
|
123
|
+
}
|
|
124
|
+
function hasTermFields(envelope) {
|
|
125
|
+
return envelope.planId !== undefined || envelope.term !== undefined;
|
|
126
|
+
}
|
|
127
|
+
/** Both fields, when present, in the shapes a verifier keeps. */
|
|
128
|
+
function termFieldsWellFormed(envelope) {
|
|
129
|
+
const planId = envelope.planId;
|
|
130
|
+
return ((planId === undefined || (typeof planId === "string" && planId.length >= 1 && planId.length <= LICENSE_VERDICT_PLAN_ID_MAX)) &&
|
|
131
|
+
(envelope.term === undefined || isTerm(envelope.term)));
|
|
132
|
+
}
|
|
79
133
|
export function signLicenseVerdict(envelope, privateKeyBase64) {
|
|
80
134
|
const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, "base64"), format: "der", type: "pkcs8" });
|
|
81
135
|
return sign(null, canonicalizeLicenseVerdict(envelope), key).toString("base64");
|
|
82
136
|
}
|
|
137
|
+
/** S317: what the marketplace's validation route returns. `signature` is
|
|
138
|
+
* signLicenseVerdict's, byte for byte (Ed25519 is deterministic), so every
|
|
139
|
+
* verifier built before S317 accepts it; `termSignature` is added only when
|
|
140
|
+
* the envelope carries a plan or a term. Throws RangeError for a malformed
|
|
141
|
+
* plan or term: the marketplace never signs one. */
|
|
142
|
+
export function signLicenseVerdictWithTerm(envelope, privateKeyBase64) {
|
|
143
|
+
const signature = signLicenseVerdict(envelope, privateKeyBase64);
|
|
144
|
+
if (!hasTermFields(envelope))
|
|
145
|
+
return { envelope, signature };
|
|
146
|
+
if (!termFieldsWellFormed(envelope))
|
|
147
|
+
throw new RangeError("signLicenseVerdictWithTerm: the plan or term is malformed");
|
|
148
|
+
const key = createPrivateKey({ key: Buffer.from(privateKeyBase64, "base64"), format: "der", type: "pkcs8" });
|
|
149
|
+
return { envelope, signature, termSignature: sign(null, canonicalizeLicenseVerdictTerm(envelope), key).toString("base64") };
|
|
150
|
+
}
|
|
83
151
|
function isEnvelope(value) {
|
|
84
152
|
if (typeof value !== "object" || value === null)
|
|
85
153
|
return false;
|
|
@@ -94,7 +162,7 @@ function isEnvelope(value) {
|
|
|
94
162
|
typeof e.nonce === "string" &&
|
|
95
163
|
(e.status === "valid" || e.status === "invalid" || e.status === "revoked") &&
|
|
96
164
|
// A licence server that naturally serialises `reason: row.reason ??
|
|
97
|
-
// null` must not be misread as malformed
|
|
165
|
+
// null` must not be misread as malformed: null and "absent" mean the
|
|
98
166
|
// same thing here, and are normalized to undefined below once the
|
|
99
167
|
// signature has been checked.
|
|
100
168
|
(e.reason === undefined || e.reason === null || typeof e.reason === "string") &&
|
|
@@ -108,15 +176,15 @@ function isSigned(value) {
|
|
|
108
176
|
const s = value;
|
|
109
177
|
return typeof s.signature === "string" && s.signature.length > 0 && isEnvelope(s.envelope);
|
|
110
178
|
}
|
|
111
|
-
/** The key lookup and signature check, shared by
|
|
112
|
-
*
|
|
113
|
-
function
|
|
179
|
+
/** The key lookup and signature check over given bytes, shared by the base
|
|
180
|
+
* and the term signature so there is one definition of "authentic". */
|
|
181
|
+
function checkBytes(keyId, bytes, signature, trustedKeys) {
|
|
114
182
|
// Re-derive rather than trust the label, exactly as trusted-keys.ts does:
|
|
115
183
|
// an unauthenticated keyId would otherwise let a signature made by one
|
|
116
184
|
// key be attributed to another.
|
|
117
185
|
const match = trustedKeys.find((k) => {
|
|
118
186
|
try {
|
|
119
|
-
return deriveKeyId(k.publicKey) ===
|
|
187
|
+
return deriveKeyId(k.publicKey) === keyId;
|
|
120
188
|
}
|
|
121
189
|
catch {
|
|
122
190
|
return false;
|
|
@@ -125,20 +193,35 @@ function checkSignature(envelope, signature, trustedKeys) {
|
|
|
125
193
|
if (!match)
|
|
126
194
|
return "untrusted-key";
|
|
127
195
|
try {
|
|
128
|
-
const ok = verify(null,
|
|
196
|
+
const ok = verify(null, bytes, createPublicKey({ key: Buffer.from(match.publicKey, "base64"), format: "der", type: "spki" }), Buffer.from(signature, "base64"));
|
|
129
197
|
return ok ? "ok" : "bad-signature";
|
|
130
198
|
}
|
|
131
199
|
catch {
|
|
132
200
|
return "bad-signature";
|
|
133
201
|
}
|
|
134
202
|
}
|
|
203
|
+
function checkSignature(envelope, signature, trustedKeys) {
|
|
204
|
+
return checkBytes(envelope.keyId, canonicalizeLicenseVerdict(envelope), signature, trustedKeys);
|
|
205
|
+
}
|
|
206
|
+
/** S317: true when the envelope's plan and term are well formed and
|
|
207
|
+
* `termSignature` verifies over them with the same key as the base
|
|
208
|
+
* signature. Anything else reads the verdict as one without them. */
|
|
209
|
+
function termVerified(signed, envelope, trustedKeys) {
|
|
210
|
+
if (!hasTermFields(envelope) || !termFieldsWellFormed(envelope))
|
|
211
|
+
return false;
|
|
212
|
+
const termSignature = signed.termSignature;
|
|
213
|
+
if (typeof termSignature !== "string" || termSignature.length === 0)
|
|
214
|
+
return false;
|
|
215
|
+
return checkBytes(envelope.keyId, canonicalizeLicenseVerdictTerm(envelope), termSignature, trustedKeys) === "ok";
|
|
216
|
+
}
|
|
135
217
|
/** Rebuild from only the signed fields rather than returning the caller's
|
|
136
218
|
* object verbatim, so an extra unsigned property the server happened to
|
|
137
219
|
* attach cannot ride along on a result labelled verified. This also
|
|
138
220
|
* normalizes a `reason: null` producer to `undefined`, matching the type,
|
|
139
221
|
* and leaves `tamper` and `detail` out entirely when the envelope had
|
|
140
|
-
* none.
|
|
141
|
-
|
|
222
|
+
* none. `planId` and `term` are kept only when `withTerm` (their own
|
|
223
|
+
* signature verified, `termVerified`). */
|
|
224
|
+
function signedFieldsOnly(envelope, withTerm) {
|
|
142
225
|
return {
|
|
143
226
|
v: envelope.v,
|
|
144
227
|
alg: envelope.alg,
|
|
@@ -153,6 +236,17 @@ function signedFieldsOnly(envelope) {
|
|
|
153
236
|
issuedAt: envelope.issuedAt,
|
|
154
237
|
...(envelope.tamper !== undefined ? { tamper: envelope.tamper } : {}),
|
|
155
238
|
...(envelope.detail !== undefined ? { detail: envelope.detail } : {}),
|
|
239
|
+
...(withTerm && envelope.planId !== undefined ? { planId: envelope.planId } : {}),
|
|
240
|
+
...(withTerm && envelope.term !== undefined
|
|
241
|
+
? {
|
|
242
|
+
term: {
|
|
243
|
+
state: envelope.term.state,
|
|
244
|
+
endsAt: envelope.term.endsAt,
|
|
245
|
+
renewalAmountCents: envelope.term.renewalAmountCents,
|
|
246
|
+
cancelAtPeriodEnd: envelope.term.cancelAtPeriodEnd,
|
|
247
|
+
},
|
|
248
|
+
}
|
|
249
|
+
: {}),
|
|
156
250
|
};
|
|
157
251
|
}
|
|
158
252
|
/** Verifies a verdict the way a plugin can: the signature against a trusted
|
|
@@ -181,7 +275,7 @@ export function verifyLicenseVerdictSignature(signed, trustedKeys, opts = {}) {
|
|
|
181
275
|
return { ok: false, reason: "future" };
|
|
182
276
|
if (nowMs - issued > maxAgeMs)
|
|
183
277
|
return { ok: false, reason: "expired" };
|
|
184
|
-
return { ok: true, envelope: signedFieldsOnly(envelope) };
|
|
278
|
+
return { ok: true, envelope: signedFieldsOnly(envelope, termVerified(signed, envelope, trustedKeys)) };
|
|
185
279
|
}
|
|
186
280
|
export function verifyLicenseVerdict(signedVerdict, challenge, trustedKeys, now = new Date()) {
|
|
187
281
|
// A challenge answers at most one question. Consuming it here (before
|
|
@@ -203,7 +297,7 @@ export function verifyLicenseVerdict(signedVerdict, challenge, trustedKeys, now
|
|
|
203
297
|
if (authentic === "bad-signature")
|
|
204
298
|
return { verdict: "unverifiable", reason: "bad-signature" };
|
|
205
299
|
// Subject binding. Without this a single genuine "valid" verdict, once
|
|
206
|
-
// captured, would unlock every plugin on every domain
|
|
300
|
+
// captured, would unlock every plugin on every domain, and without the
|
|
207
301
|
// nonce comparison specifically, it would unlock every future request
|
|
208
302
|
// too, regardless of issuedAt. A verdict answering a different challenge
|
|
209
303
|
// is exactly as wrong as one for a different plugin.
|
|
@@ -219,10 +313,10 @@ export function verifyLicenseVerdict(signedVerdict, challenge, trustedKeys, now
|
|
|
219
313
|
if (!Number.isFinite(issued) || Math.abs(now.getTime() - issued) > MAX_VERDICT_AGE_MS) {
|
|
220
314
|
return { verdict: "unverifiable", reason: "stale" };
|
|
221
315
|
}
|
|
222
|
-
const verifiedEnvelope = signedFieldsOnly(envelope);
|
|
316
|
+
const verifiedEnvelope = signedFieldsOnly(envelope, termVerified(signedVerdict, envelope, trustedKeys));
|
|
223
317
|
// Authentication is done; now, and only now, does the envelope's own
|
|
224
318
|
// `status` decide the verdict. `"valid"` is the sole branch a caller can
|
|
225
|
-
// use to unlock something
|
|
319
|
+
// use to unlock something; `"invalid"` and `"revoked"` are just as
|
|
226
320
|
// authentic but must never reach an `unlock()` call.
|
|
227
321
|
if (verifiedEnvelope.status === "valid") {
|
|
228
322
|
return { verdict: "licensed", envelope: verifiedEnvelope };
|
|
@@ -21,14 +21,14 @@ export type PackageContractResult = PackageContractCheck & {
|
|
|
21
21
|
warnings: string[];
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* <dir>/README.md must exist and contain something other than whitespace
|
|
24
|
+
* <dir>/README.md must exist and contain something other than whitespace:
|
|
25
25
|
* a file that exists but says nothing is worse than none: it would render
|
|
26
26
|
* as a blank listing description in the marketplace.
|
|
27
27
|
*/
|
|
28
28
|
export declare function checkReadmeContract(dir: string): PackageContractCheck;
|
|
29
29
|
/**
|
|
30
30
|
* <dir>/marketplace/cover.png must exist, be a real PNG, and be exactly
|
|
31
|
-
* COVER_WIDTH x COVER_HEIGHT
|
|
31
|
+
* COVER_WIDTH x COVER_HEIGHT: the marketplace grid renders every listing's
|
|
32
32
|
* cover at a fixed aspect, so anything else would be cropped or distorted.
|
|
33
33
|
* The failure reason names both the required size and the size found,
|
|
34
34
|
* since "wrong size" without the numbers makes a developer guess.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { capViolations, checkDocsContract, isFile, readDocsContractInput } from "./docs-contract.js";
|
|
4
|
-
// S206 Task 4: the marketplace-listing contract
|
|
4
|
+
// S206 Task 4: the marketplace-listing contract: a non-empty README.md
|
|
5
5
|
// plus a fixed-size cover image: used to live only in kardalum plugin's CLI
|
|
6
6
|
// (packages/cli/src/plugin/checks/package-contract.ts), a dev-machine
|
|
7
7
|
// package apps/server can't import from. Moved here because
|
|
@@ -9,13 +9,13 @@ import { capViolations, checkDocsContract, isFile, readDocsContractInput } from
|
|
|
9
9
|
// AND kardalum plugin all already depend on: one implementation, no second
|
|
10
10
|
// place to keep in sync. kardalum plugin's checks/package-contract.ts now
|
|
11
11
|
// delegates to checkReadmeContract/checkCoverContract below rather than
|
|
12
|
-
// keeping its own copy
|
|
12
|
+
// keeping its own copy; see that file for why its two exports keep their
|
|
13
13
|
// original names, CheckResult shape, and exact failure messages (its own
|
|
14
14
|
// tests, and `kardalum plugin validate`'s output, depend on them).
|
|
15
15
|
//
|
|
16
16
|
// checkPackageContract is the door-level gate: the server's upload route
|
|
17
17
|
// (apps/server/src/routes/plugin-upload.ts) just needs "does this package
|
|
18
|
-
// qualify, and if not, why"
|
|
18
|
+
// qualify, and if not, why"; it has no use for which of the two rules
|
|
19
19
|
// failed independently the way kardalum plugin's per-check report does.
|
|
20
20
|
export const COVER_PATH = "marketplace/cover.png";
|
|
21
21
|
export const COVER_WIDTH = 1200;
|
|
@@ -33,7 +33,7 @@ function fail(reasons) {
|
|
|
33
33
|
return { ok: false, reason: reasons[0], reasons };
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
* <dir>/README.md must exist and contain something other than whitespace
|
|
36
|
+
* <dir>/README.md must exist and contain something other than whitespace:
|
|
37
37
|
* a file that exists but says nothing is worse than none: it would render
|
|
38
38
|
* as a blank listing description in the marketplace.
|
|
39
39
|
*/
|
|
@@ -54,7 +54,7 @@ export function checkReadmeContract(dir) {
|
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* <dir>/marketplace/cover.png must exist, be a real PNG, and be exactly
|
|
57
|
-
* COVER_WIDTH x COVER_HEIGHT
|
|
57
|
+
* COVER_WIDTH x COVER_HEIGHT: the marketplace grid renders every listing's
|
|
58
58
|
* cover at a fixed aspect, so anything else would be cropped or distorted.
|
|
59
59
|
* The failure reason names both the required size and the size found,
|
|
60
60
|
* since "wrong size" without the numbers makes a developer guess.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The signed payload. Field order here is normative
|
|
1
|
+
/** The signed payload. Field order here is normative: canonicalizeEnvelope
|
|
2
2
|
* serializes in exactly this order, and signer and verifier must agree byte
|
|
3
3
|
* for byte. */
|
|
4
4
|
export interface SignatureEnvelope {
|