@icure/api 8.6.3 → 8.6.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 (93) hide show
  1. package/icc-api/model/CryptoActorStub.d.ts +2 -0
  2. package/icc-api/model/CryptoActorStub.js.map +1 -1
  3. package/icc-api/model/Device.d.ts +1 -0
  4. package/icc-api/model/Device.js.map +1 -1
  5. package/icc-api/model/HealthcareParty.d.ts +1 -0
  6. package/icc-api/model/HealthcareParty.js.map +1 -1
  7. package/icc-api/model/ModelHelper.d.ts +1 -1
  8. package/icc-api/model/ModelHelper.js +15 -2
  9. package/icc-api/model/ModelHelper.js.map +1 -1
  10. package/icc-api/model/Patient.d.ts +1 -0
  11. package/icc-api/model/Patient.js.map +1 -1
  12. package/icc-api/model/User.d.ts +1 -0
  13. package/icc-api/model/User.js.map +1 -1
  14. package/icc-x-api/crypto/AES.js +1 -1
  15. package/icc-x-api/crypto/AES.js.map +1 -1
  16. package/icc-x-api/crypto/BaseExchangeDataManager.js +14 -14
  17. package/icc-x-api/crypto/BaseExchangeDataManager.js.map +1 -1
  18. package/icc-x-api/crypto/BaseExchangeKeysManager.js +1 -1
  19. package/icc-x-api/crypto/BaseExchangeKeysManager.js.map +1 -1
  20. package/icc-x-api/crypto/CryptoPrimitives.js +3 -2
  21. package/icc-x-api/crypto/CryptoPrimitives.js.map +1 -1
  22. package/icc-x-api/crypto/CryptoStrategies.d.ts +2 -1
  23. package/icc-x-api/crypto/CryptoStrategies.js.map +1 -1
  24. package/icc-x-api/crypto/ExchangeDataManager.js +3 -3
  25. package/icc-x-api/crypto/ExchangeDataManager.js.map +1 -1
  26. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +1 -1
  27. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
  28. package/icc-x-api/crypto/KeyRecovery.js +3 -3
  29. package/icc-x-api/crypto/KeyRecovery.js.map +1 -1
  30. package/icc-x-api/crypto/NativeCryptoPrimitivesBridge.js +13 -13
  31. package/icc-x-api/crypto/NativeCryptoPrimitivesBridge.js.map +1 -1
  32. package/icc-x-api/crypto/RSA.js +2 -2
  33. package/icc-x-api/crypto/RSA.js.map +1 -1
  34. package/icc-x-api/crypto/RecoveryDataEncryption.js +5 -5
  35. package/icc-x-api/crypto/RecoveryDataEncryption.js.map +1 -1
  36. package/icc-x-api/crypto/SecureDelegationsManager.js +1 -1
  37. package/icc-x-api/crypto/SecureDelegationsManager.js.map +1 -1
  38. package/icc-x-api/crypto/ShamirKeysManager.js +1 -1
  39. package/icc-x-api/crypto/ShamirKeysManager.js.map +1 -1
  40. package/icc-x-api/crypto/UserEncryptionKeysManager.js +2 -2
  41. package/icc-x-api/crypto/UserEncryptionKeysManager.js.map +1 -1
  42. package/icc-x-api/crypto/utils.js +1 -1
  43. package/icc-x-api/crypto/utils.js.map +1 -1
  44. package/icc-x-api/filters/HealthElementByHcPartyCodeFilter.d.ts +24 -0
  45. package/icc-x-api/filters/HealthElementByHcPartyCodeFilter.js +24 -0
  46. package/icc-x-api/filters/HealthElementByHcPartyCodeFilter.js.map +1 -0
  47. package/icc-x-api/filters/HealthElementByHcPartyIdentifiersVersioningFilter.d.ts +22 -0
  48. package/icc-x-api/filters/HealthElementByHcPartyIdentifiersVersioningFilter.js +24 -0
  49. package/icc-x-api/filters/HealthElementByHcPartyIdentifiersVersioningFilter.js.map +1 -0
  50. package/icc-x-api/filters/HealthElementByHcPartyStatusVersioningFilter.d.ts +21 -0
  51. package/icc-x-api/filters/HealthElementByHcPartyStatusVersioningFilter.js +24 -0
  52. package/icc-x-api/filters/HealthElementByHcPartyStatusVersioningFilter.js.map +1 -0
  53. package/icc-x-api/filters/HealthElementByHcPartyTagFilter.d.ts +24 -0
  54. package/icc-x-api/filters/HealthElementByHcPartyTagFilter.js +24 -0
  55. package/icc-x-api/filters/HealthElementByHcPartyTagFilter.js.map +1 -0
  56. package/icc-x-api/filters/VersionFiltering.d.ts +14 -0
  57. package/icc-x-api/filters/VersionFiltering.js +19 -0
  58. package/icc-x-api/filters/VersionFiltering.js.map +1 -0
  59. package/icc-x-api/filters/filters.d.ts +8 -4
  60. package/icc-x-api/filters/filters.js +4 -0
  61. package/icc-x-api/filters/filters.js.map +1 -1
  62. package/icc-x-api/icc-receipt-x-api.js +1 -1
  63. package/icc-x-api/icc-receipt-x-api.js.map +1 -1
  64. package/icc-x-api/utils/binary-utils.js +1 -1
  65. package/icc-x-api/utils/binary-utils.js.map +1 -1
  66. package/package.json +1 -1
  67. package/test/icc-api/api/IccAnonymousAccessApi.js +1 -1
  68. package/test/icc-api/api/IccAnonymousAccessApi.js.map +1 -1
  69. package/test/icc-api/api/IccDocumentApi.js +13 -12
  70. package/test/icc-api/api/IccDocumentApi.js.map +1 -1
  71. package/test/icc-x-api/crud/comprehensive-crud-test.js +2 -2
  72. package/test/icc-x-api/crud/comprehensive-crud-test.js.map +1 -1
  73. package/test/icc-x-api/crypto/crypto-utils.js +1 -1
  74. package/test/icc-x-api/crypto/crypto-utils.js.map +1 -1
  75. package/test/icc-x-api/crypto/soft-deleted-data-owners.js +1 -1
  76. package/test/icc-x-api/crypto/soft-deleted-data-owners.js.map +1 -1
  77. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js +1 -1
  78. package/test/icc-x-api/crypto/user-encryption-keys-manager-test.js.map +1 -1
  79. package/test/icc-x-api/filters/healthelement.d.ts +1 -0
  80. package/test/icc-x-api/filters/healthelement.js +333 -0
  81. package/test/icc-x-api/filters/healthelement.js.map +1 -0
  82. package/test/icc-x-api/test-legacy-data-support.js +4 -4
  83. package/test/icc-x-api/test-legacy-data-support.js.map +1 -1
  84. package/test/support/CSM-729.d.ts +1 -0
  85. package/test/support/CSM-729.js +225 -0
  86. package/test/support/CSM-729.js.map +1 -0
  87. package/test/utils/TestCryptoStrategies.js +1 -1
  88. package/test/utils/TestCryptoStrategies.js.map +1 -1
  89. package/test/utils/roles.d.ts +1 -0
  90. package/test/utils/roles.js +1 -0
  91. package/test/utils/roles.js.map +1 -1
  92. package/test/utils/test_utils.js +2 -2
  93. package/test/utils/test_utils.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"test-legacy-data-support.js","sourceRoot":"","sources":["../../../test/icc-x-api/test-legacy-data-support.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AACzB,wCAA2D;AAC3D,wCAAkJ;AAClJ,+CASwB;AACxB,oDAAgF;AAEhF,+BAA6B;AAC7B,mCAAkC;AAElC,+BAAiC;AACjC,yEAAqE;AACrE,sDAAuF;AACvF,wEAAoE;AACpE,wFAAoF;AACpF,mDAAmE;AACnE,wDAAiG;AACjG,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,uBAAuB,CAAA;AA+B3E,SAAS,kBAAkB,CAAC,MAAqB,EAAE,QAAuB,EAAE,UAAkB;IAC5F,IAAA,aAAM,EAAC,MAAM,CAAC,aAAa,EAAE,GAAG,UAAU,mBAAmB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IAC/F,IAAA,aAAM,EAAC,MAAM,CAAC,SAAS,EAAE,GAAG,UAAU,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAChG,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;QAC5C,IAAA,aAAM,EAAC,MAAM,CAAC,SAAS,EAAE,GAAG,UAAU,cAAc,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAC9E,CAAC;IACD,IAAA,aAAM,EAAC,MAAM,CAAC,eAAe,EAAE,GAAG,UAAU,qBAAqB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;IAClH,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,eAAe,EAAE,CAAC;QACl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B,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,6CAA6C,OAAO,GAAG,CAAC,CAAA;wBACnI,MAAM,gBAAgB,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC,CAAA;wBAChG,kBAAkB,CAAC,MAAM,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,+BAA+B,OAAO,GAAG,CAAC,CAAA;oBACjH,CAAC;oBACD,kBAAkB,CAAC,MAAM,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,2CAA2C,CAAC,CAAA;gBACtH,CAAC;aAAA,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\nimport { Api as ApiV6, User as UserV6 } from '@icure/apiV6'\nimport { CryptoStrategies as CryptoStrategiesV7, DataOwnerWithType as DataOwnerWithTypeV7, IcureApi as ApiV7, User as UserV7 } from '@icure/apiV7'\nimport {\n WebCryptoPrimitives,\n EntityWithDelegationTypeName,\n hex2ua,\n IcureApi as ApiV8,\n RSAUtils,\n RSAUtilsImpl,\n ShaVersion,\n ua2hex,\n} from '../../icc-x-api'\nimport { getEnvironmentInitializer, setLocalStorage } from '../utils/test_utils'\nimport { KeyPair } from '../../icc-x-api/crypto/RSA'\nimport { expect } from 'chai'\nimport { webcrypto } from 'crypto'\nimport { CryptoPrimitives } from '../../icc-x-api/crypto/CryptoPrimitives'\nimport { v4 as uuid } from 'uuid'\nimport { HealthcareParty } from '../../icc-api/model/HealthcareParty'\nimport { TestKeyStorage, TestStorage, testStorageWithKeys } from '../utils/TestStorage'\nimport { TestCryptoStrategies } from '../utils/TestCryptoStrategies'\nimport { EntityShareRequest } from '../../icc-api/model/requests/EntityShareRequest'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from '../../icc-x-api/crypto/utils'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\n\ntype UserCredentials = {\n login: string\n password: string\n ownerId: string\n key: KeyPair<CryptoKey>\n}\ntype EncryptedData = {\n secretContent: string\n secretIds: string[]\n owningEntityIds: string[]\n}\n\ninterface UniformizedMasterApi {\n createUser(): Promise<UserCredentials>\n}\n\ninterface UniformizedTestApi {\n userDetails(): Promise<{ userId: string; dataOwnerId: string }>\n createEncryptedData(): Promise<{ id: string } & EncryptedData>\n getDecryptedData(id: string): Promise<EncryptedData>\n shareEncryptedData(dataId: string, delegateId: string): Promise<void>\n}\n\ninterface ApiFactory {\n readonly version: string\n masterApi(env: TestVars): Promise<UniformizedMasterApi>\n testApi(credentials: UserCredentials): Promise<UniformizedTestApi>\n}\n\nfunction checkEncryptedData(actual: EncryptedData, expected: EncryptedData, actualName: string) {\n expect(actual.secretContent, `${actualName} - secret content`).to.equal(expected.secretContent)\n expect(actual.secretIds, `${actualName} - secret ids`).to.have.length(expected.secretIds.length)\n for (const expectedId of expected.secretIds) {\n expect(actual.secretIds, `${actualName} - secret id`).to.contain(expectedId)\n }\n expect(actual.owningEntityIds, `${actualName} - owning entity id`).to.have.length(expected.owningEntityIds.length)\n for (const expectedId of expected.owningEntityIds) {\n expect(actual.owningEntityIds, `${actualName} - owning entity id`).to.contain(expectedId)\n }\n}\n\nsetLocalStorage(fetch)\nconst cryptoPrimitives = new WebCryptoPrimitives(webcrypto as any)\nlet env: TestVars\n\nclass ApiFactoryV6 implements ApiFactory {\n readonly version: string = 'apiV6.x'\n\n async masterApi(env: TestVars): Promise<UniformizedMasterApi> {\n const apis = await ApiV6(\n env.iCureUrl + '/rest/v1',\n env.masterHcp!.user,\n env.masterHcp!.password,\n webcrypto as any,\n fetch,\n false,\n false,\n new TestStorage(),\n new TestKeyStorage()\n )\n return <UniformizedMasterApi>{\n createUser: async () => {\n const pair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha1)\n const hcp = await apis.healthcarePartyApi.createHealthcareParty(new HealthcareParty({ id: uuid(), firstName: `name`, lastName: 'v6' }))\n const user = await apis.userApi.createUser(\n new UserV6({\n id: uuid(),\n login: `v6-${uuid()}`,\n status: 'ACTIVE',\n healthcarePartyId: hcp.id,\n })\n )\n return {\n login: user.login,\n password: await apis.userApi.getToken(user.id!, uuid()),\n key: pair,\n ownerId: hcp.id,\n }\n },\n }\n }\n\n async testApi(credentials: UserCredentials): Promise<UniformizedTestApi> {\n const apis = await ApiV6(env.iCureUrl + '/rest/v1', credentials.login, credentials.password, webcrypto as any, fetch)\n // await apis.cryptoApi.cacheKeyPair(await cryptoPrimitives.RSA.exportKeys(credentials.key, \"jwk\", \"jwk\"))\n const user = await apis.userApi.getCurrentUser()\n await apis.cryptoApi.addKeyPairForOwner(\n apis.maintenanceTaskApi,\n user,\n await apis.cryptoApi.getDataOwner(credentials.ownerId),\n credentials.key,\n false,\n false\n )\n return {\n userDetails: async () => {\n return { userId: user.id!, dataOwnerId: credentials.ownerId }\n },\n createEncryptedData: async () => {\n const note = `v6 note ${uuid()}`\n const patient = await apis.patientApi.createPatientWithUser(user, await apis.patientApi.newInstance(user))\n const healthdata = await apis.healthcareElementApi.createHealthElementWithUser(\n user,\n await apis.healthcareElementApi.newInstance(user, patient, { note })\n )\n return {\n id: healthdata.id,\n secretContent: note,\n secretIds: (await apis.cryptoApi.extractDelegationsSFKs(healthdata, credentials.ownerId)).extractedKeys,\n owningEntityIds: [patient.id! as string],\n }\n },\n getDecryptedData: async (id) => {\n const healthdata = await apis.healthcareElementApi.getHealthElementWithUser(user, id)\n return {\n secretContent: healthdata.note!,\n secretIds: (await apis.cryptoApi.extractDelegationsSFKs(healthdata, credentials.ownerId)).extractedKeys,\n owningEntityIds: (await apis.cryptoApi.extractCryptedFKs(healthdata, credentials.ownerId)).extractedKeys,\n }\n },\n shareEncryptedData: async (dataId, delegateId) => {\n const healthElement = await apis.healthcareElementApi.getHealthElementWithUser(user, dataId)\n const patientIds = (await apis.cryptoApi.extractCryptedFKs(healthElement, credentials.ownerId)).extractedKeys\n expect(patientIds).to.have.length(1)\n const patient = await apis.patientApi.getPatientWithUser(user, patientIds[0])\n const secretIds = (await apis.cryptoApi.extractDelegationsSFKs(healthElement, credentials.ownerId)).extractedKeys\n expect(secretIds).to.have.length(1)\n await apis.healthcareElementApi.modifyHealthElementWithUser(\n user,\n (\n await apis.cryptoApi.extendedDelegationsAndCryptedForeignKeys(healthElement, patient, credentials.ownerId, delegateId, secretIds[0])\n ).modifiedObject\n )\n },\n }\n }\n}\n\nclass TestCryptoStrategiesV7 implements CryptoStrategiesV7 {\n private readonly RSA = new RSAUtilsImpl(webcrypto as any)\n constructor(private readonly key: KeyPair<CryptoKey> | undefined) {}\n\n async generateNewKeyForDataOwner(self: DataOwnerWithTypeV7): Promise<KeyPair<CryptoKey> | boolean> {\n if (!this.key) return false\n const knownKeys = new Set(...hexPublicKeysWithSha1Of(self))\n if (knownKeys.size <= 0) return this.key\n return false\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithTypeV7\n unknownKeys: string[]\n unavailableKeys: string[]\n }[]\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n const self = keysData[keysData.length - 1].dataOwner\n const knownKeys = new Set([...hexPublicKeysWithSha1Of(self.dataOwner), ...hexPublicKeysWithSha256Of(self.dataOwner)])\n const publicKey = this.key ? ua2hex(await this.RSA.exportKey(this.key.publicKey, 'spki')) : undefined\n return Object.fromEntries(\n await Promise.all(\n keysData.map(async (currData) => {\n if (currData.dataOwner.dataOwner.id! !== self.dataOwner.id!) {\n return [\n currData.dataOwner.dataOwner.id!,\n {\n recoveredKeys: {},\n keyAuthenticity: {},\n },\n ]\n } else if (publicKey === undefined || !knownKeys.has(publicKey)) {\n return [currData.dataOwner.dataOwner.id!, { recoveredKeys: {}, keyAuthenticity: {} }]\n } else {\n return [currData.dataOwner.dataOwner.id!, { recoveredKeys: { [publicKey.slice(-32)]: this.key }, keyAuthenticity: {} }]\n }\n })\n )\n )\n }\n\n verifyDelegatePublicKeys(delegate: any, publicKeys: string[]): Promise<string[]> {\n return Promise.resolve(publicKeys)\n }\n}\nclass ApiFactoryV7 implements ApiFactory {\n readonly version: string = 'apiV7.x'\n\n async masterApi(env: TestVars): Promise<UniformizedMasterApi> {\n const key = {\n privateKey: await cryptoPrimitives.RSA.importKey('pkcs8', hex2ua(env.masterHcp!.privateKey), ['decrypt'], ShaVersion.Sha1),\n publicKey: await cryptoPrimitives.RSA.importKey('spki', hex2ua(env.masterHcp!.publicKey), ['encrypt'], ShaVersion.Sha1),\n }\n const apis = await ApiV7.initialise(\n env.iCureUrl,\n { username: env.masterHcp!.user, password: env.masterHcp!.password },\n new TestCryptoStrategiesV7(key),\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n return <UniformizedMasterApi>{\n createUser: async () => {\n const pair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha1)\n const hcp = await apis.healthcarePartyApi.createHealthcareParty(new HealthcareParty({ id: uuid(), firstName: `name`, lastName: 'v7' }))\n const user = await apis.userApi.createUser(\n new UserV7({\n id: uuid(),\n login: `v7-${uuid()}`,\n status: 'ACTIVE',\n healthcarePartyId: hcp.id,\n })\n )\n return {\n login: user.login,\n password: await apis.userApi.getToken(user.id!, uuid()),\n key: pair,\n ownerId: hcp.id,\n }\n },\n }\n }\n\n async testApi(credentials: UserCredentials): Promise<UniformizedTestApi> {\n const testStorage = await testStorageWithKeys([\n {\n dataOwnerId: credentials.ownerId,\n pairs: [\n {\n keyPair: {\n publicKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.publicKey, 'spki')),\n privateKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.privateKey, 'pkcs8')),\n },\n shaVersion: ShaVersion.Sha1,\n },\n ],\n },\n ])\n const apis = await ApiV7.initialise(\n env.iCureUrl,\n {\n username: credentials.login,\n password: credentials.password,\n },\n new TestCryptoStrategiesV7(credentials.key),\n webcrypto as any,\n fetch,\n {\n storage: testStorage.storage,\n keyStorage: testStorage.keyStorage,\n entryKeysFactory: testStorage.keyFactory,\n }\n )\n const user = await apis.userApi.getCurrentUser()\n return {\n userDetails: async () => {\n return { userId: user.id!, dataOwnerId: credentials.ownerId }\n },\n createEncryptedData: async () => {\n const note = `v7 note ${uuid}`\n const patient = await apis.patientApi.createPatientWithUser(user, await apis.patientApi.newInstance(user))\n const healthdata = await apis.healthcareElementApi.createHealthElementWithUser(\n user,\n await apis.healthcareElementApi.newInstance(user, patient, { note })\n )\n const secretIds = await apis.cryptoApi.entities.secretIdsOf(healthdata)\n expect(secretIds).to.have.length(1)\n return {\n id: healthdata.id,\n secretContent: note,\n secretIds,\n owningEntityIds: [patient.id! as string],\n }\n },\n getDecryptedData: async (id) => {\n const healthdata = await apis.healthcareElementApi.getHealthElementWithUser(user, id)\n return {\n secretContent: healthdata.note!,\n secretIds: await apis.cryptoApi.entities.secretIdsOf(healthdata),\n owningEntityIds: await apis.cryptoApi.entities.owningEntityIdsOf(healthdata),\n }\n },\n shareEncryptedData: async (dataId, delegateId) => {\n const healthElement = await apis.healthcareElementApi.getHealthElementWithUser(user, dataId)\n const encryptionKeys = await apis.cryptoApi.entities.encryptionKeysOf(healthElement)\n const secretIds = await apis.cryptoApi.entities.secretIdsOf(healthElement)\n const owningEntityIds = await apis.cryptoApi.entities.owningEntityIdsOf(healthElement)\n await apis.healthcareElementApi.modifyHealthElementWithUser(\n user,\n await apis.cryptoApi.entities.entityWithExtendedEncryptedMetadata(healthElement, delegateId, secretIds, encryptionKeys, owningEntityIds, [])\n )\n },\n }\n }\n}\n\nclass ApiFactoryV8 implements ApiFactory {\n readonly version: string = 'apiV8.x'\n\n async masterApi(env: TestVars): Promise<UniformizedMasterApi> {\n const key = {\n privateKey: await cryptoPrimitives.RSA.importKey('pkcs8', hex2ua(env.masterHcp!.privateKey), ['decrypt'], ShaVersion.Sha1),\n publicKey: await cryptoPrimitives.RSA.importKey('spki', hex2ua(env.masterHcp!.publicKey), ['encrypt'], ShaVersion.Sha1),\n }\n const apis = await ApiV8.initialise(\n env.iCureUrl,\n { username: env.masterHcp!.user, password: env.masterHcp!.password },\n new TestCryptoStrategies(key),\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n return <UniformizedMasterApi>{\n createUser: async () => {\n const pair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha256)\n const hcp = await apis.healthcarePartyApi.createHealthcareParty(new HealthcareParty({ id: uuid(), firstName: `name`, lastName: 'v7' }))\n const user = await apis.userApi.createUser(\n new UserV7({\n id: uuid(),\n login: `v7-${uuid()}`,\n status: 'ACTIVE',\n healthcarePartyId: hcp.id,\n })\n )\n return {\n login: user.login,\n password: await apis.userApi.getToken(user.id!, uuid()),\n key: pair,\n ownerId: hcp.id,\n }\n },\n }\n }\n\n async testApi(credentials: UserCredentials): Promise<UniformizedTestApi> {\n const testStorage = await testStorageWithKeys([\n {\n dataOwnerId: credentials.ownerId,\n pairs: [\n {\n keyPair: {\n publicKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.publicKey, 'spki')),\n privateKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.privateKey, 'pkcs8')),\n },\n shaVersion: ShaVersion.Sha1,\n },\n ],\n },\n ])\n const apis = await ApiV8.initialise(\n env.iCureUrl,\n {\n username: credentials.login,\n password: credentials.password,\n },\n new TestCryptoStrategies(credentials.key),\n webcrypto as any,\n fetch,\n {\n storage: testStorage.storage,\n keyStorage: testStorage.keyStorage,\n entryKeysFactory: testStorage.keyFactory,\n }\n )\n const user = await apis.userApi.getCurrentUser()\n return {\n userDetails: async () => {\n return { userId: user.id!, dataOwnerId: credentials.ownerId }\n },\n createEncryptedData: async () => {\n const note = `v8 note ${uuid()}`\n const patient = await apis.patientApi.createPatientWithUser(user, await apis.patientApi.newInstance(user))\n const healthdata = await apis.healthcareElementApi.createHealthElementWithUser(\n user,\n await apis.healthcareElementApi.newInstance(user, patient, { note })\n )\n return {\n id: healthdata.id,\n secretContent: note,\n secretIds: [],\n owningEntityIds: [patient.id! as string],\n }\n },\n getDecryptedData: async (id) => {\n const healthdata = await apis.healthcareElementApi.getHealthElementWithUser(user, id)\n return {\n secretContent: healthdata.note!,\n secretIds: await apis.cryptoApi.xapi.secretIdsOf({ entity: healthdata, type: EntityWithDelegationTypeName.HealthElement }, undefined),\n owningEntityIds: await apis.healthcareElementApi.decryptPatientIdOf(healthdata),\n }\n },\n shareEncryptedData: async (dataId, delegateId) => {\n const healthElement = await apis.healthcareElementApi.getHealthElementWithUser(user, dataId)\n await apis.healthcareElementApi.shareWith(delegateId, healthElement, { requestedPermissions: RequestedPermissionEnum.MAX_WRITE })\n },\n }\n }\n}\n\n// Api factories in chronological version order\nlet chronologicalApiFactories: ApiFactory[] = [new ApiFactoryV6(), new ApiFactoryV7(), new ApiFactoryV8()]\n\ndescribe('All apis versions', async function () {\n before(async function () {\n this.timeout(600_000)\n env = await getEnvironmentInitializer().then((initializer) => initializer.execute(getEnvVariables()))\n })\n\n for (let legacyApiIndex = 0; legacyApiIndex < chronologicalApiFactories.length - 1; legacyApiIndex++) {\n const legacyApiFactory = chronologicalApiFactories[legacyApiIndex]\n const newApiFactories = chronologicalApiFactories.slice(legacyApiIndex + 1)\n it(`should be able to read and share data from older apis without affecting accessibility for older apis - ${legacyApiFactory.version}`, async function () {\n const legacyMasterApi = await legacyApiFactory.masterApi(env)\n const legacyUserCredentials = await legacyMasterApi.createUser()\n const legacyUserApi = await legacyApiFactory.testApi(legacyUserCredentials)\n const data = await legacyUserApi.createEncryptedData()\n checkEncryptedData(await legacyUserApi.getDecryptedData(data.id), data, 'Original decrypted data')\n const newApis = await Promise.all(\n newApiFactories.map(async (factory) => {\n const newLegacyUserApi = await factory.testApi(legacyUserCredentials)\n const newUser = await factory.masterApi(env).then((masterApi) => masterApi.createUser())\n const newUserApi = await factory.testApi(newUser)\n return { newLegacyUserApi, newUserApi, version: factory.version }\n })\n )\n for (const { newLegacyUserApi, newUserApi, version } of newApis) {\n checkEncryptedData(await newLegacyUserApi.getDecryptedData(data.id), data, `Data decrypted by legacy user on new api (${version})`)\n await newLegacyUserApi.shareEncryptedData(data.id, (await newUserApi.userDetails()).dataOwnerId)\n checkEncryptedData(await newUserApi.getDecryptedData(data.id), data, `Data decrypted by new user (${version})`)\n }\n checkEncryptedData(await legacyUserApi.getDecryptedData(data.id), data, `Data after changes by new versions of api`)\n })\n }\n})\n"]}
1
+ {"version":3,"file":"test-legacy-data-support.js","sourceRoot":"","sources":["../../../test/icc-x-api/test-legacy-data-support.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AACzB,wCAA2D;AAC3D,wCAAkJ;AAClJ,+CAUwB;AACxB,oDAAgF;AAEhF,+BAA6B;AAC7B,mCAAkC;AAElC,+BAAiC;AACjC,yEAAqE;AACrE,sDAAuF;AACvF,wEAAoE;AACpE,wFAAoF;AACpF,mDAAmE;AACnE,wDAAiG;AACjG,IAAO,uBAAuB,GAAG,uCAAkB,CAAC,uBAAuB,CAAA;AA+B3E,SAAS,kBAAkB,CAAC,MAAqB,EAAE,QAAuB,EAAE,UAAkB;IAC5F,IAAA,aAAM,EAAC,MAAM,CAAC,aAAa,EAAE,GAAG,UAAU,mBAAmB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IAC/F,IAAA,aAAM,EAAC,MAAM,CAAC,SAAS,EAAE,GAAG,UAAU,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAChG,KAAK,MAAM,UA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AAO,CAAC,qBAAqB,CAAC,CAAA;wBACrE,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,CAAA;wBACxF,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;wBACjD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAA;oBACnE,CAAC,CAAA,CAAC,CACH,CAAA;oBACD,KAAK,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,OAAO,EAAE,CAAC;wBAChE,kBAAkB,CAAC,MAAM,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,6CAA6C,OAAO,GAAG,CAAC,CAAA;wBACnI,MAAM,gBAAgB,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC,CAAA;wBAChG,kBAAkB,CAAC,MAAM,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,+BAA+B,OAAO,GAAG,CAAC,CAAA;oBACjH,CAAC;oBACD,kBAAkB,CAAC,MAAM,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,2CAA2C,CAAC,CAAA;gBACtH,CAAC;aAAA,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\nimport { Api as ApiV6, User as UserV6 } from '@icure/apiV6'\nimport { CryptoStrategies as CryptoStrategiesV7, DataOwnerWithType as DataOwnerWithTypeV7, IcureApi as ApiV7, User as UserV7 } from '@icure/apiV7'\nimport {\n WebCryptoPrimitives,\n EntityWithDelegationTypeName,\n hex2ua,\n IcureApi as ApiV8,\n RSAUtils,\n RSAUtilsImpl,\n ShaVersion,\n ua2hex,\n ua2ab,\n} from '../../icc-x-api'\nimport { getEnvironmentInitializer, setLocalStorage } from '../utils/test_utils'\nimport { KeyPair } from '../../icc-x-api/crypto/RSA'\nimport { expect } from 'chai'\nimport { webcrypto } from 'crypto'\nimport { CryptoPrimitives } from '../../icc-x-api/crypto/CryptoPrimitives'\nimport { v4 as uuid } from 'uuid'\nimport { HealthcareParty } from '../../icc-api/model/HealthcareParty'\nimport { TestKeyStorage, TestStorage, testStorageWithKeys } from '../utils/TestStorage'\nimport { TestCryptoStrategies } from '../utils/TestCryptoStrategies'\nimport { EntityShareRequest } from '../../icc-api/model/requests/EntityShareRequest'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from '../../icc-x-api/crypto/utils'\nimport RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum\n\ntype UserCredentials = {\n login: string\n password: string\n ownerId: string\n key: KeyPair<CryptoKey>\n}\ntype EncryptedData = {\n secretContent: string\n secretIds: string[]\n owningEntityIds: string[]\n}\n\ninterface UniformizedMasterApi {\n createUser(): Promise<UserCredentials>\n}\n\ninterface UniformizedTestApi {\n userDetails(): Promise<{ userId: string; dataOwnerId: string }>\n createEncryptedData(): Promise<{ id: string } & EncryptedData>\n getDecryptedData(id: string): Promise<EncryptedData>\n shareEncryptedData(dataId: string, delegateId: string): Promise<void>\n}\n\ninterface ApiFactory {\n readonly version: string\n masterApi(env: TestVars): Promise<UniformizedMasterApi>\n testApi(credentials: UserCredentials): Promise<UniformizedTestApi>\n}\n\nfunction checkEncryptedData(actual: EncryptedData, expected: EncryptedData, actualName: string) {\n expect(actual.secretContent, `${actualName} - secret content`).to.equal(expected.secretContent)\n expect(actual.secretIds, `${actualName} - secret ids`).to.have.length(expected.secretIds.length)\n for (const expectedId of expected.secretIds) {\n expect(actual.secretIds, `${actualName} - secret id`).to.contain(expectedId)\n }\n expect(actual.owningEntityIds, `${actualName} - owning entity id`).to.have.length(expected.owningEntityIds.length)\n for (const expectedId of expected.owningEntityIds) {\n expect(actual.owningEntityIds, `${actualName} - owning entity id`).to.contain(expectedId)\n }\n}\n\nsetLocalStorage(fetch)\nconst cryptoPrimitives = new WebCryptoPrimitives(webcrypto as any)\nlet env: TestVars\n\nclass ApiFactoryV6 implements ApiFactory {\n readonly version: string = 'apiV6.x'\n\n async masterApi(env: TestVars): Promise<UniformizedMasterApi> {\n const apis = await ApiV6(\n env.iCureUrl + '/rest/v1',\n env.masterHcp!.user,\n env.masterHcp!.password,\n webcrypto as any,\n fetch,\n false,\n false,\n new TestStorage(),\n new TestKeyStorage()\n )\n return <UniformizedMasterApi>{\n createUser: async () => {\n const pair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha1)\n const hcp = await apis.healthcarePartyApi.createHealthcareParty(new HealthcareParty({ id: uuid(), firstName: `name`, lastName: 'v6' }))\n const user = await apis.userApi.createUser(\n new UserV6({\n id: uuid(),\n login: `v6-${uuid()}`,\n status: 'ACTIVE',\n healthcarePartyId: hcp.id,\n })\n )\n return {\n login: user.login,\n password: await apis.userApi.getToken(user.id!, uuid()),\n key: pair,\n ownerId: hcp.id,\n }\n },\n }\n }\n\n async testApi(credentials: UserCredentials): Promise<UniformizedTestApi> {\n const apis = await ApiV6(env.iCureUrl + '/rest/v1', credentials.login, credentials.password, webcrypto as any, fetch)\n // await apis.cryptoApi.cacheKeyPair(await cryptoPrimitives.RSA.exportKeys(credentials.key, \"jwk\", \"jwk\"))\n const user = await apis.userApi.getCurrentUser()\n await apis.cryptoApi.addKeyPairForOwner(\n apis.maintenanceTaskApi,\n user,\n await apis.cryptoApi.getDataOwner(credentials.ownerId),\n credentials.key,\n false,\n false\n )\n return {\n userDetails: async () => {\n return { userId: user.id!, dataOwnerId: credentials.ownerId }\n },\n createEncryptedData: async () => {\n const note = `v6 note ${uuid()}`\n const patient = await apis.patientApi.createPatientWithUser(user, await apis.patientApi.newInstance(user))\n const healthdata = await apis.healthcareElementApi.createHealthElementWithUser(\n user,\n await apis.healthcareElementApi.newInstance(user, patient, { note })\n )\n return {\n id: healthdata.id,\n secretContent: note,\n secretIds: (await apis.cryptoApi.extractDelegationsSFKs(healthdata, credentials.ownerId)).extractedKeys,\n owningEntityIds: [patient.id! as string],\n }\n },\n getDecryptedData: async (id) => {\n const healthdata = await apis.healthcareElementApi.getHealthElementWithUser(user, id)\n return {\n secretContent: healthdata.note!,\n secretIds: (await apis.cryptoApi.extractDelegationsSFKs(healthdata, credentials.ownerId)).extractedKeys,\n owningEntityIds: (await apis.cryptoApi.extractCryptedFKs(healthdata, credentials.ownerId)).extractedKeys,\n }\n },\n shareEncryptedData: async (dataId, delegateId) => {\n const healthElement = await apis.healthcareElementApi.getHealthElementWithUser(user, dataId)\n const patientIds = (await apis.cryptoApi.extractCryptedFKs(healthElement, credentials.ownerId)).extractedKeys\n expect(patientIds).to.have.length(1)\n const patient = await apis.patientApi.getPatientWithUser(user, patientIds[0])\n const secretIds = (await apis.cryptoApi.extractDelegationsSFKs(healthElement, credentials.ownerId)).extractedKeys\n expect(secretIds).to.have.length(1)\n await apis.healthcareElementApi.modifyHealthElementWithUser(\n user,\n (\n await apis.cryptoApi.extendedDelegationsAndCryptedForeignKeys(healthElement, patient, credentials.ownerId, delegateId, secretIds[0])\n ).modifiedObject\n )\n },\n }\n }\n}\n\nclass TestCryptoStrategiesV7 implements CryptoStrategiesV7 {\n private readonly RSA = new RSAUtilsImpl(webcrypto as any)\n constructor(private readonly key: KeyPair<CryptoKey> | undefined) {}\n\n async generateNewKeyForDataOwner(self: DataOwnerWithTypeV7): Promise<KeyPair<CryptoKey> | boolean> {\n if (!this.key) return false\n const knownKeys = new Set(...hexPublicKeysWithSha1Of(self))\n if (knownKeys.size <= 0) return this.key\n return false\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithTypeV7\n unknownKeys: string[]\n unavailableKeys: string[]\n }[]\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n const self = keysData[keysData.length - 1].dataOwner\n const knownKeys = new Set([...hexPublicKeysWithSha1Of(self.dataOwner), ...hexPublicKeysWithSha256Of(self.dataOwner)])\n const publicKey = this.key ? ua2hex(await this.RSA.exportKey(this.key.publicKey, 'spki')) : undefined\n return Object.fromEntries(\n await Promise.all(\n keysData.map(async (currData) => {\n if (currData.dataOwner.dataOwner.id! !== self.dataOwner.id!) {\n return [\n currData.dataOwner.dataOwner.id!,\n {\n recoveredKeys: {},\n keyAuthenticity: {},\n },\n ]\n } else if (publicKey === undefined || !knownKeys.has(publicKey)) {\n return [currData.dataOwner.dataOwner.id!, { recoveredKeys: {}, keyAuthenticity: {} }]\n } else {\n return [currData.dataOwner.dataOwner.id!, { recoveredKeys: { [publicKey.slice(-32)]: this.key }, keyAuthenticity: {} }]\n }\n })\n )\n )\n }\n\n verifyDelegatePublicKeys(delegate: any, publicKeys: string[]): Promise<string[]> {\n return Promise.resolve(publicKeys)\n }\n}\nclass ApiFactoryV7 implements ApiFactory {\n readonly version: string = 'apiV7.x'\n\n async masterApi(env: TestVars): Promise<UniformizedMasterApi> {\n const key = {\n privateKey: await cryptoPrimitives.RSA.importKey('pkcs8', ua2ab(hex2ua(env.masterHcp!.privateKey)), ['decrypt'], ShaVersion.Sha1),\n publicKey: await cryptoPrimitives.RSA.importKey('spki', ua2ab(hex2ua(env.masterHcp!.publicKey)), ['encrypt'], ShaVersion.Sha1),\n }\n const apis = await ApiV7.initialise(\n env.iCureUrl,\n { username: env.masterHcp!.user, password: env.masterHcp!.password },\n new TestCryptoStrategiesV7(key),\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n return <UniformizedMasterApi>{\n createUser: async () => {\n const pair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha1)\n const hcp = await apis.healthcarePartyApi.createHealthcareParty(new HealthcareParty({ id: uuid(), firstName: `name`, lastName: 'v7' }))\n const user = await apis.userApi.createUser(\n new UserV7({\n id: uuid(),\n login: `v7-${uuid()}`,\n status: 'ACTIVE',\n healthcarePartyId: hcp.id,\n })\n )\n return {\n login: user.login,\n password: await apis.userApi.getToken(user.id!, uuid()),\n key: pair,\n ownerId: hcp.id,\n }\n },\n }\n }\n\n async testApi(credentials: UserCredentials): Promise<UniformizedTestApi> {\n const testStorage = await testStorageWithKeys([\n {\n dataOwnerId: credentials.ownerId,\n pairs: [\n {\n keyPair: {\n publicKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.publicKey, 'spki')),\n privateKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.privateKey, 'pkcs8')),\n },\n shaVersion: ShaVersion.Sha1,\n },\n ],\n },\n ])\n const apis = await ApiV7.initialise(\n env.iCureUrl,\n {\n username: credentials.login,\n password: credentials.password,\n },\n new TestCryptoStrategiesV7(credentials.key),\n webcrypto as any,\n fetch,\n {\n storage: testStorage.storage,\n keyStorage: testStorage.keyStorage,\n entryKeysFactory: testStorage.keyFactory,\n }\n )\n const user = await apis.userApi.getCurrentUser()\n return {\n userDetails: async () => {\n return { userId: user.id!, dataOwnerId: credentials.ownerId }\n },\n createEncryptedData: async () => {\n const note = `v7 note ${uuid}`\n const patient = await apis.patientApi.createPatientWithUser(user, await apis.patientApi.newInstance(user))\n const healthdata = await apis.healthcareElementApi.createHealthElementWithUser(\n user,\n await apis.healthcareElementApi.newInstance(user, patient, { note })\n )\n const secretIds = await apis.cryptoApi.entities.secretIdsOf(healthdata)\n expect(secretIds).to.have.length(1)\n return {\n id: healthdata.id,\n secretContent: note,\n secretIds,\n owningEntityIds: [patient.id! as string],\n }\n },\n getDecryptedData: async (id) => {\n const healthdata = await apis.healthcareElementApi.getHealthElementWithUser(user, id)\n return {\n secretContent: healthdata.note!,\n secretIds: await apis.cryptoApi.entities.secretIdsOf(healthdata),\n owningEntityIds: await apis.cryptoApi.entities.owningEntityIdsOf(healthdata),\n }\n },\n shareEncryptedData: async (dataId, delegateId) => {\n const healthElement = await apis.healthcareElementApi.getHealthElementWithUser(user, dataId)\n const encryptionKeys = await apis.cryptoApi.entities.encryptionKeysOf(healthElement)\n const secretIds = await apis.cryptoApi.entities.secretIdsOf(healthElement)\n const owningEntityIds = await apis.cryptoApi.entities.owningEntityIdsOf(healthElement)\n await apis.healthcareElementApi.modifyHealthElementWithUser(\n user,\n await apis.cryptoApi.entities.entityWithExtendedEncryptedMetadata(healthElement, delegateId, secretIds, encryptionKeys, owningEntityIds, [])\n )\n },\n }\n }\n}\n\nclass ApiFactoryV8 implements ApiFactory {\n readonly version: string = 'apiV8.x'\n\n async masterApi(env: TestVars): Promise<UniformizedMasterApi> {\n const key = {\n privateKey: await cryptoPrimitives.RSA.importKey('pkcs8', ua2ab(hex2ua(env.masterHcp!.privateKey)), ['decrypt'], ShaVersion.Sha1),\n publicKey: await cryptoPrimitives.RSA.importKey('spki', ua2ab(hex2ua(env.masterHcp!.publicKey)), ['encrypt'], ShaVersion.Sha1),\n }\n const apis = await ApiV8.initialise(\n env.iCureUrl,\n { username: env.masterHcp!.user, password: env.masterHcp!.password },\n new TestCryptoStrategies(key),\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n return <UniformizedMasterApi>{\n createUser: async () => {\n const pair = await cryptoPrimitives.RSA.generateKeyPair(ShaVersion.Sha256)\n const hcp = await apis.healthcarePartyApi.createHealthcareParty(new HealthcareParty({ id: uuid(), firstName: `name`, lastName: 'v7' }))\n const user = await apis.userApi.createUser(\n new UserV7({\n id: uuid(),\n login: `v7-${uuid()}`,\n status: 'ACTIVE',\n healthcarePartyId: hcp.id,\n })\n )\n return {\n login: user.login,\n password: await apis.userApi.getToken(user.id!, uuid()),\n key: pair,\n ownerId: hcp.id,\n }\n },\n }\n }\n\n async testApi(credentials: UserCredentials): Promise<UniformizedTestApi> {\n const testStorage = await testStorageWithKeys([\n {\n dataOwnerId: credentials.ownerId,\n pairs: [\n {\n keyPair: {\n publicKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.publicKey, 'spki')),\n privateKey: ua2hex(await cryptoPrimitives.RSA.exportKey(credentials.key.privateKey, 'pkcs8')),\n },\n shaVersion: ShaVersion.Sha1,\n },\n ],\n },\n ])\n const apis = await ApiV8.initialise(\n env.iCureUrl,\n {\n username: credentials.login,\n password: credentials.password,\n },\n new TestCryptoStrategies(credentials.key),\n webcrypto as any,\n fetch,\n {\n storage: testStorage.storage,\n keyStorage: testStorage.keyStorage,\n entryKeysFactory: testStorage.keyFactory,\n }\n )\n const user = await apis.userApi.getCurrentUser()\n return {\n userDetails: async () => {\n return { userId: user.id!, dataOwnerId: credentials.ownerId }\n },\n createEncryptedData: async () => {\n const note = `v8 note ${uuid()}`\n const patient = await apis.patientApi.createPatientWithUser(user, await apis.patientApi.newInstance(user))\n const healthdata = await apis.healthcareElementApi.createHealthElementWithUser(\n user,\n await apis.healthcareElementApi.newInstance(user, patient, { note })\n )\n return {\n id: healthdata.id,\n secretContent: note,\n secretIds: [],\n owningEntityIds: [patient.id! as string],\n }\n },\n getDecryptedData: async (id) => {\n const healthdata = await apis.healthcareElementApi.getHealthElementWithUser(user, id)\n return {\n secretContent: healthdata.note!,\n secretIds: await apis.cryptoApi.xapi.secretIdsOf({ entity: healthdata, type: EntityWithDelegationTypeName.HealthElement }, undefined),\n owningEntityIds: await apis.healthcareElementApi.decryptPatientIdOf(healthdata),\n }\n },\n shareEncryptedData: async (dataId, delegateId) => {\n const healthElement = await apis.healthcareElementApi.getHealthElementWithUser(user, dataId)\n await apis.healthcareElementApi.shareWith(delegateId, healthElement, { requestedPermissions: RequestedPermissionEnum.MAX_WRITE })\n },\n }\n }\n}\n\n// Api factories in chronological version order\nlet chronologicalApiFactories: ApiFactory[] = [new ApiFactoryV6(), new ApiFactoryV7(), new ApiFactoryV8()]\n\ndescribe('All apis versions', async function () {\n before(async function () {\n this.timeout(600_000)\n env = await getEnvironmentInitializer().then((initializer) => initializer.execute(getEnvVariables()))\n })\n\n for (let legacyApiIndex = 0; legacyApiIndex < chronologicalApiFactories.length - 1; legacyApiIndex++) {\n const legacyApiFactory = chronologicalApiFactories[legacyApiIndex]\n const newApiFactories = chronologicalApiFactories.slice(legacyApiIndex + 1)\n it(`should be able to read and share data from older apis without affecting accessibility for older apis - ${legacyApiFactory.version}`, async function () {\n const legacyMasterApi = await legacyApiFactory.masterApi(env)\n const legacyUserCredentials = await legacyMasterApi.createUser()\n const legacyUserApi = await legacyApiFactory.testApi(legacyUserCredentials)\n const data = await legacyUserApi.createEncryptedData()\n checkEncryptedData(await legacyUserApi.getDecryptedData(data.id), data, 'Original decrypted data')\n const newApis = await Promise.all(\n newApiFactories.map(async (factory) => {\n const newLegacyUserApi = await factory.testApi(legacyUserCredentials)\n const newUser = await factory.masterApi(env).then((masterApi) => masterApi.createUser())\n const newUserApi = await factory.testApi(newUser)\n return { newLegacyUserApi, newUserApi, version: factory.version }\n })\n )\n for (const { newLegacyUserApi, newUserApi, version } of newApis) {\n checkEncryptedData(await newLegacyUserApi.getDecryptedData(data.id), data, `Data decrypted by legacy user on new api (${version})`)\n await newLegacyUserApi.shareEncryptedData(data.id, (await newUserApi.userDetails()).dataOwnerId)\n checkEncryptedData(await newUserApi.getDecryptedData(data.id), data, `Data decrypted by new user (${version})`)\n }\n checkEncryptedData(await legacyUserApi.getDecryptedData(data.id), data, `Data after changes by new versions of api`)\n })\n }\n})\n"]}
@@ -0,0 +1 @@
1
+ import 'isomorphic-fetch';
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const test_utils_1 = require("../utils/test_utils");
13
+ const icc_x_api_1 = require("../../icc-x-api");
14
+ const chai_1 = require("chai");
15
+ require("isomorphic-fetch");
16
+ const types_1 = require("@icure/test-setup/types");
17
+ const chaiAsPromised = require("chai-as-promised");
18
+ const utils_1 = require("../../icc-x-api/crypto/utils");
19
+ const DataOwnerTypeEnum_1 = require("../../icc-api/model/DataOwnerTypeEnum");
20
+ const crypto_1 = require("crypto");
21
+ const TestStorage_1 = require("../utils/TestStorage");
22
+ const SecureDelegation_1 = require("../../icc-api/model/SecureDelegation");
23
+ var AccessLevelEnum = SecureDelegation_1.SecureDelegation.AccessLevelEnum;
24
+ var initMasterApi = test_utils_1.TestUtils.initMasterApi;
25
+ (0, test_utils_1.setLocalStorage)(fetch);
26
+ (0, chai_1.use)(chaiAsPromised);
27
+ let env;
28
+ const untrustedKeyPropId = 'untrustedKey';
29
+ class TrustedKeysStrategy {
30
+ constructor(parentKeys, selfKeys, options = {}) {
31
+ this.parentKeys = parentKeys;
32
+ this.selfKeys = selfKeys;
33
+ this.options = options;
34
+ }
35
+ dataOwnerRequiresAnonymousDelegation(dataOwner) {
36
+ return dataOwner.type != DataOwnerTypeEnum_1.DataOwnerTypeEnum.Hcp;
37
+ }
38
+ recoverAndVerifySelfHierarchyKeys(keysData, cryptoPrimitives, keyPairRecoverer) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ if (this.options.failRecoverAndVerifySelfHierarchyKeys) {
41
+ throw new Error("Shouldn't call this method now");
42
+ }
43
+ (0, chai_1.expect)(keysData).to.have.length(2);
44
+ const parentKeysWithFp = yield Promise.all(this.parentKeys.map((k) => __awaiter(this, void 0, void 0, function* () {
45
+ return ({
46
+ trusted: k.trusted,
47
+ fp: (0, utils_1.fingerprintV1)(k.pub),
48
+ keypair: yield cryptoPrimitives.RSA.importKeyPair('pkcs8', (0, icc_x_api_1.ua2ab)((0, icc_x_api_1.hex2ua)(k.priv)), 'spki', (0, icc_x_api_1.ua2ab)((0, icc_x_api_1.hex2ua)(k.pub)), k.shaVersion),
49
+ });
50
+ })));
51
+ const selfKeysWithFp = yield Promise.all(this.selfKeys.map((k) => __awaiter(this, void 0, void 0, function* () {
52
+ return ({
53
+ trusted: k.trusted,
54
+ fp: (0, utils_1.fingerprintV1)(k.pub),
55
+ keypair: yield cryptoPrimitives.RSA.importKeyPair('pkcs8', (0, icc_x_api_1.ua2ab)((0, icc_x_api_1.hex2ua)(k.priv)), 'spki', (0, icc_x_api_1.ua2ab)((0, icc_x_api_1.hex2ua)(k.pub)), k.shaVersion),
56
+ });
57
+ })));
58
+ return {
59
+ [keysData[0].dataOwner.dataOwner.id]: {
60
+ recoveredKeys: Object.fromEntries(parentKeysWithFp.map((k) => [k.fp, k.keypair])),
61
+ keyAuthenticity: Object.fromEntries(parentKeysWithFp.map((k) => [k.fp, k.trusted])),
62
+ },
63
+ [keysData[1].dataOwner.dataOwner.id]: {
64
+ recoveredKeys: Object.fromEntries(selfKeysWithFp.map((k) => [k.fp, k.keypair])),
65
+ keyAuthenticity: Object.fromEntries(selfKeysWithFp.map((k) => [k.fp, k.trusted])),
66
+ },
67
+ };
68
+ });
69
+ }
70
+ verifyDelegatePublicKeys(delegate, publicKeys, cryptoPrimitives) {
71
+ var _a;
72
+ const untrusted = new Set((_a = delegate.stub.cryptoActorProperties) === null || _a === void 0 ? void 0 : _a.flatMap((p) => {
73
+ var _a;
74
+ if (p.id == untrustedKeyPropId && ((_a = p.typedValue) === null || _a === void 0 ? void 0 : _a.stringValue) != undefined) {
75
+ return [p.typedValue.stringValue];
76
+ }
77
+ else {
78
+ return [];
79
+ }
80
+ }));
81
+ return Promise.resolve(publicKeys.filter((k) => !untrusted.has((0, utils_1.fingerprintV2)(k))));
82
+ }
83
+ generateNewKeyForDataOwner(self, cryptoPrimitives) {
84
+ if (this.options.overrideGenerateNewKeyForDataOwner) {
85
+ return this.options.overrideGenerateNewKeyForDataOwner();
86
+ }
87
+ return Promise.reject(new Error('Should not be called now'));
88
+ }
89
+ }
90
+ describe('CSM-729', function () {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ before(function () {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ this.timeout(600000);
95
+ const initializer = yield (0, test_utils_1.getEnvironmentInitializer)();
96
+ env = yield initializer.execute((0, types_1.getEnvVariables)());
97
+ });
98
+ });
99
+ it('User with untrusted key', function () {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ const { grandCredentials: parent, parentCredentials: hcp } = yield (0, test_utils_1.createHcpHierarchyApis)(env);
102
+ // Create some data to use the original keys
103
+ const initialApi = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: hcp.user, password: hcp.password }, new TrustedKeysStrategy([{ priv: parent.privateKey, pub: parent.publicKey, trusted: true, shaVersion: icc_x_api_1.ShaVersion.Sha1 }], [{ priv: hcp.privateKey, pub: hcp.publicKey, trusted: true, shaVersion: icc_x_api_1.ShaVersion.Sha1 }]), crypto_1.webcrypto, fetch, {
104
+ storage: new TestStorage_1.TestStorage(),
105
+ keyStorage: new TestStorage_1.TestKeyStorage(),
106
+ });
107
+ const user = yield initialApi.userApi.getCurrentUser();
108
+ const pat1 = yield initialApi.patientApi.createPatientWithUser(user, yield initialApi.patientApi.newInstance(user, {
109
+ firstName: 'John',
110
+ lastName: 'Doe',
111
+ note: 'Secret note',
112
+ }, {
113
+ additionalDelegates: { [parent.dataOwnerId]: AccessLevelEnum.WRITE },
114
+ }));
115
+ // Check exchange data was created as expected
116
+ const selfSelfXdata = yield initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, hcp.dataOwnerId);
117
+ const selfParentXdata = yield initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, parent.dataOwnerId);
118
+ (0, chai_1.expect)(selfSelfXdata).to.not.be.undefined;
119
+ (0, chai_1.expect)(selfParentXdata).to.not.be.undefined;
120
+ (0, chai_1.expect)(selfSelfXdata).to.have.length(1);
121
+ (0, chai_1.expect)(selfParentXdata).to.have.length(1);
122
+ // Prepare for new api with untrusted key
123
+ //// Mark self hcp keys as untrusted
124
+ let selfHcp = yield initialApi.healthcarePartyApi.getCurrentHealthcareParty();
125
+ selfHcp = yield initialApi.healthcarePartyApi.modifyHealthcareParty(Object.assign(Object.assign({}, selfHcp), { cryptoActorProperties: [
126
+ ...(selfHcp.cryptoActorProperties || []),
127
+ {
128
+ id: untrustedKeyPropId,
129
+ typedValue: { stringValue: (0, utils_1.fingerprintV2)(hcp.publicKey) },
130
+ },
131
+ ] }));
132
+ //// Mark parent hcp keys as untrusted and add new key (currently can't be done through crypto strategies)
133
+ const newParentKey = yield initialApi.cryptoApi.primitives.RSA.generateKeyPair(icc_x_api_1.ShaVersion.Sha256);
134
+ const newParentKeySpki = (0, icc_x_api_1.ua2hex)(yield initialApi.cryptoApi.primitives.RSA.exportKey(newParentKey.publicKey, 'spki'));
135
+ const newParentKeyPkcs8 = (0, icc_x_api_1.ua2hex)(yield initialApi.cryptoApi.primitives.RSA.exportKey(newParentKey.privateKey, 'pkcs8'));
136
+ const adminApi = yield initMasterApi(env);
137
+ let parentHcp = yield adminApi.healthcarePartyApi.getHealthcareParty(parent.dataOwnerId);
138
+ parentHcp = yield adminApi.healthcarePartyApi.modifyHealthcareParty(Object.assign(Object.assign({}, parentHcp), { cryptoActorProperties: [
139
+ ...(parentHcp.cryptoActorProperties || []),
140
+ {
141
+ id: untrustedKeyPropId,
142
+ typedValue: { stringValue: (0, utils_1.fingerprintV2)(parent.publicKey) },
143
+ },
144
+ ], publicKeysForOaepWithSha256: [...(parentHcp.publicKeysForOaepWithSha256 || []), newParentKeySpki] }));
145
+ //// No need to invalidate exchange data, as untrusted keys are not used to validate it
146
+ // Setup new api
147
+ let didCreateNewKey = false;
148
+ const newHcpKey = yield initialApi.cryptoApi.primitives.RSA.generateKeyPair(icc_x_api_1.ShaVersion.Sha256);
149
+ const newHcpKeySpki = (0, icc_x_api_1.ua2hex)(yield initialApi.cryptoApi.primitives.RSA.exportKey(newHcpKey.publicKey, 'spki'));
150
+ const newHcpKeyPkcs8 = (0, icc_x_api_1.ua2hex)(yield initialApi.cryptoApi.primitives.RSA.exportKey(newHcpKey.privateKey, 'pkcs8'));
151
+ const apiWithUntrustedKeysStorages = {
152
+ // Using a new storage, simulates wiping the local storage
153
+ storage: new TestStorage_1.TestStorage(),
154
+ keyStorage: new TestStorage_1.TestKeyStorage(),
155
+ };
156
+ const apiWithUntrustedKey = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: hcp.user, password: hcp.password }, new TrustedKeysStrategy([
157
+ { priv: parent.privateKey, pub: parent.publicKey, trusted: false, shaVersion: icc_x_api_1.ShaVersion.Sha1 },
158
+ { priv: newParentKeyPkcs8, pub: newParentKeySpki, trusted: true, shaVersion: icc_x_api_1.ShaVersion.Sha256 },
159
+ ], [{ priv: hcp.privateKey, pub: hcp.publicKey, trusted: false, shaVersion: icc_x_api_1.ShaVersion.Sha1 }], {
160
+ overrideGenerateNewKeyForDataOwner: () => {
161
+ didCreateNewKey = true;
162
+ return Promise.resolve(newHcpKey);
163
+ },
164
+ }), crypto_1.webcrypto, fetch, apiWithUntrustedKeysStorages);
165
+ (0, chai_1.expect)(didCreateNewKey).to.eq(true);
166
+ // Check all keys are available but only new keys are trusted
167
+ (0, chai_1.expect)(yield apiWithUntrustedKey.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(yield apiWithUntrustedKey.healthcarePartyApi.getHealthcareParty(hcp.dataOwnerId))).to.have.members([newHcpKeySpki]);
168
+ (0, chai_1.expect)(yield apiWithUntrustedKey.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(yield apiWithUntrustedKey.healthcarePartyApi.getHealthcareParty(parent.dataOwnerId))).to.have.members([newParentKeySpki]);
169
+ (0, chai_1.expect)(yield apiWithUntrustedKey.cryptoApi.userKeysManager.getCurrentUserHierarchyAvailablePublicKeysHex()).to.have.members([
170
+ newHcpKeySpki,
171
+ hcp.publicKey,
172
+ parent.publicKey,
173
+ newParentKeySpki,
174
+ ]);
175
+ (0, chai_1.expect)(yield apiWithUntrustedKey.cryptoApi.userKeysManager.getCurrentUserAvailablePublicKeysHex(false)).to.have.members([
176
+ newHcpKeySpki,
177
+ hcp.publicKey,
178
+ ]);
179
+ // Check can still read old data
180
+ const pat1Recovered = yield apiWithUntrustedKey.patientApi.getPatientWithUser(user, pat1.id);
181
+ (0, chai_1.expect)(pat1Recovered.note).to.eq('Secret note');
182
+ // Check can create new data
183
+ const pat2 = yield initialApi.patientApi.createPatientWithUser(user, yield initialApi.patientApi.newInstance(user, {
184
+ firstName: 'Joe',
185
+ lastName: 'Doe',
186
+ note: 'Secret note',
187
+ }, {
188
+ additionalDelegates: { [parent.dataOwnerId]: AccessLevelEnum.WRITE },
189
+ }));
190
+ // Check created new exchange data and only used the new trusted keys for it
191
+ const selfSelfXdata2 = yield initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, hcp.dataOwnerId);
192
+ const selfParentXdata2 = yield initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, parent.dataOwnerId);
193
+ (0, chai_1.expect)(selfSelfXdata2).to.not.be.undefined;
194
+ (0, chai_1.expect)(selfParentXdata2).to.not.be.undefined;
195
+ (0, chai_1.expect)(selfSelfXdata2).to.have.length(2);
196
+ (0, chai_1.expect)(selfParentXdata2).to.have.length(2);
197
+ const newSelfSelfXdata = selfSelfXdata2.filter((xd) => xd.id !== selfSelfXdata[0].id);
198
+ (0, chai_1.expect)(newSelfSelfXdata).to.have.length(1);
199
+ const newSelfSelfXDataUsedFps = Object.keys(newSelfSelfXdata[0].exchangeKey);
200
+ (0, chai_1.expect)(newSelfSelfXDataUsedFps).to.have.length(1);
201
+ (0, chai_1.expect)(newSelfSelfXDataUsedFps[0]).to.eq((0, utils_1.fingerprintV2)(newHcpKeySpki));
202
+ const newSelfParentXdata = selfParentXdata2.filter((xd) => xd.id !== selfParentXdata[0].id);
203
+ (0, chai_1.expect)(newSelfParentXdata).to.have.length(1);
204
+ const newSelfParentXDataUsedFps = Object.keys(newSelfParentXdata[0].exchangeKey);
205
+ (0, chai_1.expect)(newSelfParentXDataUsedFps).to.have.length(2);
206
+ (0, chai_1.expect)(newSelfParentXDataUsedFps).to.have.members([(0, utils_1.fingerprintV2)(newHcpKeySpki), (0, utils_1.fingerprintV2)(newParentKeySpki)]);
207
+ // Check after reinitialization with keys already in storage the "verified" situation is unchanged.
208
+ const apiWithUntrustedKey2 = yield icc_x_api_1.IcureApi.initialise(env.iCureUrl, { username: hcp.user, password: hcp.password }, new TrustedKeysStrategy([], [], { failRecoverAndVerifySelfHierarchyKeys: true }), crypto_1.webcrypto, fetch, apiWithUntrustedKeysStorages);
209
+ (0, chai_1.expect)(yield apiWithUntrustedKey2.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(yield apiWithUntrustedKey2.healthcarePartyApi.getHealthcareParty(hcp.dataOwnerId))).to.have.members([newHcpKeySpki]);
210
+ (0, chai_1.expect)(yield apiWithUntrustedKey2.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(yield apiWithUntrustedKey2.healthcarePartyApi.getHealthcareParty(parent.dataOwnerId))).to.have.members([newParentKeySpki]);
211
+ (0, chai_1.expect)(yield apiWithUntrustedKey2.cryptoApi.userKeysManager.getCurrentUserHierarchyAvailablePublicKeysHex()).to.have.members([
212
+ newHcpKeySpki,
213
+ hcp.publicKey,
214
+ parent.publicKey,
215
+ newParentKeySpki,
216
+ ]);
217
+ (0, chai_1.expect)(yield apiWithUntrustedKey2.cryptoApi.userKeysManager.getCurrentUserAvailablePublicKeysHex(false)).to.have.members([
218
+ newHcpKeySpki,
219
+ hcp.publicKey,
220
+ ]);
221
+ });
222
+ });
223
+ });
224
+ });
225
+ //# sourceMappingURL=CSM-729.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CSM-729.js","sourceRoot":"","sources":["../../../test/support/CSM-729.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAAmH;AACnH,+CAA0H;AAC1H,+BAA6C;AAC7C,4BAAyB;AACzB,mDAAmE;AACnE,mDAAkD;AAClD,wDAA2E;AAI3E,6EAAyE;AACzE,mCAAkC;AAClC,sDAAkE;AAClE,2EAAuE;AACvE,IAAO,eAAe,GAAG,mCAAgB,CAAC,eAAe,CAAA;AACzD,IAAO,aAAa,GAAG,sBAAS,CAAC,aAAa,CAAA;AAE9C,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AAEtB,IAAA,UAAO,EAAC,cAAc,CAAC,CAAA;AAEvB,IAAI,GAAa,CAAA;AAEjB,MAAM,kBAAkB,GAAG,cAAc,CAAA;AAEzC,MAAM,mBAAmB;IACvB,YACmB,UAAqF,EACrF,QAAmF,EACnF,UAGb,EAAE;QALW,eAAU,GAAV,UAAU,CAA2E;QACrF,aAAQ,GAAR,QAAQ,CAA2E;QACnF,YAAO,GAAP,OAAO,CAGlB;IACL,CAAC;IAEJ,oCAAoC,CAAC,SAAkC;QACrE,OAAO,SAAS,CAAC,IAAI,IAAI,qCAAiB,CAAC,GAAG,CAAA;IAChD,CAAC;IAEK,iCAAiC,CACrC,QAIG,EACH,gBAAkC,EAClC,gBAAkC;;YAIlC,IAAI,IAAI,CAAC,OAAO,CAAC,qCAAqC,EAAE,CAAC;gBACvD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;YACnD,CAAC;YACD,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CA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aAAM,EAAC,MAAM,oBAAoB,CAAC,SAAS,CAAC,eAAe,CAAC,6CAA6C,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;oBAC3H,aAAa;oBACb,GAAG,CAAC,SAAS;oBACb,MAAM,CAAC,SAAS;oBAChB,gBAAgB;iBACjB,CAAC,CAAA;gBACF,IAAA,aAAM,EAAC,MAAM,oBAAoB,CAAC,SAAS,CAAC,eAAe,CAAC,oCAAoC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC;oBACvH,aAAa;oBACb,GAAG,CAAC,SAAS;iBACd,CAAC,CAAA;YACJ,CAAC;SAAA,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import { createHcpHierarchyApis, getEnvironmentInitializer, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { CryptoPrimitives, CryptoStrategies, hex2ua, IcureApi, KeyPair, ShaVersion, ua2ab, ua2hex } from '../../icc-x-api'\nimport { expect, use as chaiUse } from 'chai'\nimport 'isomorphic-fetch'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport * as chaiAsPromised from 'chai-as-promised'\nimport { fingerprintV1, fingerprintV2 } from '../../icc-x-api/crypto/utils'\nimport { KeyPairRecoverer } from '../../icc-x-api/crypto/KeyPairRecoverer'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\nimport { DataOwnerTypeEnum } from '../../icc-api/model/DataOwnerTypeEnum'\nimport { webcrypto } from 'crypto'\nimport { TestKeyStorage, TestStorage } from '../utils/TestStorage'\nimport { SecureDelegation } from '../../icc-api/model/SecureDelegation'\nimport AccessLevelEnum = SecureDelegation.AccessLevelEnum\nimport initMasterApi = TestUtils.initMasterApi\n\nsetLocalStorage(fetch)\n\nchaiUse(chaiAsPromised)\n\nlet env: TestVars\n\nconst untrustedKeyPropId = 'untrustedKey'\n\nclass TrustedKeysStrategy implements CryptoStrategies {\n constructor(\n private readonly parentKeys: { pub: string; priv: string; trusted: boolean; shaVersion: ShaVersion }[],\n private readonly selfKeys: { pub: string; priv: string; trusted: boolean; shaVersion: ShaVersion }[],\n private readonly options: {\n failRecoverAndVerifySelfHierarchyKeys?: boolean\n overrideGenerateNewKeyForDataOwner?: () => Promise<KeyPair<CryptoKey> | boolean | 'keyless'>\n } = {}\n ) {}\n\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type != DataOwnerTypeEnum.Hcp\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: {\n dataOwner: DataOwnerWithType\n unknownKeys: string[]\n unavailableKeys: string[]\n }[],\n cryptoPrimitives: CryptoPrimitives,\n keyPairRecoverer: KeyPairRecoverer\n ): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n if (this.options.failRecoverAndVerifySelfHierarchyKeys) {\n throw new Error(\"Shouldn't call this method now\")\n }\n expect(keysData).to.have.length(2)\n const parentKeysWithFp = await Promise.all(\n this.parentKeys.map(async (k) => ({\n trusted: k.trusted,\n fp: fingerprintV1(k.pub),\n keypair: await cryptoPrimitives.RSA.importKeyPair('pkcs8', ua2ab(hex2ua(k.priv)), 'spki', ua2ab(hex2ua(k.pub)), k.shaVersion),\n }))\n )\n const selfKeysWithFp = await Promise.all(\n this.selfKeys.map(async (k) => ({\n trusted: k.trusted,\n fp: fingerprintV1(k.pub),\n keypair: await cryptoPrimitives.RSA.importKeyPair('pkcs8', ua2ab(hex2ua(k.priv)), 'spki', ua2ab(hex2ua(k.pub)), k.shaVersion),\n }))\n )\n return {\n [keysData[0].dataOwner.dataOwner.id!]: {\n recoveredKeys: Object.fromEntries(parentKeysWithFp.map((k) => [k.fp, k.keypair])),\n keyAuthenticity: Object.fromEntries(parentKeysWithFp.map((k) => [k.fp, k.trusted])),\n },\n [keysData[1].dataOwner.dataOwner.id!]: {\n recoveredKeys: Object.fromEntries(selfKeysWithFp.map((k) => [k.fp, k.keypair])),\n keyAuthenticity: Object.fromEntries(selfKeysWithFp.map((k) => [k.fp, k.trusted])),\n },\n }\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]> {\n const untrusted = new Set(\n delegate.stub.cryptoActorProperties?.flatMap((p) => {\n if (p.id == untrustedKeyPropId && p.typedValue?.stringValue != undefined) {\n return [p.typedValue.stringValue]\n } else {\n return []\n }\n })\n )\n return Promise.resolve(publicKeys.filter((k) => !untrusted.has(fingerprintV2(k))))\n }\n\n generateNewKeyForDataOwner(self: DataOwnerWithType, cryptoPrimitives: CryptoPrimitives): Promise<KeyPair<CryptoKey> | boolean | 'keyless'> {\n if (this.options.overrideGenerateNewKeyForDataOwner) {\n return this.options.overrideGenerateNewKeyForDataOwner()\n }\n return Promise.reject(new Error('Should not be called now'))\n }\n}\n\ndescribe('CSM-729', async function () {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n it('User with untrusted key', async function () {\n const { grandCredentials: parent, parentCredentials: hcp } = await createHcpHierarchyApis(env)\n // Create some data to use the original keys\n const initialApi = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcp.user, password: hcp.password },\n new TrustedKeysStrategy(\n [{ priv: parent.privateKey, pub: parent.publicKey, trusted: true, shaVersion: ShaVersion.Sha1 }],\n [{ priv: hcp.privateKey, pub: hcp.publicKey, trusted: true, shaVersion: ShaVersion.Sha1 }]\n ),\n webcrypto as any,\n fetch,\n {\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n )\n const user = await initialApi.userApi.getCurrentUser()\n const pat1 = await initialApi.patientApi.createPatientWithUser(\n user,\n await initialApi.patientApi.newInstance(\n user,\n {\n firstName: 'John',\n lastName: 'Doe',\n note: 'Secret note',\n },\n {\n additionalDelegates: { [parent.dataOwnerId]: AccessLevelEnum.WRITE },\n }\n )\n )\n // Check exchange data was created as expected\n const selfSelfXdata = await initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, hcp.dataOwnerId)\n const selfParentXdata = await initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, parent.dataOwnerId)\n expect(selfSelfXdata).to.not.be.undefined\n expect(selfParentXdata).to.not.be.undefined\n expect(selfSelfXdata).to.have.length(1)\n expect(selfParentXdata).to.have.length(1)\n // Prepare for new api with untrusted key\n //// Mark self hcp keys as untrusted\n let selfHcp = await initialApi.healthcarePartyApi.getCurrentHealthcareParty()\n selfHcp = await initialApi.healthcarePartyApi.modifyHealthcareParty({\n ...selfHcp,\n cryptoActorProperties: [\n ...(selfHcp.cryptoActorProperties || []),\n {\n id: untrustedKeyPropId,\n typedValue: { stringValue: fingerprintV2(hcp.publicKey) },\n },\n ],\n })\n //// Mark parent hcp keys as untrusted and add new key (currently can't be done through crypto strategies)\n const newParentKey = await initialApi.cryptoApi.primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n const newParentKeySpki = ua2hex(await initialApi.cryptoApi.primitives.RSA.exportKey(newParentKey.publicKey, 'spki'))\n const newParentKeyPkcs8 = ua2hex(await initialApi.cryptoApi.primitives.RSA.exportKey(newParentKey.privateKey, 'pkcs8'))\n const adminApi = await initMasterApi(env)\n let parentHcp = await adminApi.healthcarePartyApi.getHealthcareParty(parent.dataOwnerId)\n parentHcp = await adminApi.healthcarePartyApi.modifyHealthcareParty({\n // Hcp normally doesn't have right to modify parent, depends on permissions\n ...parentHcp,\n cryptoActorProperties: [\n ...(parentHcp.cryptoActorProperties || []),\n {\n id: untrustedKeyPropId,\n typedValue: { stringValue: fingerprintV2(parent.publicKey) },\n },\n ],\n publicKeysForOaepWithSha256: [...(parentHcp.publicKeysForOaepWithSha256 || []), newParentKeySpki],\n })\n //// No need to invalidate exchange data, as untrusted keys are not used to validate it\n // Setup new api\n let didCreateNewKey = false\n const newHcpKey = await initialApi.cryptoApi.primitives.RSA.generateKeyPair(ShaVersion.Sha256)\n const newHcpKeySpki = ua2hex(await initialApi.cryptoApi.primitives.RSA.exportKey(newHcpKey.publicKey, 'spki'))\n const newHcpKeyPkcs8 = ua2hex(await initialApi.cryptoApi.primitives.RSA.exportKey(newHcpKey.privateKey, 'pkcs8'))\n const apiWithUntrustedKeysStorages = {\n // Using a new storage, simulates wiping the local storage\n storage: new TestStorage(),\n keyStorage: new TestKeyStorage(),\n }\n const apiWithUntrustedKey = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcp.user, password: hcp.password },\n new TrustedKeysStrategy(\n [\n { priv: parent.privateKey, pub: parent.publicKey, trusted: false, shaVersion: ShaVersion.Sha1 },\n { priv: newParentKeyPkcs8, pub: newParentKeySpki, trusted: true, shaVersion: ShaVersion.Sha256 },\n ],\n [{ priv: hcp.privateKey, pub: hcp.publicKey, trusted: false, shaVersion: ShaVersion.Sha1 }],\n {\n overrideGenerateNewKeyForDataOwner: () => {\n didCreateNewKey = true\n return Promise.resolve(newHcpKey)\n },\n }\n ),\n webcrypto as any,\n fetch,\n apiWithUntrustedKeysStorages\n )\n expect(didCreateNewKey).to.eq(true)\n // Check all keys are available but only new keys are trusted\n expect(\n await apiWithUntrustedKey.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(\n await apiWithUntrustedKey.healthcarePartyApi.getHealthcareParty(hcp.dataOwnerId)\n )\n ).to.have.members([newHcpKeySpki])\n expect(\n await apiWithUntrustedKey.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(\n await apiWithUntrustedKey.healthcarePartyApi.getHealthcareParty(parent.dataOwnerId)\n )\n ).to.have.members([newParentKeySpki])\n expect(await apiWithUntrustedKey.cryptoApi.userKeysManager.getCurrentUserHierarchyAvailablePublicKeysHex()).to.have.members([\n newHcpKeySpki,\n hcp.publicKey,\n parent.publicKey,\n newParentKeySpki,\n ])\n expect(await apiWithUntrustedKey.cryptoApi.userKeysManager.getCurrentUserAvailablePublicKeysHex(false)).to.have.members([\n newHcpKeySpki,\n hcp.publicKey,\n ])\n // Check can still read old data\n const pat1Recovered = await apiWithUntrustedKey.patientApi.getPatientWithUser(user, pat1.id!)\n expect(pat1Recovered.note).to.eq('Secret note')\n // Check can create new data\n const pat2 = await initialApi.patientApi.createPatientWithUser(\n user,\n await initialApi.patientApi.newInstance(\n user,\n {\n firstName: 'Joe',\n lastName: 'Doe',\n note: 'Secret note',\n },\n {\n additionalDelegates: { [parent.dataOwnerId]: AccessLevelEnum.WRITE },\n }\n )\n )\n // Check created new exchange data and only used the new trusted keys for it\n const selfSelfXdata2 = await initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, hcp.dataOwnerId)\n const selfParentXdata2 = await initialApi.cryptoApi.exchangeData.base.getExchangeDataByDelegatorDelegatePair(hcp.dataOwnerId, parent.dataOwnerId)\n expect(selfSelfXdata2).to.not.be.undefined\n expect(selfParentXdata2).to.not.be.undefined\n expect(selfSelfXdata2).to.have.length(2)\n expect(selfParentXdata2).to.have.length(2)\n const newSelfSelfXdata = selfSelfXdata2.filter((xd) => xd.id !== selfSelfXdata[0].id)!\n expect(newSelfSelfXdata).to.have.length(1)\n const newSelfSelfXDataUsedFps = Object.keys(newSelfSelfXdata[0].exchangeKey)\n expect(newSelfSelfXDataUsedFps).to.have.length(1)\n expect(newSelfSelfXDataUsedFps[0]).to.eq(fingerprintV2(newHcpKeySpki))\n const newSelfParentXdata = selfParentXdata2.filter((xd) => xd.id !== selfParentXdata[0].id)!\n expect(newSelfParentXdata).to.have.length(1)\n const newSelfParentXDataUsedFps = Object.keys(newSelfParentXdata[0].exchangeKey)\n expect(newSelfParentXDataUsedFps).to.have.length(2)\n expect(newSelfParentXDataUsedFps).to.have.members([fingerprintV2(newHcpKeySpki), fingerprintV2(newParentKeySpki)])\n // Check after reinitialization with keys already in storage the \"verified\" situation is unchanged.\n const apiWithUntrustedKey2 = await IcureApi.initialise(\n env.iCureUrl,\n { username: hcp.user, password: hcp.password },\n new TrustedKeysStrategy([], [], { failRecoverAndVerifySelfHierarchyKeys: true }),\n webcrypto as any,\n fetch,\n apiWithUntrustedKeysStorages\n )\n expect(\n await apiWithUntrustedKey2.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(\n await apiWithUntrustedKey2.healthcarePartyApi.getHealthcareParty(hcp.dataOwnerId)\n )\n ).to.have.members([newHcpKeySpki])\n expect(\n await apiWithUntrustedKey2.cryptoApi.userKeysManager.getVerifiedPublicKeysFor(\n await apiWithUntrustedKey2.healthcarePartyApi.getHealthcareParty(parent.dataOwnerId)\n )\n ).to.have.members([newParentKeySpki])\n expect(await apiWithUntrustedKey2.cryptoApi.userKeysManager.getCurrentUserHierarchyAvailablePublicKeysHex()).to.have.members([\n newHcpKeySpki,\n hcp.publicKey,\n parent.publicKey,\n newParentKeySpki,\n ])\n expect(await apiWithUntrustedKey2.cryptoApi.userKeysManager.getCurrentUserAvailablePublicKeysHex(false)).to.have.members([\n newHcpKeySpki,\n hcp.publicKey,\n ])\n })\n})\n"]}
@@ -46,7 +46,7 @@ class TestCryptoStrategies {
46
46
  {
47
47
  recoveredKeys: recoveredKey
48
48
  ? {
49
- [recoveredKey.pair.publicKey.slice(-32)]: yield cryptoPrimitives.RSA.importKeyPair('pkcs8', (0, icc_x_api_1.hex2ua)(recoveredKey.pair.privateKey), 'spki', (0, icc_x_api_1.hex2ua)(recoveredKey.pair.publicKey), recoveredKey.shaVersion),
49
+ [recoveredKey.pair.publicKey.slice(-32)]: yield cryptoPrimitives.RSA.importKeyPair('pkcs8', (0, icc_x_api_1.ua2ab)((0, icc_x_api_1.hex2ua)(recoveredKey.pair.privateKey)), 'spki', (0, icc_x_api_1.ua2ab)((0, icc_x_api_1.hex2ua)(recoveredKey.pair.publicKey)), recoveredKey.shaVersion),
50
50
  }
51
51
  : {},
52
52
  keyAuthenticity: {},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,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;oBAChE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,EAAG,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC,CAAA;gBAC1G,CAAC;qBAAM,CAAC;oBACN,OAAO;wBACL,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,EAAG;wBAChC,EAAE,aAAa,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,gBAAgB,EAAE;qBACpG,CAAA;gBACH,CAAC;YACH,CAAC,CAAA,CAAC,CACH,CACF,CAAA;QACH,CAAC;KAAA;IAED,wBAAwB,CAAC,QAAiC,EAAE,UAAoB;QAC9E,IAAI,IAAI,CAAC,0BAA0B,EAAE,CAAC;YACpC,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA2B,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3F,CAAC;;YAAM,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAC3C,CAAC;IAED,oCAAoC,CAAC,SAAkC;QACrE,OAAO,SAAS,CAAC,IAAI,KAAK,KAAK,CAAA;IACjC,CAAC;CACF;AAtED,oDAsEC","sourcesContent":["import { CryptoStrategies } from '../../icc-x-api/crypto/CryptoStrategies'\nimport { KeyPair, RSAUtils, RSAUtilsImpl, ShaVersion } from '../../icc-x-api/crypto/RSA'\nimport { hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from '../../icc-x-api/crypto/utils'\nimport { webcrypto } from 'crypto'\nimport { CryptoPrimitives, hex2ua, ua2hex } from '../../icc-x-api'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\n\nexport class TestCryptoStrategies implements CryptoStrategies {\n private readonly RSA = new RSAUtilsImpl(webcrypto as any)\n recoverAndVerifyCallsParams: Array<{ dataOwner: DataOwnerWithType; unknownKeys: string[]; unavailableKeys: string[] }[]> = []\n\n constructor(\n private readonly keyPair?: KeyPair<CryptoKey>,\n private readonly verifiedSelfKeys: { [p: string]: boolean } = {},\n private readonly limitVerifiedDelegatesKeys?: Set<string>,\n private readonly recoveredParentKeys: { [parentId: string]: { pair: KeyPair<string>; shaVersion: ShaVersion } } = {}\n ) {}\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType): Promise<KeyPair<CryptoKey> | boolean> {\n if (!this.keyPair) return false\n const knownKeys = new Set([...hexPublicKeysWithSha1Of(self), ...hexPublicKeysWithSha256Of(self)])\n const publicKey = ua2hex(await this.RSA.exportKey(this.keyPair.publicKey, 'spki'))\n return knownKeys.has(publicKey) ? false : this.keyPair\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: { dataOwner: DataOwnerWithType; unknownKeys: string[]; unavailableKeys: string[] }[],\n cryptoPrimitives: CryptoPrimitives\n ): Promise<{ [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } } }> {\n this.recoverAndVerifyCallsParams.push(keysData)\n const self = keysData[keysData.length - 1].dataOwner\n const knownKeys = new Set([...hexPublicKeysWithSha1Of(self.dataOwner), ...hexPublicKeysWithSha256Of(self.dataOwner)])\n const publicKey = this.keyPair ? ua2hex(await this.RSA.exportKey(this.keyPair.publicKey, 'spki')) : undefined\n return Object.fromEntries(\n await Promise.all(\n keysData.map(async (currData) => {\n if (currData.dataOwner.dataOwner.id! !== self.dataOwner.id!) {\n const recoveredKey = this.recoveredParentKeys[currData.dataOwner.dataOwner.id!]\n return [\n currData.dataOwner.dataOwner.id!,\n {\n recoveredKeys: recoveredKey\n ? {\n [recoveredKey.pair.publicKey.slice(-32)]: await cryptoPrimitives.RSA.importKeyPair(\n 'pkcs8',\n hex2ua(recoveredKey.pair.privateKey),\n 'spki',\n hex2ua(recoveredKey.pair.publicKey),\n recoveredKey.shaVersion\n ),\n }\n : {},\n keyAuthenticity: {},\n },\n ]\n } else if (publicKey === undefined || !knownKeys.has(publicKey)) {\n return [currData.dataOwner.dataOwner.id!, { recoveredKeys: {}, keyAuthenticity: this.verifiedSelfKeys }]\n } else {\n return [\n currData.dataOwner.dataOwner.id!,\n { recoveredKeys: { [publicKey.slice(-32)]: this.keyPair }, keyAuthenticity: this.verifiedSelfKeys },\n ]\n }\n })\n )\n )\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[]): Promise<string[]> {\n if (this.limitVerifiedDelegatesKeys) {\n return Promise.resolve(publicKeys.filter((x) => this.limitVerifiedDelegatesKeys!.has(x)))\n } else return Promise.resolve(publicKeys)\n }\n\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type !== 'hcp'\n }\n}\n"]}
1
+ {"version":3,"file":"TestCryptoStrategies.js","sourceRoot":"","sources":["../../../test/utils/TestCryptoStrategies.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAAwF;AACxF,wDAAiG;AACjG,mCAAkC;AAClC,+CAAyE;AAIzE,MAAa,oBAAoB;IAI/B,YACmB,OAA4B,EAC5B,mBAA6C,EAAE,EAC/C,0BAAwC,EACxC,sBAAiG,EAAE;QAHnG,YAAO,GAAP,OAAO,CAAqB;QAC5B,qBAAgB,GAAhB,gBAAgB,CAA+B;QAC/C,+BAA0B,GAA1B,0BAA0B,CAAc;QACxC,wBAAmB,GAAnB,mBAAmB,CAAgF;QAPrG,QAAG,GAAG,IAAI,kBAAY,CAAC,kBAAgB,CAAC,CAAA;QACzD,gCAA2B,GAAgG,EAAE,CAAA;IAO1H,CAAC;IA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gB,EAAE;qBACpG,CAAA;gBACH,CAAC;YACH,CAAC,CAAA,CAAC,CACH,CACF,CAAA;QACH,CAAC;KAAA;IAED,wBAAwB,CAAC,QAAiC,EAAE,UAAoB;QAC9E,IAAI,IAAI,CAAC,0BAA0B,EAAE,CAAC;YACpC,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA2B,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3F,CAAC;;YAAM,OAAO,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAC3C,CAAC;IAED,oCAAoC,CAAC,SAAkC;QACrE,OAAO,SAAS,CAAC,IAAI,KAAK,KAAK,CAAA;IACjC,CAAC;CACF;AAtED,oDAsEC","sourcesContent":["import { CryptoStrategies } from '../../icc-x-api/crypto/CryptoStrategies'\nimport { KeyPair, RSAUtils, RSAUtilsImpl, ShaVersion } from '../../icc-x-api/crypto/RSA'\nimport { hexPublicKeysWithSha1Of, hexPublicKeysWithSha256Of } from '../../icc-x-api/crypto/utils'\nimport { webcrypto } from 'crypto'\nimport { CryptoPrimitives, hex2ua, ua2ab, ua2hex } from '../../icc-x-api'\nimport { CryptoActorStubWithType } from '../../icc-api/model/CryptoActorStub'\nimport { DataOwnerWithType } from '../../icc-api/model/DataOwnerWithType'\n\nexport class TestCryptoStrategies implements CryptoStrategies {\n private readonly RSA = new RSAUtilsImpl(webcrypto as any)\n recoverAndVerifyCallsParams: Array<{ dataOwner: DataOwnerWithType; unknownKeys: string[]; unavailableKeys: string[] }[]> = []\n\n constructor(\n private readonly keyPair?: KeyPair<CryptoKey>,\n private readonly verifiedSelfKeys: { [p: string]: boolean } = {},\n private readonly limitVerifiedDelegatesKeys?: Set<string>,\n private readonly recoveredParentKeys: { [parentId: string]: { pair: KeyPair<string>; shaVersion: ShaVersion } } = {}\n ) {}\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType): Promise<KeyPair<CryptoKey> | boolean> {\n if (!this.keyPair) return false\n const knownKeys = new Set([...hexPublicKeysWithSha1Of(self), ...hexPublicKeysWithSha256Of(self)])\n const publicKey = ua2hex(await this.RSA.exportKey(this.keyPair.publicKey, 'spki'))\n return knownKeys.has(publicKey) ? false : this.keyPair\n }\n\n async recoverAndVerifySelfHierarchyKeys(\n keysData: { dataOwner: DataOwnerWithType; unknownKeys: string[]; unavailableKeys: string[] }[],\n cryptoPrimitives: CryptoPrimitives\n ): Promise<{ [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } } }> {\n this.recoverAndVerifyCallsParams.push(keysData)\n const self = keysData[keysData.length - 1].dataOwner\n const knownKeys = new Set([...hexPublicKeysWithSha1Of(self.dataOwner), ...hexPublicKeysWithSha256Of(self.dataOwner)])\n const publicKey = this.keyPair ? ua2hex(await this.RSA.exportKey(this.keyPair.publicKey, 'spki')) : undefined\n return Object.fromEntries(\n await Promise.all(\n keysData.map(async (currData) => {\n if (currData.dataOwner.dataOwner.id! !== self.dataOwner.id!) {\n const recoveredKey = this.recoveredParentKeys[currData.dataOwner.dataOwner.id!]\n return [\n currData.dataOwner.dataOwner.id!,\n {\n recoveredKeys: recoveredKey\n ? {\n [recoveredKey.pair.publicKey.slice(-32)]: await cryptoPrimitives.RSA.importKeyPair(\n 'pkcs8',\n ua2ab(hex2ua(recoveredKey.pair.privateKey)),\n 'spki',\n ua2ab(hex2ua(recoveredKey.pair.publicKey)),\n recoveredKey.shaVersion\n ),\n }\n : {},\n keyAuthenticity: {},\n },\n ]\n } else if (publicKey === undefined || !knownKeys.has(publicKey)) {\n return [currData.dataOwner.dataOwner.id!, { recoveredKeys: {}, keyAuthenticity: this.verifiedSelfKeys }]\n } else {\n return [\n currData.dataOwner.dataOwner.id!,\n { recoveredKeys: { [publicKey.slice(-32)]: this.keyPair }, keyAuthenticity: this.verifiedSelfKeys },\n ]\n }\n })\n )\n )\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[]): Promise<string[]> {\n if (this.limitVerifiedDelegatesKeys) {\n return Promise.resolve(publicKeys.filter((x) => this.limitVerifiedDelegatesKeys!.has(x)))\n } else return Promise.resolve(publicKeys)\n }\n\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return dataOwner.type !== 'hcp'\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  export declare const defaultRoles: {
2
+ ANY_ACTING_SCOPE: string[];
2
3
  BASIC_DATA_OWNER: string[];
3
4
  HIERARCHICAL_DATA_OWNER: string[];
4
5
  PATIENT_USER_MANAGER: string[];
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultRoles = void 0;
4
4
  exports.defaultRoles = {
5
+ ANY_ACTING_SCOPE: ['DataOwner.ActingScope.OfChildren'],
5
6
  BASIC_DATA_OWNER: [
6
7
  'HealthElementManagement.Create',
7
8
  'HealthElementManagement.Purge',