@tinfoilsh/verifier 1.0.4 → 1.1.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 +4 -3
- package/dist/attestation.d.ts +4 -10
- package/dist/attestation.d.ts.map +1 -1
- package/dist/attestation.js +11 -31
- package/dist/attestation.js.map +1 -1
- package/dist/bundle.d.ts +15 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +128 -0
- package/dist/bundle.js.map +1 -0
- package/dist/cert-verify.d.ts +2 -4
- package/dist/cert-verify.d.ts.map +1 -1
- package/dist/cert-verify.js +12 -16
- package/dist/cert-verify.js.map +1 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +24 -48
- package/dist/client.js.map +1 -1
- package/dist/dcode.d.ts.map +1 -1
- package/dist/dcode.js +3 -2
- package/dist/dcode.js.map +1 -1
- package/dist/errors.d.ts +91 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +102 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/sev/cert-chain.d.ts +1 -2
- package/dist/sev/cert-chain.d.ts.map +1 -1
- package/dist/sev/cert-chain.js +40 -91
- package/dist/sev/cert-chain.js.map +1 -1
- package/dist/sev/constants.d.ts +0 -1
- package/dist/sev/constants.d.ts.map +1 -1
- package/dist/sev/constants.js +1 -1
- package/dist/sev/constants.js.map +1 -1
- package/dist/sev/report.d.ts.map +1 -1
- package/dist/sev/report.js +19 -54
- package/dist/sev/report.js.map +1 -1
- package/dist/sev/utils.d.ts +0 -1
- package/dist/sev/utils.d.ts.map +1 -1
- package/dist/sev/utils.js +1 -1
- package/dist/sev/utils.js.map +1 -1
- package/dist/sev/validation.d.ts.map +1 -1
- package/dist/sev/validation.js +53 -52
- package/dist/sev/validation.js.map +1 -1
- package/dist/sev/verify.d.ts.map +1 -1
- package/dist/sev/verify.js +8 -7
- package/dist/sev/verify.js.map +1 -1
- package/dist/sigstore-trusted-root.d.ts +94 -0
- package/dist/sigstore-trusted-root.d.ts.map +1 -0
- package/dist/sigstore-trusted-root.js +127 -0
- package/dist/sigstore-trusted-root.js.map +1 -0
- package/dist/sigstore.d.ts +5 -4
- package/dist/sigstore.d.ts.map +1 -1
- package/dist/sigstore.js +15 -14
- package/dist/sigstore.js.map +1 -1
- package/dist/types.d.ts +1 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -26
- package/dist/types.js.map +1 -1
- package/package.json +13 -8
- package/dist/github.d.ts +0 -22
- package/dist/github.d.ts.map +0 -1
- package/dist/github.js +0 -69
- package/dist/github.js.map +0 -1
- package/dist/sev/index.d.ts +0 -10
- package/dist/sev/index.d.ts.map +0 -1
- package/dist/sev/index.js +0 -9
- package/dist/sev/index.js.map +0 -1
- package/dist/sigstore-trusted-root.json +0 -126
package/dist/dcode.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Decode dcode-encoded data from certificate SANs.
|
|
3
3
|
* Format: NN<base32-chunk>.<prefix>.<domain> where NN is chunk index.
|
|
4
4
|
*/
|
|
5
|
+
import { AttestationError } from './errors.js';
|
|
5
6
|
const B32 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
|
6
7
|
function base32Decode(input) {
|
|
7
8
|
const s = input.toUpperCase().replace(/=+$/, '');
|
|
@@ -12,7 +13,7 @@ function base32Decode(input) {
|
|
|
12
13
|
for (const c of s) {
|
|
13
14
|
const i = B32.indexOf(c);
|
|
14
15
|
if (i < 0)
|
|
15
|
-
throw new
|
|
16
|
+
throw new AttestationError(`Invalid certificate data: Unexpected character "${c}" in base32-encoded field`);
|
|
16
17
|
val = (val << 5) | i;
|
|
17
18
|
if ((bits += 5) >= 8)
|
|
18
19
|
out[idx++] = (val >> (bits -= 8)) & 0xff;
|
|
@@ -27,7 +28,7 @@ export function decodeDomains(domains, prefix) {
|
|
|
27
28
|
.map(d => d.split('.')[0].slice(2))
|
|
28
29
|
.join('');
|
|
29
30
|
if (!chunks)
|
|
30
|
-
throw new
|
|
31
|
+
throw new AttestationError(`Invalid certificate: Missing expected DNS names with prefix "${prefix}"`);
|
|
31
32
|
return base32Decode(chunks);
|
|
32
33
|
}
|
|
33
34
|
export const bytesToHex = (b) => [...b].map(x => x.toString(16).padStart(2, '0')).join('');
|
package/dist/dcode.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dcode.js","sourceRoot":"","sources":["../src/dcode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,GAAG,GAAG,kCAAkC,CAAC;AAE/C,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAEjC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzD,IAAI,IAAI,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;IAE/B,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAClB,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"dcode.js","sourceRoot":"","sources":["../src/dcode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,GAAG,GAAG,kCAAkC,CAAC;AAE/C,SAAS,YAAY,CAAC,KAAa;IACjC,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IAEjC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACzD,IAAI,IAAI,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC;IAE/B,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAClB,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,gBAAgB,CAAC,mDAAmD,CAAC,2BAA2B,CAAC,CAAC;QACvH,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC;YAAE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACjE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAiB,EAAE,MAAc;IAC7D,MAAM,OAAO,GAAG,IAAI,MAAM,GAAG,CAAC;IAC9B,MAAM,MAAM,GAAG,OAAO;SACnB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SAChC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC/C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAClC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEZ,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,gBAAgB,CAAC,gEAAgE,MAAM,GAAG,CAAC,CAAC;IACnH,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAa,EAAE,EAAE,CAC1C,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for the Tinfoil SDK.
|
|
3
|
+
*
|
|
4
|
+
* Hierarchy:
|
|
5
|
+
* ```
|
|
6
|
+
* TinfoilError (base)
|
|
7
|
+
* ├── ConfigurationError - Client misconfigured or used incorrectly
|
|
8
|
+
* ├── FetchError - Couldn't fetch attestation materials
|
|
9
|
+
* └── AttestationError - Attestation failed (security issue)
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Base error class for all Tinfoil SDK errors.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TinfoilError extends Error {
|
|
16
|
+
cause?: Error;
|
|
17
|
+
constructor(message: string, options?: {
|
|
18
|
+
cause?: Error;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Thrown when the client is misconfigured or used incorrectly.
|
|
23
|
+
*
|
|
24
|
+
* Examples:
|
|
25
|
+
* - Missing required options (serverURL, configRepo, apiKey)
|
|
26
|
+
* - Invalid option values
|
|
27
|
+
* - Calling methods before client is ready
|
|
28
|
+
* - Using the wrong client type
|
|
29
|
+
*
|
|
30
|
+
* Action: Fix your code
|
|
31
|
+
*/
|
|
32
|
+
export declare class ConfigurationError extends TinfoilError {
|
|
33
|
+
constructor(message: string, options?: {
|
|
34
|
+
cause?: Error;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Thrown when fetching attestation materials fails.
|
|
39
|
+
*
|
|
40
|
+
* Examples:
|
|
41
|
+
* - Network unreachable
|
|
42
|
+
* - HTTP errors (404, 500, etc.)
|
|
43
|
+
* - Invalid response format (bad JSON, wrong schema)
|
|
44
|
+
* - Timeout
|
|
45
|
+
*
|
|
46
|
+
* Action: Retry, check network connectivity
|
|
47
|
+
*/
|
|
48
|
+
export declare class FetchError extends TinfoilError {
|
|
49
|
+
constructor(message: string, options?: {
|
|
50
|
+
cause?: Error;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Thrown when attestation verification fails.
|
|
55
|
+
*
|
|
56
|
+
* This covers all attestation-related security errors:
|
|
57
|
+
* - Material verification failures (parsing, signatures, certificates)
|
|
58
|
+
* - Policy validation failures (measurement mismatch, policy violation)
|
|
59
|
+
*
|
|
60
|
+
* Examples:
|
|
61
|
+
* - Data parsing failed (malformed report, invalid base64, bad structure)
|
|
62
|
+
* - Sigstore signature invalid
|
|
63
|
+
* - Hardware certificate chain invalid
|
|
64
|
+
* - Report signature invalid
|
|
65
|
+
* - Measurement mismatch (enclave code doesn't match signed release)
|
|
66
|
+
* - Policy violation (debug enabled, TCB too low)
|
|
67
|
+
* - Key binding mismatch (transport keys don't match attested keys)
|
|
68
|
+
*
|
|
69
|
+
* Action: Stop - security issue - you should retry the entire attestation protocol.
|
|
70
|
+
*/
|
|
71
|
+
export declare class AttestationError extends TinfoilError {
|
|
72
|
+
constructor(message: string, options?: {
|
|
73
|
+
cause?: Error;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Helper to handle errors in catch blocks.
|
|
78
|
+
* - If the error is already a TinfoilError, rethrow it as-is
|
|
79
|
+
* - Otherwise, wrap it in the specified error class
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* try {
|
|
84
|
+
* await someOperation();
|
|
85
|
+
* } catch (e) {
|
|
86
|
+
* wrapOrThrow(e, AttestationError, 'Operation failed');
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function wrapOrThrow(e: unknown, ErrorClass: typeof AttestationError | typeof FetchError | typeof ConfigurationError, message: string): never;
|
|
91
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC;gBACV,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAOzD;AAED;;;;;;;;;;GAUG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAIzD;AAED;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,YAAY;gBAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAIzD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;gBACpC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAIzD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,CAAC,EAAE,OAAO,EACV,UAAU,EAAE,OAAO,gBAAgB,GAAG,OAAO,UAAU,GAAG,OAAO,kBAAkB,EACnF,OAAO,EAAE,MAAM,GACd,KAAK,CAKP"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error classes for the Tinfoil SDK.
|
|
3
|
+
*
|
|
4
|
+
* Hierarchy:
|
|
5
|
+
* ```
|
|
6
|
+
* TinfoilError (base)
|
|
7
|
+
* ├── ConfigurationError - Client misconfigured or used incorrectly
|
|
8
|
+
* ├── FetchError - Couldn't fetch attestation materials
|
|
9
|
+
* └── AttestationError - Attestation failed (security issue)
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Base error class for all Tinfoil SDK errors.
|
|
14
|
+
*/
|
|
15
|
+
export class TinfoilError extends Error {
|
|
16
|
+
constructor(message, options) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'TinfoilError';
|
|
19
|
+
if (options?.cause) {
|
|
20
|
+
this.cause = options.cause;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Thrown when the client is misconfigured or used incorrectly.
|
|
26
|
+
*
|
|
27
|
+
* Examples:
|
|
28
|
+
* - Missing required options (serverURL, configRepo, apiKey)
|
|
29
|
+
* - Invalid option values
|
|
30
|
+
* - Calling methods before client is ready
|
|
31
|
+
* - Using the wrong client type
|
|
32
|
+
*
|
|
33
|
+
* Action: Fix your code
|
|
34
|
+
*/
|
|
35
|
+
export class ConfigurationError extends TinfoilError {
|
|
36
|
+
constructor(message, options) {
|
|
37
|
+
super(message, options);
|
|
38
|
+
this.name = 'ConfigurationError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Thrown when fetching attestation materials fails.
|
|
43
|
+
*
|
|
44
|
+
* Examples:
|
|
45
|
+
* - Network unreachable
|
|
46
|
+
* - HTTP errors (404, 500, etc.)
|
|
47
|
+
* - Invalid response format (bad JSON, wrong schema)
|
|
48
|
+
* - Timeout
|
|
49
|
+
*
|
|
50
|
+
* Action: Retry, check network connectivity
|
|
51
|
+
*/
|
|
52
|
+
export class FetchError extends TinfoilError {
|
|
53
|
+
constructor(message, options) {
|
|
54
|
+
super(message, options);
|
|
55
|
+
this.name = 'FetchError';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Thrown when attestation verification fails.
|
|
60
|
+
*
|
|
61
|
+
* This covers all attestation-related security errors:
|
|
62
|
+
* - Material verification failures (parsing, signatures, certificates)
|
|
63
|
+
* - Policy validation failures (measurement mismatch, policy violation)
|
|
64
|
+
*
|
|
65
|
+
* Examples:
|
|
66
|
+
* - Data parsing failed (malformed report, invalid base64, bad structure)
|
|
67
|
+
* - Sigstore signature invalid
|
|
68
|
+
* - Hardware certificate chain invalid
|
|
69
|
+
* - Report signature invalid
|
|
70
|
+
* - Measurement mismatch (enclave code doesn't match signed release)
|
|
71
|
+
* - Policy violation (debug enabled, TCB too low)
|
|
72
|
+
* - Key binding mismatch (transport keys don't match attested keys)
|
|
73
|
+
*
|
|
74
|
+
* Action: Stop - security issue - you should retry the entire attestation protocol.
|
|
75
|
+
*/
|
|
76
|
+
export class AttestationError extends TinfoilError {
|
|
77
|
+
constructor(message, options) {
|
|
78
|
+
super(message, options);
|
|
79
|
+
this.name = 'AttestationError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Helper to handle errors in catch blocks.
|
|
84
|
+
* - If the error is already a TinfoilError, rethrow it as-is
|
|
85
|
+
* - Otherwise, wrap it in the specified error class
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* try {
|
|
90
|
+
* await someOperation();
|
|
91
|
+
* } catch (e) {
|
|
92
|
+
* wrapOrThrow(e, AttestationError, 'Operation failed');
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function wrapOrThrow(e, ErrorClass, message) {
|
|
97
|
+
if (e instanceof TinfoilError) {
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
throw new ErrorClass(message, { cause: e });
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAErC,YAAY,OAAe,EAAE,OAA2B;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC7B,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAClD,YAAY,OAAe,EAAE,OAA2B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAO,UAAW,SAAQ,YAAY;IAC1C,YAAY,OAAe,EAAE,OAA2B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,gBAAiB,SAAQ,YAAY;IAChD,YAAY,OAAe,EAAE,OAA2B;QACtD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CACzB,CAAU,EACV,UAAmF,EACnF,OAAe;IAEf,IAAI,CAAC,YAAY,YAAY,EAAE,CAAC;QAC9B,MAAM,CAAC,CAAC;IACV,CAAC;IACD,MAAM,IAAI,UAAU,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAU,EAAE,CAAC,CAAC;AACvD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { TinfoilError, ConfigurationError, FetchError, AttestationError, } from './errors.js';
|
|
2
|
+
export { verifyAttestation } from './attestation.js';
|
|
3
|
+
export { assembleAttestationBundle } from './bundle.js';
|
|
2
4
|
export { Verifier } from './client.js';
|
|
3
|
-
export {
|
|
4
|
-
export { PredicateType, compareMeasurements, measurementFingerprint, AttestationError, FormatMismatchError, MeasurementMismatchError, hashAttestationDocument } from './types.js';
|
|
5
|
+
export { PredicateType, compareMeasurements, measurementFingerprint, hashAttestationDocument } from './types.js';
|
|
5
6
|
export type { AttestationDocument, AttestationMeasurement, AttestationResponse, AttestationBundle, VerificationDocument, VerificationStepState, HardwareMeasurement } from './types.js';
|
|
6
7
|
export type { VerifierOptions } from './client.js';
|
|
7
|
-
export { verifyCertificate, type CertVerificationResult
|
|
8
|
+
export { verifyCertificate, type CertVerificationResult } from './cert-verify.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACjH,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACxL,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
// Error classes
|
|
2
|
+
export { TinfoilError, ConfigurationError, FetchError, AttestationError, } from './errors.js';
|
|
3
|
+
// Verification
|
|
4
|
+
export { verifyAttestation } from './attestation.js';
|
|
5
|
+
export { assembleAttestationBundle } from './bundle.js';
|
|
2
6
|
export { Verifier } from './client.js';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export { verifyCertificate, CertificateVerificationError } from './cert-verify.js';
|
|
7
|
+
export { PredicateType, compareMeasurements, measurementFingerprint, hashAttestationDocument } from './types.js';
|
|
8
|
+
export { verifyCertificate } from './cert-verify.js';
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,UAAU,EACV,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,eAAe;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGjH,OAAO,EAAE,iBAAiB,EAA+B,MAAM,kBAAkB,CAAC"}
|
package/dist/sev/cert-chain.d.ts
CHANGED
|
@@ -6,8 +6,7 @@ export declare class CertificateChain {
|
|
|
6
6
|
ask: X509Certificate;
|
|
7
7
|
vcek: X509Certificate;
|
|
8
8
|
constructor(ark: X509Certificate, ask: X509Certificate, vcek: X509Certificate);
|
|
9
|
-
static fromReport(report: Report, vcekDer
|
|
10
|
-
private static fetchVcekForReport;
|
|
9
|
+
static fromReport(report: Report, vcekDer: Uint8Array): Promise<CertificateChain>;
|
|
11
10
|
verifyChain(): Promise<boolean>;
|
|
12
11
|
validateVcekTcb(tcb: TCBParts): void;
|
|
13
12
|
validateVcekHwid(chipId: Uint8Array): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cert-chain.d.ts","sourceRoot":"","sources":["../../src/sev/cert-chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"cert-chain.d.ts","sourceRoot":"","sources":["../../src/sev/cert-chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AA6BnE,qBAAa,gBAAgB;IAElB,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,eAAe;IACpB,IAAI,EAAE,eAAe;gBAFrB,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,eAAe;WAGjB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAgBjF,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAyCrC,eAAe,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IA0CpC,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAY1C,OAAO,CAAC,iBAAiB;IAqBzB,OAAO,CAAC,iBAAiB;IAqBzB,OAAO,CAAC,kBAAkB;IA2D1B,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,wBAAwB;IAMhC,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,sBAAsB;IAM9B,IAAI,aAAa,IAAI,OAAO,CAAC,SAAS,CAAC,CAEtC;CACF"}
|
package/dist/sev/cert-chain.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReportSigner } from './constants.js';
|
|
2
2
|
import { ARK_CERT, ASK_CERT } from './certs.js';
|
|
3
|
-
import { tcbFromInt, bytesToHex } from './utils.js';
|
|
4
3
|
import { X509Certificate } from '@freedomofpress/sigstore-browser';
|
|
5
4
|
import { ASN1Obj, uint8ArrayEqual } from '@freedomofpress/crypto-browser';
|
|
5
|
+
import { AttestationError, wrapOrThrow } from '../errors.js';
|
|
6
6
|
// SEV-SNP VCEK OID definitions
|
|
7
7
|
const SnpOid = {
|
|
8
8
|
STRUCT_VERSION: '1.3.6.1.4.1.3704.1.1',
|
|
@@ -27,46 +27,23 @@ const OID_RSASSA_PSS = '1.2.840.113549.1.1.10';
|
|
|
27
27
|
const OID_EC_PUBLIC_KEY = '1.2.840.10045.2.1';
|
|
28
28
|
const OID_SECP384R1 = '1.3.132.0.34';
|
|
29
29
|
export class CertificateChain {
|
|
30
|
-
ark;
|
|
31
|
-
ask;
|
|
32
|
-
vcek;
|
|
33
30
|
constructor(ark, ask, vcek) {
|
|
34
31
|
this.ark = ark;
|
|
35
32
|
this.ask = ask;
|
|
36
33
|
this.vcek = vcek;
|
|
37
34
|
}
|
|
38
35
|
static async fromReport(report, vcekDer) {
|
|
39
|
-
// Validate report
|
|
40
36
|
if (report.productName !== 'Genoa') {
|
|
41
|
-
throw new
|
|
37
|
+
throw new AttestationError(`Unsupported processor: ${report.productName}. This verifier only supports AMD EPYC Genoa processors`);
|
|
42
38
|
}
|
|
43
39
|
if (report.signerInfoParsed.signingKey !== ReportSigner.VcekReportSigner) {
|
|
44
|
-
throw new
|
|
40
|
+
throw new AttestationError('Unsupported signing key: This verifier only supports VCEK-signed attestation reports');
|
|
45
41
|
}
|
|
46
|
-
// Fetch VCEK if not provided
|
|
47
|
-
const vcek = vcekDer ?? await this.fetchVcekForReport(report);
|
|
48
42
|
const ark = X509Certificate.parse(ARK_CERT);
|
|
49
43
|
const ask = X509Certificate.parse(ASK_CERT);
|
|
50
|
-
const vcekCert = X509Certificate.parse(
|
|
44
|
+
const vcekCert = X509Certificate.parse(vcekDer);
|
|
51
45
|
return new CertificateChain(ark, ask, vcekCert);
|
|
52
46
|
}
|
|
53
|
-
static async fetchVcekForReport(report) {
|
|
54
|
-
const vcekUrl = buildVCEKUrl(report.productName, report.chipId, report.reportedTcb);
|
|
55
|
-
const isBrowser = typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
|
|
56
|
-
if (isBrowser) { // Browser supports local caching
|
|
57
|
-
const cached = localStorage.getItem(vcekUrl);
|
|
58
|
-
if (cached) {
|
|
59
|
-
try { // Base64 decode and return as Uint8Array
|
|
60
|
-
return Uint8Array.from(atob(cached), c => c.charCodeAt(0));
|
|
61
|
-
}
|
|
62
|
-
catch { // Base64 decode failed, remove from cache
|
|
63
|
-
localStorage.removeItem(vcekUrl);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return fetchAndCacheVCEK(vcekUrl);
|
|
67
|
-
}
|
|
68
|
-
return fetchVCEK(vcekUrl);
|
|
69
|
-
}
|
|
70
47
|
async verifyChain() {
|
|
71
48
|
try {
|
|
72
49
|
// Validate certificate formats
|
|
@@ -76,166 +53,166 @@ export class CertificateChain {
|
|
|
76
53
|
// Validate certificate validity periods
|
|
77
54
|
const now = new Date();
|
|
78
55
|
if (!this.ark.validForDate(now)) {
|
|
79
|
-
throw new
|
|
56
|
+
throw new AttestationError('AMD Root Key (ARK) certificate has expired or is not yet valid');
|
|
80
57
|
}
|
|
81
58
|
if (!this.ask.validForDate(now)) {
|
|
82
|
-
throw new
|
|
59
|
+
throw new AttestationError('AMD SEV Key (ASK) certificate has expired or is not yet valid');
|
|
83
60
|
}
|
|
84
61
|
if (!this.vcek.validForDate(now)) {
|
|
85
|
-
throw new
|
|
62
|
+
throw new AttestationError('VCEK certificate has expired or is not yet valid');
|
|
86
63
|
}
|
|
87
64
|
// Verify signature chain: ARK self-signed, ARK signs ASK, ASK signs VCEK
|
|
88
65
|
const arkSelfSigned = await this.ark.verify();
|
|
89
66
|
if (!arkSelfSigned) {
|
|
90
|
-
throw new
|
|
67
|
+
throw new AttestationError('AMD Root Key (ARK) certificate signature verification failed: Not properly self-signed');
|
|
91
68
|
}
|
|
92
69
|
const askSignedByArk = await this.ask.verify(this.ark);
|
|
93
70
|
if (!askSignedByArk) {
|
|
94
|
-
throw new
|
|
71
|
+
throw new AttestationError('AMD SEV Key (ASK) certificate signature verification failed: Not signed by ARK');
|
|
95
72
|
}
|
|
96
73
|
const vcekSignedByAsk = await this.vcek.verify(this.ask);
|
|
97
74
|
if (!vcekSignedByAsk) {
|
|
98
|
-
throw new
|
|
75
|
+
throw new AttestationError('VCEK certificate signature verification failed: Not signed by ASK');
|
|
99
76
|
}
|
|
100
77
|
return true;
|
|
101
78
|
}
|
|
102
79
|
catch (e) {
|
|
103
|
-
|
|
80
|
+
wrapOrThrow(e, AttestationError, 'AMD certificate chain verification failed');
|
|
104
81
|
}
|
|
105
82
|
}
|
|
106
83
|
validateVcekTcb(tcb) {
|
|
107
84
|
// Validate BL_SPL
|
|
108
85
|
const blSplExt = this.vcek.extension(SnpOid.BL_SPL);
|
|
109
86
|
if (!blSplExt) {
|
|
110
|
-
throw new
|
|
87
|
+
throw new AttestationError('Invalid VCEK certificate: Missing bootloader security patch level (BL_SPL) extension');
|
|
111
88
|
}
|
|
112
89
|
const blSpl = this.decodeExtensionInteger(blSplExt.value);
|
|
113
90
|
if (blSpl !== tcb.blSpl) {
|
|
114
|
-
throw new
|
|
91
|
+
throw new AttestationError(`VCEK TCB mismatch: Bootloader SPL in certificate (${blSpl}) does not match report (${tcb.blSpl})`);
|
|
115
92
|
}
|
|
116
93
|
// Validate TEE_SPL
|
|
117
94
|
const teeSplExt = this.vcek.extension(SnpOid.TEE_SPL);
|
|
118
95
|
if (!teeSplExt) {
|
|
119
|
-
throw new
|
|
96
|
+
throw new AttestationError('Invalid VCEK certificate: Missing TEE security patch level (TEE_SPL) extension');
|
|
120
97
|
}
|
|
121
98
|
const teeSpl = this.decodeExtensionInteger(teeSplExt.value);
|
|
122
99
|
if (teeSpl !== tcb.teeSpl) {
|
|
123
|
-
throw new
|
|
100
|
+
throw new AttestationError(`VCEK TCB mismatch: TEE SPL in certificate (${teeSpl}) does not match report (${tcb.teeSpl})`);
|
|
124
101
|
}
|
|
125
102
|
// Validate SNP_SPL
|
|
126
103
|
const snpSplExt = this.vcek.extension(SnpOid.SNP_SPL);
|
|
127
104
|
if (!snpSplExt) {
|
|
128
|
-
throw new
|
|
105
|
+
throw new AttestationError('Invalid VCEK certificate: Missing SNP security patch level (SNP_SPL) extension');
|
|
129
106
|
}
|
|
130
107
|
const snpSpl = this.decodeExtensionInteger(snpSplExt.value);
|
|
131
108
|
if (snpSpl !== tcb.snpSpl) {
|
|
132
|
-
throw new
|
|
109
|
+
throw new AttestationError(`VCEK TCB mismatch: SNP SPL in certificate (${snpSpl}) does not match report (${tcb.snpSpl})`);
|
|
133
110
|
}
|
|
134
111
|
// Validate UCODE
|
|
135
112
|
const ucodeExt = this.vcek.extension(SnpOid.UCODE);
|
|
136
113
|
if (!ucodeExt) {
|
|
137
|
-
throw new
|
|
114
|
+
throw new AttestationError('Invalid VCEK certificate: Missing microcode security patch level (UCODE) extension');
|
|
138
115
|
}
|
|
139
116
|
const ucodeSpl = this.decodeExtensionInteger(ucodeExt.value);
|
|
140
117
|
if (ucodeSpl !== tcb.ucodeSpl) {
|
|
141
|
-
throw new
|
|
118
|
+
throw new AttestationError(`VCEK TCB mismatch: Microcode SPL in certificate (${ucodeSpl}) does not match report (${tcb.ucodeSpl})`);
|
|
142
119
|
}
|
|
143
120
|
}
|
|
144
121
|
validateVcekHwid(chipId) {
|
|
145
122
|
const hwidExt = this.vcek.extension(SnpOid.HWID);
|
|
146
123
|
if (!hwidExt) {
|
|
147
|
-
throw new
|
|
124
|
+
throw new AttestationError('Invalid VCEK certificate: Missing hardware ID (HWID) extension');
|
|
148
125
|
}
|
|
149
126
|
// The HWID extension value is the raw chip ID bytes
|
|
150
127
|
if (!uint8ArrayEqual(hwidExt.value, chipId)) {
|
|
151
|
-
throw new
|
|
128
|
+
throw new AttestationError('VCEK hardware ID mismatch: Certificate HWID does not match the chip ID in the attestation report');
|
|
152
129
|
}
|
|
153
130
|
}
|
|
154
131
|
validateArkFormat() {
|
|
155
132
|
// Validate certificate version (must be v3)
|
|
156
133
|
if (this.ark.version !== 'v3') {
|
|
157
|
-
throw new
|
|
134
|
+
throw new AttestationError(`Invalid ARK certificate: Expected X.509 version v3, got ${this.ark.version}`);
|
|
158
135
|
}
|
|
159
136
|
// Validate AMD location for issuer and subject
|
|
160
137
|
if (!this.validateAmdLocation(this.ark.issuerDN)) {
|
|
161
|
-
throw new
|
|
138
|
+
throw new AttestationError('Invalid ARK certificate: Issuer is not a valid AMD organization');
|
|
162
139
|
}
|
|
163
140
|
if (!this.validateAmdLocation(this.ark.subjectDN)) {
|
|
164
|
-
throw new
|
|
141
|
+
throw new AttestationError('Invalid ARK certificate: Subject is not a valid AMD organization');
|
|
165
142
|
}
|
|
166
143
|
// Check common name
|
|
167
144
|
const cn = this.ark.subjectDN.get('CN');
|
|
168
145
|
if (cn !== 'ARK-Genoa') {
|
|
169
|
-
throw new
|
|
146
|
+
throw new AttestationError(`Invalid ARK certificate: Expected common name "ARK-Genoa", got "${cn}"`);
|
|
170
147
|
}
|
|
171
148
|
}
|
|
172
149
|
validateAskFormat() {
|
|
173
150
|
// Validate certificate version (must be v3)
|
|
174
151
|
if (this.ask.version !== 'v3') {
|
|
175
|
-
throw new
|
|
152
|
+
throw new AttestationError(`Invalid ASK certificate: Expected X.509 version v3, got ${this.ask.version}`);
|
|
176
153
|
}
|
|
177
154
|
// Validate AMD location
|
|
178
155
|
if (!this.validateAmdLocation(this.ask.issuerDN)) {
|
|
179
|
-
throw new
|
|
156
|
+
throw new AttestationError('Invalid ASK certificate: Issuer is not a valid AMD organization');
|
|
180
157
|
}
|
|
181
158
|
if (!this.validateAmdLocation(this.ask.subjectDN)) {
|
|
182
|
-
throw new
|
|
159
|
+
throw new AttestationError('Invalid ASK certificate: Subject is not a valid AMD organization');
|
|
183
160
|
}
|
|
184
161
|
// Check common name is exactly "SEV-Genoa" (ASK cert uses SEV-Genoa)
|
|
185
162
|
const cn = this.ask.subjectDN.get('CN');
|
|
186
163
|
if (cn !== 'SEV-Genoa') {
|
|
187
|
-
throw new
|
|
164
|
+
throw new AttestationError(`Invalid ASK certificate: Expected common name "SEV-Genoa", got "${cn}"`);
|
|
188
165
|
}
|
|
189
166
|
}
|
|
190
167
|
validateVcekFormat() {
|
|
191
168
|
// Validate certificate version (must be v3)
|
|
192
169
|
if (this.vcek.version !== 'v3') {
|
|
193
|
-
throw new
|
|
170
|
+
throw new AttestationError(`Invalid VCEK certificate: Expected X.509 version v3, got ${this.vcek.version}`);
|
|
194
171
|
}
|
|
195
172
|
// Validate AMD location
|
|
196
173
|
if (!this.validateAmdLocation(this.vcek.issuerDN)) {
|
|
197
|
-
throw new
|
|
174
|
+
throw new AttestationError('Invalid VCEK certificate: Issuer is not a valid AMD organization');
|
|
198
175
|
}
|
|
199
176
|
if (!this.validateAmdLocation(this.vcek.subjectDN)) {
|
|
200
|
-
throw new
|
|
177
|
+
throw new AttestationError('Invalid VCEK certificate: Subject is not a valid AMD organization');
|
|
201
178
|
}
|
|
202
179
|
// Validate common name
|
|
203
180
|
const cn = this.vcek.subjectDN.get('CN');
|
|
204
181
|
if (cn !== 'SEV-VCEK') {
|
|
205
|
-
throw new
|
|
182
|
+
throw new AttestationError(`Invalid VCEK certificate: Expected common name "SEV-VCEK", got "${cn}"`);
|
|
206
183
|
}
|
|
207
184
|
// Validate signature algorithm (must be RSASSA-PSS for VCEK signed by ASK)
|
|
208
185
|
const sigAlgOid = this.getSignatureAlgorithmOid(this.vcek);
|
|
209
186
|
if (sigAlgOid !== OID_RSASSA_PSS) {
|
|
210
|
-
throw new
|
|
187
|
+
throw new AttestationError('Invalid VCEK certificate: Signature algorithm must be RSASSA-PSS');
|
|
211
188
|
}
|
|
212
189
|
// Validate public key algorithm and curve
|
|
213
190
|
const { algorithm, curve } = this.getPublicKeyInfo(this.vcek);
|
|
214
191
|
if (algorithm !== OID_EC_PUBLIC_KEY) {
|
|
215
|
-
throw new
|
|
192
|
+
throw new AttestationError('Invalid VCEK certificate: Public key must be ECDSA');
|
|
216
193
|
}
|
|
217
194
|
if (curve !== OID_SECP384R1) {
|
|
218
|
-
throw new
|
|
195
|
+
throw new AttestationError('Invalid VCEK certificate: Public key curve must be secp384r1 (P-384)');
|
|
219
196
|
}
|
|
220
197
|
// CSP_ID must NOT be present (critical for VCEK vs VLEK distinction)
|
|
221
198
|
const cspIdExt = this.vcek.extension(SnpOid.CSP_ID);
|
|
222
199
|
if (cspIdExt) {
|
|
223
|
-
throw new
|
|
200
|
+
throw new AttestationError('Invalid VCEK certificate: CSP_ID extension should not be present (this looks like a VLEK certificate)');
|
|
224
201
|
}
|
|
225
202
|
// HWID must be present and correct length
|
|
226
203
|
const hwidExt = this.vcek.extension(SnpOid.HWID);
|
|
227
204
|
if (!hwidExt || hwidExt.value.length !== 64) {
|
|
228
|
-
throw new
|
|
205
|
+
throw new AttestationError('Invalid VCEK certificate: Missing or malformed hardware ID (HWID) extension');
|
|
229
206
|
}
|
|
230
207
|
// Product name validation
|
|
231
208
|
const productNameExt = this.vcek.extension(SnpOid.PRODUCT_NAME);
|
|
232
209
|
if (!productNameExt) {
|
|
233
|
-
throw new
|
|
210
|
+
throw new AttestationError('Invalid VCEK certificate: Missing product name extension');
|
|
234
211
|
}
|
|
235
212
|
// The extension value should be DER-encoded IA5String: tag 0x16, length 0x05, value "Genoa"
|
|
236
213
|
const expectedProductName = new Uint8Array([0x16, 0x05, 0x47, 0x65, 0x6e, 0x6f, 0x61]);
|
|
237
214
|
if (!uint8ArrayEqual(productNameExt.value, expectedProductName)) {
|
|
238
|
-
throw new
|
|
215
|
+
throw new AttestationError('Invalid VCEK certificate: Product name must be "Genoa"');
|
|
239
216
|
}
|
|
240
217
|
}
|
|
241
218
|
validateAmdLocation(name) {
|
|
@@ -273,32 +250,4 @@ export class CertificateChain {
|
|
|
273
250
|
return this.vcek.publicKeyObj;
|
|
274
251
|
}
|
|
275
252
|
}
|
|
276
|
-
async function fetchAndCacheVCEK(vcekUrl) {
|
|
277
|
-
const vcekDer = await fetchVCEK(vcekUrl);
|
|
278
|
-
// Cache for future use (URL serves as cache key)
|
|
279
|
-
if (typeof localStorage !== 'undefined') {
|
|
280
|
-
try {
|
|
281
|
-
const base64 = btoa(String.fromCharCode(...vcekDer));
|
|
282
|
-
localStorage.setItem(vcekUrl, base64);
|
|
283
|
-
}
|
|
284
|
-
catch {
|
|
285
|
-
// Cache storage failed (quota exceeded, etc), continue anyway
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return vcekDer;
|
|
289
|
-
}
|
|
290
|
-
function buildVCEKUrl(productName, chipId, reportedTcb) {
|
|
291
|
-
const tcb = tcbFromInt(reportedTcb);
|
|
292
|
-
const chipIdHex = bytesToHex(chipId);
|
|
293
|
-
const baseUrl = 'https://kds-proxy.tinfoil.sh/vcek/v1';
|
|
294
|
-
return `${baseUrl}/${productName}/${chipIdHex}?blSPL=${tcb.blSpl}&teeSPL=${tcb.teeSpl}&snpSPL=${tcb.snpSpl}&ucodeSPL=${tcb.ucodeSpl}`;
|
|
295
|
-
}
|
|
296
|
-
async function fetchVCEK(url) {
|
|
297
|
-
const response = await fetch(url);
|
|
298
|
-
if (!response.ok) {
|
|
299
|
-
throw new Error(`Failed to fetch VCEK certificate: ${response.status} ${response.statusText}`);
|
|
300
|
-
}
|
|
301
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
302
|
-
return new Uint8Array(arrayBuffer);
|
|
303
|
-
}
|
|
304
253
|
//# sourceMappingURL=cert-chain.js.map
|