@icure/api 8.0.0-RC.3 → 8.0.0-RC.5

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.
Files changed (64) hide show
  1. package/icc-api/api/IccInsuranceApi.d.ts +2 -0
  2. package/icc-api/api/IccInsuranceApi.js +12 -0
  3. package/icc-api/api/IccInsuranceApi.js.map +1 -1
  4. package/icc-api/api/IccMessageApi.d.ts +6 -0
  5. package/icc-api/api/IccMessageApi.js +15 -0
  6. package/icc-api/api/IccMessageApi.js.map +1 -1
  7. package/icc-api/api/{IccExchangeDataApi.d.ts → internal/IccExchangeDataApi.d.ts} +4 -4
  8. package/icc-api/api/{IccExchangeDataApi.js → internal/IccExchangeDataApi.js} +5 -5
  9. package/icc-api/api/internal/IccExchangeDataApi.js.map +1 -0
  10. package/icc-api/api/{IccExchangeDataMapApi.d.ts → internal/IccExchangeDataMapApi.d.ts} +4 -4
  11. package/icc-api/api/{IccExchangeDataMapApi.js → internal/IccExchangeDataMapApi.js} +5 -5
  12. package/icc-api/api/internal/IccExchangeDataMapApi.js.map +1 -0
  13. package/icc-api/api/internal/IccRecoveryDataApi.d.ts +19 -0
  14. package/icc-api/api/internal/IccRecoveryDataApi.js +83 -0
  15. package/icc-api/api/internal/IccRecoveryDataApi.js.map +1 -0
  16. package/icc-api/api/{IccSecureDelegationKeyMapApi.d.ts → internal/IccSecureDelegationKeyMapApi.d.ts} +6 -6
  17. package/icc-api/api/{IccSecureDelegationKeyMapApi.js → internal/IccSecureDelegationKeyMapApi.js} +5 -5
  18. package/icc-api/api/internal/IccSecureDelegationKeyMapApi.js.map +1 -0
  19. package/icc-api/model/PaginatedListInsurance.d.ts +20 -0
  20. package/icc-api/model/PaginatedListInsurance.js +10 -0
  21. package/icc-api/model/PaginatedListInsurance.js.map +1 -0
  22. package/icc-api/model/User.d.ts +19 -0
  23. package/icc-api/model/User.js +6 -0
  24. package/icc-api/model/User.js.map +1 -1
  25. package/icc-api/model/internal/ExchangeData.d.ts +20 -4
  26. package/icc-api/model/internal/ExchangeData.js +8 -2
  27. package/icc-api/model/internal/ExchangeData.js.map +1 -1
  28. package/icc-api/model/internal/RecoveryData.d.ts +47 -0
  29. package/icc-api/model/internal/RecoveryData.js +34 -0
  30. package/icc-api/model/internal/RecoveryData.js.map +1 -0
  31. package/icc-x-api/auth/JwtBridgedAuthService.d.ts +1 -0
  32. package/icc-x-api/auth/JwtBridgedAuthService.js +10 -3
  33. package/icc-x-api/auth/JwtBridgedAuthService.js.map +1 -1
  34. package/icc-x-api/crypto/BaseExchangeDataManager.d.ts +37 -25
  35. package/icc-x-api/crypto/BaseExchangeDataManager.js +123 -64
  36. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  37. package/icc-x-api/crypto/CryptoPrimitives.d.ts +3 -0
  38. package/icc-x-api/crypto/CryptoPrimitives.js +5 -0
  39. package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -1
  40. package/icc-x-api/crypto/DelegationsDeAnonymization.js +1 -1
  41. package/icc-x-api/crypto/DelegationsDeAnonymization.js.map +1 -1
  42. package/icc-x-api/crypto/ExchangeDataManager.js +14 -6
  43. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  44. package/icc-x-api/crypto/ExchangeDataMapManager.d.ts +1 -1
  45. package/icc-x-api/crypto/ExchangeDataMapManager.js.map +1 -1
  46. package/icc-x-api/crypto/HMACUtils.d.ts +10 -0
  47. package/icc-x-api/crypto/HMACUtils.js +48 -0
  48. package/icc-x-api/crypto/HMACUtils.js.map +1 -0
  49. package/icc-x-api/crypto/SecureDelegationsManager.js +3 -0
  50. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
  51. package/icc-x-api/icc-icure-maintenance-x-api.d.ts +1 -1
  52. package/icc-x-api/icc-icure-maintenance-x-api.js.map +1 -1
  53. package/icc-x-api/icc-message-x-api.d.ts +1 -1
  54. package/icc-x-api/icc-message-x-api.js +3 -3
  55. package/icc-x-api/icc-message-x-api.js.map +1 -1
  56. package/icc-x-api/icc-recovery-x-api.d.ts +0 -0
  57. package/icc-x-api/icc-recovery-x-api.js +2 -0
  58. package/icc-x-api/icc-recovery-x-api.js.map +1 -0
  59. package/icc-x-api/index.js +2 -2
  60. package/icc-x-api/index.js.map +1 -1
  61. package/package.json +1 -1
  62. package/icc-api/api/IccExchangeDataApi.js.map +0 -1
  63. package/icc-api/api/IccExchangeDataMapApi.js.map +0 -1
  64. package/icc-api/api/IccSecureDelegationKeyMapApi.js.map +0 -1
@@ -78,47 +78,41 @@ class BaseExchangeDataManager {
78
78
  });
79
79
  });
80
80
  }
81
- /**
82
- * Filters exchange data returning only the instances that could be verified using their signature and the provided verification
83
- * keys.
84
- * Note that all exchange data created by data owners other than the current data owner (including members of his hierarchy)
85
- * will always be unverified.
86
- * @param exchangeData the exchange data to verify.
87
- * @param getVerificationKey function to retrieve keys to use for verification by fingerprint.
88
- * @return the exchange data which could be verified given his signature and the available verification keys.
89
- * @throws if any of the provided exchange data has been created by a data owner other than the current data owner.
90
- */
91
- filterVerifiedExchangeData(exchangeData, getVerificationKey) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const verified = [];
94
- for (const ed of exchangeData) {
95
- if (yield this.verifyExchangeData(ed, (x) => getVerificationKey(x)))
96
- verified.push(ed);
97
- }
98
- return verified;
99
- });
100
- }
101
81
  /**
102
82
  * Verifies the authenticity of the exchange data by checking the signature.
103
83
  * Note that all exchange data created by data owners other than the current data owner (including members of his hierarchy)
104
84
  * will always be unverified.
105
- * @param exchangeData the exchange data to verify.
85
+ * @param data collects the following information about the exchange data being verified:
86
+ * - exchangeData the exchange data to verify.
87
+ * - decryptedAccessControlSecret the access control secret decrypted from the exchange data.
88
+ * - decryptedExchangeKey the exchange key decrypted from the exchange data.
89
+ * - decryptedSharedSignatureKey the shared signature key decrypted from the exchange data.
106
90
  * @param getVerificationKey function to retrieve keys to use for verification by fingerprint.
91
+ * @param verifyAsDelegator if true the method will also verify that the hmac key used for the signature was created by the delegator of the
92
+ * exchange data. If true and the data was not created by the current data owner this method will return false.
107
93
  * @return the exchange data which could be verified given his signature and the available verification keys.
108
94
  * @throws if any of the provided exchange data has been created by a data owner other than the current data owner.
109
95
  */
110
- verifyExchangeData(exchangeData, getVerificationKey) {
96
+ verifyExchangeData(data, getVerificationKey, verifyAsDelegator) {
111
97
  return __awaiter(this, void 0, void 0, function* () {
112
- const dataOwnerId = yield this.dataOwnerApi.getCurrentDataOwnerId();
113
- if (exchangeData.delegator !== dataOwnerId)
98
+ if (verifyAsDelegator && data.exchangeData.delegator !== (yield this.dataOwnerApi.getCurrentDataOwnerId()))
114
99
  return false;
115
- const signatureData = yield this.bytesToSign(exchangeData);
116
- for (const [fp, signature] of Object.entries(exchangeData.signature)) {
117
- const verificationKey = yield getVerificationKey(fp.slice(-32));
118
- if (verificationKey && (yield this.primitives.RSA.verifySignature(verificationKey, (0, utils_1.b64_2ua)(signature), signatureData)))
119
- return true;
120
- }
121
- return false;
100
+ if (verifyAsDelegator && !(yield this.verifyDelegatorSignature(data.exchangeData, data.decryptedSharedSignatureKey, getVerificationKey)))
101
+ return false;
102
+ const sharedSignatureData = yield this.bytesToSignForSharedSignature({
103
+ decryptedAccessControlSecret: data.decryptedAccessControlSecret,
104
+ decryptedExchangeKey: data.decryptedExchangeKey,
105
+ delegator: data.exchangeData.delegator,
106
+ delegate: data.exchangeData.delegate,
107
+ publicKeysFingerprintsV2: [
108
+ ...new Set([
109
+ ...Object.keys(data.exchangeData.exchangeKey),
110
+ ...Object.keys(data.exchangeData.accessControlSecret),
111
+ ...Object.keys(data.exchangeData.sharedSignatureKey),
112
+ ]),
113
+ ],
114
+ });
115
+ return yield this.verifyDataWithSharedKey(sharedSignatureData, data.decryptedSharedSignatureKey, data.exchangeData.sharedSignature);
122
116
  });
123
117
  }
124
118
  /**
@@ -149,6 +143,19 @@ class BaseExchangeDataManager {
149
143
  return yield this.tryDecryptExchangeData(exchangeData, decryptionKeys, (ed) => ed.exchangeKey, (d) => this.importExchangeKey(new Uint8Array(d)));
150
144
  });
151
145
  }
146
+ /**
147
+ * Extract and decrypts the shared signature key from the provided exchange data.
148
+ * @param exchangeData the exchange data from which to extract exchange keys.
149
+ * @param decryptionKeys rsa key pairs to use for the decryption of the exchange keys.
150
+ * @return an object composed of:
151
+ * - successfulDecryptions: array containing the successfully decrypted exchange keys.
152
+ * - failedDecryptions: array containing all exchange data for which the access control key could not be decrypted (using the provided keys).
153
+ */
154
+ tryDecryptSharedSignatureKeys(exchangeData, decryptionKeys) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ return yield this.tryDecryptExchangeData(exchangeData, decryptionKeys, (ed) => ed.sharedSignatureKey, (d) => this.importSharedSignatureKey(new Uint8Array(d)));
157
+ });
158
+ }
152
159
  tryDecryptExchangeData(exchangeData, decryptionKeys, encryptedDataSelector, unmarshalDecrypted) {
153
160
  return __awaiter(this, void 0, void 0, function* () {
154
161
  const successfulDecryptions = [];
@@ -180,7 +187,7 @@ class BaseExchangeDataManager {
180
187
  try {
181
188
  const key = (_a = decryptionKeysWithV2Fp[fp]) === null || _a === void 0 ? void 0 : _a.privateKey;
182
189
  if (key)
183
- return (0, utils_1.hex2ua)((0, utils_1.ua2utf8)(yield this.primitives.RSA.decrypt(key, (0, utils_1.b64_2ua)(encrypted))));
190
+ return yield this.primitives.RSA.decrypt(key, (0, utils_1.b64_2ua)(encrypted));
184
191
  }
185
192
  catch (e) {
186
193
  // Try with another key
@@ -205,17 +212,29 @@ class BaseExchangeDataManager {
205
212
  }
206
213
  const exchangeKey = yield this.generateExchangeKey();
207
214
  const accessControlSecret = yield this.generateAccessControlSecret();
215
+ const sharedSignatureKey = yield this.generateSharedSignatureKey();
208
216
  const encryptedExchangeKey = yield this.encryptDataWithKeys(exchangeKey.rawBytes, encryptionKeys);
209
217
  const encryptedAccessControlSecret = yield this.encryptDataWithKeys(accessControlSecret.rawBytes, encryptionKeys);
218
+ const encryptedSharedSignatureKey = yield this.encryptDataWithKeys(sharedSignatureKey.rawBytes, encryptionKeys);
210
219
  const baseExchangeData = {
211
220
  id: (_a = optionalAttributes.id) !== null && _a !== void 0 ? _a : this.primitives.randomUuid(),
212
221
  delegator: yield this.dataOwnerApi.getCurrentDataOwnerId(),
213
222
  delegate: delegateId,
214
223
  exchangeKey: encryptedExchangeKey,
215
224
  accessControlSecret: encryptedAccessControlSecret,
225
+ sharedSignatureKey: encryptedSharedSignatureKey,
216
226
  };
217
- const signature = yield this.signDataWithKeys(yield this.bytesToSign(baseExchangeData), signatureKeys);
218
- const exchangeData = new ExchangeData_1.ExchangeData(Object.assign(Object.assign({}, baseExchangeData), { signature }));
227
+ const sharedSignature = yield this.signDataWithSharedKey(yield this.bytesToSignForSharedSignature({
228
+ delegate: baseExchangeData.delegate,
229
+ delegator: baseExchangeData.delegator,
230
+ decryptedAccessControlSecret: accessControlSecret.secret,
231
+ decryptedExchangeKey: exchangeKey.key,
232
+ publicKeysFingerprintsV2: Object.keys(encryptionKeys).map(utils_2.fingerprintV1toV2),
233
+ }), sharedSignatureKey.key);
234
+ const delegatorSignature = yield this.signDataWithDelegatorKeys(yield this.bytesToSignForDelegatorSignature({
235
+ sharedSignatureKey: sharedSignatureKey.key,
236
+ }), signatureKeys);
237
+ const exchangeData = new ExchangeData_1.ExchangeData(Object.assign(Object.assign({}, baseExchangeData), { delegatorSignature, sharedSignature }));
219
238
  return {
220
239
  exchangeData: yield this.api.createExchangeData(exchangeData),
221
240
  exchangeKey: exchangeKey.key,
@@ -228,67 +247,73 @@ class BaseExchangeDataManager {
228
247
  * where one of the data owners involved in the exchange data has lost one of his keys.
229
248
  * If the content of the exchange data could not be decrypted using the provided keys the method will not update anything and will return undefined.
230
249
  * This method assumes that the new encryption keys have been verified.
231
- * If the current data owner is also the delegator of the provided exchange data and at least one of the verification keys can be used to
232
- * validate the current exchange data then the signature will be updated using the signature keys.
233
- * Instead, if the current data owner is not the delegator of the provided exchange data, or the exchange data could not be verified using
234
- * the provided verification keys then the updated exchange data will become unverified, and won't ever be verifiable again.
235
250
  * @param exchangeData exchange data to update.
236
251
  * @param decryptionKeys keys to use to extract the content of the exchange data which will be shared with the new keys.
237
- * @param signatureKeys keys to use for the new signature of the updated exchange data.
238
252
  * @param newEncryptionKeys new keys to add to the exchange data.
239
- * @param getVerificationKey function to retrieve keys to use for verification by fingerprint.
240
253
  * @return the updated exchange data, and its decrypted exchange key and access control secret, or undefined if the exchange data content could not
241
254
  * be decrypted and the exchange data could not be updated.
242
255
  */
243
- tryUpdateExchangeData(exchangeData, decryptionKeys, newEncryptionKeys, signatureKeys, getVerificationKey) {
256
+ tryUpdateExchangeData(exchangeData, decryptionKeys, newEncryptionKeys) {
244
257
  return __awaiter(this, void 0, void 0, function* () {
245
258
  const dataOwnerId = yield this.dataOwnerApi.getCurrentDataOwnerId();
246
259
  const rawExchangeKey = yield this.tryDecrypt(exchangeData.exchangeKey, decryptionKeys);
247
260
  const rawAccessControlSecret = yield this.tryDecrypt(exchangeData.accessControlSecret, decryptionKeys);
248
- if (!rawExchangeKey || !rawAccessControlSecret)
261
+ const rawSharedSignatureKey = yield this.tryDecrypt(exchangeData.sharedSignatureKey, decryptionKeys);
262
+ if (!rawExchangeKey || !rawAccessControlSecret || !rawSharedSignatureKey)
249
263
  return undefined;
250
264
  const exchangeKey = yield this.importExchangeKey(new Uint8Array(rawExchangeKey));
251
265
  const accessControlSecret = yield this.importAccessControlSecret(new Uint8Array(rawAccessControlSecret));
266
+ const sharedSignatureKey = yield this.importSharedSignatureKey(new Uint8Array(rawSharedSignatureKey));
252
267
  const existingExchangeKeyEntries = new Set(Object.keys(exchangeData.exchangeKey));
253
268
  const existingAcsEntries = new Set(Object.keys(exchangeData.accessControlSecret));
254
- const missingEntries = Object.keys(newEncryptionKeys).filter((fp) => !existingAcsEntries.has(fp) || !existingExchangeKeyEntries.has(fp));
269
+ const existingSharedSignatureKeyEntries = new Set(Object.keys(exchangeData.sharedSignatureKey));
270
+ const missingEntries = Object.keys(newEncryptionKeys).filter((fp) => !existingAcsEntries.has(fp) || !existingExchangeKeyEntries.has(fp) || !existingSharedSignatureKeyEntries.has(fp));
255
271
  if (!missingEntries.length)
256
272
  return { exchangeData, exchangeKey, accessControlSecret };
257
273
  const encryptionKeysForMissingEntries = missingEntries.reduce((obj, fp) => {
258
274
  obj[fp] = newEncryptionKeys[fp];
259
275
  return obj;
260
276
  }, {});
261
- const isVerified = exchangeData.delegator == dataOwnerId && (yield this.verifyExchangeData(exchangeData, (fp) => getVerificationKey(fp)));
262
277
  const updatedExchangeData = _.cloneDeep(exchangeData);
263
278
  updatedExchangeData.exchangeKey = Object.assign(Object.assign({}, exchangeData.exchangeKey), (yield this.encryptDataWithKeys(rawExchangeKey, encryptionKeysForMissingEntries)));
264
279
  updatedExchangeData.accessControlSecret = Object.assign(Object.assign({}, exchangeData.accessControlSecret), (yield this.encryptDataWithKeys(rawAccessControlSecret, encryptionKeysForMissingEntries)));
280
+ updatedExchangeData.sharedSignatureKey = Object.assign(Object.assign({}, exchangeData.sharedSignatureKey), (yield this.encryptDataWithKeys(rawSharedSignatureKey, encryptionKeysForMissingEntries)));
281
+ const isVerified = yield this.verifyExchangeData({
282
+ exchangeData,
283
+ decryptedAccessControlSecret: accessControlSecret,
284
+ decryptedExchangeKey: exchangeKey,
285
+ decryptedSharedSignatureKey: sharedSignatureKey,
286
+ }, () => Promise.resolve(undefined), false);
265
287
  if (isVerified) {
266
- const newDataToSign = yield this.bytesToSign(updatedExchangeData);
267
- updatedExchangeData.signature = yield this.signDataWithKeys(newDataToSign, signatureKeys);
288
+ updatedExchangeData.sharedSignature = yield this.signDataWithSharedKey(yield this.bytesToSignForSharedSignature({
289
+ delegate: updatedExchangeData.delegate,
290
+ delegator: updatedExchangeData.delegator,
291
+ decryptedAccessControlSecret: accessControlSecret,
292
+ decryptedExchangeKey: exchangeKey,
293
+ publicKeysFingerprintsV2: Object.keys(updatedExchangeData.exchangeKey),
294
+ }), sharedSignatureKey);
268
295
  }
269
296
  return { exchangeData: yield this.api.modifyExchangeData(new ExchangeData_1.ExchangeData(updatedExchangeData)), exchangeKey, accessControlSecret };
270
297
  });
271
298
  }
272
- // Gets a byte representation of the parts of exchange data which should be included in the signature.
273
- // Equivalent json representations of the exchange data should provide the same bytes (even if the order of entries
274
- // is different).
275
- bytesToSign(exchangeData) {
299
+ bytesToSignForSharedSignature(data) {
276
300
  return __awaiter(this, void 0, void 0, function* () {
277
- function sortObject(obj) {
278
- return Object.keys(obj)
279
- .sort()
280
- .reduce((sorted, key) => {
281
- return [...sorted, [key, obj[key]]];
282
- }, []);
283
- }
301
+ // Use array of array to ensure that order is preserved regardless of how the specific js implementation orders
302
+ // the keys of an object
284
303
  const signObject = [
285
- ['delegator', exchangeData.delegator],
286
- ['delegate', exchangeData.delegate],
287
- ['exchangeKey', sortObject(exchangeData.exchangeKey)],
288
- ['accessControlSecret', sortObject(exchangeData.accessControlSecret)],
304
+ ['delegator', data.delegator],
305
+ ['delegate', data.delegate],
306
+ ['exchangeKey', (0, utils_1.ua2hex)(yield this.primitives.AES.exportKey(data.decryptedExchangeKey, 'raw'))],
307
+ ['accessControlSecret', data.decryptedAccessControlSecret],
308
+ ['publicKeysFingerprints', data.publicKeysFingerprintsV2.sort()],
289
309
  ];
290
310
  const signJson = JSON.stringify(signObject);
291
- return this.primitives.sha256((0, utils_1.utf8_2ua)(signJson));
311
+ return (0, utils_1.utf8_2ua)(signJson);
312
+ });
313
+ }
314
+ bytesToSignForDelegatorSignature(data) {
315
+ return __awaiter(this, void 0, void 0, function* () {
316
+ return this.primitives.sha256(yield this.primitives.HMAC.exportKey(data.sharedSignatureKey));
292
317
  });
293
318
  }
294
319
  // Generates a new exchange key
@@ -306,6 +331,17 @@ class BaseExchangeDataManager {
306
331
  return yield this.primitives.AES.importKey('raw', decryptedBytes);
307
332
  });
308
333
  }
334
+ generateSharedSignatureKey() {
335
+ return __awaiter(this, void 0, void 0, function* () {
336
+ const key = yield this.primitives.HMAC.generateKey();
337
+ return { key, rawBytes: yield this.primitives.HMAC.exportKey(key) };
338
+ });
339
+ }
340
+ importSharedSignatureKey(decryptedBytes) {
341
+ return __awaiter(this, void 0, void 0, function* () {
342
+ return yield this.primitives.HMAC.importKey(decryptedBytes);
343
+ });
344
+ }
309
345
  // Generates a new access control secret
310
346
  generateAccessControlSecret() {
311
347
  return __awaiter(this, void 0, void 0, function* () {
@@ -323,12 +359,12 @@ class BaseExchangeDataManager {
323
359
  return __awaiter(this, void 0, void 0, function* () {
324
360
  const res = {};
325
361
  for (const [fp, key] of Object.entries(keys)) {
326
- res[(0, utils_2.fingerprintIsV1)(fp) ? (0, utils_2.fingerprintV1toV2)(fp) : fp] = (0, utils_1.ua2b64)(yield this.primitives.RSA.encrypt(key, (0, utils_1.utf8_2ua)((0, utils_1.ua2hex)(rawData))));
362
+ res[(0, utils_2.fingerprintIsV1)(fp) ? (0, utils_2.fingerprintV1toV2)(fp) : fp] = (0, utils_1.ua2b64)(yield this.primitives.RSA.encrypt(key, new Uint8Array(rawData)));
327
363
  }
328
364
  return res;
329
365
  });
330
366
  }
331
- signDataWithKeys(rawData, keys) {
367
+ signDataWithDelegatorKeys(rawData, keys) {
332
368
  return __awaiter(this, void 0, void 0, function* () {
333
369
  const res = {};
334
370
  for (const [fp, key] of Object.entries(keys)) {
@@ -337,6 +373,29 @@ class BaseExchangeDataManager {
337
373
  return res;
338
374
  });
339
375
  }
376
+ verifyDelegatorSignature(exchangeData, decryptedSharedSignatureKey, getVerificationKey) {
377
+ return __awaiter(this, void 0, void 0, function* () {
378
+ const delegatorSignatureData = yield this.bytesToSignForDelegatorSignature({
379
+ sharedSignatureKey: decryptedSharedSignatureKey,
380
+ });
381
+ for (const [fp, signature] of Object.entries(exchangeData.delegatorSignature)) {
382
+ const verificationKey = yield getVerificationKey(fp.slice(-32));
383
+ if (verificationKey && (yield this.primitives.RSA.verifySignature(verificationKey, (0, utils_1.b64_2ua)(signature), delegatorSignatureData)))
384
+ return true;
385
+ }
386
+ return false;
387
+ });
388
+ }
389
+ signDataWithSharedKey(rawData, key) {
390
+ return __awaiter(this, void 0, void 0, function* () {
391
+ return (0, utils_1.ua2b64)(yield this.primitives.HMAC.sign(key, new Uint8Array(rawData)));
392
+ });
393
+ }
394
+ verifyDataWithSharedKey(rawData, key, signature) {
395
+ return __awaiter(this, void 0, void 0, function* () {
396
+ return yield this.primitives.HMAC.verify(key, new Uint8Array(rawData), (0, utils_1.b64_2ua)(signature));
397
+ });
398
+ }
340
399
  }
341
400
  exports.BaseExchangeDataManager = BaseExchangeDataManager;
342
401
  //# sourceMappingURL=BaseExchangeDataManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseExchangeDataManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/BaseExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,4EAAwE;AAExE,+CAA2C;AAC3C,IAAO,QAAQ,GAAG,SAAG,CAAC,QAAQ,CAAA;AAE9B,oCAA6E;AAC7E,4BAA2B;AAC3B,mCAA4D;AAE5D;;;;GAIG;AACH,MAAa,uBAAuB;IAClC,YACW,GAAuB,EACf,YAA8B,EAC9B,UAA4B,EAC5B,gCAAyC;QAHjD,QAAG,GAAH,GAAG,CAAoB;QACf,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,eAAU,GAAV,UAAU,CAAkB;QAC5B,qCAAgC,GAAhC,gCAAgC,CAAS;IACzD,CAAC;IAEJ;;;;;;OAMG;IACG,8CAA8C;;;YAClD,IAAI,CAAC,IAAI,CAAC,gCAAgC;gBAAE,OAAO,SAAS,CAAA;YAC5D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAA;YACnE,IAAI,YAAY,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,4BAA4B,CAAC,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;YAC5F,MAAM,YAAY,GAAG,MAAA,YAAY,CAAC,IAAI,mCAAI,EAAE,CAAA;YAC5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,EAAE,CAAC,GAAG,IAAA,cAAM,EAAC,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;aAC/E;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;KAAA;CACF;AArXD,0DAqXC","sourcesContent":["import { IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { KeyPair } from './RSA'\nimport { ExchangeData } from '../../icc-api/model/internal/ExchangeData'\nimport { IccExchangeDataApi } from '../../icc-api/api/IccExchangeDataApi'\nimport { XHR } from '../../icc-api/api/XHR'\nimport XHRError = XHR.XHRError\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { b64_2ua, hex2ua, ua2b64, ua2hex, ua2utf8, utf8_2ua } from '../utils'\nimport * as _ from 'lodash'\nimport { fingerprintV1toV2, fingerprintIsV1 } from './utils'\n\n/**\n * @internal this class is intended for internal use only and may be modified without notice\n * Functions to create and get exchange data.\n * The methods of this api require to pass the appropriate keys for encryption/decryption manually.\n */\nexport class BaseExchangeDataManager {\n constructor(\n readonly api: IccExchangeDataApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly primitives: CryptoPrimitives,\n private readonly selfRequiresAnonymousDelegations: boolean\n ) {}\n\n /**\n * Get all the exchange data where the current data owner is the delegator or the delegate. However, some data owners, generally HCPs, may have a\n * prohibitively high amount of exchange data. If the crypto strategies specify that the current data owner requires anonymous delegation this\n * method returns all the exchange data found for the data owner, else the method returns undefined.\n * @return all the exchange data for the current data owner or undefined if the crypto strategies don't allow to retrieve all data for the current\n * data owner.\n */\n async getAllExchangeDataForCurrentDataOwnerIfAllowed(): Promise<ExchangeData[] | undefined> {\n if (!this.selfRequiresAnonymousDelegations) return undefined\n const dataOwnerId = await this.dataOwnerApi.getCurrentDataOwnerId()\n let latestResult = await this.api.getExchangeDataByParticipant(dataOwnerId, undefined, 1000)\n const allRetrieved = latestResult.rows ?? []\n while (latestResult.nextKeyPair?.startKeyDocId) {\n latestResult = await this.api.getExchangeDataByParticipant(dataOwnerId, latestResult.nextKeyPair.startKeyDocId, 1000)\n if (latestResult.rows) allRetrieved.push(...latestResult.rows)\n }\n return allRetrieved\n }\n\n /**\n * Get all exchange data for the provided delegator-delegate pair.\n * @param delegatorId id of a delegator data owner.\n * @param delegateId id of a delegate data owner.\n * @return all exchange data for the provided delegator-delegate pair.\n */\n async getExchangeDataByDelegatorDelegatePair(delegatorId: string, delegateId: string): Promise<ExchangeData[]> {\n return await this.api.getExchangeDataByDelegatorDelegate(delegatorId, delegateId)\n }\n\n /**\n * Get the exchange data with the provided id.\n * @param exchangeDataId id of the exchange data.\n * @return the exchange data with the provided id or undefined if no exchange data with such id could be found.\n */\n async getExchangeDataById(exchangeDataId: string): Promise<ExchangeData | undefined> {\n return await this.api.getExchangeDataById(exchangeDataId).catch((e) => {\n if (e instanceof XHRError && e.statusCode === 404) {\n return undefined\n } else throw e\n })\n }\n\n /**\n * Filters exchange data returning only the instances that could be verified using their signature and the provided verification\n * keys.\n * Note that all exchange data created by data owners other than the current data owner (including members of his hierarchy)\n * will always be unverified.\n * @param exchangeData the exchange data to verify.\n * @param getVerificationKey function to retrieve keys to use for verification by fingerprint.\n * @return the exchange data which could be verified given his signature and the available verification keys.\n * @throws if any of the provided exchange data has been created by a data owner other than the current data owner.\n */\n async filterVerifiedExchangeData(\n exchangeData: ExchangeData[],\n getVerificationKey: (publicKeyFingerprint: string) => Promise<CryptoKey | undefined>\n ): Promise<ExchangeData[]> {\n const verified: ExchangeData[] = []\n for (const ed of exchangeData) {\n if (await this.verifyExchangeData(ed, (x) => getVerificationKey(x))) verified.push(ed)\n }\n return verified\n }\n\n /**\n * Verifies the authenticity of the exchange data by checking the signature.\n * Note that all exchange data created by data owners other than the current data owner (including members of his hierarchy)\n * will always be unverified.\n * @param exchangeData the exchange data to verify.\n * @param getVerificationKey function to retrieve keys to use for verification by fingerprint.\n * @return the exchange data which could be verified given his signature and the available verification keys.\n * @throws if any of the provided exchange data has been created by a data owner other than the current data owner.\n */\n async verifyExchangeData(\n exchangeData: ExchangeData,\n getVerificationKey: (publicKeyFingerprint: string) => Promise<CryptoKey | undefined>\n ): Promise<boolean> {\n const dataOwnerId = await this.dataOwnerApi.getCurrentDataOwnerId()\n if (exchangeData.delegator !== dataOwnerId) return false\n const signatureData = await this.bytesToSign(exchangeData)\n for (const [fp, signature] of Object.entries(exchangeData.signature)) {\n const verificationKey = await getVerificationKey(fp.slice(-32))\n if (verificationKey && (await this.primitives.RSA.verifySignature(verificationKey, b64_2ua(signature), signatureData))) return true\n }\n return false\n }\n\n /**\n * Extracts and decrypts the access control secret from the provided exchange data.\n * These need to be hashed together with the entity class and confidentiality level in order to get the actual access control key\n * which will be sent to the server.\n * @param exchangeData the exchange data from which to extract access control secrets.\n * @param decryptionKeys rsa key pairs to use for decryption of the access control secret.\n * @return an object composed of:\n * - successfulDecryptions: array of all successfully decrypted access control keys\n * - failedDecryptions: array containing all exchange data for which the access control key could not be decrypted (using the provided keys).\n */\n async tryDecryptAccessControlSecret(\n exchangeData: ExchangeData[],\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> }\n ): Promise<{\n successfulDecryptions: string[]\n failedDecryptions: ExchangeData[]\n }> {\n return await this.tryDecryptExchangeData(\n exchangeData,\n decryptionKeys,\n (ed) => ed.accessControlSecret,\n (d) => this.importAccessControlSecret(new Uint8Array(d))\n )\n }\n\n /**\n * Extract and decrypts the exchange keys from the provided exchange data.\n * @param exchangeData the exchange data from which to extract exchange keys.\n * @param decryptionKeys rsa key pairs to use for the decryption of the exchange keys.\n * @return an object composed of:\n * - successfulDecryptions: array containing the successfully decrypted exchange keys.\n * - failedDecryptions: array containing all exchange data for which the access control key could not be decrypted (using the provided keys).\n */\n async tryDecryptExchangeKeys(\n exchangeData: ExchangeData[],\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> }\n ): Promise<{\n successfulDecryptions: CryptoKey[]\n failedDecryptions: ExchangeData[]\n }> {\n return await this.tryDecryptExchangeData(\n exchangeData,\n decryptionKeys,\n (ed) => ed.exchangeKey,\n (d) => this.importExchangeKey(new Uint8Array(d))\n )\n }\n\n private async tryDecryptExchangeData<T>(\n exchangeData: ExchangeData[],\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> },\n encryptedDataSelector: (data: ExchangeData) => { [keyPairFingerprint: string]: string },\n unmarshalDecrypted: (decrypted: ArrayBuffer) => Promise<T>\n ): Promise<{\n successfulDecryptions: T[]\n failedDecryptions: ExchangeData[]\n }> {\n const successfulDecryptions: T[] = []\n const failedDecryptions: ExchangeData[] = []\n for (const ed of exchangeData) {\n try {\n const decrypted = await this.tryDecrypt(encryptedDataSelector(ed), decryptionKeys)\n if (decrypted) {\n successfulDecryptions.push(await unmarshalDecrypted(decrypted))\n } else {\n failedDecryptions.push(ed)\n }\n } catch (e) {\n failedDecryptions.push(ed)\n }\n }\n return { successfulDecryptions, failedDecryptions }\n }\n\n private async tryDecrypt(\n encryptedData: { [keyPairFingerprintV2: string]: string },\n decryptionKeys: { [publicKeyFingerprintV1: string]: KeyPair<CryptoKey> }\n ): Promise<ArrayBuffer | undefined> {\n const decryptionKeysWithV2Fp = Object.keys(decryptionKeys).reduce((prev, fp) => {\n return {\n ...prev,\n [fingerprintIsV1(fp) ? fingerprintV1toV2(fp) : fp]: decryptionKeys[fp],\n }\n }, {} as { [publicKeyFingerprint: string]: KeyPair<CryptoKey> })\n for (const [fp, encrypted] of Object.entries(encryptedData)) {\n try {\n const key = decryptionKeysWithV2Fp[fp]?.privateKey\n if (key) return hex2ua(ua2utf8(await this.primitives.RSA.decrypt(key, b64_2ua(encrypted))))\n } catch (e) {\n // Try with another key\n }\n }\n }\n\n /**\n * Creates exchange data from the current data owner to the provided delegate, uploading the newly created exchange data to the cloud.\n * This assumes that the keys have been verified.\n * @param delegateId id of the delegate for the new exchange data.\n * @param signatureKeys private keys to use for signing the created data.\n * @param encryptionKeys public keys to use for the encryption of the exchange data (from delegator and delegate).\n * @param optionalAttributes optional precalculated attributes for the creation of data\n * @return the newly created exchange data, and its decrypted exchange key and access control secret.\n */\n async createExchangeData(\n delegateId: string,\n signatureKeys: { [keyPairFingerprint: string]: CryptoKey },\n encryptionKeys: { [keyPairFingerprint: string]: CryptoKey },\n optionalAttributes: {\n id?: string\n } = {}\n ): Promise<{\n exchangeData: ExchangeData\n exchangeKey: CryptoKey\n accessControlSecret: string\n }> {\n if (!Object.keys(signatureKeys).length || !Object.keys(encryptionKeys).length) {\n throw new Error('Must specify at least one signature key and ')\n }\n const exchangeKey = await this.generateExchangeKey()\n const accessControlSecret = await this.generateAccessControlSecret()\n const encryptedExchangeKey = await this.encryptDataWithKeys(exchangeKey.rawBytes, encryptionKeys)\n const encryptedAccessControlSecret = await this.encryptDataWithKeys(accessControlSecret.rawBytes, encryptionKeys)\n const baseExchangeData = {\n id: optionalAttributes.id ?? this.primitives.randomUuid(),\n delegator: await this.dataOwnerApi.getCurrentDataOwnerId(),\n delegate: delegateId,\n exchangeKey: encryptedExchangeKey,\n accessControlSecret: encryptedAccessControlSecret,\n }\n const signature = await this.signDataWithKeys(await this.bytesToSign(baseExchangeData), signatureKeys)\n const exchangeData = new ExchangeData({ ...baseExchangeData, signature })\n return {\n exchangeData: await this.api.createExchangeData(exchangeData),\n exchangeKey: exchangeKey.key,\n accessControlSecret: accessControlSecret.secret,\n }\n }\n\n /**\n * Updates existing exchange data and uploads it to the cloud in order to share it also with additional public keys, useful for example in cases\n * where one of the data owners involved in the exchange data has lost one of his keys.\n * If the content of the exchange data could not be decrypted using the provided keys the method will not update anything and will return undefined.\n * This method assumes that the new encryption keys have been verified.\n * If the current data owner is also the delegator of the provided exchange data and at least one of the verification keys can be used to\n * validate the current exchange data then the signature will be updated using the signature keys.\n * Instead, if the current data owner is not the delegator of the provided exchange data, or the exchange data could not be verified using\n * the provided verification keys then the updated exchange data will become unverified, and won't ever be verifiable again.\n * @param exchangeData exchange data to update.\n * @param decryptionKeys keys to use to extract the content of the exchange data which will be shared with the new keys.\n * @param signatureKeys keys to use for the new signature of the updated exchange data.\n * @param newEncryptionKeys new keys to add to the exchange data.\n * @param getVerificationKey function to retrieve keys to use for verification by fingerprint.\n * @return the updated exchange data, and its decrypted exchange key and access control secret, or undefined if the exchange data content could not\n * be decrypted and the exchange data could not be updated.\n */\n async tryUpdateExchangeData(\n exchangeData: ExchangeData,\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> },\n newEncryptionKeys: { [keyPairFingerprint: string]: CryptoKey },\n signatureKeys: { [keyPairFingerprint: string]: CryptoKey },\n getVerificationKey: (publicKeyFingerprint: string) => Promise<CryptoKey | undefined>\n ): Promise<\n | {\n exchangeData: ExchangeData\n exchangeKey: CryptoKey\n accessControlSecret: string\n }\n | undefined\n > {\n const dataOwnerId = await this.dataOwnerApi.getCurrentDataOwnerId()\n const rawExchangeKey = await this.tryDecrypt(exchangeData.exchangeKey, decryptionKeys)\n const rawAccessControlSecret = await this.tryDecrypt(exchangeData.accessControlSecret, decryptionKeys)\n if (!rawExchangeKey || !rawAccessControlSecret) return undefined\n const exchangeKey = await this.importExchangeKey(new Uint8Array(rawExchangeKey))\n const accessControlSecret = await this.importAccessControlSecret(new Uint8Array(rawAccessControlSecret))\n const existingExchangeKeyEntries = new Set(Object.keys(exchangeData.exchangeKey))\n const existingAcsEntries = new Set(Object.keys(exchangeData.accessControlSecret))\n const missingEntries = Object.keys(newEncryptionKeys).filter((fp) => !existingAcsEntries.has(fp) || !existingExchangeKeyEntries.has(fp))\n if (!missingEntries.length) return { exchangeData, exchangeKey, accessControlSecret }\n const encryptionKeysForMissingEntries = missingEntries.reduce((obj, fp) => {\n obj[fp] = newEncryptionKeys[fp]\n return obj\n }, {} as { [keyPairFingerprint: string]: CryptoKey })\n const isVerified = exchangeData.delegator == dataOwnerId && (await this.verifyExchangeData(exchangeData, (fp) => getVerificationKey(fp)))\n const updatedExchangeData = _.cloneDeep(exchangeData)\n updatedExchangeData.exchangeKey = {\n ...exchangeData.exchangeKey,\n ...(await this.encryptDataWithKeys(rawExchangeKey, encryptionKeysForMissingEntries)),\n }\n updatedExchangeData.accessControlSecret = {\n ...exchangeData.accessControlSecret,\n ...(await this.encryptDataWithKeys(rawAccessControlSecret, encryptionKeysForMissingEntries)),\n }\n if (isVerified) {\n const newDataToSign = await this.bytesToSign(updatedExchangeData)\n updatedExchangeData.signature = await this.signDataWithKeys(newDataToSign, signatureKeys)\n }\n return { exchangeData: await this.api.modifyExchangeData(new ExchangeData(updatedExchangeData)), exchangeKey, accessControlSecret }\n }\n\n // Gets a byte representation of the parts of exchange data which should be included in the signature.\n // Equivalent json representations of the exchange data should provide the same bytes (even if the order of entries\n // is different).\n private async bytesToSign(exchangeData: {\n delegate: string\n delegator: string\n exchangeKey: { [k: string]: string }\n accessControlSecret: { [k: string]: string }\n }): Promise<ArrayBuffer> {\n function sortObject(obj: { [k: string]: string }): [string, string][] {\n return Object.keys(obj)\n .sort()\n .reduce((sorted, key) => {\n return [...sorted, [key, obj[key]]]\n }, [] as [string, string][])\n }\n const signObject = [\n ['delegator', exchangeData.delegator],\n ['delegate', exchangeData.delegate],\n ['exchangeKey', sortObject(exchangeData.exchangeKey)],\n ['accessControlSecret', sortObject(exchangeData.accessControlSecret)],\n ]\n const signJson = JSON.stringify(signObject)\n return this.primitives.sha256(utf8_2ua(signJson))\n }\n\n // Generates a new exchange key\n private async generateExchangeKey(): Promise<{\n key: CryptoKey // the imported key\n rawBytes: ArrayBuffer // the bytes to encrypt for in the exchange data\n }> {\n const rawBytes = await this.primitives.randomBytes(32)\n return {\n key: await this.importExchangeKey(rawBytes),\n rawBytes,\n }\n }\n\n private async importExchangeKey(decryptedBytes: ArrayBuffer): Promise<CryptoKey> {\n return await this.primitives.AES.importKey('raw', decryptedBytes)\n }\n\n // Generates a new access control secret\n private async generateAccessControlSecret(): Promise<{\n secret: string // the imported secret\n rawBytes: ArrayBuffer // the bytes to encrypt for in the exchange data\n }> {\n const rawBytes = await this.primitives.randomBytes(16)\n return {\n secret: await this.importAccessControlSecret(rawBytes),\n rawBytes,\n }\n }\n\n private importAccessControlSecret(decryptedBytes: ArrayBuffer): Promise<string> {\n return Promise.resolve(ua2hex(decryptedBytes))\n }\n\n private async encryptDataWithKeys(\n rawData: ArrayBuffer,\n keys: { [keyPairFingerprintV1: string]: CryptoKey }\n ): Promise<{ [keyPairFingerprintV2: string]: string }> {\n const res: { [keyPairFingerprintV2: string]: string } = {}\n for (const [fp, key] of Object.entries(keys)) {\n res[fingerprintIsV1(fp) ? fingerprintV1toV2(fp) : fp] = ua2b64(await this.primitives.RSA.encrypt(key, utf8_2ua(ua2hex(rawData))))\n }\n return res\n }\n\n private async signDataWithKeys(\n rawData: ArrayBuffer,\n keys: { [keyPairFingerprint: string]: CryptoKey }\n ): Promise<{ [keyPairFingerprint: string]: string }> {\n const res: { [keyPairFingerprint: string]: string } = {}\n for (const [fp, key] of Object.entries(keys)) {\n res[fp] = ua2b64(await this.primitives.RSA.sign(key, new Uint8Array(rawData)))\n }\n return res\n }\n}\n"]}
1
+ {"version":3,"file":"BaseExchangeDataManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/BaseExchangeDataManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,4EAAwE;AAExE,+CAA2C;AAC3C,IAAO,QAAQ,GAAG,SAAG,CAAC,QAAQ,CAAA;AAE9B,oCAA6E;AAC7E,4BAA2B;AAC3B,mCAA4D;AAE5D;;;;GAIG;AACH,MAAa,uBAAuB;IAClC,YACW,GAAuB,EACf,YAA8B,EAC9B,UAA4B,EAC5B,gCAAyC;QAHjD,QAAG,GAAH,GAAG,CAAoB;QACf,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,eAAU,GAAV,UAAU,CAAkB;QAC5B,qCAAgC,GAAhC,gCAAgC,CAAS;IACzD,CAAC;IAEJ;;;;;;OAMG;IACG,8CAA8C;;;YAClD,IAAI,CAA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AG,CAAA;QACZ,CAAC;KAAA;IAEa,wBAAwB,CACpC,YAA0B,EAC1B,2BAAsC,EACtC,kBAAoF;;YAEpF,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAAC,gCAAgC,CAAC;gBACzE,kBAAkB,EAAE,2BAA2B;aAChD,CAAC,CAAA;YACF,KAAK,MAAM,CAAC,EAAE,EAAE,SAAS,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,kBAAkB,CAAC,EAAE;gBAC7E,MAAM,eAAe,GAAG,MAAM,kBAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;gBAC/D,IAAI,eAAe,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,eAAe,CAAC,eAAe,EAAE,IAAA,eAAO,EAAC,SAAS,CAAC,EAAE,sBAAsB,CAAC,CAAC;oBAAE,OAAO,IAAI,CAAA;aAC7I;YACD,OAAO,KAAK,CAAA;QACd,CAAC;KAAA;IAEa,qBAAqB,CAAC,OAAoB,EAAE,GAAc;;YACtE,OAAO,IAAA,cAAM,EAAC,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QAC9E,CAAC;KAAA;IAEa,uBAAuB,CAAC,OAAoB,EAAE,GAAc,EAAE,SAAiB;;YAC3F,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,IAAA,eAAO,EAAC,SAAS,CAAC,CAAC,CAAA;QAC5F,CAAC;KAAA;CACF;AAjdD,0DAidC","sourcesContent":["import { IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { KeyPair } from './RSA'\nimport { ExchangeData } from '../../icc-api/model/internal/ExchangeData'\nimport { IccExchangeDataApi } from '../../icc-api/api/internal/IccExchangeDataApi'\nimport { XHR } from '../../icc-api/api/XHR'\nimport XHRError = XHR.XHRError\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { b64_2ua, hex2ua, ua2b64, ua2hex, ua2utf8, utf8_2ua } from '../utils'\nimport * as _ from 'lodash'\nimport { fingerprintV1toV2, fingerprintIsV1 } from './utils'\n\n/**\n * @internal this class is intended for internal use only and may be modified without notice\n * Functions to create and get exchange data.\n * The methods of this api require to pass the appropriate keys for encryption/decryption manually.\n */\nexport class BaseExchangeDataManager {\n constructor(\n readonly api: IccExchangeDataApi,\n private readonly dataOwnerApi: IccDataOwnerXApi,\n private readonly primitives: CryptoPrimitives,\n private readonly selfRequiresAnonymousDelegations: boolean\n ) {}\n\n /**\n * Get all the exchange data where the current data owner is the delegator or the delegate. However, some data owners, generally HCPs, may have a\n * prohibitively high amount of exchange data. If the crypto strategies specify that the current data owner requires anonymous delegation this\n * method returns all the exchange data found for the data owner, else the method returns undefined.\n * @return all the exchange data for the current data owner or undefined if the crypto strategies don't allow to retrieve all data for the current\n * data owner.\n */\n async getAllExchangeDataForCurrentDataOwnerIfAllowed(): Promise<ExchangeData[] | undefined> {\n if (!this.selfRequiresAnonymousDelegations) return undefined\n const dataOwnerId = await this.dataOwnerApi.getCurrentDataOwnerId()\n let latestResult = await this.api.getExchangeDataByParticipant(dataOwnerId, undefined, 1000)\n const allRetrieved = latestResult.rows ?? []\n while (latestResult.nextKeyPair?.startKeyDocId) {\n latestResult = await this.api.getExchangeDataByParticipant(dataOwnerId, latestResult.nextKeyPair.startKeyDocId, 1000)\n if (latestResult.rows) allRetrieved.push(...latestResult.rows)\n }\n return allRetrieved\n }\n\n /**\n * Get all exchange data for the provided delegator-delegate pair.\n * @param delegatorId id of a delegator data owner.\n * @param delegateId id of a delegate data owner.\n * @return all exchange data for the provided delegator-delegate pair.\n */\n async getExchangeDataByDelegatorDelegatePair(delegatorId: string, delegateId: string): Promise<ExchangeData[]> {\n return await this.api.getExchangeDataByDelegatorDelegate(delegatorId, delegateId)\n }\n\n /**\n * Get the exchange data with the provided id.\n * @param exchangeDataId id of the exchange data.\n * @return the exchange data with the provided id or undefined if no exchange data with such id could be found.\n */\n async getExchangeDataById(exchangeDataId: string): Promise<ExchangeData | undefined> {\n return await this.api.getExchangeDataById(exchangeDataId).catch((e) => {\n if (e instanceof XHRError && e.statusCode === 404) {\n return undefined\n } else throw e\n })\n }\n\n /**\n * Verifies the authenticity of the exchange data by checking the signature.\n * Note that all exchange data created by data owners other than the current data owner (including members of his hierarchy)\n * will always be unverified.\n * @param data collects the following information about the exchange data being verified:\n * - exchangeData the exchange data to verify.\n * - decryptedAccessControlSecret the access control secret decrypted from the exchange data.\n * - decryptedExchangeKey the exchange key decrypted from the exchange data.\n * - decryptedSharedSignatureKey the shared signature key decrypted from the exchange data.\n * @param getVerificationKey function to retrieve keys to use for verification by fingerprint.\n * @param verifyAsDelegator if true the method will also verify that the hmac key used for the signature was created by the delegator of the\n * exchange data. If true and the data was not created by the current data owner this method will return false.\n * @return the exchange data which could be verified given his signature and the available verification keys.\n * @throws if any of the provided exchange data has been created by a data owner other than the current data owner.\n */\n async verifyExchangeData(\n data: {\n exchangeData: ExchangeData\n decryptedAccessControlSecret: string\n decryptedExchangeKey: CryptoKey\n decryptedSharedSignatureKey: CryptoKey\n },\n getVerificationKey: (publicKeyFingerprint: string) => Promise<CryptoKey | undefined>,\n verifyAsDelegator: boolean\n ): Promise<boolean> {\n if (verifyAsDelegator && data.exchangeData.delegator !== (await this.dataOwnerApi.getCurrentDataOwnerId())) return false\n if (verifyAsDelegator && !(await this.verifyDelegatorSignature(data.exchangeData, data.decryptedSharedSignatureKey, getVerificationKey)))\n return false\n const sharedSignatureData = await this.bytesToSignForSharedSignature({\n decryptedAccessControlSecret: data.decryptedAccessControlSecret,\n decryptedExchangeKey: data.decryptedExchangeKey,\n delegator: data.exchangeData.delegator,\n delegate: data.exchangeData.delegate,\n publicKeysFingerprintsV2: [\n ...new Set([\n ...Object.keys(data.exchangeData.exchangeKey),\n ...Object.keys(data.exchangeData.accessControlSecret),\n ...Object.keys(data.exchangeData.sharedSignatureKey),\n ]),\n ],\n })\n return await this.verifyDataWithSharedKey(sharedSignatureData, data.decryptedSharedSignatureKey, data.exchangeData.sharedSignature)\n }\n\n /**\n * Extracts and decrypts the access control secret from the provided exchange data.\n * These need to be hashed together with the entity class and confidentiality level in order to get the actual access control key\n * which will be sent to the server.\n * @param exchangeData the exchange data from which to extract access control secrets.\n * @param decryptionKeys rsa key pairs to use for decryption of the access control secret.\n * @return an object composed of:\n * - successfulDecryptions: array of all successfully decrypted access control keys\n * - failedDecryptions: array containing all exchange data for which the access control key could not be decrypted (using the provided keys).\n */\n async tryDecryptAccessControlSecret(\n exchangeData: ExchangeData[],\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> }\n ): Promise<{\n successfulDecryptions: string[]\n failedDecryptions: ExchangeData[]\n }> {\n return await this.tryDecryptExchangeData(\n exchangeData,\n decryptionKeys,\n (ed) => ed.accessControlSecret,\n (d) => this.importAccessControlSecret(new Uint8Array(d))\n )\n }\n\n /**\n * Extract and decrypts the exchange keys from the provided exchange data.\n * @param exchangeData the exchange data from which to extract exchange keys.\n * @param decryptionKeys rsa key pairs to use for the decryption of the exchange keys.\n * @return an object composed of:\n * - successfulDecryptions: array containing the successfully decrypted exchange keys.\n * - failedDecryptions: array containing all exchange data for which the access control key could not be decrypted (using the provided keys).\n */\n async tryDecryptExchangeKeys(\n exchangeData: ExchangeData[],\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> }\n ): Promise<{\n successfulDecryptions: CryptoKey[]\n failedDecryptions: ExchangeData[]\n }> {\n return await this.tryDecryptExchangeData(\n exchangeData,\n decryptionKeys,\n (ed) => ed.exchangeKey,\n (d) => this.importExchangeKey(new Uint8Array(d))\n )\n }\n\n /**\n * Extract and decrypts the shared signature key from the provided exchange data.\n * @param exchangeData the exchange data from which to extract exchange keys.\n * @param decryptionKeys rsa key pairs to use for the decryption of the exchange keys.\n * @return an object composed of:\n * - successfulDecryptions: array containing the successfully decrypted exchange keys.\n * - failedDecryptions: array containing all exchange data for which the access control key could not be decrypted (using the provided keys).\n */\n async tryDecryptSharedSignatureKeys(\n exchangeData: ExchangeData[],\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> }\n ): Promise<{\n successfulDecryptions: CryptoKey[]\n failedDecryptions: ExchangeData[]\n }> {\n return await this.tryDecryptExchangeData(\n exchangeData,\n decryptionKeys,\n (ed) => ed.sharedSignatureKey,\n (d) => this.importSharedSignatureKey(new Uint8Array(d))\n )\n }\n\n private async tryDecryptExchangeData<T>(\n exchangeData: ExchangeData[],\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> },\n encryptedDataSelector: (data: ExchangeData) => { [keyPairFingerprint: string]: string },\n unmarshalDecrypted: (decrypted: ArrayBuffer) => Promise<T>\n ): Promise<{\n successfulDecryptions: T[]\n failedDecryptions: ExchangeData[]\n }> {\n const successfulDecryptions: T[] = []\n const failedDecryptions: ExchangeData[] = []\n for (const ed of exchangeData) {\n try {\n const decrypted = await this.tryDecrypt(encryptedDataSelector(ed), decryptionKeys)\n if (decrypted) {\n successfulDecryptions.push(await unmarshalDecrypted(decrypted))\n } else {\n failedDecryptions.push(ed)\n }\n } catch (e) {\n failedDecryptions.push(ed)\n }\n }\n return { successfulDecryptions, failedDecryptions }\n }\n\n private async tryDecrypt(\n encryptedData: { [keyPairFingerprintV2: string]: string },\n decryptionKeys: { [publicKeyFingerprintV1: string]: KeyPair<CryptoKey> }\n ): Promise<ArrayBuffer | undefined> {\n const decryptionKeysWithV2Fp = Object.keys(decryptionKeys).reduce((prev, fp) => {\n return {\n ...prev,\n [fingerprintIsV1(fp) ? fingerprintV1toV2(fp) : fp]: decryptionKeys[fp],\n }\n }, {} as { [publicKeyFingerprint: string]: KeyPair<CryptoKey> })\n for (const [fp, encrypted] of Object.entries(encryptedData)) {\n try {\n const key = decryptionKeysWithV2Fp[fp]?.privateKey\n if (key) return await this.primitives.RSA.decrypt(key, b64_2ua(encrypted))\n } catch (e) {\n // Try with another key\n }\n }\n }\n\n /**\n * Creates exchange data from the current data owner to the provided delegate, uploading the newly created exchange data to the cloud.\n * This assumes that the keys have been verified.\n * @param delegateId id of the delegate for the new exchange data.\n * @param signatureKeys private keys to use for signing the created data.\n * @param encryptionKeys public keys to use for the encryption of the exchange data (from delegator and delegate).\n * @param optionalAttributes optional precalculated attributes for the creation of data\n * @return the newly created exchange data, and its decrypted exchange key and access control secret.\n */\n async createExchangeData(\n delegateId: string,\n signatureKeys: { [keyPairFingerprint: string]: CryptoKey },\n encryptionKeys: { [keyPairFingerprint: string]: CryptoKey },\n optionalAttributes: {\n id?: string\n } = {}\n ): Promise<{\n exchangeData: ExchangeData\n exchangeKey: CryptoKey\n accessControlSecret: string\n }> {\n if (!Object.keys(signatureKeys).length || !Object.keys(encryptionKeys).length) {\n throw new Error('Must specify at least one signature key and ')\n }\n const exchangeKey = await this.generateExchangeKey()\n const accessControlSecret = await this.generateAccessControlSecret()\n const sharedSignatureKey = await this.generateSharedSignatureKey()\n const encryptedExchangeKey = await this.encryptDataWithKeys(exchangeKey.rawBytes, encryptionKeys)\n const encryptedAccessControlSecret = await this.encryptDataWithKeys(accessControlSecret.rawBytes, encryptionKeys)\n const encryptedSharedSignatureKey = await this.encryptDataWithKeys(sharedSignatureKey.rawBytes, encryptionKeys)\n const baseExchangeData = {\n id: optionalAttributes.id ?? this.primitives.randomUuid(),\n delegator: await this.dataOwnerApi.getCurrentDataOwnerId(),\n delegate: delegateId,\n exchangeKey: encryptedExchangeKey,\n accessControlSecret: encryptedAccessControlSecret,\n sharedSignatureKey: encryptedSharedSignatureKey,\n }\n const sharedSignature = await this.signDataWithSharedKey(\n await this.bytesToSignForSharedSignature({\n delegate: baseExchangeData.delegate,\n delegator: baseExchangeData.delegator,\n decryptedAccessControlSecret: accessControlSecret.secret,\n decryptedExchangeKey: exchangeKey.key,\n publicKeysFingerprintsV2: Object.keys(encryptionKeys).map(fingerprintV1toV2),\n }),\n sharedSignatureKey.key\n )\n const delegatorSignature = await this.signDataWithDelegatorKeys(\n await this.bytesToSignForDelegatorSignature({\n sharedSignatureKey: sharedSignatureKey.key,\n }),\n signatureKeys\n )\n const exchangeData = new ExchangeData({ ...baseExchangeData, delegatorSignature, sharedSignature })\n return {\n exchangeData: await this.api.createExchangeData(exchangeData),\n exchangeKey: exchangeKey.key,\n accessControlSecret: accessControlSecret.secret,\n }\n }\n\n /**\n * Updates existing exchange data and uploads it to the cloud in order to share it also with additional public keys, useful for example in cases\n * where one of the data owners involved in the exchange data has lost one of his keys.\n * If the content of the exchange data could not be decrypted using the provided keys the method will not update anything and will return undefined.\n * This method assumes that the new encryption keys have been verified.\n * @param exchangeData exchange data to update.\n * @param decryptionKeys keys to use to extract the content of the exchange data which will be shared with the new keys.\n * @param newEncryptionKeys new keys to add to the exchange data.\n * @return the updated exchange data, and its decrypted exchange key and access control secret, or undefined if the exchange data content could not\n * be decrypted and the exchange data could not be updated.\n */\n async tryUpdateExchangeData(\n exchangeData: ExchangeData,\n decryptionKeys: { [publicKeyFingerprint: string]: KeyPair<CryptoKey> },\n newEncryptionKeys: { [keyPairFingerprint: string]: CryptoKey }\n ): Promise<\n | {\n exchangeData: ExchangeData\n exchangeKey: CryptoKey\n accessControlSecret: string\n }\n | undefined\n > {\n const dataOwnerId = await this.dataOwnerApi.getCurrentDataOwnerId()\n const rawExchangeKey = await this.tryDecrypt(exchangeData.exchangeKey, decryptionKeys)\n const rawAccessControlSecret = await this.tryDecrypt(exchangeData.accessControlSecret, decryptionKeys)\n const rawSharedSignatureKey = await this.tryDecrypt(exchangeData.sharedSignatureKey, decryptionKeys)\n if (!rawExchangeKey || !rawAccessControlSecret || !rawSharedSignatureKey) return undefined\n const exchangeKey = await this.importExchangeKey(new Uint8Array(rawExchangeKey))\n const accessControlSecret = await this.importAccessControlSecret(new Uint8Array(rawAccessControlSecret))\n const sharedSignatureKey = await this.importSharedSignatureKey(new Uint8Array(rawSharedSignatureKey))\n const existingExchangeKeyEntries = new Set(Object.keys(exchangeData.exchangeKey))\n const existingAcsEntries = new Set(Object.keys(exchangeData.accessControlSecret))\n const existingSharedSignatureKeyEntries = new Set(Object.keys(exchangeData.sharedSignatureKey))\n const missingEntries = Object.keys(newEncryptionKeys).filter(\n (fp) => !existingAcsEntries.has(fp) || !existingExchangeKeyEntries.has(fp) || !existingSharedSignatureKeyEntries.has(fp)\n )\n if (!missingEntries.length) return { exchangeData, exchangeKey, accessControlSecret }\n const encryptionKeysForMissingEntries = missingEntries.reduce((obj, fp) => {\n obj[fp] = newEncryptionKeys[fp]\n return obj\n }, {} as { [keyPairFingerprint: string]: CryptoKey })\n const updatedExchangeData = _.cloneDeep(exchangeData)\n updatedExchangeData.exchangeKey = {\n ...exchangeData.exchangeKey,\n ...(await this.encryptDataWithKeys(rawExchangeKey, encryptionKeysForMissingEntries)),\n }\n updatedExchangeData.accessControlSecret = {\n ...exchangeData.accessControlSecret,\n ...(await this.encryptDataWithKeys(rawAccessControlSecret, encryptionKeysForMissingEntries)),\n }\n updatedExchangeData.sharedSignatureKey = {\n ...exchangeData.sharedSignatureKey,\n ...(await this.encryptDataWithKeys(rawSharedSignatureKey, encryptionKeysForMissingEntries)),\n }\n const isVerified = await this.verifyExchangeData(\n {\n exchangeData,\n decryptedAccessControlSecret: accessControlSecret,\n decryptedExchangeKey: exchangeKey,\n decryptedSharedSignatureKey: sharedSignatureKey,\n },\n () => Promise.resolve(undefined),\n false\n )\n if (isVerified) {\n updatedExchangeData.sharedSignature = await this.signDataWithSharedKey(\n await this.bytesToSignForSharedSignature({\n delegate: updatedExchangeData.delegate,\n delegator: updatedExchangeData.delegator,\n decryptedAccessControlSecret: accessControlSecret,\n decryptedExchangeKey: exchangeKey,\n publicKeysFingerprintsV2: Object.keys(updatedExchangeData.exchangeKey),\n }),\n sharedSignatureKey\n )\n }\n return { exchangeData: await this.api.modifyExchangeData(new ExchangeData(updatedExchangeData)), exchangeKey, accessControlSecret }\n }\n\n private async bytesToSignForSharedSignature(data: {\n delegator: string\n delegate: string\n decryptedAccessControlSecret: string\n decryptedExchangeKey: CryptoKey\n publicKeysFingerprintsV2: string[]\n }): Promise<ArrayBuffer> {\n // Use array of array to ensure that order is preserved regardless of how the specific js implementation orders\n // the keys of an object\n const signObject = [\n ['delegator', data.delegator],\n ['delegate', data.delegate],\n ['exchangeKey', ua2hex(await this.primitives.AES.exportKey(data.decryptedExchangeKey, 'raw'))],\n ['accessControlSecret', data.decryptedAccessControlSecret],\n ['publicKeysFingerprints', data.publicKeysFingerprintsV2.sort()],\n ]\n const signJson = JSON.stringify(signObject)\n return utf8_2ua(signJson)\n }\n\n private async bytesToSignForDelegatorSignature(data: { sharedSignatureKey: CryptoKey }): Promise<ArrayBuffer> {\n return this.primitives.sha256(await this.primitives.HMAC.exportKey(data.sharedSignatureKey))\n }\n\n // Generates a new exchange key\n private async generateExchangeKey(): Promise<{\n key: CryptoKey // the imported key\n rawBytes: ArrayBuffer // the bytes to encrypt for in the exchange data\n }> {\n const rawBytes = await this.primitives.randomBytes(32)\n return {\n key: await this.importExchangeKey(rawBytes),\n rawBytes,\n }\n }\n\n private async importExchangeKey(decryptedBytes: ArrayBuffer): Promise<CryptoKey> {\n return await this.primitives.AES.importKey('raw', decryptedBytes)\n }\n\n private async generateSharedSignatureKey(): Promise<{\n key: CryptoKey // the imported key\n rawBytes: ArrayBuffer // the bytes to encrypt for in the exchange data\n }> {\n const key = await this.primitives.HMAC.generateKey()\n return { key, rawBytes: await this.primitives.HMAC.exportKey(key) }\n }\n\n private async importSharedSignatureKey(decryptedBytes: ArrayBuffer): Promise<CryptoKey> {\n return await this.primitives.HMAC.importKey(decryptedBytes)\n }\n\n // Generates a new access control secret\n private async generateAccessControlSecret(): Promise<{\n secret: string // the imported secret\n rawBytes: ArrayBuffer // the bytes to encrypt for in the exchange data\n }> {\n const rawBytes = await this.primitives.randomBytes(16)\n return {\n secret: await this.importAccessControlSecret(rawBytes),\n rawBytes,\n }\n }\n\n private importAccessControlSecret(decryptedBytes: ArrayBuffer): Promise<string> {\n return Promise.resolve(ua2hex(decryptedBytes))\n }\n\n private async encryptDataWithKeys(\n rawData: ArrayBuffer,\n keys: { [keyPairFingerprintV1: string]: CryptoKey }\n ): Promise<{ [keyPairFingerprintV2: string]: string }> {\n const res: { [keyPairFingerprintV2: string]: string } = {}\n for (const [fp, key] of Object.entries(keys)) {\n res[fingerprintIsV1(fp) ? fingerprintV1toV2(fp) : fp] = ua2b64(await this.primitives.RSA.encrypt(key, new Uint8Array(rawData)))\n }\n return res\n }\n\n private async signDataWithDelegatorKeys(\n rawData: ArrayBuffer,\n keys: { [keyPairFingerprint: string]: CryptoKey }\n ): Promise<{ [keyPairFingerprint: string]: string }> {\n const res: { [keyPairFingerprint: string]: string } = {}\n for (const [fp, key] of Object.entries(keys)) {\n res[fp] = ua2b64(await this.primitives.RSA.sign(key, new Uint8Array(rawData)))\n }\n return res\n }\n\n private async verifyDelegatorSignature(\n exchangeData: ExchangeData,\n decryptedSharedSignatureKey: CryptoKey,\n getVerificationKey: (publicKeyFingerprint: string) => Promise<CryptoKey | undefined>\n ): Promise<Boolean> {\n const delegatorSignatureData = await this.bytesToSignForDelegatorSignature({\n sharedSignatureKey: decryptedSharedSignatureKey,\n })\n for (const [fp, signature] of Object.entries(exchangeData.delegatorSignature)) {\n const verificationKey = await getVerificationKey(fp.slice(-32))\n if (verificationKey && (await this.primitives.RSA.verifySignature(verificationKey, b64_2ua(signature), delegatorSignatureData))) return true\n }\n return false\n }\n\n private async signDataWithSharedKey(rawData: ArrayBuffer, key: CryptoKey): Promise<string> {\n return ua2b64(await this.primitives.HMAC.sign(key, new Uint8Array(rawData)))\n }\n\n private async verifyDataWithSharedKey(rawData: ArrayBuffer, key: CryptoKey, signature: string): Promise<boolean> {\n return await this.primitives.HMAC.verify(key, new Uint8Array(rawData), b64_2ua(signature))\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { RSAUtils } from './RSA';
2
2
  import { AESUtils } from './AES';
3
3
  import { ShamirClass } from './shamir';
4
+ import { HMACUtils } from './HMACUtils';
4
5
  /**
5
6
  * Gives access to cryptographic primitives.
6
7
  */
@@ -9,10 +10,12 @@ export declare class CryptoPrimitives {
9
10
  private readonly _aes;
10
11
  private readonly _shamir;
11
12
  private readonly _crypto;
13
+ private readonly _hmac;
12
14
  get crypto(): Crypto;
13
15
  get shamir(): ShamirClass;
14
16
  get RSA(): RSAUtils;
15
17
  get AES(): AESUtils;
18
+ get HMAC(): HMACUtils;
16
19
  constructor(crypto?: Crypto);
17
20
  /**
18
21
  * Generates a UUID using a cryptographically secure random number generator.
@@ -4,6 +4,7 @@ exports.CryptoPrimitives = void 0;
4
4
  const RSA_1 = require("./RSA");
5
5
  const AES_1 = require("./AES");
6
6
  const shamir_1 = require("./shamir");
7
+ const HMACUtils_1 = require("./HMACUtils");
7
8
  /**
8
9
  * Gives access to cryptographic primitives.
9
10
  */
@@ -20,11 +21,15 @@ class CryptoPrimitives {
20
21
  get AES() {
21
22
  return this._aes;
22
23
  }
24
+ get HMAC() {
25
+ return this._hmac;
26
+ }
23
27
  constructor(crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : {}) {
24
28
  this._crypto = crypto;
25
29
  this._rsa = new RSA_1.RSAUtils(crypto);
26
30
  this._aes = new AES_1.AESUtils(crypto);
27
31
  this._shamir = new shamir_1.ShamirClass(crypto);
32
+ this._hmac = new HMACUtils_1.HMACUtils(crypto);
28
33
  }
29
34
  /**
30
35
  * Generates a UUID using a cryptographically secure random number generator.
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoPrimitives.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/CryptoPrimitives.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAChC,+BAAgC;AAChC,qCAAsC;AAEtC;;GAEG;AACH,MAAa,gBAAgB;IAM3B,IAAI,MAAM;Q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,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,CAAS;QACnB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;QAC7B,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;QAChC,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AAzDD,4CAyDC","sourcesContent":["import { RSAUtils } from './RSA'\nimport { AESUtils } from './AES'\nimport { ShamirClass } from './shamir'\n\n/**\n * Gives access to cryptographic primitives.\n */\nexport class CryptoPrimitives {\n private readonly _rsa: RSAUtils\n private readonly _aes: AESUtils\n private readonly _shamir: ShamirClass\n private readonly _crypto: Crypto\n\n get crypto(): Crypto {\n return this._crypto\n }\n\n get shamir(): ShamirClass {\n return this._shamir\n }\n\n get RSA(): RSAUtils {\n return this._rsa\n }\n\n get AES(): AESUtils {\n return this._aes\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this._crypto = crypto\n this._rsa = new RSAUtils(crypto)\n this._aes = new AESUtils(crypto)\n this._shamir = new ShamirClass(crypto)\n }\n\n /**\n * Generates a UUID using a cryptographically secure random number generator.\n */\n randomUuid() {\n return ((1e7).toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(\n /[018]/g,\n //Keep next inlined or you will lose the random\n (c) => (Number(c) ^ ((this.crypto.getRandomValues(new Uint8Array(1))! as Uint8Array)[0] & (15 >> (Number(c) / 4)))).toString(16)\n )\n }\n\n /**\n * @param data some data\n * @return the sha256 hash of {@link data}\n */\n sha256(data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer> {\n return this.crypto.subtle.digest('SHA-256', data)\n }\n\n /**\n * @param n how many bytes to generate\n * @return an array with n random bytes\n */\n randomBytes(n: number): Uint8Array {\n const res = new Uint8Array(n)\n this.crypto.getRandomValues(res)\n return res\n }\n}\n"]}
1
+ {"version":3,"file":"CryptoPrimitives.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/CryptoPrimitives.ts"],"names":[],"mappings":";;;AAAA,+BAAgC;AAChC,+BAAgC;AAChC,qCAAsC;AACtC,2CAAuC;AAEvC;;GAEG;AACH,MAAa,gBAAgB;IAO3B,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QACrI,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,cAAQ,CAAC,MAAM,CAAC,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,cAAQ,CAAC,MAAM,CAAC,CAAA;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,oBAAW,CAAC,MAAM,CAAC,CAAA;QACtC,IAAI,CAAC,KAAK,GAAG,IAAI,qBAAS,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAC5D,QAAQ;QACR,+CAA+C;QAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAE,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CACjI,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,IAA8B;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAED;;;OAGG;IACH,WAAW,CAAC,CAAS;QACnB,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAA;QAC7B,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;QAChC,OAAO,GAAG,CAAA;IACZ,CAAC;CACF;AA/DD,4CA+DC","sourcesContent":["import { RSAUtils } from './RSA'\nimport { AESUtils } from './AES'\nimport { ShamirClass } from './shamir'\nimport { HMACUtils } from './HMACUtils'\n\n/**\n * Gives access to cryptographic primitives.\n */\nexport class CryptoPrimitives {\n private readonly _rsa: RSAUtils\n private readonly _aes: AESUtils\n private readonly _shamir: ShamirClass\n private readonly _crypto: Crypto\n private readonly _hmac: HMACUtils\n\n get crypto(): Crypto {\n return this._crypto\n }\n\n get shamir(): ShamirClass {\n return this._shamir\n }\n\n get RSA(): RSAUtils {\n return this._rsa\n }\n\n get AES(): AESUtils {\n return this._aes\n }\n\n get HMAC(): HMACUtils {\n return this._hmac\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this._crypto = crypto\n this._rsa = new RSAUtils(crypto)\n this._aes = new AESUtils(crypto)\n this._shamir = new ShamirClass(crypto)\n this._hmac = new HMACUtils(crypto)\n }\n\n /**\n * Generates a UUID using a cryptographically secure random number generator.\n */\n randomUuid() {\n return ((1e7).toString() + -1e3 + -4e3 + -8e3 + -1e11).replace(\n /[018]/g,\n //Keep next inlined or you will lose the random\n (c) => (Number(c) ^ ((this.crypto.getRandomValues(new Uint8Array(1))! as Uint8Array)[0] & (15 >> (Number(c) / 4)))).toString(16)\n )\n }\n\n /**\n * @param data some data\n * @return the sha256 hash of {@link data}\n */\n sha256(data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer> {\n return this.crypto.subtle.digest('SHA-256', data)\n }\n\n /**\n * @param n how many bytes to generate\n * @return an array with n random bytes\n */\n randomBytes(n: number): Uint8Array {\n const res = new Uint8Array(n)\n this.crypto.getRandomValues(res)\n return res\n }\n}\n"]}
@@ -17,7 +17,7 @@ const ShareMetadataBehaviour_1 = require("./ShareMetadataBehaviour");
17
17
  const EntityShareRequest_1 = require("../../icc-api/model/requests/EntityShareRequest");
18
18
  var RequestedPermissionEnum = EntityShareRequest_1.EntityShareRequest.RequestedPermissionEnum;
19
19
  const utils_1 = require("../utils");
20
- const IccSecureDelegationKeyMapApi_1 = require("../../icc-api/api/IccSecureDelegationKeyMapApi");
20
+ const IccSecureDelegationKeyMapApi_1 = require("../../icc-api/api/internal/IccSecureDelegationKeyMapApi");
21
21
  const XHR_1 = require("../../icc-api/api/XHR");
22
22
  const AuthenticationProvider_1 = require("../auth/AuthenticationProvider");
23
23
  const AccessControlKeysHeadersProvider_1 = require("./AccessControlKeysHeadersProvider");