node-tpm2 0.0.4-beta.3 → 0.0.5-beta.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/README.md +396 -88
- package/api.js +233 -0
- package/docs/api-reference.md +1029 -0
- package/docs/roadmap.md +216 -0
- package/docs/windows-pcp.md +21 -0
- package/examples/nv-smoke.mjs +77 -0
- package/index.d.ts +89 -23
- package/native.cjs +65 -52
- package/native.d.ts +76 -0
- package/package.json +12 -10
package/docs/roadmap.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# API roadmap
|
|
2
|
+
|
|
3
|
+
Plan to complete the public `node-tpm2` API: subsystem namespaces, exportable key
|
|
4
|
+
handles, and parity between Linux (TBS) and Windows (TBS for general ops, PCP for
|
|
5
|
+
attestation persistence where required).
|
|
6
|
+
|
|
7
|
+
This library is standalone. Consumers integrate via npm; nothing in this repo references
|
|
8
|
+
or depends on downstream products.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Current state (0.0.5-beta)
|
|
13
|
+
|
|
14
|
+
**Shipped and validated on real Windows 11 hardware (Intel TPM, non-virtual):** attestation (user + machine provision, cross-user quote, SYSTEM provision), `random`, `keys` (sign + RSA decrypt), `pcr.read` / `pcr.extend` (admin on Windows), `nv` (read/write/define/undefine/readPublic), `seal` / `unseal`.
|
|
15
|
+
|
|
16
|
+
| Namespace | Methods |
|
|
17
|
+
|-----------|---------|
|
|
18
|
+
| Root | `Tpm.isAvailable()`, `Tpm.open()`, `Tpm.info()`, `tpm.readPublic()` |
|
|
19
|
+
| `tpm.random` | `bytes(n)` |
|
|
20
|
+
| `tpm.pcr` | `read`, `extend` |
|
|
21
|
+
| `tpm.nv` | `read`, `write`, `readPublic`, `define`, `undefine` |
|
|
22
|
+
| `tpm.keys` | `create`, `load`; `KeyHandle.sign`, `export`, `decrypt` |
|
|
23
|
+
| `tpm.seal` | `seal`, `unseal` |
|
|
24
|
+
| `tpm.attest` | `provisionAk`, `quote`, `ekCertificate` |
|
|
25
|
+
| `AkHandle` | `export`, `quote`, `activateCredential`, `publicKeyDer` |
|
|
26
|
+
| Flat | Parity wrappers for all of the above (`Tpm.pcrRead`, `Tpm.nvDefine`, `Tpm.seal`, …) |
|
|
27
|
+
|
|
28
|
+
**Platform split:** General ops (keys, seal, NV, PCR, random) use TBS on both OSes. Attestation persistence on Windows uses NCrypt PCP (`PCP1` / `PCP2` blobs); Linux uses TBS-wrapped ECDSA AK blobs.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Target API
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { Tpm, TpmError } from 'node-tpm2';
|
|
36
|
+
|
|
37
|
+
await using tpm = await Tpm.open();
|
|
38
|
+
|
|
39
|
+
// ── Root ──────────────────────────────────────────────────────────
|
|
40
|
+
await Tpm.isAvailable();
|
|
41
|
+
await tpm.info();
|
|
42
|
+
|
|
43
|
+
// ── random ────────────────────────────────────────────────────────
|
|
44
|
+
await tpm.random.bytes(32);
|
|
45
|
+
|
|
46
|
+
// ── pcr ───────────────────────────────────────────────────────────
|
|
47
|
+
await tpm.pcr.read([0, 1, 7], 'sha256');
|
|
48
|
+
await tpm.pcr.extend(7, digest); // digest: Buffer, 32 bytes for sha256 bank
|
|
49
|
+
|
|
50
|
+
// ── nv ────────────────────────────────────────────────────────────
|
|
51
|
+
await tpm.nv.read('0x01c00002'); // handle or well-known name
|
|
52
|
+
await tpm.nv.write('0x01800001', data, opts); // opts: auth, offset — policy-dependent
|
|
53
|
+
|
|
54
|
+
// ── keys ──────────────────────────────────────────────────────────
|
|
55
|
+
const key = await tpm.keys.create({
|
|
56
|
+
type: 'ecc', // 'ecc' | 'rsa'
|
|
57
|
+
sign: true,
|
|
58
|
+
decrypt: false,
|
|
59
|
+
});
|
|
60
|
+
const blob = key.export();
|
|
61
|
+
const loaded = await tpm.keys.load(blob);
|
|
62
|
+
await loaded.sign(digest); // Buffer in → signature Buffer out
|
|
63
|
+
await loaded.decrypt(cipher); // when key was created with decrypt: true
|
|
64
|
+
|
|
65
|
+
// ── seal ──────────────────────────────────────────────────────────
|
|
66
|
+
const sealed = await tpm.seal({
|
|
67
|
+
data: secret,
|
|
68
|
+
pcrSelection: [7],
|
|
69
|
+
pcrPolicy: 'current' | digest, // bind to current PCR state or explicit digest
|
|
70
|
+
});
|
|
71
|
+
const plain = await tpm.unseal(sealed);
|
|
72
|
+
|
|
73
|
+
// ── attest (opinionated attestation — unchanged intent) ───────────
|
|
74
|
+
const ak = await tpm.attest.provisionAk({ scope, keyName, overwrite });
|
|
75
|
+
await ak.quote({ pcrSelection, qualifyingData });
|
|
76
|
+
await tpm.attest.ekCertificate();
|
|
77
|
+
await ak.activateCredential({ credentialBlob, secret });
|
|
78
|
+
|
|
79
|
+
// ── plumbing ──────────────────────────────────────────────────────
|
|
80
|
+
await tpm.readPublic('0x81010001');
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Flat equivalents remain on `Tpm.*` for every operation (thin wrappers over the same native calls).
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Platform strategy
|
|
88
|
+
|
|
89
|
+
| Concern | Linux | Windows |
|
|
90
|
+
|---------|-------|---------|
|
|
91
|
+
| Transport | `/dev/tpmrm0` | TBS (`Tbsip_Submit_Command`) |
|
|
92
|
+
| General keys (`keys.*`) | TBS wrapped TPM2B blobs | TBS wrapped blobs (same codec as Linux) |
|
|
93
|
+
| Attestation AK (`attest.provisionAk`) | TBS wrapped ECDSA AK | NCrypt PCP persisted key (`PCP1` / `PCP2` blob) |
|
|
94
|
+
| Quote / activate | Load blob transiently → operate → flush | PCP open by key name + TBS for quote crypto |
|
|
95
|
+
| Seal / unseal | TBS policy-bound object | TBS (same commands; no PCP required) |
|
|
96
|
+
| NV | TBS NV_Read / NV_Write | TBS NV commands |
|
|
97
|
+
|
|
98
|
+
**Rule:** PCP is for **attestation key persistence and fleet cross-user quote**, not for every key operation. General `keys.*` and `seal` use the shared TBS command path on both OSes so behavior and blobs stay aligned.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Implementation phases
|
|
103
|
+
|
|
104
|
+
### Phase 0 — API hygiene ✅ (this branch)
|
|
105
|
+
|
|
106
|
+
**Goal:** Published types match runtime; namespace skeleton on `TpmHandle`.
|
|
107
|
+
|
|
108
|
+
- [x] Remove bogus top-level exports from `index.d.ts`
|
|
109
|
+
- [x] Add namespace objects on `TpmHandle`: `random`, `nv`, `keys`, `seal`, `pcr.extend`
|
|
110
|
+
- [x] Add `KeyHandle` / `KeyBlob` types; unimplemented methods throw `NOT_SUPPORTED`
|
|
111
|
+
- [ ] Acceptance: `npm run verify:package`
|
|
112
|
+
|
|
113
|
+
### Phase 1 — `tpm.random.bytes` ✅ (this branch)
|
|
114
|
+
|
|
115
|
+
**Goal:** Public `GetRandom`.
|
|
116
|
+
|
|
117
|
+
- [x] Rust: `random.rs` — marshal `TPM2_GetRandom`, ≤64 bytes per call, loop for larger
|
|
118
|
+
- [x] NAPI: `randomBytes`
|
|
119
|
+
- [x] JS: `tpm.random.bytes(n)`, `Tpm.randomBytes(n)`
|
|
120
|
+
- [ ] Tests: integration on Linux + Windows VM
|
|
121
|
+
|
|
122
|
+
### Phase 2 — `tpm.keys` ✅
|
|
123
|
+
|
|
124
|
+
**Goal:** General exportable signing keys via TBS wrapped blobs (both OSes).
|
|
125
|
+
|
|
126
|
+
- [x] `keys.create` / `keys.load` / `key.sign` — ECC + RSA sign keys
|
|
127
|
+
- [x] Unit tests: templates, Sign command golden, option validation, HW roundtrip
|
|
128
|
+
- [x] `key.decrypt` — RSA OAEP
|
|
129
|
+
- [ ] Windows VM sign smoke
|
|
130
|
+
|
|
131
|
+
### Phase 3 — `tpm.pcr.extend` ✅ (this branch)
|
|
132
|
+
|
|
133
|
+
**Goal:** Software measurement hook.
|
|
134
|
+
|
|
135
|
+
- [x] Rust: `TPM2_PCR_Extend` with SHA-256 bank selection matching `pcr.read`.
|
|
136
|
+
- [x] JS: `tpm.pcr.extend(index, digest)`.
|
|
137
|
+
- [x] Tests: extend → read → digest changed.
|
|
138
|
+
- [x] Caveats: some firmware policies lock PCRs; surface `TPM_RC` / `COMMAND_BLOCKED` cleanly.
|
|
139
|
+
- [x] Acceptance: Linux unprivileged on swtpm/dev VM; **Windows Administrator** on real client hardware (PCR 23 validated).
|
|
140
|
+
|
|
141
|
+
### Phase 4 — `tpm.nv` ✅ (this branch)
|
|
142
|
+
|
|
143
|
+
**Goal:** General NV index access beyond EK cert helper.
|
|
144
|
+
|
|
145
|
+
- [x] Rust: `nv.read_public(handle)` — size + attributes via `nv_read_public`.
|
|
146
|
+
- [x] `nv.read(handle, offset, size)`.
|
|
147
|
+
- [x] `nv.write(handle, offset, data, auth?)` — optional auth for password-protected indices.
|
|
148
|
+
- [x] `nv.define` / `nv.undefine` — owner-auth; owner NV range only; refuses EK indices.
|
|
149
|
+
- [x] Migrate `readEkCertificate` to call `nv.read` on well-known EK cert index internally.
|
|
150
|
+
- [x] JS: `tpm.nv.read`, `tpm.nv.write`, `tpm.nv.readPublic`, `tpm.nv.define`, `tpm.nv.undefine`; document which indices are safe on consumer hardware.
|
|
151
|
+
- [ ] Acceptance: EK cert read unchanged; optional integration test against swtpm-defined NV index (hardware: use `examples/nv-smoke.mjs` on test machine).
|
|
152
|
+
|
|
153
|
+
### Phase 5 — `tpm.seal` / `tpm.unseal` ✅ (this branch)
|
|
154
|
+
|
|
155
|
+
**Goal:** TPM-bound secrets with optional PCR policy.
|
|
156
|
+
|
|
157
|
+
- [x] Rust: `seal({ data, pcrSelection? })` — storage primary, `Create` sealed object, export blob.
|
|
158
|
+
- [x] `unseal(blob)` — load + `Unseal`.
|
|
159
|
+
- [x] PCR policy: `PolicyPCR` session when `pcrSelection` provided.
|
|
160
|
+
- [x] JS: `tpm.seal`, `tpm.unseal`; flat aliases.
|
|
161
|
+
- [x] Tests: roundtrip without PCR; unit tests for marshalling.
|
|
162
|
+
- [ ] Acceptance: Linux + Windows TBS; roundtrip with PCR extend before unseal on hardware.
|
|
163
|
+
|
|
164
|
+
### Phase 6 — Hardening & 1.0 (ongoing)
|
|
165
|
+
|
|
166
|
+
- Real hardware matrix (firmware TPM, Hyper-V, physical laptop).
|
|
167
|
+
- Fuzz/malformed response handling on codec.
|
|
168
|
+
- Stable semver on error codes (`latest` tag).
|
|
169
|
+
- Performance: reuse TBS context per `TpmHandle` where safe (today: per-call context on Windows TBS path).
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Dependency order
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
Phase 0 (hygiene)
|
|
177
|
+
↓
|
|
178
|
+
Phase 1 (random) ─────────────────────────────┐
|
|
179
|
+
↓ │
|
|
180
|
+
Phase 2 (keys) ──→ Phase 5 (seal uses keys) │
|
|
181
|
+
↓ │
|
|
182
|
+
Phase 3 (pcr.extend) ──→ Phase 5 (PCR policy) │
|
|
183
|
+
↓ │
|
|
184
|
+
Phase 4 (nv) ─────────────────────────────────┘
|
|
185
|
+
↓
|
|
186
|
+
Phase 6 (1.0)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Phases 1 and 3 can run in parallel after Phase 0. Phase 2 blocks Phase 5. Phase 4 is independent.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Testing strategy
|
|
194
|
+
|
|
195
|
+
| Layer | Tool |
|
|
196
|
+
|-------|------|
|
|
197
|
+
| Command golden bytes | Rust unit tests |
|
|
198
|
+
| Privilege / elevation | `tbs-probe` (repo only) + `examples/smoke-test.mjs` (published) |
|
|
199
|
+
| Cross-platform | Linux CI + Windows VM manual gate before each beta |
|
|
200
|
+
| NV / seal edge cases | swtpm with scripted NV define in CI (Linux) |
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Out of scope (remain non-goals)
|
|
205
|
+
|
|
206
|
+
- macOS TPM (no hardware).
|
|
207
|
+
- Persistent handle / `EvictControl` in the public API.
|
|
208
|
+
- Full TPM2 policy language exposed to JS (only fixed recipes: activate-credential, seal-with-PCR).
|
|
209
|
+
- PKCS#11, OpenSSL engine, or platform keystore integration.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Versioning
|
|
214
|
+
|
|
215
|
+
- Implement phases on `dev`; beta publish after each phase or logical group (e.g. **0.0.5-beta.0** = full NV + seal + keys decrypt).
|
|
216
|
+
- `1.0.0` when Phases 0–5 acceptance criteria pass on real hardware and API surface in README matches implementation.
|
package/docs/windows-pcp.md
CHANGED
|
@@ -7,6 +7,7 @@ On Windows, node-tpm2 uses the **Microsoft Platform Crypto Provider** for attest
|
|
|
7
7
|
| Operation | Standard user | Elevated admin | SYSTEM |
|
|
8
8
|
|-----------|---------------|----------------|--------|
|
|
9
9
|
| `Tpm.isAvailable()`, PCR read, `readPublic` | Yes | Yes | Yes |
|
|
10
|
+
| `tpm.pcr.extend` | No (`REQUIRES_ELEVATION`) | Yes † | Yes † |
|
|
10
11
|
| `provisionAk()` user scope (`PCP1`) | Yes | Yes | Yes |
|
|
11
12
|
| `quote()` | Yes | Yes | Yes |
|
|
12
13
|
| `provisionAk({ scope: 'machine' })` (`PCP2`) | No | Yes | Yes (production enroll) |
|
|
@@ -14,6 +15,8 @@ On Windows, node-tpm2 uses the **Microsoft Platform Crypto Provider** for attest
|
|
|
14
15
|
|
|
15
16
|
**Runtime apps** typically only need `quote()` with a blob/locator from enrollment. Activation is an enrollment-time proof-of-possession step.
|
|
16
17
|
|
|
18
|
+
**† `pcr.extend`:** Prefer PCR indices **16–23** (not **0–7**, which are boot/Secure Boot measurements). Standard users receive **`REQUIRES_ELEVATION`** (`hresult` `0x80280400`); **Administrator** can extend (validated on real Intel laptop). Linux standard user can extend unless firmware locks the index.
|
|
19
|
+
|
|
17
20
|
## AK blob formats
|
|
18
21
|
|
|
19
22
|
| Magic | Scope | Meaning |
|
|
@@ -23,6 +26,24 @@ On Windows, node-tpm2 uses the **Microsoft Platform Crypto Provider** for attest
|
|
|
23
26
|
|
|
24
27
|
Blob layout: magic + key name + PCP creation attestation fields (`public` holds metadata; `private` is empty).
|
|
25
28
|
|
|
29
|
+
## Threat model: device vs application
|
|
30
|
+
|
|
31
|
+
**A quote proves an enrolled device, not a specific app or user.**
|
|
32
|
+
|
|
33
|
+
On Windows, a machine-scoped attestation key (`PCP2`) is a **host-local capability**, not a secret. The exported blob is mainly a **locator**: magic, `keyName`, and scope. At quote time the library opens the persisted PCP key by that name. Any standard-user process that knows the fleet `keyName` can obtain a valid quote from the same AK — that is how cross-user runtime quoting works after one-time elevated provisioning.
|
|
34
|
+
|
|
35
|
+
This is inherent to device attestation on Windows (and similar on Linux: anyone with read/write on `/dev/tpmrm0` can use a copied AK blob on the same TPM). It is **not** a library bug and should not be “fixed” by treating the blob as a password.
|
|
36
|
+
|
|
37
|
+
| What a quote establishes | What it does **not** establish |
|
|
38
|
+
|--------------------------|--------------------------------|
|
|
39
|
+
| The TPM that was enrolled still holds the AK | Which Windows process produced the quote |
|
|
40
|
+
| PCR values at quote time match the attestation | Which human user clicked “sign in” |
|
|
41
|
+
| `qualifyingData` matches what the verifier sent (if you set it) | That only your product binary ran |
|
|
42
|
+
|
|
43
|
+
**Your enrollment service** should bind identity at enroll time: verify `akPublicDer`, optionally verify PCP creation attestation fields in the blob, register the device once, then issue runtime challenges via `qualifyingData`. **App and user binding** are separate layers (session auth, mTLS, OS login, etc.).
|
|
44
|
+
|
|
45
|
+
Use a **vendor-prefixed, stable `keyName`** for machine scope (for example `my-app-device-ak`). Do not rely on secrecy of the blob or key name; rely on TPM possession + server-side enrollment records + challenge nonces.
|
|
46
|
+
|
|
26
47
|
## Machine key provisioning
|
|
27
48
|
|
|
28
49
|
```javascript
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* NV define / read / write / undefine cycle (owner NV index).
|
|
4
|
+
*
|
|
5
|
+
* WARNING: Mutates TPM NV storage. Use only on a test machine.
|
|
6
|
+
* Requires owner authorization (often empty password on consumer TPMs).
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* node nv-smoke.mjs
|
|
10
|
+
* node nv-smoke.mjs --handle 0x01800042 --size 64
|
|
11
|
+
*
|
|
12
|
+
* Install:
|
|
13
|
+
* npm install node-tpm2@beta
|
|
14
|
+
* node node_modules/node-tpm2/examples/nv-smoke.mjs
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Tpm } from '../index.js';
|
|
18
|
+
|
|
19
|
+
function flagValue(args, name) {
|
|
20
|
+
for (let i = 0; i < args.length; i++) {
|
|
21
|
+
if (args[i] === name && args[i + 1]) return args[++i];
|
|
22
|
+
const prefix = `${name}=`;
|
|
23
|
+
if (args[i]?.startsWith(prefix)) return args[i].slice(prefix.length);
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function main() {
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
const handle = flagValue(args, '--handle') ?? '0x01800042';
|
|
31
|
+
const size = Number(flagValue(args, '--size') ?? '64');
|
|
32
|
+
|
|
33
|
+
if (!(await Tpm.isAvailable())) {
|
|
34
|
+
console.error('FAIL: no TPM');
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await using tpm = await Tpm.open();
|
|
39
|
+
const payload = Buffer.from(`node-tpm2-nv-smoke-${Date.now()}`);
|
|
40
|
+
|
|
41
|
+
console.log(`== nv-smoke handle=${handle} size=${size} ==`);
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
await tpm.nv.undefine(handle);
|
|
45
|
+
console.log(' (pre-clean undefine OK or index absent)');
|
|
46
|
+
} catch {
|
|
47
|
+
console.log(' (pre-clean undefine skipped — index may not exist)');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
await tpm.nv.define({ handle, size });
|
|
51
|
+
console.log('PASS nv.define');
|
|
52
|
+
|
|
53
|
+
const meta = await tpm.nv.readPublic(handle);
|
|
54
|
+
console.log('PASS nv.readPublic', meta);
|
|
55
|
+
|
|
56
|
+
await tpm.nv.write(handle, payload, 0);
|
|
57
|
+
console.log('PASS nv.write', payload.length, 'bytes');
|
|
58
|
+
|
|
59
|
+
const readBack = await tpm.nv.read(handle, 0, payload.length);
|
|
60
|
+
if (!readBack.equals(payload)) {
|
|
61
|
+
console.error('FAIL: read mismatch');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
console.log('PASS nv.read roundtrip');
|
|
65
|
+
|
|
66
|
+
await tpm.nv.undefine(handle);
|
|
67
|
+
console.log('PASS nv.undefine');
|
|
68
|
+
|
|
69
|
+
console.log('\nnv-smoke: OK');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
main().catch((err) => {
|
|
73
|
+
console.error('FAIL:', err.message ?? err);
|
|
74
|
+
if (err.code) console.error(' code:', err.code);
|
|
75
|
+
if (err.tpmRc != null) console.error(' tpmRc:', err.tpmRc);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
package/index.d.ts
CHANGED
|
@@ -32,6 +32,9 @@ export declare type AkBlob = {
|
|
|
32
32
|
private: Buffer;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/** General key blob (same wire shape as AkBlob; distinct type for clarity). */
|
|
36
|
+
export declare type KeyBlob = AkBlob;
|
|
37
|
+
|
|
35
38
|
export declare type QuoteOptions = {
|
|
36
39
|
akBlob: AkBlob;
|
|
37
40
|
pcrSelection: number[];
|
|
@@ -74,6 +77,34 @@ export declare type ActivateCredentialFlatOptions = ActivateCredentialOptions &
|
|
|
74
77
|
akBlob: AkBlob;
|
|
75
78
|
};
|
|
76
79
|
|
|
80
|
+
/** General device key creation options. */
|
|
81
|
+
export declare type KeyCreateOptions = {
|
|
82
|
+
type: 'ecc' | 'rsa';
|
|
83
|
+
sign?: boolean;
|
|
84
|
+
decrypt?: boolean;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Sealed blob options. */
|
|
88
|
+
export declare type SealOptions = {
|
|
89
|
+
data: Buffer;
|
|
90
|
+
pcrSelection?: number[];
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** Owner NV index definition (requires owner authorization). */
|
|
94
|
+
export declare type NvDefineOptions = {
|
|
95
|
+
handle: string | number;
|
|
96
|
+
size: number;
|
|
97
|
+
/** Index password when attributes use AUTHREAD/AUTHWRITE. */
|
|
98
|
+
auth?: Buffer;
|
|
99
|
+
/** Owner hierarchy password (often empty on consumer TPMs). */
|
|
100
|
+
ownerAuth?: Buffer;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export declare type NvReadPublicResult = {
|
|
104
|
+
dataSize: number;
|
|
105
|
+
attributes: number;
|
|
106
|
+
};
|
|
107
|
+
|
|
77
108
|
export declare interface AkHandle {
|
|
78
109
|
export(): AkBlob;
|
|
79
110
|
readonly publicKeyDer: Buffer;
|
|
@@ -81,6 +112,13 @@ export declare interface AkHandle {
|
|
|
81
112
|
activateCredential(opts: ActivateCredentialOptions): Promise<Buffer>;
|
|
82
113
|
}
|
|
83
114
|
|
|
115
|
+
/** @throws {TpmError} when key lacks decrypt attribute */
|
|
116
|
+
export declare interface KeyHandle {
|
|
117
|
+
export(): KeyBlob;
|
|
118
|
+
sign(digest: Buffer): Promise<Buffer>;
|
|
119
|
+
decrypt(cipher: Buffer): Promise<Buffer>;
|
|
120
|
+
}
|
|
121
|
+
|
|
84
122
|
export declare type TpmInfo = {
|
|
85
123
|
manufacturer: string;
|
|
86
124
|
firmwareVersion: string;
|
|
@@ -92,6 +130,35 @@ export declare interface TpmHandle {
|
|
|
92
130
|
info(): Promise<TpmInfo>;
|
|
93
131
|
pcr: {
|
|
94
132
|
read(selection: number[], bank?: 'sha256'): Promise<Record<number, string>>;
|
|
133
|
+
extend(index: number, digest: Buffer): Promise<void>;
|
|
134
|
+
};
|
|
135
|
+
random: {
|
|
136
|
+
bytes(count: number): Promise<Buffer>;
|
|
137
|
+
};
|
|
138
|
+
nv: {
|
|
139
|
+
readPublic(handle: string | number): Promise<NvReadPublicResult>;
|
|
140
|
+
read(
|
|
141
|
+
handle: string | number,
|
|
142
|
+
offset?: number,
|
|
143
|
+
size?: number,
|
|
144
|
+
auth?: Buffer,
|
|
145
|
+
): Promise<Buffer>;
|
|
146
|
+
write(
|
|
147
|
+
handle: string | number,
|
|
148
|
+
data: Buffer,
|
|
149
|
+
offset?: number,
|
|
150
|
+
auth?: Buffer,
|
|
151
|
+
): Promise<void>;
|
|
152
|
+
define(opts: NvDefineOptions): Promise<void>;
|
|
153
|
+
undefine(handle: string | number, ownerAuth?: Buffer): Promise<void>;
|
|
154
|
+
};
|
|
155
|
+
keys: {
|
|
156
|
+
create(opts: KeyCreateOptions): Promise<KeyHandle>;
|
|
157
|
+
load(blob: KeyBlob): Promise<KeyHandle>;
|
|
158
|
+
};
|
|
159
|
+
seal: {
|
|
160
|
+
seal(opts: SealOptions): Promise<Buffer>;
|
|
161
|
+
unseal(blob: Buffer): Promise<Buffer>;
|
|
95
162
|
};
|
|
96
163
|
attest: {
|
|
97
164
|
ekCertificate(): Promise<Buffer | null>;
|
|
@@ -107,33 +174,32 @@ export declare const Tpm: {
|
|
|
107
174
|
open(): Promise<TpmHandle>;
|
|
108
175
|
getFixedProperties(): Promise<TpmInfo>;
|
|
109
176
|
info(): Promise<TpmInfo>;
|
|
177
|
+
randomBytes(count: number): Promise<Buffer>;
|
|
110
178
|
pcrRead(selection: number[], bank?: 'sha256'): Promise<Record<number, string>>;
|
|
179
|
+
pcrExtend(index: number, digest: Buffer): Promise<void>;
|
|
111
180
|
readPublic(handle: string): Promise<ReadPublicResult>;
|
|
112
181
|
readEkCertificate(): Promise<Buffer | null>;
|
|
113
182
|
quote(opts: QuoteOptions): Promise<QuoteResult>;
|
|
114
183
|
provisionAk(opts?: ProvisionAkOptions): Promise<ProvisionAkResult>;
|
|
115
184
|
activateCredential(opts: ActivateCredentialFlatOptions): Promise<Buffer>;
|
|
185
|
+
createKey(opts?: KeyCreateOptions): Promise<{ publicKeyDer: Buffer; keyBlob: KeyBlob }>;
|
|
186
|
+
signKeyBlob(opts: { keyBlob: KeyBlob; digest: Buffer }): Promise<Buffer>;
|
|
187
|
+
decryptKeyBlob(opts: { keyBlob: KeyBlob; cipher: Buffer }): Promise<Buffer>;
|
|
188
|
+
nvRead(
|
|
189
|
+
handle: string | number,
|
|
190
|
+
offset?: number,
|
|
191
|
+
size?: number,
|
|
192
|
+
auth?: Buffer,
|
|
193
|
+
): Promise<Buffer>;
|
|
194
|
+
nvWrite(
|
|
195
|
+
handle: string | number,
|
|
196
|
+
data: Buffer,
|
|
197
|
+
offset?: number,
|
|
198
|
+
auth?: Buffer,
|
|
199
|
+
): Promise<void>;
|
|
200
|
+
nvReadPublic(handle: string | number): Promise<NvReadPublicResult>;
|
|
201
|
+
nvDefine(opts: NvDefineOptions): Promise<void>;
|
|
202
|
+
nvUndefine(handle: string | number, ownerAuth?: Buffer): Promise<void>;
|
|
203
|
+
seal(opts: SealOptions): Promise<Buffer>;
|
|
204
|
+
unseal(blob: Buffer): Promise<Buffer>;
|
|
116
205
|
};
|
|
117
|
-
|
|
118
|
-
export declare function pcrRead(
|
|
119
|
-
selection: number[],
|
|
120
|
-
bank?: 'sha256',
|
|
121
|
-
): Promise<Record<number, string>>;
|
|
122
|
-
|
|
123
|
-
export declare function readPublic(handle: string): Promise<ReadPublicResult>;
|
|
124
|
-
|
|
125
|
-
export declare function readEkCertificate(): Promise<Buffer | null>;
|
|
126
|
-
|
|
127
|
-
export declare function quote(opts: QuoteOptions): Promise<QuoteResult>;
|
|
128
|
-
|
|
129
|
-
export declare function provisionAk(
|
|
130
|
-
opts?: ProvisionAkOptions,
|
|
131
|
-
): Promise<ProvisionAkResult>;
|
|
132
|
-
|
|
133
|
-
export declare function activateCredential(
|
|
134
|
-
opts: ActivateCredentialFlatOptions,
|
|
135
|
-
): Promise<Buffer>;
|
|
136
|
-
|
|
137
|
-
export declare function getFixedProperties(): Promise<TpmInfo>;
|
|
138
|
-
|
|
139
|
-
export declare function isAvailable(): Promise<boolean>;
|