@opentdf/sdk 0.3.1 → 0.3.2-beta.2
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/cjs/src/access/access-fetch.js +155 -0
- package/dist/cjs/src/access/access-rpc.js +131 -0
- package/dist/cjs/src/access.js +81 -107
- package/dist/cjs/src/auth/oidc.js +2 -2
- package/dist/cjs/src/nanotdf/Client.js +17 -13
- package/dist/cjs/src/nanotdf/models/Header.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/keyAgreement.js +2 -2
- package/dist/cjs/src/opentdf.js +42 -8
- package/dist/cjs/src/platform/authorization/authorization_pb.js +138 -0
- package/dist/cjs/src/platform/buf/validate/validate_pb.js +410 -0
- package/dist/cjs/src/platform/common/common_pb.js +79 -0
- package/dist/cjs/src/platform/entityresolution/entity_resolution_pb.js +49 -0
- package/dist/cjs/src/platform/google/api/annotations_pb.js +30 -0
- package/dist/cjs/src/platform/google/api/http_pb.js +37 -0
- package/dist/cjs/src/platform/kas/kas_pb.js +96 -0
- package/dist/cjs/src/platform/policy/actions/actions_pb.js +70 -0
- package/dist/cjs/src/platform/policy/attributes/attributes_pb.js +240 -0
- package/dist/cjs/src/platform/policy/kasregistry/key_access_server_registry_pb.js +236 -0
- package/dist/cjs/src/platform/policy/keymanagement/key_management_pb.js +70 -0
- package/dist/cjs/src/platform/policy/namespaces/namespaces_pb.js +121 -0
- package/dist/cjs/src/platform/policy/objects_pb.js +395 -0
- package/dist/cjs/src/platform/policy/registeredresources/registered_resources_pb.js +132 -0
- package/dist/cjs/src/platform/policy/resourcemapping/resource_mapping_pb.js +139 -0
- package/dist/cjs/src/platform/policy/selectors_pb.js +67 -0
- package/dist/cjs/src/platform/policy/subjectmapping/subject_mapping_pb.js +146 -0
- package/dist/cjs/src/platform/policy/unsafe/unsafe_pb.js +124 -0
- package/dist/cjs/src/platform/protoc-gen-openapiv2/options/annotations_pb.js +68 -0
- package/dist/cjs/src/platform/protoc-gen-openapiv2/options/openapiv2_pb.js +307 -0
- package/dist/cjs/src/platform/wellknownconfiguration/wellknown_configuration_pb.js +33 -0
- package/dist/cjs/src/platform.js +124 -0
- package/dist/cjs/src/policy/api.js +21 -38
- package/dist/cjs/src/policy/attributes.js +4 -1
- package/dist/cjs/src/policy/granter.js +9 -9
- package/dist/cjs/src/utils.js +31 -1
- package/dist/cjs/src/version.js +2 -2
- package/dist/cjs/tdf3/src/client/index.js +23 -18
- package/dist/cjs/tdf3/src/tdf.js +5 -5
- package/dist/types/src/access/access-fetch.d.ts +21 -0
- package/dist/types/src/access/access-fetch.d.ts.map +1 -0
- package/dist/types/src/access/access-rpc.d.ts +22 -0
- package/dist/types/src/access/access-rpc.d.ts.map +1 -0
- package/dist/types/src/access.d.ts +19 -11
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/nanotdf/Client.d.ts +3 -1
- package/dist/types/src/nanotdf/Client.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +5 -1
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/src/platform/authorization/authorization_pb.d.ts +609 -0
- package/dist/types/src/platform/authorization/authorization_pb.d.ts.map +1 -0
- package/dist/types/src/platform/buf/validate/validate_pb.d.ts +4466 -0
- package/dist/types/src/platform/buf/validate/validate_pb.d.ts.map +1 -0
- package/dist/types/src/platform/common/common_pb.d.ts +112 -0
- package/dist/types/src/platform/common/common_pb.d.ts.map +1 -0
- package/dist/types/src/platform/entityresolution/entity_resolution_pb.d.ts +199 -0
- package/dist/types/src/platform/entityresolution/entity_resolution_pb.d.ts.map +1 -0
- package/dist/types/src/platform/google/api/annotations_pb.d.ts +14 -0
- package/dist/types/src/platform/google/api/annotations_pb.d.ts.map +1 -0
- package/dist/types/src/platform/google/api/http_pb.d.ts +441 -0
- package/dist/types/src/platform/google/api/http_pb.d.ts.map +1 -0
- package/dist/types/src/platform/kas/kas_pb.d.ts +404 -0
- package/dist/types/src/platform/kas/kas_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/actions/actions_pb.d.ts +265 -0
- package/dist/types/src/platform/policy/actions/actions_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/attributes/attributes_pb.d.ts +1022 -0
- package/dist/types/src/platform/policy/attributes/attributes_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts +1306 -0
- package/dist/types/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/keymanagement/key_management_pb.d.ts +269 -0
- package/dist/types/src/platform/policy/keymanagement/key_management_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/namespaces/namespaces_pb.d.ts +448 -0
- package/dist/types/src/platform/policy/namespaces/namespaces_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/objects_pb.d.ts +1112 -0
- package/dist/types/src/platform/policy/objects_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/registeredresources/registered_resources_pb.d.ts +539 -0
- package/dist/types/src/platform/policy/registeredresources/registered_resources_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/resourcemapping/resource_mapping_pb.d.ts +558 -0
- package/dist/types/src/platform/policy/resourcemapping/resource_mapping_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/selectors_pb.d.ts +221 -0
- package/dist/types/src/platform/policy/selectors_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/subjectmapping/subject_mapping_pb.d.ts +582 -0
- package/dist/types/src/platform/policy/subjectmapping/subject_mapping_pb.d.ts.map +1 -0
- package/dist/types/src/platform/policy/unsafe/unsafe_pb.d.ts +513 -0
- package/dist/types/src/platform/policy/unsafe/unsafe_pb.d.ts.map +1 -0
- package/dist/types/src/platform/protoc-gen-openapiv2/options/annotations_pb.d.ts +62 -0
- package/dist/types/src/platform/protoc-gen-openapiv2/options/annotations_pb.d.ts.map +1 -0
- package/dist/types/src/platform/protoc-gen-openapiv2/options/openapiv2_pb.d.ts +1441 -0
- package/dist/types/src/platform/protoc-gen-openapiv2/options/openapiv2_pb.d.ts.map +1 -0
- package/dist/types/src/platform/wellknownconfiguration/wellknown_configuration_pb.d.ts +59 -0
- package/dist/types/src/platform/wellknownconfiguration/wellknown_configuration_pb.d.ts.map +1 -0
- package/dist/types/src/platform.d.ts +49 -0
- package/dist/types/src/platform.d.ts.map +1 -0
- package/dist/types/src/policy/api.d.ts +1 -1
- package/dist/types/src/policy/api.d.ts.map +1 -1
- package/dist/types/src/policy/attributes.d.ts +10 -87
- package/dist/types/src/policy/attributes.d.ts.map +1 -1
- package/dist/types/src/policy/granter.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +10 -0
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/tdf3/src/client/index.d.ts +8 -3
- package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/web/src/access/access-fetch.js +150 -0
- package/dist/web/src/access/access-rpc.js +125 -0
- package/dist/web/src/access.js +82 -110
- package/dist/web/src/auth/oidc.js +2 -2
- package/dist/web/src/nanotdf/Client.js +18 -14
- package/dist/web/src/nanotdf/models/Header.js +2 -2
- package/dist/web/src/nanotdf-crypto/keyAgreement.js +2 -2
- package/dist/web/src/opentdf.js +43 -9
- package/dist/web/src/platform/authorization/authorization_pb.js +135 -0
- package/dist/web/src/platform/buf/validate/validate_pb.js +407 -0
- package/dist/web/src/platform/common/common_pb.js +76 -0
- package/dist/web/src/platform/entityresolution/entity_resolution_pb.js +46 -0
- package/dist/web/src/platform/google/api/annotations_pb.js +27 -0
- package/dist/web/src/platform/google/api/http_pb.js +34 -0
- package/dist/web/src/platform/kas/kas_pb.js +93 -0
- package/dist/web/src/platform/policy/actions/actions_pb.js +67 -0
- package/dist/web/src/platform/policy/attributes/attributes_pb.js +237 -0
- package/dist/web/src/platform/policy/kasregistry/key_access_server_registry_pb.js +233 -0
- package/dist/web/src/platform/policy/keymanagement/key_management_pb.js +67 -0
- package/dist/web/src/platform/policy/namespaces/namespaces_pb.js +118 -0
- package/dist/web/src/platform/policy/objects_pb.js +392 -0
- package/dist/web/src/platform/policy/registeredresources/registered_resources_pb.js +129 -0
- package/dist/web/src/platform/policy/resourcemapping/resource_mapping_pb.js +136 -0
- package/dist/web/src/platform/policy/selectors_pb.js +64 -0
- package/dist/web/src/platform/policy/subjectmapping/subject_mapping_pb.js +143 -0
- package/dist/web/src/platform/policy/unsafe/unsafe_pb.js +121 -0
- package/dist/web/src/platform/protoc-gen-openapiv2/options/annotations_pb.js +65 -0
- package/dist/web/src/platform/protoc-gen-openapiv2/options/openapiv2_pb.js +304 -0
- package/dist/web/src/platform/wellknownconfiguration/wellknown_configuration_pb.js +30 -0
- package/dist/web/src/platform.js +87 -0
- package/dist/web/src/policy/api.js +23 -40
- package/dist/web/src/policy/attributes.js +3 -2
- package/dist/web/src/policy/granter.js +9 -9
- package/dist/web/src/utils.js +29 -1
- package/dist/web/src/version.js +2 -2
- package/dist/web/tdf3/src/client/index.js +25 -20
- package/dist/web/tdf3/src/tdf.js +5 -5
- package/package.json +17 -1
- package/src/access/access-fetch.ts +202 -0
- package/src/access/access-rpc.ts +175 -0
- package/src/access.ts +113 -138
- package/src/auth/oidc.ts +1 -1
- package/src/nanotdf/Client.ts +28 -18
- package/src/nanotdf/models/Header.ts +1 -1
- package/src/nanotdf-crypto/keyAgreement.ts +1 -1
- package/src/opentdf.ts +66 -10
- package/src/platform/authorization/authorization_pb.ts +689 -0
- package/src/platform/buf/validate/validate_pb.ts +4626 -0
- package/src/platform/common/common_pb.ts +135 -0
- package/src/platform/entityresolution/entity_resolution_pb.ts +233 -0
- package/src/platform/google/api/annotations_pb.ts +39 -0
- package/src/platform/google/api/http_pb.ts +474 -0
- package/src/platform/kas/kas_pb.ts +484 -0
- package/src/platform/policy/actions/actions_pb.ts +312 -0
- package/src/platform/policy/attributes/attributes_pb.ts +1181 -0
- package/src/platform/policy/kasregistry/key_access_server_registry_pb.ts +1482 -0
- package/src/platform/policy/keymanagement/key_management_pb.ts +316 -0
- package/src/platform/policy/namespaces/namespaces_pb.ts +528 -0
- package/src/platform/policy/objects_pb.ts +1319 -0
- package/src/platform/policy/registeredresources/registered_resources_pb.ts +623 -0
- package/src/platform/policy/resourcemapping/resource_mapping_pb.ts +658 -0
- package/src/platform/policy/selectors_pb.ts +277 -0
- package/src/platform/policy/subjectmapping/subject_mapping_pb.ts +687 -0
- package/src/platform/policy/unsafe/unsafe_pb.ts +593 -0
- package/src/platform/protoc-gen-openapiv2/options/annotations_pb.ts +83 -0
- package/src/platform/protoc-gen-openapiv2/options/openapiv2_pb.ts +1615 -0
- package/src/platform/wellknownconfiguration/wellknown_configuration_pb.ts +78 -0
- package/src/platform.ts +122 -0
- package/src/policy/api.ts +29 -42
- package/src/policy/attributes.ts +12 -108
- package/src/policy/granter.ts +7 -8
- package/src/utils.ts +30 -0
- package/src/version.ts +1 -1
- package/tdf3/src/client/index.ts +40 -19
- package/tdf3/src/tdf.ts +5 -6
- package/src/platform/authorization/authorization_connect.d.ts +0 -44
- package/src/platform/authorization/authorization_connect.js +0 -44
- package/src/platform/authorization/authorization_pb.d.ts +0 -707
- package/src/platform/authorization/authorization_pb.js +0 -372
- package/src/platform/common/common_pb.d.ts +0 -129
- package/src/platform/common/common_pb.js +0 -58
- package/src/platform/entityresolution/entity_resolution_connect.d.ts +0 -35
- package/src/platform/entityresolution/entity_resolution_connect.js +0 -35
- package/src/platform/entityresolution/entity_resolution_pb.d.ts +0 -242
- package/src/platform/entityresolution/entity_resolution_pb.js +0 -139
- package/src/platform/kas/kas_connect.d.ts +0 -59
- package/src/platform/kas/kas_connect.js +0 -59
- package/src/platform/kas/kas_pb.d.ts +0 -200
- package/src/platform/kas/kas_pb.js +0 -84
- package/src/platform/policy/attributes/attributes_connect.d.ts +0 -168
- package/src/platform/policy/attributes/attributes_connect.js +0 -168
- package/src/platform/policy/attributes/attributes_pb.d.ts +0 -929
- package/src/platform/policy/attributes/attributes_pb.js +0 -363
- package/src/platform/policy/kasregistry/key_access_server_registry_connect.d.ts +0 -62
- package/src/platform/policy/kasregistry/key_access_server_registry_connect.js +0 -62
- package/src/platform/policy/kasregistry/key_access_server_registry_pb.d.ts +0 -283
- package/src/platform/policy/kasregistry/key_access_server_registry_pb.js +0 -113
- package/src/platform/policy/namespaces/namespaces_connect.d.ts +0 -62
- package/src/platform/policy/namespaces/namespaces_connect.js +0 -62
- package/src/platform/policy/namespaces/namespaces_pb.d.ts +0 -270
- package/src/platform/policy/namespaces/namespaces_pb.js +0 -110
- package/src/platform/policy/objects_pb.d.ts +0 -725
- package/src/platform/policy/objects_pb.js +0 -288
- package/src/platform/policy/resourcemapping/resource_mapping_connect.d.ts +0 -259
- package/src/platform/policy/resourcemapping/resource_mapping_connect.js +0 -259
- package/src/platform/policy/resourcemapping/resource_mapping_pb.d.ts +0 -314
- package/src/platform/policy/resourcemapping/resource_mapping_pb.js +0 -142
- package/src/platform/policy/selectors_pb.d.ts +0 -269
- package/src/platform/policy/selectors_pb.js +0 -110
- package/src/platform/policy/subjectmapping/subject_mapping_connect.d.ts +0 -118
- package/src/platform/policy/subjectmapping/subject_mapping_connect.js +0 -118
- package/src/platform/policy/subjectmapping/subject_mapping_pb.d.ts +0 -672
- package/src/platform/policy/subjectmapping/subject_mapping_pb.js +0 -260
- package/src/platform/wellknownconfiguration/wellknown_configuration_connect.d.ts +0 -26
- package/src/platform/wellknownconfiguration/wellknown_configuration_connect.js +0 -26
- package/src/platform/wellknownconfiguration/wellknown_configuration_pb.d.ts +0 -75
- package/src/platform/wellknownconfiguration/wellknown_configuration_pb.js +0 -35
package/src/auth/oidc.ts
CHANGED
|
@@ -222,7 +222,7 @@ export class AccessToken {
|
|
|
222
222
|
return this.data.access_token;
|
|
223
223
|
} catch (e) {
|
|
224
224
|
console.log('access_token fails on user_info endpoint; attempting to renew', e);
|
|
225
|
-
if (this.data
|
|
225
|
+
if (this.data?.refresh_token) {
|
|
226
226
|
// Prefer the latest refresh_token if present over creds passed in
|
|
227
227
|
// to constructor
|
|
228
228
|
this.config = {
|
package/src/nanotdf/Client.ts
CHANGED
|
@@ -2,7 +2,12 @@ import * as base64 from '../encodings/base64.js';
|
|
|
2
2
|
import { generateKeyPair, keyAgreement } from '../nanotdf-crypto/index.js';
|
|
3
3
|
import getHkdfSalt from './helpers/getHkdfSalt.js';
|
|
4
4
|
import DefaultParams from './models/DefaultParams.js';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
fetchKeyAccessServers,
|
|
7
|
+
fetchWrappedKey,
|
|
8
|
+
KasPublicKeyInfo,
|
|
9
|
+
OriginAllowList,
|
|
10
|
+
} from '../access.js';
|
|
6
11
|
import { AuthProvider, isAuthProvider, reqSignature } from '../auth/providers.js';
|
|
7
12
|
import { ConfigurationError, DecryptError, TdfError, UnsafeUrlError } from '../errors.js';
|
|
8
13
|
import { cryptoPublicToPem, pemToCryptoPublicKey, validateSecureUrl } from '../utils.js';
|
|
@@ -15,6 +20,7 @@ export interface ClientConfig {
|
|
|
15
20
|
dpopKeys?: Promise<CryptoKeyPair>;
|
|
16
21
|
ephemeralKeyPair?: Promise<CryptoKeyPair>;
|
|
17
22
|
kasEndpoint: string;
|
|
23
|
+
platformUrl: string;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
function toJWSAlg(c: CryptoKey): string {
|
|
@@ -99,12 +105,13 @@ export default class Client {
|
|
|
99
105
|
static readonly INITIAL_RELEASE_IV_SIZE = 3;
|
|
100
106
|
static readonly IV_SIZE = 12;
|
|
101
107
|
|
|
102
|
-
allowedKases
|
|
108
|
+
allowedKases?: OriginAllowList;
|
|
103
109
|
/*
|
|
104
110
|
These variables are expected to be either assigned during initialization or within the methods.
|
|
105
111
|
This is needed as the flow is very specific. Errors should be thrown if the necessary step is not completed.
|
|
106
112
|
*/
|
|
107
113
|
protected kasUrl: string;
|
|
114
|
+
readonly platformUrl: string;
|
|
108
115
|
kasPubKey?: KasPublicKeyInfo;
|
|
109
116
|
readonly authProvider: AuthProvider;
|
|
110
117
|
readonly dpopEnabled: boolean;
|
|
@@ -150,7 +157,6 @@ export default class Client {
|
|
|
150
157
|
// TODO Disallow http KAS. For now just log as error
|
|
151
158
|
validateSecureUrl(kasUrl);
|
|
152
159
|
this.kasUrl = kasUrl;
|
|
153
|
-
this.allowedKases = new OriginAllowList([kasUrl]);
|
|
154
160
|
this.dpopEnabled = dpopEnabled;
|
|
155
161
|
|
|
156
162
|
if (ephemeralKeyPair) {
|
|
@@ -168,12 +174,16 @@ export default class Client {
|
|
|
168
174
|
dpopKeys,
|
|
169
175
|
ephemeralKeyPair,
|
|
170
176
|
kasEndpoint,
|
|
177
|
+
platformUrl,
|
|
171
178
|
} = optsOrOldAuthProvider;
|
|
172
179
|
this.authProvider = enwrapAuthProvider(authProvider);
|
|
173
180
|
// TODO Disallow http KAS. For now just log as error
|
|
174
181
|
validateSecureUrl(kasEndpoint);
|
|
175
182
|
this.kasUrl = kasEndpoint;
|
|
176
|
-
this.
|
|
183
|
+
this.platformUrl = platformUrl;
|
|
184
|
+
if (allowedKases?.length || ignoreAllowList) {
|
|
185
|
+
this.allowedKases = new OriginAllowList(allowedKases || [], ignoreAllowList);
|
|
186
|
+
}
|
|
177
187
|
this.dpopEnabled = !!dpopEnabled;
|
|
178
188
|
if (dpopKeys) {
|
|
179
189
|
this.requestSignerKeyPair = dpopKeys;
|
|
@@ -214,8 +224,14 @@ export default class Client {
|
|
|
214
224
|
magicNumberVersion: ArrayBufferLike,
|
|
215
225
|
clientVersion: string
|
|
216
226
|
): Promise<CryptoKey> {
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
let allowedKases = this.allowedKases;
|
|
228
|
+
|
|
229
|
+
if (!allowedKases) {
|
|
230
|
+
allowedKases = await fetchKeyAccessServers(this.platformUrl, this.authProvider);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (!allowedKases.allows(kasRewrapUrl)) {
|
|
234
|
+
throw new UnsafeUrlError(`request URL ∉ ${allowedKases.origins};`, kasRewrapUrl);
|
|
219
235
|
}
|
|
220
236
|
|
|
221
237
|
const ephemeralKeyPair = await this.ephemeralKeyPair;
|
|
@@ -243,22 +259,16 @@ export default class Client {
|
|
|
243
259
|
});
|
|
244
260
|
|
|
245
261
|
const jwtPayload = { requestBody: requestBodyStr };
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
};
|
|
262
|
+
|
|
263
|
+
const signedRequestToken = await reqSignature(jwtPayload, requestSignerKeyPair.privateKey, {
|
|
264
|
+
alg: toJWSAlg(requestSignerKeyPair.publicKey),
|
|
265
|
+
});
|
|
251
266
|
|
|
252
267
|
// Wrapped
|
|
253
|
-
const wrappedKey = await fetchWrappedKey(
|
|
254
|
-
kasRewrapUrl,
|
|
255
|
-
requestBody,
|
|
256
|
-
this.authProvider,
|
|
257
|
-
clientVersion
|
|
258
|
-
);
|
|
268
|
+
const wrappedKey = await fetchWrappedKey(kasRewrapUrl, signedRequestToken, this.authProvider);
|
|
259
269
|
|
|
260
270
|
// Extract the iv and ciphertext
|
|
261
|
-
const entityWrappedKey =
|
|
271
|
+
const entityWrappedKey = wrappedKey.entityWrappedKey;
|
|
262
272
|
const ivLength =
|
|
263
273
|
clientVersion == Client.SDK_INITIAL_RELEASE ? Client.INITIAL_RELEASE_IV_SIZE : Client.IV_SIZE;
|
|
264
274
|
const iv = entityWrappedKey.subarray(0, ivLength);
|
|
@@ -314,7 +314,7 @@ export default class Header {
|
|
|
314
314
|
*/
|
|
315
315
|
getKasRewrapUrl(): string {
|
|
316
316
|
try {
|
|
317
|
-
return `${rstrip(this.kas.url, '/')}
|
|
317
|
+
return `${rstrip(this.kas.url, '/')}`;
|
|
318
318
|
} catch (e) {
|
|
319
319
|
throw new ConfigurationError(`cannot construct KAS Rewrap URL: ${e.message}`);
|
|
320
320
|
}
|
|
@@ -71,7 +71,7 @@ export async function keyAgreement(
|
|
|
71
71
|
}
|
|
72
72
|
): Promise<CryptoKey> {
|
|
73
73
|
for (const k of [privateKey, publicKey]) {
|
|
74
|
-
const mechanism = keyAlgorithmToPublicKeyAlgorithm(k
|
|
74
|
+
const mechanism = keyAlgorithmToPublicKeyAlgorithm(k);
|
|
75
75
|
if (mechanism !== 'ec:secp256r1') {
|
|
76
76
|
throw new ConfigurationError(
|
|
77
77
|
`${k.type} CryptoKey is expected to be of type ECDSA or ECDH, not [${k.algorithm?.name}]`
|
package/src/opentdf.ts
CHANGED
|
@@ -13,7 +13,12 @@ import {
|
|
|
13
13
|
AssertionConfig,
|
|
14
14
|
AssertionVerificationKeys,
|
|
15
15
|
} from '../tdf3/src/assertions.js';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
type KasPublicKeyAlgorithm,
|
|
18
|
+
OriginAllowList,
|
|
19
|
+
fetchKeyAccessServers,
|
|
20
|
+
isPublicKeyAlgorithm,
|
|
21
|
+
} from './access.js';
|
|
17
22
|
import { type Manifest } from '../tdf3/src/models/manifest.js';
|
|
18
23
|
import { type Payload } from '../tdf3/src/models/payload.js';
|
|
19
24
|
import {
|
|
@@ -87,6 +92,7 @@ export type CreateNanoTDFOptions = CreateOptions & {
|
|
|
87
92
|
};
|
|
88
93
|
|
|
89
94
|
export type CreateNanoTDFCollectionOptions = CreateNanoTDFOptions & {
|
|
95
|
+
platformUrl: string;
|
|
90
96
|
// The maximum number of key iterations to use for a single DEK.
|
|
91
97
|
maxKeyIterations?: number;
|
|
92
98
|
};
|
|
@@ -136,6 +142,8 @@ export type CreateZTDFOptions = CreateOptions & {
|
|
|
136
142
|
export type ReadOptions = {
|
|
137
143
|
// ciphertext
|
|
138
144
|
source: Source;
|
|
145
|
+
// Platform URL
|
|
146
|
+
platformUrl?: string;
|
|
139
147
|
// list of KASes that may be contacted for a rewrap
|
|
140
148
|
allowedKASEndpoints?: string[];
|
|
141
149
|
// Optionally disable checking the allowlist
|
|
@@ -157,6 +165,9 @@ export type OpenTDFOptions = {
|
|
|
157
165
|
// Policy service endpoint
|
|
158
166
|
policyEndpoint?: string;
|
|
159
167
|
|
|
168
|
+
// Platform URL
|
|
169
|
+
platformUrl?: string;
|
|
170
|
+
|
|
160
171
|
// Auth provider for connections to the policy service and KASes.
|
|
161
172
|
authProvider: AuthProvider;
|
|
162
173
|
|
|
@@ -286,6 +297,7 @@ export type TDFReader = {
|
|
|
286
297
|
// SDK for dealing with OpenTDF data and policy services.
|
|
287
298
|
export class OpenTDF {
|
|
288
299
|
// Configuration service and more is at this URL/connectRPC endpoint
|
|
300
|
+
readonly platformUrl: string;
|
|
289
301
|
readonly policyEndpoint: string;
|
|
290
302
|
readonly authProvider: AuthProvider;
|
|
291
303
|
readonly dpopEnabled: boolean;
|
|
@@ -305,17 +317,25 @@ export class OpenTDF {
|
|
|
305
317
|
disableDPoP,
|
|
306
318
|
policyEndpoint,
|
|
307
319
|
rewrapCacheOptions,
|
|
320
|
+
platformUrl,
|
|
308
321
|
}: OpenTDFOptions) {
|
|
309
322
|
this.authProvider = authProvider;
|
|
310
323
|
this.defaultCreateOptions = defaultCreateOptions || {};
|
|
311
324
|
this.defaultReadOptions = defaultReadOptions || {};
|
|
312
325
|
this.dpopEnabled = !!disableDPoP;
|
|
326
|
+
if (platformUrl) {
|
|
327
|
+
this.platformUrl = platformUrl;
|
|
328
|
+
} else {
|
|
329
|
+
console.warn(
|
|
330
|
+
"Warning: 'platformUrl' is required for security to ensure the SDK uses the platform-configured Key Access Server list"
|
|
331
|
+
);
|
|
332
|
+
}
|
|
313
333
|
this.policyEndpoint = policyEndpoint || '';
|
|
314
334
|
this.rewrapCache = new RewrapCache(rewrapCacheOptions);
|
|
315
335
|
this.tdf3Client = new TDF3Client({
|
|
316
336
|
authProvider,
|
|
317
337
|
dpopKeys,
|
|
318
|
-
kasEndpoint: 'https://disallow.all.invalid',
|
|
338
|
+
kasEndpoint: this.platformUrl || 'https://disallow.all.invalid',
|
|
319
339
|
policyEndpoint,
|
|
320
340
|
});
|
|
321
341
|
this.dpopKeys =
|
|
@@ -333,8 +353,14 @@ export class OpenTDF {
|
|
|
333
353
|
}
|
|
334
354
|
|
|
335
355
|
async createNanoTDF(opts: CreateNanoTDFOptions): Promise<DecoratedStream> {
|
|
336
|
-
opts = {
|
|
337
|
-
|
|
356
|
+
opts = {
|
|
357
|
+
...this.defaultCreateOptions,
|
|
358
|
+
...opts,
|
|
359
|
+
};
|
|
360
|
+
const collection = await this.createNanoTDFCollection({
|
|
361
|
+
...opts,
|
|
362
|
+
platformUrl: this.platformUrl,
|
|
363
|
+
});
|
|
338
364
|
try {
|
|
339
365
|
return await collection.encrypt(opts.source);
|
|
340
366
|
} finally {
|
|
@@ -415,6 +441,9 @@ class UnknownTypeReader {
|
|
|
415
441
|
this.state = 'resolving';
|
|
416
442
|
const chunker = await fromSource(this.opts.source);
|
|
417
443
|
const prefix = await chunker(0, 3);
|
|
444
|
+
if (!this.opts.platformUrl && this.outer.platformUrl) {
|
|
445
|
+
this.opts.platformUrl = this.outer.platformUrl;
|
|
446
|
+
}
|
|
418
447
|
if (prefix[0] === 0x50 && prefix[1] === 0x4b) {
|
|
419
448
|
this.state = 'loaded';
|
|
420
449
|
return new ZTDFReader(this.outer.tdf3Client, this.opts, chunker);
|
|
@@ -466,6 +495,13 @@ class NanoTDFReader {
|
|
|
466
495
|
readonly chunker: Chunker,
|
|
467
496
|
private readonly rewrapCache: RewrapCache
|
|
468
497
|
) {
|
|
498
|
+
if (
|
|
499
|
+
!this.opts.ignoreAllowlist &&
|
|
500
|
+
!this.opts.platformUrl &&
|
|
501
|
+
!this.opts.allowedKASEndpoints?.length
|
|
502
|
+
) {
|
|
503
|
+
throw new ConfigurationError('platformUrl is required when allowedKasEndpoints is empty');
|
|
504
|
+
}
|
|
469
505
|
// lazily load the container
|
|
470
506
|
this.container = new Promise(async (resolve, reject) => {
|
|
471
507
|
try {
|
|
@@ -486,13 +522,17 @@ class NanoTDFReader {
|
|
|
486
522
|
r.header = nanotdf.header;
|
|
487
523
|
return r;
|
|
488
524
|
}
|
|
525
|
+
const platformUrl = this.opts.platformUrl || this.outer.platformUrl;
|
|
526
|
+
const kasEndpoint =
|
|
527
|
+
this.opts.allowedKASEndpoints?.[0] || platformUrl || 'https://disallow.all.invalid';
|
|
489
528
|
const nc = new Client({
|
|
490
529
|
allowedKases: this.opts.allowedKASEndpoints,
|
|
491
530
|
authProvider: this.outer.authProvider,
|
|
492
531
|
ignoreAllowList: this.opts.ignoreAllowlist,
|
|
493
532
|
dpopEnabled: this.outer.dpopEnabled,
|
|
494
533
|
dpopKeys: this.outer.dpopKeys,
|
|
495
|
-
kasEndpoint
|
|
534
|
+
kasEndpoint,
|
|
535
|
+
platformUrl,
|
|
496
536
|
});
|
|
497
537
|
// TODO: The version number should be fetched from the API
|
|
498
538
|
const version = '0.0.1';
|
|
@@ -550,10 +590,11 @@ class ZTDFReader {
|
|
|
550
590
|
noVerify: noVerifyAssertions,
|
|
551
591
|
wrappingKeyAlgorithm,
|
|
552
592
|
} = this.opts;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
593
|
+
|
|
594
|
+
if (!this.opts.ignoreAllowlist && !this.opts.allowedKASEndpoints && !this.opts.platformUrl) {
|
|
595
|
+
throw new ConfigurationError('platformUrl is required when allowedKasEndpoints is empty');
|
|
596
|
+
}
|
|
597
|
+
|
|
557
598
|
const dpopKeys = await this.client.dpopKeys;
|
|
558
599
|
|
|
559
600
|
const { authProvider, cryptoService } = this.client;
|
|
@@ -561,6 +602,17 @@ class ZTDFReader {
|
|
|
561
602
|
throw new ConfigurationError('authProvider is required');
|
|
562
603
|
}
|
|
563
604
|
|
|
605
|
+
let allowList: OriginAllowList | undefined;
|
|
606
|
+
|
|
607
|
+
if (this.opts.allowedKASEndpoints?.length || this.opts.ignoreAllowlist) {
|
|
608
|
+
allowList = new OriginAllowList(
|
|
609
|
+
this.opts.allowedKASEndpoints || [],
|
|
610
|
+
this.opts.ignoreAllowlist
|
|
611
|
+
);
|
|
612
|
+
} else if (this.opts.platformUrl) {
|
|
613
|
+
allowList = await fetchKeyAccessServers(this.opts.platformUrl, authProvider);
|
|
614
|
+
}
|
|
615
|
+
|
|
564
616
|
const overview = await this.overview;
|
|
565
617
|
const oldStream = await decryptStreamFrom(
|
|
566
618
|
{
|
|
@@ -642,10 +694,14 @@ class Collection {
|
|
|
642
694
|
break;
|
|
643
695
|
}
|
|
644
696
|
|
|
697
|
+
const kasEndpoint =
|
|
698
|
+
opts.defaultKASEndpoint || opts.platformUrl || 'https://disallow.all.invalid';
|
|
699
|
+
|
|
645
700
|
this.client = new NanoTDFDatasetClient({
|
|
646
701
|
authProvider,
|
|
647
|
-
kasEndpoint:
|
|
702
|
+
kasEndpoint: kasEndpoint,
|
|
648
703
|
maxKeyIterations: opts.maxKeyIterations,
|
|
704
|
+
platformUrl: opts.platformUrl,
|
|
649
705
|
});
|
|
650
706
|
}
|
|
651
707
|
|