@virtru/dsp-sdk 0.5.0 → 0.7.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 +15 -1
- package/README.md +81 -3
- package/dist/src/fips.d.ts +7 -0
- package/dist/src/fips.js +12 -0
- package/dist/src/lib/dsp.d.ts +17 -1
- package/dist/src/lib/dsp.js +28 -5
- package/package.json +25 -4
- package/.prettierrc +0 -3
- package/.rush/temp/chunked-rush-logs/dsp-sdk._phase_build.chunks.jsonl +0 -12
- package/.rush/temp/chunked-rush-logs/dsp-sdk._phase_test.chunks.jsonl +0 -383
- package/.rush/temp/package-deps__phase_build.json +0 -76
- package/.rush/temp/shrinkwrap-deps.json +0 -1262
- package/CHANGELOG.json +0 -299
- package/buf.gen.yaml +0 -17
- package/buf.yaml +0 -4
- package/config/jest.config.json +0 -6
- package/config/rig.json +0 -8
- package/dist/tests/dsp-client.test.d.ts +0 -1
- package/dist/tests/dsp-client.test.js +0 -73
- package/dist/tests/dsp.test.d.ts +0 -1
- package/dist/tests/dsp.test.js +0 -92
- package/dist/tests/fips-crypto.unit.test.d.ts +0 -1
- package/dist/tests/fips-crypto.unit.test.js +0 -258
- package/dist/tests/mocks/create-export-artifacts.d.ts +0 -2
- package/dist/tests/mocks/create-export-artifacts.js +0 -13
- package/dist/tests/mocks/tagging-pdp-tag.d.ts +0 -2
- package/dist/tests/mocks/tagging-pdp-tag.js +0 -11
- package/dist/tests/mocks/well-known-configuration.d.ts +0 -2
- package/dist/tests/mocks/well-known-configuration.js +0 -12
- package/dist/tests/setup-msw.d.ts +0 -9
- package/dist/tests/setup-msw.js +0 -30
- package/dist/tests/setup-unit.d.ts +0 -7
- package/dist/tests/setup-unit.js +0 -70
- package/eslint.config.mjs +0 -28
- package/lib-commonjs/src/gen/buf/validate/validate_pb.js +0 -487
- package/lib-commonjs/src/gen/config/v1/config_pb.js +0 -142
- package/lib-commonjs/src/gen/config/v1/kas_config_pb.js +0 -72
- package/lib-commonjs/src/gen/config/v1/meta_pb.js +0 -36
- package/lib-commonjs/src/gen/config/v1/outlook_config_pb.js +0 -67
- package/lib-commonjs/src/gen/config/v1/secureviewer_config_pb.js +0 -67
- package/lib-commonjs/src/gen/config/v1/tagging_pb.js +0 -246
- package/lib-commonjs/src/gen/google/api/annotations_pb.js +0 -33
- package/lib-commonjs/src/gen/google/api/http_pb.js +0 -44
- package/lib-commonjs/src/gen/policyimportexport/v1/policy_import_export_pb.js +0 -93
- package/lib-commonjs/src/gen/shared/v1/shared_pb.js +0 -95
- package/lib-commonjs/src/gen/tagging/pdp/v2/tagging_pb.js +0 -277
- package/lib-commonjs/src/gen/version/v1/version_pb.js +0 -40
- package/lib-commonjs/src/gen/virtru/common/common_pb.js +0 -76
- package/lib-commonjs/src/gen/virtru/policy/certificates/v1/certificates_pb.js +0 -77
- package/lib-commonjs/src/gen/virtru/policy/objects_pb.js +0 -143
- package/lib-commonjs/src/index.js +0 -48
- package/lib-commonjs/src/lib/client.js +0 -66
- package/lib-commonjs/src/lib/consts.js +0 -10
- package/lib-commonjs/src/lib/dsp.js +0 -49
- package/lib-commonjs/src/lib/fips-crypto/asymmetric.js +0 -126
- package/lib-commonjs/src/lib/fips-crypto/key-format.js +0 -243
- package/lib-commonjs/src/lib/fips-crypto/keys.js +0 -134
- package/lib-commonjs/src/lib/fips-crypto/primitives.js +0 -112
- package/lib-commonjs/src/lib/fips-crypto/symmetric.js +0 -162
- package/lib-commonjs/src/lib/fips-crypto-service.js +0 -57
- package/lib-commonjs/src/lib/utils.js +0 -401
- package/lib-commonjs/tests/dsp-client.test.js +0 -75
- package/lib-commonjs/tests/dsp.test.js +0 -94
- package/lib-commonjs/tests/fips-crypto.unit.test.js +0 -260
- package/lib-commonjs/tests/mocks/create-export-artifacts.js +0 -17
- package/lib-commonjs/tests/mocks/tagging-pdp-tag.js +0 -15
- package/lib-commonjs/tests/mocks/well-known-configuration.js +0 -16
- package/lib-commonjs/tests/setup-msw.js +0 -33
- package/lib-commonjs/tests/setup-unit.js +0 -72
- package/public/virtru.wasm +0 -0
- package/src/gen/buf/validate/validate_pb.ts +0 -4879
- package/src/gen/config/formatters/testdata/v1/test_pb.ts +0 -287
- package/src/gen/config/v1/config_connect.ts +0 -111
- package/src/gen/config/v1/config_pb.ts +0 -439
- package/src/gen/config/v1/kas_config_pb.ts +0 -183
- package/src/gen/config/v1/meta_pb.ts +0 -72
- package/src/gen/config/v1/outlook_config_pb.ts +0 -242
- package/src/gen/config/v1/secureviewer_config_pb.ts +0 -161
- package/src/gen/config/v1/tagging_pb.ts +0 -456
- package/src/gen/google/api/annotations_pb.ts +0 -43
- package/src/gen/google/api/http_pb.ts +0 -486
- package/src/gen/helloworld/v1/helloworld_connect.ts +0 -49
- package/src/gen/helloworld/v1/helloworld_pb.ts +0 -104
- package/src/gen/kas/nanotdf/v1/nanotdf_rewrap_connect.ts +0 -39
- package/src/gen/kas/nanotdf/v1/nanotdf_rewrap_pb.ts +0 -207
- package/src/gen/policyimportexport/v1/policy_import_export_connect.ts +0 -56
- package/src/gen/policyimportexport/v1/policy_import_export_pb.ts +0 -332
- package/src/gen/shared/v1/shared_connect.ts +0 -61
- package/src/gen/shared/v1/shared_pb.ts +0 -240
- package/src/gen/shared/v2/shared_connect.ts +0 -39
- package/src/gen/shared/v2/shared_pb.ts +0 -122
- package/src/gen/tagging/pdp/v2/externalprocessors/processor_connect.ts +0 -156
- package/src/gen/tagging/pdp/v2/externalprocessors/processor_pb.ts +0 -709
- package/src/gen/tagging/pdp/v2/stanag/stanag_pb.ts +0 -953
- package/src/gen/tagging/pdp/v2/tagging_connect.ts +0 -73
- package/src/gen/tagging/pdp/v2/tagging_pb.ts +0 -1064
- package/src/gen/version/v1/version_connect.ts +0 -31
- package/src/gen/version/v1/version_pb.ts +0 -143
- package/src/gen/virtru/common/common_pb.ts +0 -201
- package/src/gen/virtru/policy/certificates/v1/certificates_connect.ts +0 -44
- package/src/gen/virtru/policy/certificates/v1/certificates_pb.ts +0 -305
- package/src/gen/virtru/policy/objects_pb.ts +0 -253
- package/src/gen/web-admin/v1/config_connect.ts +0 -52
- package/src/gen/web-admin/v1/config_pb.ts +0 -173
- package/src/index.ts +0 -62
- package/src/lib/client.ts +0 -90
- package/src/lib/consts.ts +0 -8
- package/src/lib/dsp.ts +0 -65
- package/src/lib/fips-crypto/asymmetric.ts +0 -162
- package/src/lib/fips-crypto/key-format.ts +0 -287
- package/src/lib/fips-crypto/keys.ts +0 -190
- package/src/lib/fips-crypto/primitives.ts +0 -197
- package/src/lib/fips-crypto/symmetric.ts +0 -213
- package/src/lib/fips-crypto-service.ts +0 -58
- package/src/lib/utils.test.ts +0 -415
- package/src/lib/utils.ts +0 -525
- package/src/vite-env.d.ts +0 -7
- package/temp/build/lint/_eslint-5eVG3S6w.json +0 -38
- package/temp/test/jest/haste-map-b055a9550e6d9f9b43d8ad29b1607278-49d19aee56a0732eca9c014a51272338-8710993d07b75a801b0956e67ffc46fa +0 -0
- package/tests/dsp-client.test.ts +0 -95
- package/tests/dsp.test.ts +0 -119
- package/tests/fips-crypto.unit.test.ts +0 -412
- package/tests/mocks/create-export-artifacts.ts +0 -16
- package/tests/mocks/tagging-pdp-tag.ts +0 -13
- package/tests/mocks/well-known-configuration.ts +0 -15
- package/tests/setup-msw.ts +0 -35
- package/tests/setup-unit.ts +0 -108
- package/tsconfig.json +0 -32
- package/update-protos.sh +0 -63
- package/vitest.config.ts +0 -48
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
-
*/
|
|
6
|
-
import { expect, test, beforeAll, afterAll, describe } from 'vitest';
|
|
7
|
-
import { Binary, } from '@opentdf/sdk/singlecontainer';
|
|
8
|
-
import { FipsCryptoService, unwrapPublicKey, unwrapPrivateKey, importPrivateKey, exportPrivateKeyPem, } from '../src/lib/fips-crypto-service';
|
|
9
|
-
describe('FIPS CryptoService - Methods', () => {
|
|
10
|
-
// RSA key slots are finite in the WASM keystore. Each describe group that
|
|
11
|
-
// uses RSA keys creates ONE shared key pair in beforeAll and releases it in
|
|
12
|
-
// afterAll so slots are reclaimed before the next group starts.
|
|
13
|
-
describe('sign and verify (asymmetric)', () => {
|
|
14
|
-
let keyPair;
|
|
15
|
-
beforeAll(async () => {
|
|
16
|
-
keyPair = await FipsCryptoService.generateSigningKeyPair();
|
|
17
|
-
}, 60000);
|
|
18
|
-
afterAll(() => {
|
|
19
|
-
unwrapPublicKey(keyPair.publicKey).release();
|
|
20
|
-
});
|
|
21
|
-
test('should sign and verify with RS256', async () => {
|
|
22
|
-
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
23
|
-
const signature = await FipsCryptoService.sign(data, keyPair.privateKey, 'RS256');
|
|
24
|
-
const isValid = await FipsCryptoService.verify(data, signature, keyPair.publicKey, 'RS256');
|
|
25
|
-
expect(isValid).toBe(true);
|
|
26
|
-
});
|
|
27
|
-
test('should reject tampered data', async () => {
|
|
28
|
-
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
29
|
-
const signature = await FipsCryptoService.sign(data, keyPair.privateKey, 'RS256');
|
|
30
|
-
const tamperedData = new Uint8Array([1, 2, 3, 4, 6]);
|
|
31
|
-
const isValid = await FipsCryptoService.verify(tamperedData, signature, keyPair.publicKey, 'RS256');
|
|
32
|
-
expect(isValid).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
test('should throw error for ES256 (EC not supported)', async () => {
|
|
35
|
-
await expect(FipsCryptoService.sign(new Uint8Array([1, 2, 3, 4]), keyPair.privateKey, 'ES256')).rejects.toThrow('not supported in FIPS mode');
|
|
36
|
-
});
|
|
37
|
-
test('encryption key pair (RSA-OAEP) should not be usable for signing', async () => {
|
|
38
|
-
// Catches algorithm mismatch: if generateKeyPair() incorrectly used
|
|
39
|
-
// RSASSA-PKCS1-v1_5 params, signing would succeed here instead of throwing.
|
|
40
|
-
const encKeyPair = await FipsCryptoService.generateKeyPair();
|
|
41
|
-
await expect(FipsCryptoService.sign(new Uint8Array([1, 2, 3]), encKeyPair.privateKey, 'RS256')).rejects.toThrow();
|
|
42
|
-
unwrapPublicKey(encKeyPair.publicKey).release();
|
|
43
|
-
unwrapPrivateKey(encKeyPair.privateKey).release();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
describe('hmac and verifyHmac', () => {
|
|
47
|
-
test('should compute and verify HMAC-SHA256', async () => {
|
|
48
|
-
const crypto = FipsCryptoService;
|
|
49
|
-
const keyBytes = await crypto.randomBytes(32);
|
|
50
|
-
const symKey = await crypto.importSymmetricKey(keyBytes);
|
|
51
|
-
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
52
|
-
const signature = await crypto.hmac(data, symKey);
|
|
53
|
-
const isValid = await crypto.verifyHmac(data, signature, symKey);
|
|
54
|
-
expect(isValid).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
test('should reject invalid signature', async () => {
|
|
57
|
-
const crypto = FipsCryptoService;
|
|
58
|
-
const symKey = await crypto.generateKey(32);
|
|
59
|
-
const data = new Uint8Array([1, 2, 3, 4]);
|
|
60
|
-
const signature = await crypto.hmac(data, symKey);
|
|
61
|
-
signature[0] ^= 1; // Flip a bit
|
|
62
|
-
const isValid = await crypto.verifyHmac(data, signature, symKey);
|
|
63
|
-
expect(isValid).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
test('should reject signature with wrong key', async () => {
|
|
66
|
-
const crypto = FipsCryptoService;
|
|
67
|
-
const symKey1 = await crypto.importSymmetricKey(await crypto.randomBytes(32));
|
|
68
|
-
const symKey2 = await crypto.importSymmetricKey(await crypto.randomBytes(32));
|
|
69
|
-
const data = new Uint8Array([1, 2, 3, 4]);
|
|
70
|
-
const signature = await crypto.hmac(data, symKey1);
|
|
71
|
-
const isValid = await crypto.verifyHmac(data, signature, symKey2);
|
|
72
|
-
expect(isValid).toBe(false);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
describe('digest', () => {
|
|
76
|
-
test('should compute SHA-256 hash', async () => {
|
|
77
|
-
const data = new Uint8Array([1, 2, 3, 4]);
|
|
78
|
-
const hash = await FipsCryptoService.digest('SHA-256', data);
|
|
79
|
-
expect(hash).toBeInstanceOf(Uint8Array);
|
|
80
|
-
expect(hash.byteLength).toBe(32);
|
|
81
|
-
});
|
|
82
|
-
test('should produce consistent hashes', async () => {
|
|
83
|
-
const data = new Uint8Array([1, 2, 3, 4]);
|
|
84
|
-
const hash1 = await FipsCryptoService.digest('SHA-256', data);
|
|
85
|
-
const hash2 = await FipsCryptoService.digest('SHA-256', data);
|
|
86
|
-
expect(hash1).toEqual(hash2);
|
|
87
|
-
});
|
|
88
|
-
test('should throw error for SHA-384 (not supported)', async () => {
|
|
89
|
-
await expect(FipsCryptoService.digest('SHA-384', new Uint8Array([1, 2, 3, 4]))).rejects.toThrow('not supported in FIPS mode');
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
describe('EC placeholder methods', () => {
|
|
93
|
-
test('should throw error for generateECKeyPair', async () => {
|
|
94
|
-
await expect(FipsCryptoService.generateECKeyPair()).rejects.toThrow('not supported in FIPS mode');
|
|
95
|
-
});
|
|
96
|
-
test('should throw error for deriveKeyFromECDH', async () => {
|
|
97
|
-
await expect(FipsCryptoService.deriveKeyFromECDH({}, {}, {
|
|
98
|
-
hash: 'SHA-256',
|
|
99
|
-
salt: new Uint8Array(),
|
|
100
|
-
})).rejects.toThrow('not supported in FIPS mode');
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('exportPublicKeyPem', () => {
|
|
104
|
-
let keyPair;
|
|
105
|
-
beforeAll(async () => {
|
|
106
|
-
keyPair = await FipsCryptoService.generateKeyPair();
|
|
107
|
-
}, 60000);
|
|
108
|
-
afterAll(() => {
|
|
109
|
-
unwrapPublicKey(keyPair.publicKey).release();
|
|
110
|
-
});
|
|
111
|
-
test('should export generated public key to PEM', async () => {
|
|
112
|
-
const pem = await FipsCryptoService.exportPublicKeyPem(keyPair.publicKey);
|
|
113
|
-
expect(pem).toContain('-----BEGIN PUBLIC KEY-----');
|
|
114
|
-
expect(pem).toContain('-----END PUBLIC KEY-----');
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
describe('importPublicKey', () => {
|
|
118
|
-
let keyPair;
|
|
119
|
-
let importedKey;
|
|
120
|
-
beforeAll(async () => {
|
|
121
|
-
const crypto = FipsCryptoService;
|
|
122
|
-
keyPair = await crypto.generateKeyPair(2048);
|
|
123
|
-
const pem = await crypto.exportPublicKeyPem(keyPair.publicKey);
|
|
124
|
-
importedKey = await crypto.importPublicKey(pem, { usage: 'encrypt' });
|
|
125
|
-
}, 60000);
|
|
126
|
-
afterAll(() => {
|
|
127
|
-
unwrapPublicKey(keyPair.publicKey).release();
|
|
128
|
-
unwrapPublicKey(importedKey).release();
|
|
129
|
-
});
|
|
130
|
-
test('should import PEM and detect RSA-2048', () => {
|
|
131
|
-
expect(importedKey.algorithm).toBe('rsa:2048');
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe('exportPublicKeyJwk', () => {
|
|
135
|
-
let keyPair;
|
|
136
|
-
beforeAll(async () => {
|
|
137
|
-
keyPair = await FipsCryptoService.generateKeyPair(2048);
|
|
138
|
-
}, 60000);
|
|
139
|
-
afterAll(() => {
|
|
140
|
-
unwrapPublicKey(keyPair.publicKey).release();
|
|
141
|
-
});
|
|
142
|
-
test('should export public key to JWK', async () => {
|
|
143
|
-
const jwk = await FipsCryptoService.exportPublicKeyJwk(keyPair.publicKey);
|
|
144
|
-
expect(jwk.kty).toBe('RSA');
|
|
145
|
-
expect(jwk.n).toBeDefined();
|
|
146
|
-
expect(jwk.e).toBeDefined();
|
|
147
|
-
expect(typeof jwk.n).toBe('string');
|
|
148
|
-
expect(typeof jwk.e).toBe('string');
|
|
149
|
-
});
|
|
150
|
-
test('should produce a JWK that round-trips back to SPKI', async () => {
|
|
151
|
-
const jwk = await FipsCryptoService.exportPublicKeyJwk(keyPair.publicKey);
|
|
152
|
-
const webKey = await globalThis.crypto.subtle.importKey('jwk', jwk, { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, true, ['verify']);
|
|
153
|
-
const spki = await globalThis.crypto.subtle.exportKey('spki', webKey);
|
|
154
|
-
expect(spki.byteLength).toBeGreaterThan(0);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe('encrypt and decrypt (symmetric AES-GCM)', () => {
|
|
158
|
-
test('should round-trip encrypt/decrypt', async () => {
|
|
159
|
-
const key = await FipsCryptoService.generateKey();
|
|
160
|
-
const iv = Binary.fromArrayBuffer((await FipsCryptoService.randomBytes(12)).buffer);
|
|
161
|
-
const plaintext = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
162
|
-
const { payload: cipher, authTag } = await FipsCryptoService.encrypt(Binary.fromArrayBuffer(plaintext.buffer), key, iv);
|
|
163
|
-
const { payload: recovered } = await FipsCryptoService.decrypt(cipher, key, iv, undefined, authTag);
|
|
164
|
-
expect(new Uint8Array(recovered.asArrayBuffer())).toEqual(plaintext);
|
|
165
|
-
});
|
|
166
|
-
test('should produce different ciphertext for different IVs', async () => {
|
|
167
|
-
const key = await FipsCryptoService.generateKey();
|
|
168
|
-
const plaintext = Binary.fromArrayBuffer(new Uint8Array([1, 2, 3, 4]).buffer);
|
|
169
|
-
const iv1 = Binary.fromArrayBuffer((await FipsCryptoService.randomBytes(12)).buffer);
|
|
170
|
-
const iv2 = Binary.fromArrayBuffer((await FipsCryptoService.randomBytes(12)).buffer);
|
|
171
|
-
const { payload: cipher1 } = await FipsCryptoService.encrypt(plaintext, key, iv1);
|
|
172
|
-
const { payload: cipher2 } = await FipsCryptoService.encrypt(plaintext, key, iv2);
|
|
173
|
-
expect(new Uint8Array(cipher1.asArrayBuffer())).not.toEqual(new Uint8Array(cipher2.asArrayBuffer()));
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
describe('encryptWithPublicKey and decryptWithPrivateKey (RSA-OAEP)', () => {
|
|
177
|
-
let keyPair;
|
|
178
|
-
beforeAll(async () => {
|
|
179
|
-
keyPair = await FipsCryptoService.generateKeyPair();
|
|
180
|
-
}, 60000);
|
|
181
|
-
afterAll(() => {
|
|
182
|
-
unwrapPublicKey(keyPair.publicKey).release();
|
|
183
|
-
});
|
|
184
|
-
test('should round-trip RSA encrypt/decrypt', async () => {
|
|
185
|
-
const plaintext = new Uint8Array([10, 20, 30, 40, 50]);
|
|
186
|
-
const encrypted = await FipsCryptoService.encryptWithPublicKey(Binary.fromArrayBuffer(plaintext.buffer), keyPair.publicKey);
|
|
187
|
-
const decrypted = await FipsCryptoService.decryptWithPrivateKey(encrypted, keyPair.privateKey);
|
|
188
|
-
expect(new Uint8Array(decrypted.asArrayBuffer())).toEqual(plaintext);
|
|
189
|
-
});
|
|
190
|
-
test('should produce different ciphertext each call (RSA-OAEP is randomized)', async () => {
|
|
191
|
-
const payload = Binary.fromArrayBuffer(new Uint8Array([1, 2, 3]).buffer);
|
|
192
|
-
const enc1 = await FipsCryptoService.encryptWithPublicKey(payload, keyPair.publicKey);
|
|
193
|
-
const enc2 = await FipsCryptoService.encryptWithPublicKey(payload, keyPair.publicKey);
|
|
194
|
-
expect(new Uint8Array(enc1.asArrayBuffer())).not.toEqual(new Uint8Array(enc2.asArrayBuffer()));
|
|
195
|
-
});
|
|
196
|
-
test('signing key pair (RSASSA-PKCS1-v1_5) should not be usable for encryption', async () => {
|
|
197
|
-
// Catches algorithm mismatch: if generateSigningKeyPair() incorrectly used
|
|
198
|
-
// RSA-OAEP params, encryption would succeed here instead of throwing.
|
|
199
|
-
const signingKp = await FipsCryptoService.generateSigningKeyPair();
|
|
200
|
-
await expect(FipsCryptoService.encryptWithPublicKey(Binary.fromArrayBuffer(new Uint8Array([1, 2, 3]).buffer), signingKp.publicKey)).rejects.toThrow();
|
|
201
|
-
unwrapPublicKey(signingKp.publicKey).release();
|
|
202
|
-
unwrapPrivateKey(signingKp.privateKey).release();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
describe('importPrivateKey and exportPrivateKeyPem', () => {
|
|
206
|
-
let privKey;
|
|
207
|
-
beforeAll(async () => {
|
|
208
|
-
const kp = await globalThis.crypto.subtle.generateKey({
|
|
209
|
-
name: 'RSASSA-PKCS1-v1_5',
|
|
210
|
-
modulusLength: 2048,
|
|
211
|
-
publicExponent: new Uint8Array([1, 0, 1]),
|
|
212
|
-
hash: 'SHA-256',
|
|
213
|
-
}, true, ['sign', 'verify']);
|
|
214
|
-
const pkcs8 = await globalThis.crypto.subtle.exportKey('pkcs8', kp.privateKey);
|
|
215
|
-
const b64 = btoa(String.fromCharCode(...new Uint8Array(pkcs8)));
|
|
216
|
-
const pem = `-----BEGIN PRIVATE KEY-----\n${b64
|
|
217
|
-
.match(/.{1,64}/g)
|
|
218
|
-
.join('\n')}\n-----END PRIVATE KEY-----`;
|
|
219
|
-
privKey = await importPrivateKey(pem, {
|
|
220
|
-
usage: 'sign',
|
|
221
|
-
extractable: true,
|
|
222
|
-
});
|
|
223
|
-
}, 60000);
|
|
224
|
-
afterAll(() => {
|
|
225
|
-
unwrapPrivateKey(privKey).release();
|
|
226
|
-
});
|
|
227
|
-
test('should import PKCS#8 PEM private key', () => {
|
|
228
|
-
expect(privKey.algorithm).toBe('rsa:2048');
|
|
229
|
-
});
|
|
230
|
-
test('should export imported private key back to PEM', async () => {
|
|
231
|
-
const exported = await exportPrivateKeyPem(privKey);
|
|
232
|
-
expect(exported).toContain('-----BEGIN PRIVATE KEY-----');
|
|
233
|
-
expect(exported).toContain('-----END PRIVATE KEY-----');
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
describe('splitSymmetricKey and mergeSymmetricKeys', () => {
|
|
237
|
-
test('splitSymmetricKey with 1 share returns the same key (single-KAS identity)', async () => {
|
|
238
|
-
const key = await FipsCryptoService.generateKey();
|
|
239
|
-
const shares = await FipsCryptoService.splitSymmetricKey(key, 1);
|
|
240
|
-
expect(shares).toHaveLength(1);
|
|
241
|
-
expect(shares[0]).toBe(key);
|
|
242
|
-
});
|
|
243
|
-
test('mergeSymmetricKeys with 1 share returns the same key (single-KAS identity)', async () => {
|
|
244
|
-
const key = await FipsCryptoService.generateKey();
|
|
245
|
-
const merged = await FipsCryptoService.mergeSymmetricKeys([key]);
|
|
246
|
-
expect(merged).toBe(key);
|
|
247
|
-
});
|
|
248
|
-
test('splitSymmetricKey with 2 shares throws (multi-KAS not yet supported)', async () => {
|
|
249
|
-
const key = await FipsCryptoService.generateKey();
|
|
250
|
-
await expect(FipsCryptoService.splitSymmetricKey(key, 2)).rejects.toThrow('not yet supported in FIPS mode');
|
|
251
|
-
});
|
|
252
|
-
test('mergeSymmetricKeys with 2 shares throws (multi-KAS not yet supported)', async () => {
|
|
253
|
-
const key1 = await FipsCryptoService.generateKey();
|
|
254
|
-
const key2 = await FipsCryptoService.generateKey();
|
|
255
|
-
await expect(FipsCryptoService.mergeSymmetricKeys([key1, key2])).rejects.toThrow('not yet supported in FIPS mode');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
-
*/
|
|
6
|
-
import {} from '@src/gen/policyimportexport/v1/policy_import_export_pb';
|
|
7
|
-
export const mockCreateExportArtifactsResponse = () => ({
|
|
8
|
-
$typeName: 'policyimportexport.v1.CreateExportArtifactsResponse',
|
|
9
|
-
artifact: {
|
|
10
|
-
case: undefined,
|
|
11
|
-
value: undefined,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
-
*/
|
|
6
|
-
import {} from '@src/gen/tagging/pdp/v2/tagging_pb';
|
|
7
|
-
export const mockTaggingPDPResponse = () => ({
|
|
8
|
-
$typeName: 'tagging.pdp.v2.TaggingPDPResponse',
|
|
9
|
-
events: [],
|
|
10
|
-
tags: [],
|
|
11
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
-
*/
|
|
6
|
-
import {} from '@opentdf/sdk/platform/wellknownconfiguration/wellknown_configuration_pb.js';
|
|
7
|
-
export const mockWellKnownConfiguration = () => ({
|
|
8
|
-
$typeName: 'wellknownconfiguration.GetWellKnownConfigurationResponse',
|
|
9
|
-
configuration: {
|
|
10
|
-
wellKnown: {},
|
|
11
|
-
},
|
|
12
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type SetupWorker } from 'msw/browser';
|
|
2
|
-
import { HttpHandler } from 'msw';
|
|
3
|
-
/**
|
|
4
|
-
* Sets up the MSW (Mock Service Worker) for testing.
|
|
5
|
-
*
|
|
6
|
-
* @param handlers - An array of HTTP handlers to be used with MSW.
|
|
7
|
-
* @returns The MSW worker instance.
|
|
8
|
-
*/
|
|
9
|
-
export declare function setupMSW(handlers: HttpHandler[]): SetupWorker | undefined;
|
package/dist/tests/setup-msw.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
-
*/
|
|
6
|
-
import { setupWorker } from 'msw/browser';
|
|
7
|
-
import { beforeAll, afterEach, afterAll } from 'vitest';
|
|
8
|
-
import { HttpHandler } from 'msw';
|
|
9
|
-
let worker;
|
|
10
|
-
/**
|
|
11
|
-
* Sets up the MSW (Mock Service Worker) for testing.
|
|
12
|
-
*
|
|
13
|
-
* @param handlers - An array of HTTP handlers to be used with MSW.
|
|
14
|
-
* @returns The MSW worker instance.
|
|
15
|
-
*/
|
|
16
|
-
export function setupMSW(handlers) {
|
|
17
|
-
if (!worker) {
|
|
18
|
-
worker = setupWorker(...handlers);
|
|
19
|
-
beforeAll(async () => {
|
|
20
|
-
await worker.start();
|
|
21
|
-
});
|
|
22
|
-
afterEach(() => worker.resetHandlers());
|
|
23
|
-
afterAll(() => worker.stop());
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// If worker already exists, just update handlers
|
|
27
|
-
worker.resetHandlers(...handlers);
|
|
28
|
-
}
|
|
29
|
-
return worker;
|
|
30
|
-
}
|
package/dist/tests/setup-unit.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Virtru Corporation. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Your use of this file is governed by the Virtu Terms of Service <https://www.virtru.com/terms-of-service/>.
|
|
5
|
-
*/
|
|
6
|
-
import { Buffer } from 'buffer';
|
|
7
|
-
import { access, readFile } from 'node:fs/promises';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import { TextEncoder, TextDecoder } from 'node:util';
|
|
10
|
-
globalThis.Buffer = Buffer;
|
|
11
|
-
if (!globalThis.TextEncoder) {
|
|
12
|
-
globalThis.TextEncoder = TextEncoder;
|
|
13
|
-
}
|
|
14
|
-
if (!globalThis.TextDecoder) {
|
|
15
|
-
globalThis.TextDecoder = TextDecoder;
|
|
16
|
-
}
|
|
17
|
-
if (typeof window !== 'undefined' && !window.Module) {
|
|
18
|
-
window.Module = {};
|
|
19
|
-
}
|
|
20
|
-
// Prefer the copied local WASM artifact used by package scripts.
|
|
21
|
-
const copiedWasmFilePath = path.resolve(process.cwd(), 'public/virtru.wasm');
|
|
22
|
-
// Fallback for direct local runs when copy-wasm has not been executed.
|
|
23
|
-
const sourceWasmFilePath = path.resolve(process.cwd(), '../fips-crypto-js/src/utils/virtru.wasm');
|
|
24
|
-
let resolvedWasmFilePath = copiedWasmFilePath;
|
|
25
|
-
try {
|
|
26
|
-
await access(copiedWasmFilePath);
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
resolvedWasmFilePath = sourceWasmFilePath;
|
|
30
|
-
}
|
|
31
|
-
const originalFetch = globalThis.fetch;
|
|
32
|
-
globalThis.fetch = async function (input, init) {
|
|
33
|
-
const url = typeof input === 'string'
|
|
34
|
-
? input
|
|
35
|
-
: input instanceof URL
|
|
36
|
-
? input.href
|
|
37
|
-
: input.url;
|
|
38
|
-
if (url && url.includes('virtru.wasm')) {
|
|
39
|
-
const wasmBytes = await readFile(resolvedWasmFilePath);
|
|
40
|
-
return new Response(wasmBytes, {
|
|
41
|
-
status: 200,
|
|
42
|
-
headers: {
|
|
43
|
-
'content-type': 'application/wasm',
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return originalFetch(input, init);
|
|
48
|
-
};
|
|
49
|
-
await import('@virtru-private/fips-crypto-js');
|
|
50
|
-
const isFipsReady = (candidate) => {
|
|
51
|
-
return (!!candidate &&
|
|
52
|
-
typeof candidate === 'object' &&
|
|
53
|
-
'isInitialized' in candidate &&
|
|
54
|
-
candidate.isInitialized === true &&
|
|
55
|
-
'generateKey' in candidate &&
|
|
56
|
-
typeof candidate.generateKey === 'function');
|
|
57
|
-
};
|
|
58
|
-
if (!isFipsReady(window.VirtruFipsWasmLib)) {
|
|
59
|
-
await new Promise((resolve, reject) => {
|
|
60
|
-
const timeout = setTimeout(() => reject(new Error('Timeout waiting for VirtruCrypto WASM initialization in unit setup.')), 10000);
|
|
61
|
-
const onReady = () => {
|
|
62
|
-
clearTimeout(timeout);
|
|
63
|
-
resolve();
|
|
64
|
-
};
|
|
65
|
-
window.addEventListener('wasmReady', onReady, { once: true });
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (!isFipsReady(window.VirtruFipsWasmLib)) {
|
|
69
|
-
throw new Error('VirtruCrypto was loaded but not initialized in unit setup.');
|
|
70
|
-
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js';
|
|
2
|
-
import globals from 'globals';
|
|
3
|
-
import tseslint from 'typescript-eslint';
|
|
4
|
-
import { defineConfig } from 'eslint/config';
|
|
5
|
-
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
6
|
-
|
|
7
|
-
export default defineConfig(
|
|
8
|
-
[
|
|
9
|
-
tseslint.configs.recommended,
|
|
10
|
-
eslintPluginPrettierRecommended,
|
|
11
|
-
{
|
|
12
|
-
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
|
13
|
-
plugins: { js, tseslint },
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
|
17
|
-
languageOptions: { globals: globals.browser },
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
{
|
|
21
|
-
ignores: ['dist/**'],
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
linterOptions: {
|
|
25
|
-
reportUnusedDisableDirectives: 'off',
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
);
|