@push.rocks/smartsecret 1.1.0 → 1.2.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/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @push.rocks/smartsecret
2
2
 
3
- OS keychain-based secret storage with encrypted-file fallback for Node.js.
3
+ OS-backed secret storage plus strict Linux kernel-keyring and envelope APIs for Node.js.
4
4
 
5
5
  ## Issue Reporting and Security
6
6
 
@@ -172,6 +172,55 @@ Key loading is an immutable per-instance snapshot. Replacing a credential file d
172
172
 
173
173
  The package never persists envelopes. The consumer owns durable envelope storage, compare-and-swap coordination during rewrap, and any metadata updates after recovery testing.
174
174
 
175
+ ## SmartSecret Kernel Store
176
+
177
+ `SmartSecretKernelStore` is a separate, fail-closed API for small secrets in the Linux kernel keyring. It does not change the legacy `SmartSecret` backend selection or add a fallback to it. The store requires Node.js 25 on Linux x64 and starts only the package-owned static worker at `dist_rust/smartsecret-kernel_linux_amd64`. It never searches `PATH`, accepts an environment override, invokes a shell, probes Secret Service, or persists secret values to the filesystem.
178
+
179
+ ```typescript
180
+ import { SmartSecretKernelStore } from '@push.rocks/smartsecret';
181
+
182
+ const store = await SmartSecretKernelStore.create({
183
+ service: 'example.application',
184
+ });
185
+
186
+ try {
187
+ await store.setEntry('oidc-client-secret', new TextEncoder().encode('secret'));
188
+ const value = await store.getEntry('oidc-client-secret');
189
+ const deleted = await store.deleteEntry('oidc-client-secret');
190
+ value?.fill(0);
191
+ } finally {
192
+ await store.close();
193
+ }
194
+ ```
195
+
196
+ Service and account strings must contain valid Unicode scalar values and encode to 1 through 1,024 UTF-8 bytes. Values may contain 0 through 1,024 bytes. The stored value is framed with a fixed version and exact length before publication. Existing service rings and entries are accepted only when their type, description, owner, and private permissions match the package contract.
197
+
198
+ `setEntry()` copies its input before dispatch, and `getEntry()` returns a fresh byte array. The caller still owns its input and returned copies and should wipe them when no longer needed. JavaScript and operating-system buffers can retain additional copies, so this remains best-effort zeroization rather than guaranteed memory erasure.
199
+
200
+ The store uses one persistent-user-owned service ring and stages unpublished objects in the process keyring. An inherited session link is preserved and revalidated, but it cannot override or conflict with the persistent root. A revoked inherited session keyring, which can remain after PAM logout, is treated as absent because it is optional and unusable; any failure to establish or validate the required process and persistent roots still fails closed. Publication is verified before staging ownership is removed. Every operation also acquires a service-wide `NamedMutex`, which coordinates cooperating processes running as the same OS identity on the same machine.
201
+
202
+ Generic and legacy searches classify missing, revoked, or expired matches as absent only after the authoritative root revalidates. An unusable root remains a fail-closed kernel error rather than an absent entry.
203
+
204
+ Kernel keyring permissions are an isolation boundary between OS identities, not between processes running under the same UID. Same-UID processes with access to the relevant keyrings may be able to read entries. Persistent keyrings can expire under kernel policy and are cleared by reboot. Applications must treat `null` as absence, not as evidence that a secret existed previously.
205
+
206
+ Operation timeouts default to 5 seconds and may be set from 1 through 60,000 milliseconds. A timeout or abort covers queueing, mutex acquisition, and the worker request under one monotonic deadline. If a mutating request is interrupted after dispatch, or publication/release cannot be confirmed, the store rejects with a `SmartSecretKernelStoreError` whose code is `MUTATION_OUTCOME_UNKNOWN`, terminates the worker, and remains poisoned. Read-side worker integrity failures also poison and terminate the store. Always await `close()`; it waits for already-reserved operations and confirms worker termination.
207
+
208
+ ### DevIdP v1 keyutils migration
209
+
210
+ The two `DevIdP` migration methods are intentionally narrow. They are available only on a store created with service `global.idp.devidp` and accept only accounts matching `v1:[a-f0-9]{64}`:
211
+
212
+ ```typescript
213
+ const source = await store.readDevIdpV1Legacy(legacyAccount);
214
+ if (source) {
215
+ // Parse the DevIdP envelope and durably verify every destination first.
216
+ await store.deleteDevIdpV1Legacy(source.receipt);
217
+ }
218
+ ```
219
+
220
+ `readDevIdpV1Legacy()` returns 1 through 16,384 opaque bytes plus a one-use, store-bound receipt. Deletion reacquires the same mutex and atomically rechecks the source serial, root membership, byte length, and SHA-256 digest inside one worker command. A replacement or changed value is not deleted and rejects with a `SmartSecretKernelStoreError` whose code is `SOURCE_CHANGED`. Linux keyutils does not provide compare-and-delete against an uncooperative writer that updates the same serial, so the legacy writer must be stopped or otherwise operationally quiescent before migration.
221
+
222
+ This migration surface covers only a legacy record proven to have been written through the `@napi-rs/keyring` keyutils fallback. It does not probe or migrate Secret Service. If Secret Service could own the source, that source-specific migration must be implemented at its owning layer before treating a kernel-keyring miss as authoritative.
223
+
175
224
  ## API Reference
176
225
 
177
226
  ### `SmartSecret`
@@ -218,6 +267,27 @@ SmartSecretKeyring.create(config: ISmartSecretKeyringConfig): Promise<SmartSecre
218
267
 
219
268
  All keyring failures are `SmartSecretKeyringError` instances with a stable `TSmartSecretKeyringErrorCode`. Their message, JSON representation, Node.js inspection output, and stack contain only the code and fixed package boilerplate. Filesystem and SmartCrypto causes are not retained.
220
269
 
270
+ ### `SmartSecretKernelStore`
271
+
272
+ Create kernel stores through the asynchronous factory. The constructor is not public.
273
+
274
+ ```typescript
275
+ SmartSecretKernelStore.create(
276
+ options: ISmartSecretKernelStoreOptions,
277
+ ): Promise<SmartSecretKernelStore>
278
+ ```
279
+
280
+ | Method | Signature | Description |
281
+ | --- | --- | --- |
282
+ | `getEntry` | `(account: string, options?) => Promise<Uint8Array \| null>` | Read a copied raw value or return `null` when absent |
283
+ | `setEntry` | `(account: string, value: Uint8Array, options?) => Promise<void>` | Create or replace one framed entry |
284
+ | `deleteEntry` | `(account: string, options?) => Promise<boolean>` | Delete an entry and report whether it existed |
285
+ | `readDevIdpV1Legacy` | `(account: string, options?) => Promise<IDevIdpV1LegacyRead \| null>` | Read one verified, opaque keyutils legacy value |
286
+ | `deleteDevIdpV1Legacy` | `(receipt, options?) => Promise<'deleted' \| 'alreadyAbsent'>` | Revalidate and consume one legacy receipt |
287
+ | `close` | `() => Promise<void>` | Wait for reserved operations and confirm worker termination |
288
+
289
+ Operation options contain optional `timeoutMs` and `signal: AbortSignal` properties. Failures are code-only `SmartSecretKernelStoreError` instances. Stable codes distinguish invalid input, unsupported runtime, unavailable kernel/worker/mutex resources, root conflicts, corrupt entries, changed migration sources, pre-dispatch aborts/timeouts, unknown mutation outcomes, poisoned/closed lifecycle state, and worker integrity failures. Secret values and underlying causes are never retained on these errors.
290
+
221
291
  ### Types
222
292
 
223
293
  ```typescript
@@ -283,6 +353,8 @@ Both paths can be influenced by providing a custom `vaultPath` in the constructo
283
353
 
284
354
  This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.
285
355
 
356
+ The packaged Linux kernel worker contains statically linked third-party Rust components. Their copyright and license notices are reproduced in [third-party-notices.md](./third-party-notices.md).
357
+
286
358
  **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
287
359
 
288
360
  ### Trademarks
@@ -0,0 +1,177 @@
1
+ # Third-Party Notices
2
+
3
+ The `smartsecret-kernel_linux_amd64` executable distributed with this package is
4
+ statically linked. The following notices cover its third-party Rust components
5
+ and the compile-time components recorded by its reproducible Cargo lockfile.
6
+
7
+ ## Component Inventory
8
+
9
+ The package uses the MIT option where a component is offered under
10
+ `MIT OR Apache-2.0`, and the MIT option where `memchr` is offered under
11
+ `MIT OR Unlicense`.
12
+
13
+ | Component | Version | Selected license |
14
+ | --- | --- | --- |
15
+ | base64 | 0.22.1 | MIT |
16
+ | bitflags | 1.3.2 | MIT |
17
+ | block-buffer | 0.10.4 | MIT |
18
+ | cfg-if | 1.0.4 | MIT |
19
+ | cpufeatures | 0.2.17 | MIT |
20
+ | crypto-common | 0.1.7 | MIT |
21
+ | digest | 0.10.7 | MIT |
22
+ | errno | 0.3.14 | MIT |
23
+ | generic-array | 0.14.7 | MIT |
24
+ | itoa | 1.0.18 | MIT |
25
+ | keyutils | 0.4.0 | BSD-3-Clause |
26
+ | keyutils-raw | 0.4.0 | BSD-3-Clause |
27
+ | libc | 0.2.189 | MIT |
28
+ | log | 0.4.33 | MIT |
29
+ | memchr | 2.8.3 | MIT |
30
+ | proc-macro2 | 1.0.107 | MIT |
31
+ | quote | 1.0.47 | MIT |
32
+ | serde | 1.0.229 | MIT |
33
+ | serde_core | 1.0.229 | MIT |
34
+ | serde_derive | 1.0.229 | MIT |
35
+ | serde_json | 1.0.151 | MIT |
36
+ | sha2 | 0.10.9 | MIT |
37
+ | syn | 3.0.3 | MIT |
38
+ | typenum | 1.20.1 | MIT |
39
+ | unicode-ident | 1.0.24 | MIT AND Unicode-3.0 |
40
+ | uninit | 0.3.0 | MIT |
41
+ | version_check | 0.9.5 | MIT |
42
+ | windows-link | 0.2.1 | MIT |
43
+ | windows-sys | 0.61.2 | MIT |
44
+ | zeroize | 1.9.0 | MIT |
45
+ | zmij | 1.0.23 | MIT |
46
+
47
+ The `windows-*` components are target-inactive for the distributed Linux
48
+ worker. `proc-macro2`, `quote`, `serde_derive`, `syn`, and `unicode-ident` are
49
+ compile-time components. They are listed conservatively so this notice covers
50
+ the complete locked Rust dependency graph.
51
+
52
+ ## MIT Copyright Notices
53
+
54
+ Copyright (c) 2015 Alice Maz (`base64`)
55
+
56
+ Copyright (c) 2014 The Rust Project Developers (`bitflags`, `log`)
57
+
58
+ Copyright (c) 2018-2019 The RustCrypto Project Developers (`block-buffer`)
59
+
60
+ Copyright (c) 2014 Alex Crichton (`cfg-if`)
61
+
62
+ Copyright (c) 2020-2025 The RustCrypto Project Developers (`cpufeatures`)
63
+
64
+ Copyright (c) 2021 RustCrypto Developers (`crypto-common`)
65
+
66
+ Copyright (c) 2017 Artyom Pavlov (`digest`)
67
+
68
+ Copyright (c) 2014 Chris Wong (`errno`)
69
+
70
+ Copyright (c) 2015 Bartłomiej Kamiński (`generic-array`)
71
+
72
+ Copyright (c) The Rust Project Developers (`libc`)
73
+
74
+ Copyright (c) 2015 Andrew Gallant (`memchr`)
75
+
76
+ Copyright (c) 2006-2009 Graydon Hoare (`sha2`)
77
+
78
+ Copyright (c) 2009-2013 Mozilla Foundation (`sha2`)
79
+
80
+ Copyright (c) 2016 Artyom Pavlov (`sha2`)
81
+
82
+ Copyright (c) 2014 Paho Lurie-Gregg (`typenum`)
83
+
84
+ Copyright (c) 2019 Daniel Henry-Mantilla (`uninit`)
85
+
86
+ Copyright (c) 2017-2018 Sergio Benitez (`version_check`)
87
+
88
+ Copyright (c) 2018-2026 The RustCrypto Project Developers (`zeroize`)
89
+
90
+ The remaining MIT-licensed components in the inventory publish the license
91
+ text below without an additional copyright line in their crate license file.
92
+
93
+ ### MIT License
94
+
95
+ Permission is hereby granted, free of charge, to any person obtaining a copy
96
+ of this software and associated documentation files (the "Software"), to deal
97
+ in the Software without restriction, including without limitation the rights
98
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
+ copies of the Software, and to permit persons to whom the Software is
100
+ furnished to do so, subject to the following conditions:
101
+
102
+ The above copyright notice and this permission notice shall be included in all
103
+ copies or substantial portions of the Software.
104
+
105
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
111
+ SOFTWARE.
112
+
113
+ ## BSD-3-Clause Notice for keyutils and keyutils-raw
114
+
115
+ Copyright (c) 2018, Ben Boeckel
116
+ All rights reserved.
117
+
118
+ Redistribution and use in source and binary forms, with or without
119
+ modification, are permitted provided that the following conditions are met:
120
+
121
+ 1. Redistributions of source code must retain the above copyright notice,
122
+ this list of conditions and the following disclaimer.
123
+ 2. Redistributions in binary form must reproduce the above copyright notice,
124
+ this list of conditions and the following disclaimer in the documentation
125
+ and/or other materials provided with the distribution.
126
+ 3. Neither the name of this project nor the names of its contributors may be
127
+ used to endorse or promote products derived from this software without
128
+ specific prior written permission.
129
+
130
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
131
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
132
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
133
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
134
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
135
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
136
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
137
+ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
138
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
139
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
140
+
141
+ ## Unicode License V3 for unicode-ident
142
+
143
+ COPYRIGHT AND PERMISSION NOTICE
144
+
145
+ Copyright © 1991-2023 Unicode, Inc.
146
+
147
+ NOTICE TO USER: Carefully read the following legal agreement. BY DOWNLOADING,
148
+ INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR SOFTWARE, YOU
149
+ UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE TERMS AND CONDITIONS
150
+ OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY,
151
+ DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
152
+
153
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
154
+ data files and any associated documentation (the "Data Files") or software and
155
+ any associated documentation (the "Software") to deal in the Data Files or
156
+ Software without restriction, including without limitation the rights to use,
157
+ copy, modify, merge, publish, distribute, and/or sell copies of the Data Files
158
+ or Software, and to permit persons to whom the Data Files or Software are
159
+ furnished to do so, provided that either (a) this copyright and permission
160
+ notice appear with all copies of the Data Files or Software, or (b) this
161
+ copyright and permission notice appear in associated Documentation.
162
+
163
+ THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
164
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
165
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD
166
+ PARTY RIGHTS.
167
+
168
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE
169
+ LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY
170
+ DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
171
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
172
+ CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA FILES OR SOFTWARE.
173
+
174
+ Except as contained in this notice, the name of a copyright holder shall not be
175
+ used in advertising or otherwise to promote the sale, use or other dealings in
176
+ these Data Files or Software without prior written authorization of the
177
+ copyright holder.
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartsecret',
6
- version: '1.1.0',
7
- description: 'OS keychain-based secret storage with encrypted-file fallback for Node.js.'
6
+ version: '1.2.1',
7
+ description: 'OS-backed secret storage plus strict Linux kernel-keyring and envelope APIs for Node.js.'
8
8
  }
package/ts/index.ts CHANGED
@@ -13,3 +13,9 @@ export type {
13
13
  ISmartSecretEnvelopeV1,
14
14
  TSmartSecretKeyringProfile,
15
15
  } from './smartsecret.keyring.protocol.js';
16
+ export * from './smartsecret.kernelstore.js';
17
+ export { SmartSecretKernelStoreError } from './smartsecret.kernel.error.js';
18
+ export type {
19
+ ISmartSecretKernelStoreErrorJson,
20
+ TSmartSecretKernelStoreErrorCode,
21
+ } from './smartsecret.kernel.error.js';
@@ -0,0 +1,78 @@
1
+ export type TSmartSecretKernelStoreErrorCode =
2
+ | 'ENTRY_CORRUPT'
3
+ | 'INVALID_ARGUMENT'
4
+ | 'KERNEL_UNAVAILABLE'
5
+ | 'MUTATION_OUTCOME_UNKNOWN'
6
+ | 'MUTEX_FAILED'
7
+ | 'OPERATION_ABORTED'
8
+ | 'OPERATION_TIMEOUT'
9
+ | 'RECEIPT_INVALID'
10
+ | 'ROOT_CONFLICT'
11
+ | 'SOURCE_CHANGED'
12
+ | 'STORE_CLOSED'
13
+ | 'STORE_POISONED'
14
+ | 'UNSUPPORTED_RUNTIME'
15
+ | 'WORKER_INTEGRITY_FAILED'
16
+ | 'WORKER_UNAVAILABLE';
17
+
18
+ export interface ISmartSecretKernelStoreErrorJson {
19
+ name: 'SmartSecretKernelStoreError';
20
+ code: TSmartSecretKernelStoreErrorCode;
21
+ message: string;
22
+ }
23
+
24
+ const inspectSymbol = Symbol.for('nodejs.util.inspect.custom');
25
+ const errorCodes = new Set<TSmartSecretKernelStoreErrorCode>([
26
+ 'ENTRY_CORRUPT',
27
+ 'INVALID_ARGUMENT',
28
+ 'KERNEL_UNAVAILABLE',
29
+ 'MUTATION_OUTCOME_UNKNOWN',
30
+ 'MUTEX_FAILED',
31
+ 'OPERATION_ABORTED',
32
+ 'OPERATION_TIMEOUT',
33
+ 'RECEIPT_INVALID',
34
+ 'ROOT_CONFLICT',
35
+ 'SOURCE_CHANGED',
36
+ 'STORE_CLOSED',
37
+ 'STORE_POISONED',
38
+ 'UNSUPPORTED_RUNTIME',
39
+ 'WORKER_INTEGRITY_FAILED',
40
+ 'WORKER_UNAVAILABLE',
41
+ ]);
42
+
43
+ /** A code-only error that intentionally retains no operation values or causes. */
44
+ export class SmartSecretKernelStoreError extends Error {
45
+ public readonly code: TSmartSecretKernelStoreErrorCode;
46
+ public readonly cause: undefined;
47
+
48
+ constructor(codeArg: TSmartSecretKernelStoreErrorCode) {
49
+ const code = errorCodes.has(codeArg) ? codeArg : 'INVALID_ARGUMENT';
50
+ const message = `SmartSecret kernel store operation failed (${code}).`;
51
+ super(message);
52
+ this.name = 'SmartSecretKernelStoreError';
53
+ this.code = code;
54
+ this.stack = `${this.name}: ${message}`;
55
+ Object.defineProperty(this, 'cause', {
56
+ configurable: false,
57
+ enumerable: false,
58
+ value: undefined,
59
+ writable: false,
60
+ });
61
+ }
62
+
63
+ public toJSON(): ISmartSecretKernelStoreErrorJson {
64
+ return {
65
+ name: 'SmartSecretKernelStoreError',
66
+ code: this.code,
67
+ message: this.message,
68
+ };
69
+ }
70
+
71
+ public [inspectSymbol](): ISmartSecretKernelStoreErrorJson {
72
+ return this.toJSON();
73
+ }
74
+ }
75
+
76
+ export const createSmartSecretKernelStoreError = (
77
+ codeArg: TSmartSecretKernelStoreErrorCode,
78
+ ): SmartSecretKernelStoreError => new SmartSecretKernelStoreError(codeArg);