@opentdf/sdk 0.9.0-beta.92 → 0.9.0-beta.94
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 +2 -2
- package/dist/cjs/src/access/access-fetch.js +1 -2
- package/dist/cjs/src/access/access-rpc.js +1 -3
- package/dist/cjs/src/access.js +1 -14
- package/dist/cjs/src/auth/auth.js +13 -10
- package/dist/cjs/src/auth/dpop.js +121 -0
- package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +37 -3
- package/dist/cjs/src/auth/oidc-externaljwt-provider.js +37 -3
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +37 -3
- package/dist/cjs/src/auth/oidc.js +10 -8
- package/dist/cjs/src/auth/providers.js +35 -12
- package/dist/cjs/src/crypto/index.js +16 -2
- package/dist/cjs/src/crypto/pemPublicToCrypto.js +17 -11
- package/dist/cjs/src/opentdf.js +50 -13
- package/dist/cjs/src/policy/discovery.js +2 -2
- package/dist/cjs/tdf3/index.js +4 -2
- package/dist/cjs/tdf3/src/assertions.js +71 -31
- package/dist/cjs/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/cjs/tdf3/src/ciphers/symmetric-cipher-base.js +4 -2
- package/dist/cjs/tdf3/src/client/index.js +23 -33
- package/dist/cjs/tdf3/src/crypto/crypto-utils.js +12 -5
- package/dist/cjs/tdf3/src/crypto/declarations.js +1 -1
- package/dist/cjs/tdf3/src/crypto/index.js +849 -88
- package/dist/cjs/tdf3/src/crypto/jose/jwt-claims-set.js +11 -0
- package/dist/cjs/tdf3/src/crypto/jose/validate-crit.js +8 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/buffer_utils.js +41 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/epoch.js +6 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/is_object.js +21 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.js +112 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/secs.js +60 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/lib/validate_crit.js +38 -0
- package/dist/cjs/tdf3/src/crypto/jose/vendor/util/errors.js +135 -0
- package/dist/cjs/tdf3/src/crypto/jwt.js +183 -0
- package/dist/cjs/tdf3/src/crypto/salt.js +14 -8
- package/dist/cjs/tdf3/src/models/encryption-information.js +17 -20
- package/dist/cjs/tdf3/src/models/key-access.js +43 -63
- package/dist/cjs/tdf3/src/tdf.js +75 -75
- package/dist/cjs/tdf3/src/utils/index.js +5 -39
- package/dist/types/src/access/access-fetch.d.ts.map +1 -1
- package/dist/types/src/access/access-rpc.d.ts.map +1 -1
- package/dist/types/src/access.d.ts +0 -5
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/auth.d.ts +9 -6
- package/dist/types/src/auth/auth.d.ts.map +1 -1
- package/dist/types/src/auth/dpop.d.ts +60 -0
- package/dist/types/src/auth/dpop.d.ts.map +1 -0
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts +3 -2
- package/dist/types/src/auth/oidc-clientcredentials-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts +3 -2
- package/dist/types/src/auth/oidc-externaljwt-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts +3 -2
- package/dist/types/src/auth/oidc-refreshtoken-provider.d.ts.map +1 -1
- package/dist/types/src/auth/oidc.d.ts +6 -4
- package/dist/types/src/auth/oidc.d.ts.map +1 -1
- package/dist/types/src/auth/providers.d.ts +5 -4
- package/dist/types/src/auth/providers.d.ts.map +1 -1
- package/dist/types/src/crypto/index.d.ts +2 -1
- package/dist/types/src/crypto/index.d.ts.map +1 -1
- package/dist/types/src/crypto/pemPublicToCrypto.d.ts +18 -0
- package/dist/types/src/crypto/pemPublicToCrypto.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +26 -7
- package/dist/types/src/opentdf.d.ts.map +1 -1
- package/dist/types/src/policy/discovery.d.ts +2 -2
- package/dist/types/tdf3/index.d.ts +3 -3
- package/dist/types/tdf3/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/assertions.d.ts +23 -8
- package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
- package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts +3 -3
- package/dist/types/tdf3/src/ciphers/aes-gcm-cipher.d.ts.map +1 -1
- package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts +4 -4
- package/dist/types/tdf3/src/ciphers/symmetric-cipher-base.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/builders.d.ts +2 -2
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/index.d.ts +6 -5
- package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts +14 -4
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/declarations.d.ts +283 -18
- package/dist/types/tdf3/src/crypto/declarations.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/index.d.ts +105 -28
- package/dist/types/tdf3/src/crypto/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/jose/jwt-claims-set.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/jwt-claims-set.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/validate-crit.d.ts +5 -0
- package/dist/types/tdf3/src/crypto/jose/validate-crit.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/buffer_utils.d.ts +6 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/buffer_utils.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/epoch.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/epoch.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/is_object.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/is_object.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/secs.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/secs.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/validate_crit.d.ts +3 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/lib/validate_crit.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/util/errors.d.ts +76 -0
- package/dist/types/tdf3/src/crypto/jose/vendor/util/errors.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/jwt.d.ts +76 -0
- package/dist/types/tdf3/src/crypto/jwt.d.ts.map +1 -0
- package/dist/types/tdf3/src/crypto/salt.d.ts +6 -1
- package/dist/types/tdf3/src/crypto/salt.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/encryption-information.d.ts +4 -4
- package/dist/types/tdf3/src/models/encryption-information.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/key-access.d.ts +8 -5
- package/dist/types/tdf3/src/models/key-access.d.ts.map +1 -1
- package/dist/types/tdf3/src/tdf.d.ts +8 -8
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/index.d.ts +4 -3
- package/dist/types/tdf3/src/utils/index.d.ts.map +1 -1
- package/dist/web/src/access/access-fetch.js +3 -4
- package/dist/web/src/access/access-rpc.js +3 -5
- package/dist/web/src/access.js +1 -13
- package/dist/web/src/auth/auth.js +13 -10
- package/dist/web/src/auth/dpop.js +118 -0
- package/dist/web/src/auth/oidc-clientcredentials-provider.js +4 -3
- package/dist/web/src/auth/oidc-externaljwt-provider.js +4 -3
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +4 -3
- package/dist/web/src/auth/oidc.js +11 -9
- package/dist/web/src/auth/providers.js +13 -12
- package/dist/web/src/crypto/index.js +4 -2
- package/dist/web/src/crypto/pemPublicToCrypto.js +11 -9
- package/dist/web/src/opentdf.js +17 -13
- package/dist/web/src/policy/discovery.js +2 -2
- package/dist/web/tdf3/index.js +3 -2
- package/dist/web/tdf3/src/assertions.js +71 -31
- package/dist/web/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/web/tdf3/src/ciphers/symmetric-cipher-base.js +4 -2
- package/dist/web/tdf3/src/client/index.js +25 -35
- package/dist/web/tdf3/src/crypto/crypto-utils.js +12 -5
- package/dist/web/tdf3/src/crypto/declarations.js +1 -1
- package/dist/web/tdf3/src/crypto/index.js +830 -84
- package/dist/web/tdf3/src/crypto/jose/jwt-claims-set.js +5 -0
- package/dist/web/tdf3/src/crypto/jose/validate-crit.js +3 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/buffer_utils.js +35 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/epoch.js +4 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/is_object.js +19 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.js +107 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/secs.js +58 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/lib/validate_crit.js +36 -0
- package/dist/web/tdf3/src/crypto/jose/vendor/util/errors.js +117 -0
- package/dist/web/tdf3/src/crypto/jwt.js +174 -0
- package/dist/web/tdf3/src/crypto/salt.js +13 -7
- package/dist/web/tdf3/src/models/encryption-information.js +11 -14
- package/dist/web/tdf3/src/models/key-access.js +44 -31
- package/dist/web/tdf3/src/tdf.js +71 -71
- package/dist/web/tdf3/src/utils/index.js +5 -6
- package/package.json +11 -4
- package/src/access/access-fetch.ts +2 -8
- package/src/access/access-rpc.ts +0 -7
- package/src/access.ts +0 -17
- package/src/auth/auth.ts +21 -12
- package/src/auth/dpop.ts +222 -0
- package/src/auth/oidc-clientcredentials-provider.ts +23 -15
- package/src/auth/oidc-externaljwt-provider.ts +23 -15
- package/src/auth/oidc-refreshtoken-provider.ts +23 -15
- package/src/auth/oidc.ts +21 -10
- package/src/auth/providers.ts +46 -29
- package/src/crypto/index.ts +21 -1
- package/src/crypto/pemPublicToCrypto.ts +11 -9
- package/src/opentdf.ts +36 -17
- package/src/policy/discovery.ts +2 -2
- package/tdf3/index.ts +32 -5
- package/tdf3/src/assertions.ts +99 -30
- package/tdf3/src/ciphers/aes-gcm-cipher.ts +7 -2
- package/tdf3/src/ciphers/symmetric-cipher-base.ts +7 -4
- package/tdf3/src/client/builders.ts +2 -2
- package/tdf3/src/client/index.ts +60 -59
- package/tdf3/src/crypto/crypto-utils.ts +15 -8
- package/tdf3/src/crypto/declarations.ts +338 -22
- package/tdf3/src/crypto/index.ts +1021 -118
- package/tdf3/src/crypto/jose/jwt-claims-set.ts +10 -0
- package/tdf3/src/crypto/jose/validate-crit.ts +9 -0
- package/tdf3/src/crypto/jose/vendor/lib/buffer_utils.ts +34 -0
- package/tdf3/src/crypto/jose/vendor/lib/epoch.ts +3 -0
- package/tdf3/src/crypto/jose/vendor/lib/is_object.ts +18 -0
- package/tdf3/src/crypto/jose/vendor/lib/jwt_claims_set.ts +106 -0
- package/tdf3/src/crypto/jose/vendor/lib/secs.ts +57 -0
- package/tdf3/src/crypto/jose/vendor/lib/validate_crit.ts +35 -0
- package/tdf3/src/crypto/jose/vendor/util/errors.ts +101 -0
- package/tdf3/src/crypto/jwt.ts +256 -0
- package/tdf3/src/crypto/salt.ts +16 -8
- package/tdf3/src/models/encryption-information.ts +14 -21
- package/tdf3/src/models/key-access.ts +57 -41
- package/tdf3/src/tdf.ts +110 -93
- package/tdf3/src/utils/index.ts +5 -6
package/src/auth/oidc.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { default as dpopFn } from 'dpop';
|
|
1
|
+
import { default as dpopFn } from './dpop.js';
|
|
2
2
|
import { HttpRequest, withHeaders } from './auth.js';
|
|
3
3
|
import { base64 } from '../encodings/index.js';
|
|
4
4
|
import { ConfigurationError, TdfError } from '../errors.js';
|
|
5
|
-
import {
|
|
5
|
+
import { rstrip } from '../utils.js';
|
|
6
|
+
import { type CryptoService, type KeyPair } from '../../tdf3/src/crypto/declarations.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Common fields used by all OIDC credentialing flows.
|
|
@@ -18,7 +19,7 @@ export type CommonCredentials = {
|
|
|
18
19
|
dpopEnabled?: boolean;
|
|
19
20
|
|
|
20
21
|
/** the client's public key, base64 encoded. Will be bound to the OIDC token. Deprecated. If not set in the constructor, */
|
|
21
|
-
signingKey?:
|
|
22
|
+
signingKey?: KeyPair;
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -94,13 +95,15 @@ export class AccessToken {
|
|
|
94
95
|
tokenEndpoint: string;
|
|
95
96
|
userInfoEndpoint: string;
|
|
96
97
|
|
|
97
|
-
signingKey?:
|
|
98
|
+
signingKey?: KeyPair;
|
|
98
99
|
|
|
99
100
|
extraHeaders: Record<string, string> = {};
|
|
100
101
|
|
|
101
102
|
currentAccessToken?: string;
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
cryptoService: CryptoService;
|
|
105
|
+
|
|
106
|
+
constructor(cfg: OIDCCredentials, cryptoService: CryptoService, request?: typeof fetch) {
|
|
104
107
|
if (!cfg.clientId) {
|
|
105
108
|
throw new ConfigurationError(
|
|
106
109
|
'A Keycloak client identifier is currently required for all auth mechanisms'
|
|
@@ -121,6 +124,7 @@ export class AccessToken {
|
|
|
121
124
|
throw new ConfigurationError('Invalid oidc configuration');
|
|
122
125
|
}
|
|
123
126
|
this.config = cfg;
|
|
127
|
+
this.cryptoService = cryptoService;
|
|
124
128
|
this.request = request;
|
|
125
129
|
this.baseUrl = rstrip(cfg.oidcOrigin, '/');
|
|
126
130
|
this.tokenEndpoint = cfg.oidcTokenEndpoint || `${this.baseUrl}/protocol/openid-connect/token`;
|
|
@@ -140,7 +144,12 @@ export class AccessToken {
|
|
|
140
144
|
Authorization: `Bearer ${accessToken}`,
|
|
141
145
|
} as Record<string, string>;
|
|
142
146
|
if (this.config.dpopEnabled && this.signingKey) {
|
|
143
|
-
headers.DPoP = await dpopFn(
|
|
147
|
+
headers.DPoP = await dpopFn(
|
|
148
|
+
this.signingKey,
|
|
149
|
+
this.cryptoService,
|
|
150
|
+
this.userInfoEndpoint,
|
|
151
|
+
'POST'
|
|
152
|
+
);
|
|
144
153
|
}
|
|
145
154
|
const response = await (this.request || fetch)(this.userInfoEndpoint, {
|
|
146
155
|
headers,
|
|
@@ -165,9 +174,10 @@ export class AccessToken {
|
|
|
165
174
|
if (!this.signingKey) {
|
|
166
175
|
throw new ConfigurationError('No signature configured');
|
|
167
176
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
headers
|
|
177
|
+
// Export opaque public key to PEM format for header
|
|
178
|
+
const publicKeyPem = await this.cryptoService.exportPublicKeyPem(this.signingKey.publicKey);
|
|
179
|
+
headers['X-VirtruPubKey'] = base64.encode(publicKeyPem);
|
|
180
|
+
headers.DPoP = await dpopFn(this.signingKey, this.cryptoService, url, 'POST');
|
|
171
181
|
}
|
|
172
182
|
return (this.request || fetch)(url, {
|
|
173
183
|
method: 'POST',
|
|
@@ -251,7 +261,7 @@ export class AccessToken {
|
|
|
251
261
|
*
|
|
252
262
|
* Calling this function will trigger a forcible token refresh using the cached refresh token, and contact the auth server.
|
|
253
263
|
*/
|
|
254
|
-
async refreshTokenClaimsWithClientPubkeyIfNeeded(signingKey:
|
|
264
|
+
async refreshTokenClaimsWithClientPubkeyIfNeeded(signingKey: KeyPair): Promise<void> {
|
|
255
265
|
// If we already have a token, and the pubkey changes,
|
|
256
266
|
// we need to force a refresh now - otherwise
|
|
257
267
|
// we can wait until we create the token for the first time
|
|
@@ -299,6 +309,7 @@ export class AccessToken {
|
|
|
299
309
|
if (this.config.dpopEnabled && this.signingKey) {
|
|
300
310
|
const dpopToken = await dpopFn(
|
|
301
311
|
this.signingKey,
|
|
312
|
+
this.cryptoService,
|
|
302
313
|
httpReq.url,
|
|
303
314
|
httpReq.method,
|
|
304
315
|
/* nonce */ undefined,
|
package/src/auth/providers.ts
CHANGED
|
@@ -10,6 +10,8 @@ import { type AuthProvider } from './auth.js';
|
|
|
10
10
|
import { OIDCRefreshTokenProvider } from './oidc-refreshtoken-provider.js';
|
|
11
11
|
import { isBrowser } from '../utils.js';
|
|
12
12
|
import { ConfigurationError } from '../errors.js';
|
|
13
|
+
import { type CryptoService } from '../../tdf3/src/crypto/declarations.js';
|
|
14
|
+
import * as defaultCryptoService from '../../tdf3/src/crypto/index.js';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Creates an OIDC Client Credentials Provider for non-browser contexts.
|
|
@@ -30,15 +32,19 @@ import { ConfigurationError } from '../errors.js';
|
|
|
30
32
|
*
|
|
31
33
|
*/
|
|
32
34
|
export const clientSecretAuthProvider = async (
|
|
33
|
-
clientConfig: ClientSecretCredentials
|
|
35
|
+
clientConfig: ClientSecretCredentials,
|
|
36
|
+
cryptoService: CryptoService = defaultCryptoService
|
|
34
37
|
): Promise<OIDCClientCredentialsProvider> => {
|
|
35
|
-
return new OIDCClientCredentialsProvider(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
return new OIDCClientCredentialsProvider(
|
|
39
|
+
{
|
|
40
|
+
clientId: clientConfig.clientId,
|
|
41
|
+
clientSecret: clientConfig.clientSecret,
|
|
42
|
+
oidcOrigin: clientConfig.oidcOrigin,
|
|
43
|
+
oidcTokenEndpoint: clientConfig.oidcTokenEndpoint,
|
|
44
|
+
oidcUserInfoEndpoint: clientConfig.oidcUserInfoEndpoint,
|
|
45
|
+
},
|
|
46
|
+
cryptoService
|
|
47
|
+
);
|
|
42
48
|
};
|
|
43
49
|
|
|
44
50
|
/**
|
|
@@ -58,15 +64,19 @@ export const clientSecretAuthProvider = async (
|
|
|
58
64
|
* {@link updateClientPublicKey}, which will force an explicit token refresh.
|
|
59
65
|
*/
|
|
60
66
|
export const externalAuthProvider = async (
|
|
61
|
-
clientConfig: ExternalJwtCredentials
|
|
67
|
+
clientConfig: ExternalJwtCredentials,
|
|
68
|
+
cryptoService: CryptoService = defaultCryptoService
|
|
62
69
|
): Promise<OIDCExternalJwtProvider> => {
|
|
63
|
-
return new OIDCExternalJwtProvider(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
return new OIDCExternalJwtProvider(
|
|
71
|
+
{
|
|
72
|
+
clientId: clientConfig.clientId,
|
|
73
|
+
externalJwt: clientConfig.externalJwt,
|
|
74
|
+
oidcOrigin: clientConfig.oidcOrigin,
|
|
75
|
+
oidcTokenEndpoint: clientConfig.oidcTokenEndpoint,
|
|
76
|
+
oidcUserInfoEndpoint: clientConfig.oidcUserInfoEndpoint,
|
|
77
|
+
},
|
|
78
|
+
cryptoService
|
|
79
|
+
);
|
|
70
80
|
};
|
|
71
81
|
|
|
72
82
|
/**
|
|
@@ -84,15 +94,19 @@ export const externalAuthProvider = async (
|
|
|
84
94
|
* {@link updateClientPublicKey} which will force an explicit token refresh
|
|
85
95
|
*/
|
|
86
96
|
export const refreshAuthProvider = async (
|
|
87
|
-
clientConfig: RefreshTokenCredentials
|
|
97
|
+
clientConfig: RefreshTokenCredentials,
|
|
98
|
+
cryptoService: CryptoService = defaultCryptoService
|
|
88
99
|
): Promise<OIDCRefreshTokenProvider> => {
|
|
89
|
-
return new OIDCRefreshTokenProvider(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
return new OIDCRefreshTokenProvider(
|
|
101
|
+
{
|
|
102
|
+
clientId: clientConfig.clientId,
|
|
103
|
+
refreshToken: clientConfig.refreshToken,
|
|
104
|
+
oidcOrigin: clientConfig.oidcOrigin,
|
|
105
|
+
oidcTokenEndpoint: clientConfig.oidcTokenEndpoint,
|
|
106
|
+
oidcUserInfoEndpoint: clientConfig.oidcUserInfoEndpoint,
|
|
107
|
+
},
|
|
108
|
+
cryptoService
|
|
109
|
+
);
|
|
96
110
|
};
|
|
97
111
|
|
|
98
112
|
/**
|
|
@@ -100,7 +114,10 @@ export const refreshAuthProvider = async (
|
|
|
100
114
|
* @param clientConfig OIDC client credentials
|
|
101
115
|
* @returns a promise for a new auth provider with the requested excahnge type
|
|
102
116
|
*/
|
|
103
|
-
export const clientAuthProvider = async (
|
|
117
|
+
export const clientAuthProvider = async (
|
|
118
|
+
clientConfig: OIDCCredentials,
|
|
119
|
+
cryptoService: CryptoService = defaultCryptoService
|
|
120
|
+
): Promise<AuthProvider> => {
|
|
104
121
|
if (!clientConfig.clientId) {
|
|
105
122
|
throw new ConfigurationError('Client ID must be provided to constructor');
|
|
106
123
|
}
|
|
@@ -116,13 +133,13 @@ export const clientAuthProvider = async (clientConfig: OIDCCredentials): Promise
|
|
|
116
133
|
//and provide us with a valid refresh token/clientId obtained from that process.
|
|
117
134
|
switch (clientConfig.exchange) {
|
|
118
135
|
case 'refresh': {
|
|
119
|
-
return refreshAuthProvider(clientConfig);
|
|
136
|
+
return refreshAuthProvider(clientConfig, cryptoService);
|
|
120
137
|
}
|
|
121
138
|
case 'external': {
|
|
122
|
-
return externalAuthProvider(clientConfig);
|
|
139
|
+
return externalAuthProvider(clientConfig, cryptoService);
|
|
123
140
|
}
|
|
124
141
|
case 'client': {
|
|
125
|
-
return clientSecretAuthProvider(clientConfig);
|
|
142
|
+
return clientSecretAuthProvider(clientConfig, cryptoService);
|
|
126
143
|
}
|
|
127
144
|
default:
|
|
128
145
|
throw new ConfigurationError(`Unsupported client type`);
|
|
@@ -136,7 +153,7 @@ export const clientAuthProvider = async (clientConfig: OIDCCredentials): Promise
|
|
|
136
153
|
'When using client credentials, must supply both client ID and client secret to constructor'
|
|
137
154
|
);
|
|
138
155
|
}
|
|
139
|
-
return clientSecretAuthProvider(clientConfig);
|
|
156
|
+
return clientSecretAuthProvider(clientConfig, cryptoService);
|
|
140
157
|
};
|
|
141
158
|
|
|
142
159
|
export * from './auth.js';
|
package/src/crypto/index.ts
CHANGED
|
@@ -6,5 +6,25 @@ export { generateKeyPair } from './generateKeyPair.js';
|
|
|
6
6
|
export { keyAgreement } from './keyAgreement.js';
|
|
7
7
|
export { default as exportCryptoKey } from './exportCryptoKey.js';
|
|
8
8
|
export { generateRandomNumber } from './generateRandomNumber.js';
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
pemPublicToCrypto,
|
|
11
|
+
pemCertToCrypto,
|
|
12
|
+
guessAlgorithmName,
|
|
13
|
+
guessCurveName,
|
|
14
|
+
toJwsAlg,
|
|
15
|
+
RSA_OID,
|
|
16
|
+
EC_OID,
|
|
17
|
+
P256_OID,
|
|
18
|
+
P384_OID,
|
|
19
|
+
P521_OID,
|
|
20
|
+
type AlgorithmName,
|
|
21
|
+
} from './pemPublicToCrypto.js';
|
|
10
22
|
export * as enums from './enums.js';
|
|
23
|
+
|
|
24
|
+
// PEM Formatting Utilities from tdf3
|
|
25
|
+
export {
|
|
26
|
+
formatAsPem,
|
|
27
|
+
removePemFormatting,
|
|
28
|
+
isPemKeyPair,
|
|
29
|
+
isCryptoKeyPair,
|
|
30
|
+
} from '../../tdf3/src/crypto/crypto-utils.js';
|
|
@@ -33,11 +33,12 @@ import { encodeArrayBuffer as hexEncodeArrayBuffer } from '../encodings/hex.js';
|
|
|
33
33
|
import { ConfigurationError, TdfError } from '../errors.js';
|
|
34
34
|
import { NamedCurve } from './enums.js';
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
36
|
+
// OID constants for algorithm detection (hex-encoded ASN.1 OIDs)
|
|
37
|
+
export const RSA_OID = '06092a864886f70d010101';
|
|
38
|
+
export const EC_OID = '06072a8648ce3d0201';
|
|
39
|
+
export const P256_OID = '06082a8648ce3d030107';
|
|
40
|
+
export const P384_OID = '06052b81040022';
|
|
41
|
+
export const P521_OID = '06052b81040023';
|
|
41
42
|
const SHA_512 = 'SHA-512';
|
|
42
43
|
const SPKI = 'spki';
|
|
43
44
|
const CERT_BEGIN = '-----BEGIN CERTIFICATE-----';
|
|
@@ -47,7 +48,7 @@ const ECDH = 'ECDH';
|
|
|
47
48
|
const ECDSA = 'ECDSA';
|
|
48
49
|
const RSA_OAEP = 'RSA-OAEP';
|
|
49
50
|
const RSA_PSS = 'RSA-PSS';
|
|
50
|
-
type AlgorithmName = typeof ECDH | typeof ECDSA | typeof RSA_OAEP | typeof RSA_PSS;
|
|
51
|
+
export type AlgorithmName = typeof ECDH | typeof ECDSA | typeof RSA_OAEP | typeof RSA_PSS;
|
|
51
52
|
|
|
52
53
|
interface PemPublicToCryptoOptions {
|
|
53
54
|
name?: string;
|
|
@@ -71,7 +72,7 @@ function guessKeyUsages(algorithmName: AlgorithmName, usages?: KeyUsage[]): KeyU
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
function guessAlgorithmName(hex: string, algorithmName?: string): AlgorithmName {
|
|
75
|
+
export function guessAlgorithmName(hex: string, algorithmName?: string): AlgorithmName {
|
|
75
76
|
if (hex.includes(EC_OID)) {
|
|
76
77
|
if (!algorithmName || algorithmName === ECDH) {
|
|
77
78
|
return ECDH;
|
|
@@ -88,7 +89,7 @@ function guessAlgorithmName(hex: string, algorithmName?: string): AlgorithmName
|
|
|
88
89
|
throw new TypeError(`Invalid public key, ${algorithmName}`);
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
function guessCurveName(hex: string): NamedCurve {
|
|
92
|
+
export function guessCurveName(hex: string): NamedCurve {
|
|
92
93
|
if (hex.includes(P256_OID)) {
|
|
93
94
|
return NamedCurve.P256;
|
|
94
95
|
} else if (hex.includes(P384_OID)) {
|
|
@@ -155,9 +156,10 @@ export async function pemPublicToCrypto(
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
/**
|
|
159
|
+
* Detect JWS algorithm from hex-encoded key/certificate data.
|
|
158
160
|
* Look up JWK algorithm at https://github.com/panva/jose/issues/210
|
|
159
161
|
*/
|
|
160
|
-
function toJwsAlg(hex: string) {
|
|
162
|
+
export function toJwsAlg(hex: string) {
|
|
161
163
|
const a = guessAlgorithmName(hex);
|
|
162
164
|
if (a === ECDH) {
|
|
163
165
|
return 'ECDH-ES';
|
package/src/opentdf.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { ConfigurationError, InvalidFileError } from './errors.js';
|
|
|
3
3
|
export { Client as TDF3Client } from '../tdf3/src/client/index.js';
|
|
4
4
|
import { Chunker, fromSource, sourceToStream, type Source } from './seekable.js';
|
|
5
5
|
import { Client as TDF3Client } from '../tdf3/src/client/index.js';
|
|
6
|
+
import { type CryptoService, type KeyPair } from '../tdf3/src/crypto/declarations.js';
|
|
7
|
+
import * as DefaultCryptoService from '../tdf3/src/crypto/index.js';
|
|
6
8
|
import {
|
|
7
9
|
type Assertion,
|
|
8
10
|
AssertionConfig,
|
|
@@ -33,6 +35,7 @@ import { Policy } from '../tdf3/src/models/policy.js';
|
|
|
33
35
|
|
|
34
36
|
export {
|
|
35
37
|
type Assertion,
|
|
38
|
+
type CryptoService,
|
|
36
39
|
type EncryptionInformation,
|
|
37
40
|
type IntegrityAlgorithm,
|
|
38
41
|
type KasPublicKeyAlgorithm,
|
|
@@ -96,7 +99,10 @@ export type SplitStep = {
|
|
|
96
99
|
sid?: string;
|
|
97
100
|
};
|
|
98
101
|
|
|
99
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Options specific to the ZTDF container format.
|
|
104
|
+
* @deprecated Use {@link CreateTDFOptions} instead.
|
|
105
|
+
*/
|
|
100
106
|
export type CreateZTDFOptions = CreateOptions & {
|
|
101
107
|
/** Configuration for bound metadata. */
|
|
102
108
|
assertionConfigs?: AssertionConfig[];
|
|
@@ -123,6 +129,9 @@ export type CreateZTDFOptions = CreateOptions & {
|
|
|
123
129
|
tdfSpecVersion?: '4.2.2' | '4.3.0';
|
|
124
130
|
};
|
|
125
131
|
|
|
132
|
+
/** Options for creating a TDF. */
|
|
133
|
+
export type CreateTDFOptions = CreateZTDFOptions;
|
|
134
|
+
|
|
126
135
|
/** Settings for decrypting any variety of TDF file. */
|
|
127
136
|
export type ReadOptions = {
|
|
128
137
|
/** The ciphertext source. */
|
|
@@ -172,7 +181,14 @@ export type OpenTDFOptions = {
|
|
|
172
181
|
* These often must be registered via a DPoP flow with the IdP
|
|
173
182
|
* which is out of the scope of this library.
|
|
174
183
|
*/
|
|
175
|
-
dpopKeys?: Promise<
|
|
184
|
+
dpopKeys?: Promise<KeyPair>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Optional custom CryptoService implementation.
|
|
188
|
+
* If not provided, defaults to the browser's native Web Crypto API.
|
|
189
|
+
* This allows injecting HSM-backed or other secure crypto implementations.
|
|
190
|
+
*/
|
|
191
|
+
cryptoService?: CryptoService;
|
|
176
192
|
};
|
|
177
193
|
|
|
178
194
|
/** A decorated readable stream. */
|
|
@@ -235,7 +251,7 @@ export type TDFReader = {
|
|
|
235
251
|
* platformUrl: 'https://platform.example.com',
|
|
236
252
|
* });
|
|
237
253
|
*
|
|
238
|
-
* const cipherText = await client.
|
|
254
|
+
* const cipherText = await client.createTDF({
|
|
239
255
|
* source: { type: 'stream', location: source },
|
|
240
256
|
* autoconfigure: false,
|
|
241
257
|
* });
|
|
@@ -257,7 +273,9 @@ export class OpenTDF {
|
|
|
257
273
|
/** Default options for reading TDF objects. */
|
|
258
274
|
defaultReadOptions: Omit<ReadOptions, 'source'>;
|
|
259
275
|
/** The DPoP keys for this instance, if any. */
|
|
260
|
-
readonly dpopKeys: Promise<
|
|
276
|
+
readonly dpopKeys: Promise<KeyPair>;
|
|
277
|
+
/** The CryptoService implementation for this instance. */
|
|
278
|
+
readonly cryptoService: CryptoService;
|
|
261
279
|
/** The TDF3 client for encrypting and decrypting ZTDF files. */
|
|
262
280
|
readonly tdf3Client: TDF3Client;
|
|
263
281
|
|
|
@@ -269,6 +287,7 @@ export class OpenTDF {
|
|
|
269
287
|
disableDPoP,
|
|
270
288
|
policyEndpoint,
|
|
271
289
|
platformUrl,
|
|
290
|
+
cryptoService,
|
|
272
291
|
}: OpenTDFOptions) {
|
|
273
292
|
this.authProvider = authProvider;
|
|
274
293
|
this.defaultCreateOptions = defaultCreateOptions || {};
|
|
@@ -282,28 +301,28 @@ export class OpenTDF {
|
|
|
282
301
|
);
|
|
283
302
|
}
|
|
284
303
|
this.policyEndpoint = policyEndpoint || '';
|
|
304
|
+
this.cryptoService = cryptoService ?? DefaultCryptoService;
|
|
285
305
|
this.tdf3Client = new TDF3Client({
|
|
286
306
|
authProvider,
|
|
287
307
|
dpopKeys,
|
|
288
308
|
kasEndpoint: this.platformUrl || 'https://disallow.all.invalid',
|
|
289
309
|
platformUrl,
|
|
290
310
|
policyEndpoint,
|
|
311
|
+
cryptoService: this.cryptoService,
|
|
291
312
|
});
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
300
|
-
},
|
|
301
|
-
true,
|
|
302
|
-
['sign', 'verify']
|
|
303
|
-
);
|
|
313
|
+
// Use CryptoService for key generation (returns opaque KeyPair)
|
|
314
|
+
this.dpopKeys = dpopKeys ?? this.cryptoService.generateSigningKeyPair();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Creates a new TDF stream. */
|
|
318
|
+
async createTDF(opts: CreateTDFOptions): Promise<DecoratedStream> {
|
|
319
|
+
return this.createZTDF(opts);
|
|
304
320
|
}
|
|
305
321
|
|
|
306
|
-
/**
|
|
322
|
+
/**
|
|
323
|
+
* Creates a new TDF stream.
|
|
324
|
+
* @deprecated Use {@link createTDF} instead.
|
|
325
|
+
*/
|
|
307
326
|
async createZTDF(opts: CreateZTDFOptions): Promise<DecoratedStream> {
|
|
308
327
|
opts = { ...this.defaultCreateOptions, ...opts };
|
|
309
328
|
const oldStream = await this.tdf3Client.encrypt({
|
package/src/policy/discovery.ts
CHANGED
|
@@ -32,7 +32,7 @@ const ATTRIBUTE_FQN_RE = /^https?:\/\/[a-zA-Z0-9._~%-]+\/attr\/[a-zA-Z0-9._~%-]+
|
|
|
32
32
|
* Returns all active attributes available on the platform, auto-paginating through all results.
|
|
33
33
|
* An optional namespace name or ID may be provided to filter results.
|
|
34
34
|
*
|
|
35
|
-
* Use this before calling `
|
|
35
|
+
* Use this before calling `createTDF()` to see what attributes are available for data tagging.
|
|
36
36
|
*
|
|
37
37
|
* @param platformUrl The platform base URL.
|
|
38
38
|
* @param authProvider An auth provider for the request.
|
|
@@ -86,7 +86,7 @@ export async function listAttributes(
|
|
|
86
86
|
* Checks that all provided attribute value FQNs exist on the platform.
|
|
87
87
|
* Validates FQN format first, then verifies existence via the platform API.
|
|
88
88
|
*
|
|
89
|
-
* Use this before `
|
|
89
|
+
* Use this before `createTDF()` to catch missing or misspelled attributes early
|
|
90
90
|
* instead of discovering the problem at decryption time.
|
|
91
91
|
*
|
|
92
92
|
* @param platformUrl The platform base URL.
|
package/tdf3/index.ts
CHANGED
|
@@ -14,10 +14,23 @@ import {
|
|
|
14
14
|
} from './src/client/builders.js';
|
|
15
15
|
import { type ClientConfig, createSessionKeys } from './src/client/index.js';
|
|
16
16
|
import {
|
|
17
|
+
type AsymmetricSigningAlgorithm,
|
|
17
18
|
type CryptoService,
|
|
18
19
|
type DecryptResult,
|
|
20
|
+
type ECCurve,
|
|
19
21
|
type EncryptResult,
|
|
22
|
+
type HashAlgorithm,
|
|
23
|
+
type HkdfParams,
|
|
24
|
+
type KeyPair,
|
|
25
|
+
type KeyOptions,
|
|
26
|
+
type KeyAlgorithm,
|
|
20
27
|
type PemKeyPair,
|
|
28
|
+
type PrivateKey,
|
|
29
|
+
type PublicKey,
|
|
30
|
+
type PublicKeyInfo,
|
|
31
|
+
type SigningAlgorithm,
|
|
32
|
+
type SymmetricKey,
|
|
33
|
+
type SymmetricSigningAlgorithm,
|
|
21
34
|
} from './src/crypto/declarations.js';
|
|
22
35
|
import { Client, Errors, TDF3Client } from './src/index.js';
|
|
23
36
|
import {
|
|
@@ -35,18 +48,31 @@ import { type Chunker } from '../src/seekable.js';
|
|
|
35
48
|
export type {
|
|
36
49
|
AlgorithmName,
|
|
37
50
|
AlgorithmUrn,
|
|
51
|
+
AsymmetricSigningAlgorithm,
|
|
38
52
|
AuthProvider,
|
|
39
53
|
Chunker,
|
|
40
54
|
CryptoService,
|
|
55
|
+
DecryptKeyMiddleware,
|
|
41
56
|
DecryptResult,
|
|
57
|
+
DecryptStreamMiddleware,
|
|
58
|
+
ECCurve,
|
|
59
|
+
EncryptKeyMiddleware,
|
|
42
60
|
EncryptResult,
|
|
61
|
+
EncryptStreamMiddleware,
|
|
62
|
+
HashAlgorithm,
|
|
63
|
+
HkdfParams,
|
|
43
64
|
HttpMethod,
|
|
65
|
+
KeyPair,
|
|
66
|
+
KeyOptions,
|
|
67
|
+
KeyAlgorithm,
|
|
44
68
|
PemKeyPair,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
PrivateKey,
|
|
70
|
+
PublicKey,
|
|
71
|
+
PublicKeyInfo,
|
|
72
|
+
SigningAlgorithm,
|
|
49
73
|
SplitStep,
|
|
74
|
+
SymmetricKey,
|
|
75
|
+
SymmetricSigningAlgorithm,
|
|
50
76
|
};
|
|
51
77
|
|
|
52
78
|
export {
|
|
@@ -74,7 +100,8 @@ export {
|
|
|
74
100
|
version,
|
|
75
101
|
};
|
|
76
102
|
|
|
77
|
-
export
|
|
103
|
+
export { DefaultCryptoService as WebCryptoService } from './src/crypto/index.js';
|
|
104
|
+
// export the other methods from crypto/index.js that aren't part of CryptoService but are needed for JWT handling
|
|
78
105
|
export {
|
|
79
106
|
type CreateOptions,
|
|
80
107
|
type CreateZTDFOptions,
|