tinfoil 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +10 -7
- package/dist/secure-client.d.ts +1 -10
- package/dist/secure-client.js +22 -13
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -96,8 +96,7 @@ class TinfoilAI {
|
|
|
96
96
|
catch (error) {
|
|
97
97
|
throw new Error(`Failed to verify enclave: ${error}`);
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
const expectedFingerprint = Buffer.from(this.groundTruth.certFingerprint).toString('hex');
|
|
99
|
+
const expectedFingerprint = this.groundTruth.publicKeyFP;
|
|
101
100
|
// Create a custom HTTPS agent that verifies certificate fingerprints
|
|
102
101
|
const httpsAgent = new https_1.default.Agent({
|
|
103
102
|
rejectUnauthorized: true,
|
|
@@ -105,11 +104,15 @@ class TinfoilAI {
|
|
|
105
104
|
if (!cert || !cert.raw) {
|
|
106
105
|
throw new Error('No certificate found');
|
|
107
106
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
if (!cert.pubkey) {
|
|
108
|
+
throw new Error('No public key found');
|
|
109
|
+
}
|
|
110
|
+
const pemCert = `-----BEGIN CERTIFICATE-----\n${cert.raw.toString('base64')}\n-----END CERTIFICATE-----`;
|
|
111
|
+
const x509Cert = new crypto_1.X509Certificate(pemCert);
|
|
112
|
+
const publicKey = x509Cert.publicKey.export({ format: 'der', type: 'spki' });
|
|
113
|
+
const publicKeyHash = (0, crypto_1.createHash)('sha256').update(publicKey).digest('hex');
|
|
114
|
+
if (publicKeyHash !== expectedFingerprint) {
|
|
115
|
+
throw new Error(`Certificate fingerprint mismatch. Got ${publicKeyHash}, expected ${expectedFingerprint}`);
|
|
113
116
|
}
|
|
114
117
|
return undefined; // Validation successful
|
|
115
118
|
}
|
package/dist/secure-client.d.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
var Go: any;
|
|
3
|
-
var verifyEnclave: (enclaveHostname: string) => Promise<{
|
|
4
|
-
certificate: string;
|
|
5
|
-
measurement: string;
|
|
6
|
-
certFingerprint: string;
|
|
7
|
-
}>;
|
|
8
|
-
var verifyCode: (repo: string, digest: string) => Promise<string>;
|
|
9
|
-
}
|
|
10
1
|
/**
|
|
11
2
|
* Ground truth measurements from verification
|
|
12
3
|
*/
|
|
13
4
|
export interface GroundTruth {
|
|
14
|
-
|
|
5
|
+
publicKeyFP: string;
|
|
15
6
|
measurement: string;
|
|
16
7
|
}
|
|
17
8
|
/**
|
package/dist/secure-client.js
CHANGED
|
@@ -11,11 +11,16 @@ const globalThis = global;
|
|
|
11
11
|
// Performance API
|
|
12
12
|
globalThis.performance = {
|
|
13
13
|
now: () => Date.now(),
|
|
14
|
-
markResourceTiming: () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
markResourceTiming: () => {
|
|
15
|
+
},
|
|
16
|
+
mark: () => {
|
|
17
|
+
},
|
|
18
|
+
measure: () => {
|
|
19
|
+
},
|
|
20
|
+
clearMarks: () => {
|
|
21
|
+
},
|
|
22
|
+
clearMeasures: () => {
|
|
23
|
+
},
|
|
19
24
|
getEntriesByName: () => [],
|
|
20
25
|
getEntriesByType: () => [],
|
|
21
26
|
getEntries: () => []
|
|
@@ -33,13 +38,17 @@ if (!globalThis.crypto) {
|
|
|
33
38
|
}
|
|
34
39
|
};
|
|
35
40
|
}
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// Modified secure-client.ts
|
|
42
|
+
if (typeof window === 'undefined') {
|
|
43
|
+
// Node.js environment
|
|
44
|
+
globalThis.window = globalThis;
|
|
45
|
+
globalThis.document = {
|
|
46
|
+
createElement: () => ({
|
|
47
|
+
setAttribute: () => {
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
}
|
|
43
52
|
// Force process to stay running (prevent Go from exiting Node process)
|
|
44
53
|
// This is a common issue with Go WASM in Node - it calls process.exit()
|
|
45
54
|
const originalExit = process.exit;
|
|
@@ -140,7 +149,7 @@ class SecureClient {
|
|
|
140
149
|
throw new Error('Measurements do not match');
|
|
141
150
|
}
|
|
142
151
|
return {
|
|
143
|
-
|
|
152
|
+
publicKeyFP: attestationResponse.certificate,
|
|
144
153
|
measurement: attestationResponse.measurement,
|
|
145
154
|
};
|
|
146
155
|
}
|