@icure/api 6.4.0 → 6.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/icc-api/model/models.d.ts +2 -2
- package/icc-x-api/crypto/AES.d.ts +1 -0
- package/icc-x-api/crypto/AES.js +13 -4
- package/icc-x-api/crypto/AES.js.map +1 -1
- package/icc-x-api/filters/filters.d.ts +1 -1
- package/icc-x-api/icc-accesslog-x-api.js +10 -7
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-bekmehr-x-api.d.ts +1 -1
- package/icc-x-api/icc-calendar-item-x-api.js +14 -6
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.js +12 -9
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +7 -1
- package/icc-x-api/icc-crypto-x-api.js +84 -69
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.js +5 -4
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.js +8 -2
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.js +8 -2
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.js +70 -64
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/utils/asn1-packer.d.ts +1 -1
- package/icc-x-api/utils/asn1-parser.d.ts +1 -1
- package/icc-x-api/utils/net-utils.d.ts +2 -2
- package/package.json +1 -1
|
@@ -269,5 +269,5 @@ export * from './VmpStub';
|
|
|
269
269
|
export * from './Vtm';
|
|
270
270
|
export * from './Wada';
|
|
271
271
|
export * from './Weekday';
|
|
272
|
-
export type EncryptedEntity = AccessLog | Article | CalendarItem | Classification | Contact | Document | Form | HealthElement | Invoice | MaintenanceTask | Message | Patient | Receipt;
|
|
273
|
-
export type EncryptedParentEntity = Message | Patient;
|
|
272
|
+
export declare type EncryptedEntity = AccessLog | Article | CalendarItem | Classification | Contact | Document | Form | HealthElement | Invoice | MaintenanceTask | Message | Patient | Receipt;
|
|
273
|
+
export declare type EncryptedParentEntity = Message | Patient;
|
package/icc-x-api/crypto/AES.js
CHANGED
|
@@ -12,9 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.AES = exports.AESUtils = void 0;
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
14
|
class AESUtils {
|
|
15
|
-
set debug(value) {
|
|
16
|
-
this._debug = value;
|
|
17
|
-
}
|
|
18
15
|
constructor(crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : {}) {
|
|
19
16
|
/********* AES Config **********/
|
|
20
17
|
this.ivLength = 16;
|
|
@@ -23,9 +20,13 @@ class AESUtils {
|
|
|
23
20
|
name: 'AES-CBC',
|
|
24
21
|
length: 256,
|
|
25
22
|
};
|
|
23
|
+
this.aesImportParams = { name: this.aesAlgorithmEncryptName };
|
|
26
24
|
this._debug = false;
|
|
27
25
|
this.crypto = crypto;
|
|
28
26
|
}
|
|
27
|
+
set debug(value) {
|
|
28
|
+
this._debug = value;
|
|
29
|
+
}
|
|
29
30
|
encrypt(cryptoKey, plainData, rawKey = '<NA>') {
|
|
30
31
|
return new Promise((resolve, reject) => {
|
|
31
32
|
if (plainData instanceof Uint8Array) {
|
|
@@ -137,7 +138,15 @@ class AESUtils {
|
|
|
137
138
|
return new Promise((resolve, reject) => {
|
|
138
139
|
const extractable = true;
|
|
139
140
|
const keyUsages = ['decrypt', 'encrypt'];
|
|
140
|
-
return this.crypto.subtle
|
|
141
|
+
return this.crypto.subtle
|
|
142
|
+
.importKey(format, aesKey, this.aesImportParams, extractable, keyUsages)
|
|
143
|
+
.catch((err) => {
|
|
144
|
+
if (format == 'raw' && (aesKey instanceof ArrayBuffer || ArrayBuffer.isView(aesKey))) {
|
|
145
|
+
console.warn(`Import of key ${(0, utils_1.ua2hex)(aesKey)} failed`);
|
|
146
|
+
}
|
|
147
|
+
throw err;
|
|
148
|
+
})
|
|
149
|
+
.then(resolve, reject);
|
|
141
150
|
});
|
|
142
151
|
}
|
|
143
152
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AES.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/AES.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAA+C;AAE/C,MAAa,QAAQ;IAYnB,IAAI,KAAK,CAAC,KAAc;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,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;QAfvI,iCAAiC;QACjC,aAAQ,GAAG,EAAE,CAAA;QACb,4BAAuB,GAAG,SAAS,CAAA;QAEnC,oBAAe,GAAoB;YACjC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,GAAG;SACZ,CAAA;QAEO,WAAM,GAAY,KAAK,CAAA;QAO7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,OAAO,CAAC,SAAoB,EAAE,SAAmC,EAAE,MAAM,GAAG,MAAM;QAChF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAoC,EAAE,MAA4B,EAAE,EAAE;YACxF,IAAI,SAAS,YAAY,UAAU,EAAE;gBACnC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAA;gBAC/B,SAAS,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAgB,CAAA;aAC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SAAS,CAAC,CAAA;YACpD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAa,EAAE,MAAa,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACvI,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAxKD,4BAwKC;AAEY,QAAA,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA","sourcesContent":["import { appendBuffer, ua2hex } from '../utils'\n\nexport class AESUtils {\n /********* AES Config **********/\n ivLength = 16\n aesAlgorithmEncryptName = 'AES-CBC'\n\n aesKeyGenParams: AesKeyGenParams = {\n name: 'AES-CBC',\n length: 256,\n }\n private crypto: Crypto\n private _debug: boolean = false\n\n set debug(value: boolean) {\n this._debug = value\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n encrypt(cryptoKey: CryptoKey, plainData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (plainData instanceof Uint8Array) {\n const buffer = plainData.buffer\n plainData = (buffer.byteLength > plainData.byteLength ? buffer.slice(0, plainData.byteLength) : buffer) as ArrayBuffer\n }\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: this.generateIV(this.ivLength),\n }\n this._debug && console.log(`encrypt ${ua2hex(plainData)} with ${rawKey}`)\n this.crypto.subtle\n .encrypt(\n {\n ...aesAlgorithmEncrypt,\n } /* some ill behaved implementations change the values in place */,\n cryptoKey,\n plainData\n )\n .then(\n (cipherData) => {\n this._debug && console.log(`cipherData: ${ua2hex(cipherData)}`)\n return resolve(appendBuffer(aesAlgorithmEncrypt.iv.buffer as ArrayBuffer, cipherData))\n },\n (err) => reject('AES encryption failed: ' + err)\n )\n })\n }\n\n /**\n *\n * @param cryptoKey (CryptoKey)\n * @param encryptedData (ArrayBuffer)\n * @param rawKey\n * @returns {Promise} will be ArrayBuffer\n */\n decrypt(cryptoKey: CryptoKey, encryptedData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (!cryptoKey) {\n return reject('No crypto key provided for decryption')\n }\n const encryptedDataUint8 = encryptedData instanceof ArrayBuffer ? new Uint8Array(encryptedData) : encryptedData\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: encryptedDataUint8.subarray(0, this.ivLength),\n\n /*\n * IF THIS BIT OF CODE PRODUCES A DOMEXCEPTION CODE 0 ERROR, IT MIGHT BE RELATED TO THIS:\n *\n * NOTOK:\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[hcpartyId] && hcparty.hcPartyKeys[hcpartyId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + hcpartyId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[hcpartyId][1];\n *\n * SHOULD BE:\n * var delegatorId = patient.delegations[hcpartyId][0].owner;\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[delegatorId] && hcparty.hcPartyKeys[delegatorId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + delegatorId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[delegatorId][1];\n */\n }\n this._debug && console.log(`decrypt ${ua2hex(encryptedData)} with ${rawKey}`)\n this.crypto.subtle.decrypt(aesAlgorithmEncrypt, cryptoKey, encryptedDataUint8.subarray(this.ivLength, encryptedDataUint8.length)).then(\n (decipheredData) => {\n this._debug && console.log(`decipheredData: ${ua2hex(decipheredData)}`)\n resolve(decipheredData)\n },\n (err) => {\n reject('AES decryption failed: ' + err)\n }\n )\n })\n }\n\n async decryptSome(cryptoKeys: CryptoKey[], uint8Array: Uint8Array): Promise<ArrayBuffer> {\n try {\n return this.decrypt(cryptoKeys[0], uint8Array)\n } catch (e) {\n if (cryptoKeys.length > 1) {\n return this.decryptSome(cryptoKeys.slice(1), uint8Array)\n } else {\n throw e\n }\n }\n }\n\n // generate an AES key\n // noinspection JSUnusedGlobalSymbols\n /**\n *\n * @param toHex boolean, if true, it returns hex String\n * @returns {Promise} either Hex string or CryptoKey\n */\n generateCryptoKey(toHex: false): Promise<CryptoKey>\n generateCryptoKey(toHex: true): Promise<string>\n generateCryptoKey(toHex: boolean): Promise<string | CryptoKey> {\n return new Promise((resolve: (value: CryptoKey | string) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n const cryptoKeyPromise: Promise<CryptoKey> = this.crypto.subtle.generateKey(this.aesKeyGenParams, extractable, keyUsages) as Promise<CryptoKey>\n return toHex === undefined || !toHex\n ? cryptoKeyPromise.then(resolve, reject)\n : cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve(ua2hex(raw)), reject)\n })\n }\n\n // noinspection JSMethodCanBeStatic\n generateIV(ivByteLength: number): Uint8Array {\n return new Uint8Array(this.crypto.getRandomValues(new Uint8Array(ivByteLength)))\n }\n\n /**\n * This function return a promise which will be the key Format will be either 'raw' or 'jwk'.\n * JWK: Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n *\n * @param cryptoKey CryptoKey\n * @param format will be 'raw' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKey(cryptoKey: CryptoKey, format: 'raw'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: 'jwk' | 'raw'): Promise<ArrayBuffer | JsonWebKey> {\n return new Promise((resolve: (value: ArrayBuffer | JsonWebKey) => any, reject: (reason: any) => any) => {\n return this.crypto.subtle.exportKey(format as any, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n * the ability to import a key that have already been created elsewhere, for use within the web\n * application that is invoking the import function, for use within the importing web application's\n * origin. This necessiates an interoperable key format, such as JSON Web Key [JWK] which may be\n * represented as octets.\n *\n * https://chromium.googlesource.com/chromium/blink.git/+/6b902997e3ca0384c8fa6fe56f79ecd7589d3ca6/LayoutTests/crypto/resources/common.js\n *\n * @param format 'raw' or 'jwk'\n * @param aesKey\n * @returns {*}\n */\n importKey(format: 'jwk' | 'raw', aesKey: JsonWebKey | ArrayBuffer | Uint8Array): Promise<CryptoKey> {\n return new Promise((resolve: (value: CryptoKey) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n return this.crypto.subtle.importKey(format as any, aesKey as any, this.aesKeyGenParams, extractable, keyUsages).then(resolve, reject)\n })\n }\n}\n\nexport const AES = new AESUtils()\n"]}
|
|
1
|
+
{"version":3,"file":"AES.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/AES.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAuD;AAEvD,MAAa,QAAQ;IAmBnB,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;QAlBvI,iCAAiC;QACjC,aAAQ,GAAG,EAAE,CAAA;QACb,4BAAuB,GAAG,SAAS,CAAA;QAEnC,oBAAe,GAAoB;YACjC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,GAAG;SACZ,CAAA;QAEO,oBAAe,GAAwB,EAAE,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,CAAA;QAG7E,WAAM,GAAY,KAAK,CAAA;QAO7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAND,IAAI,KAAK,CAAC,KAAc;QACtB,IAAI,CAAC,MAAM,GAAG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,OAAO,CAAC,CAAC,OAAiD,EAAE,MAA4B,EAAE,EAAE;YACrG,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,MAAa,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QACrF,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,MAAqB,EAAE,MAA6C;QAC5E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAkC,EAAE,MAA4B,EAAE,EAAE;YACtF,MAAM,WAAW,GAAG,IAAI,CAAA;YACxB,MAAM,SAAS,GAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;YACpD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM;iBACtB,SAAS,CAAC,MAAa,EAAE,MAAa,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,SAAS,CAAC;iBACrF,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,IAAI,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE;oBACpF,OAAO,CAAC,IAAI,CAAC,iBAAiB,IAAA,cAAM,EAAC,MAAM,CAAC,SAAS,CAAC,CAAA;iBACvD;gBACD,MAAM,GAAG,CAAA;YACX,CAAC,CAAC;iBACD,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAnLD,4BAmLC;AAEY,QAAA,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA","sourcesContent":["import { appendBuffer, hex2ua, ua2hex } from '../utils'\n\nexport class AESUtils {\n /********* AES Config **********/\n ivLength = 16\n aesAlgorithmEncryptName = 'AES-CBC'\n\n aesKeyGenParams: AesKeyGenParams = {\n name: 'AES-CBC',\n length: 256,\n }\n\n private aesImportParams: AlgorithmIdentifier = { name: this.aesAlgorithmEncryptName }\n\n private crypto: Crypto\n private _debug: boolean = false\n\n set debug(value: boolean) {\n this._debug = value\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n encrypt(cryptoKey: CryptoKey, plainData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (plainData instanceof Uint8Array) {\n const buffer = plainData.buffer\n plainData = (buffer.byteLength > plainData.byteLength ? buffer.slice(0, plainData.byteLength) : buffer) as ArrayBuffer\n }\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: this.generateIV(this.ivLength),\n }\n this._debug && console.log(`encrypt ${ua2hex(plainData)} with ${rawKey}`)\n this.crypto.subtle\n .encrypt(\n {\n ...aesAlgorithmEncrypt,\n } /* some ill behaved implementations change the values in place */,\n cryptoKey,\n plainData\n )\n .then(\n (cipherData) => {\n this._debug && console.log(`cipherData: ${ua2hex(cipherData)}`)\n return resolve(appendBuffer(aesAlgorithmEncrypt.iv.buffer as ArrayBuffer, cipherData))\n },\n (err) => reject('AES encryption failed: ' + err)\n )\n })\n }\n\n /**\n *\n * @param cryptoKey (CryptoKey)\n * @param encryptedData (ArrayBuffer)\n * @param rawKey\n * @returns {Promise} will be ArrayBuffer\n */\n decrypt(cryptoKey: CryptoKey, encryptedData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (!cryptoKey) {\n return reject('No crypto key provided for decryption')\n }\n const encryptedDataUint8 = encryptedData instanceof ArrayBuffer ? new Uint8Array(encryptedData) : encryptedData\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: encryptedDataUint8.subarray(0, this.ivLength),\n\n /*\n * IF THIS BIT OF CODE PRODUCES A DOMEXCEPTION CODE 0 ERROR, IT MIGHT BE RELATED TO THIS:\n *\n * NOTOK:\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[hcpartyId] && hcparty.hcPartyKeys[hcpartyId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + hcpartyId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[hcpartyId][1];\n *\n * SHOULD BE:\n * var delegatorId = patient.delegations[hcpartyId][0].owner;\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[delegatorId] && hcparty.hcPartyKeys[delegatorId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + delegatorId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[delegatorId][1];\n */\n }\n this._debug && console.log(`decrypt ${ua2hex(encryptedData)} with ${rawKey}`)\n this.crypto.subtle.decrypt(aesAlgorithmEncrypt, cryptoKey, encryptedDataUint8.subarray(this.ivLength, encryptedDataUint8.length)).then(\n (decipheredData) => {\n this._debug && console.log(`decipheredData: ${ua2hex(decipheredData)}`)\n resolve(decipheredData)\n },\n (err) => {\n reject('AES decryption failed: ' + err)\n }\n )\n })\n }\n\n async decryptSome(cryptoKeys: CryptoKey[], uint8Array: Uint8Array): Promise<ArrayBuffer> {\n try {\n return this.decrypt(cryptoKeys[0], uint8Array)\n } catch (e) {\n if (cryptoKeys.length > 1) {\n return this.decryptSome(cryptoKeys.slice(1), uint8Array)\n } else {\n throw e\n }\n }\n }\n\n // generate an AES key\n // noinspection JSUnusedGlobalSymbols\n /**\n *\n * @param toHex boolean, if true, it returns hex String\n * @returns {Promise} either Hex string or CryptoKey\n */\n generateCryptoKey(toHex: false): Promise<CryptoKey>\n generateCryptoKey(toHex: true): Promise<string>\n generateCryptoKey(toHex: boolean): Promise<string | CryptoKey> {\n return new Promise((resolve: (value: CryptoKey | string) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n const cryptoKeyPromise: Promise<CryptoKey> = this.crypto.subtle.generateKey(this.aesKeyGenParams, extractable, keyUsages) as Promise<CryptoKey>\n return toHex === undefined || !toHex\n ? cryptoKeyPromise.then(resolve, reject)\n : cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve(ua2hex(raw)), reject)\n })\n }\n\n // noinspection JSMethodCanBeStatic\n generateIV(ivByteLength: number): Uint8Array {\n return new Uint8Array(this.crypto.getRandomValues(new Uint8Array(ivByteLength)))\n }\n\n /**\n * This function return a promise which will be the key Format will be either 'raw' or 'jwk'.\n * JWK: Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n *\n * @param cryptoKey CryptoKey\n * @param format will be 'raw' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKey(cryptoKey: CryptoKey, format: 'raw'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: 'jwk' | 'raw'): Promise<ArrayBuffer | JsonWebKey> {\n return new Promise((resolve: (value: ArrayBuffer | JsonWebKey) => any, reject: (reason: any) => any) => {\n return this.crypto.subtle.exportKey(format as any, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n * the ability to import a key that have already been created elsewhere, for use within the web\n * application that is invoking the import function, for use within the importing web application's\n * origin. This necessiates an interoperable key format, such as JSON Web Key [JWK] which may be\n * represented as octets.\n *\n * https://chromium.googlesource.com/chromium/blink.git/+/6b902997e3ca0384c8fa6fe56f79ecd7589d3ca6/LayoutTests/crypto/resources/common.js\n *\n * @param format 'raw' or 'jwk'\n * @param aesKey\n * @returns {*}\n */\n importKey(format: 'jwk' | 'raw', aesKey: JsonWebKey | ArrayBuffer | Uint8Array): Promise<CryptoKey> {\n return new Promise((resolve: (value: CryptoKey) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n return this.crypto.subtle\n .importKey(format as any, aesKey as any, this.aesImportParams, extractable, keyUsages)\n .catch((err) => {\n if (format == 'raw' && (aesKey instanceof ArrayBuffer || ArrayBuffer.isView(aesKey))) {\n console.warn(`Import of key ${ua2hex(aesKey)} failed`)\n }\n throw err\n })\n .then(resolve, reject)\n })\n }\n}\n\nexport const AES = new AESUtils()\n"]}
|
|
@@ -58,7 +58,7 @@ export * from './UserByIdsFilter';
|
|
|
58
58
|
export declare class Filter {
|
|
59
59
|
static patient(): PatientFilterBuilder;
|
|
60
60
|
}
|
|
61
|
-
export type AbstractFilter<T> = T extends Patient ? AbstractFilterPatient | ConstantFilter<Patient> | IntersectionFilter<Patient> | UnionFilter<Patient> | ComplementFilter<Patient> : T extends Contact ? AbstractFilterContact | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : T extends Service ? AbstractFilterService | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T>;
|
|
61
|
+
export declare type AbstractFilter<T> = T extends Patient ? AbstractFilterPatient | ConstantFilter<Patient> | IntersectionFilter<Patient> | UnionFilter<Patient> | ComplementFilter<Patient> : T extends Contact ? AbstractFilterContact | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : T extends Service ? AbstractFilterService | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T>;
|
|
62
62
|
declare abstract class FilterBuilder<T> {
|
|
63
63
|
filterProvider?: () => AbstractFilter<T>;
|
|
64
64
|
composer: (thisFilterBuilder: FilterBuilder<T>, otherFilterBuilder: FilterBuilder<T>) => FilterBuilder<T>;
|
|
@@ -80,9 +80,9 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
80
80
|
return this.crypto
|
|
81
81
|
.extractDelegationsSFKs(patient, hcpartyId)
|
|
82
82
|
.then((secretForeignKeys) => secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0
|
|
83
|
-
?
|
|
84
|
-
this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys))
|
|
85
|
-
this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys).join(','))
|
|
83
|
+
? usingPost
|
|
84
|
+
? this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys))
|
|
85
|
+
: this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys).join(','))
|
|
86
86
|
: Promise.resolve([]));
|
|
87
87
|
}
|
|
88
88
|
findByHCPartyPatientSecretFKeys(hcPartyId, secretFKeys) {
|
|
@@ -98,11 +98,12 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
98
98
|
? this.crypto
|
|
99
99
|
.extractKeysFromDelegationsForHcpHierarchy(hcpId, accessLog.id, _.size(accessLog.encryptionKeys) ? accessLog.encryptionKeys : accessLog.delegations)
|
|
100
100
|
.then(({ extractedKeys: sfks }) => {
|
|
101
|
+
sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks);
|
|
101
102
|
if (!sfks || !sfks.length) {
|
|
102
103
|
//console.log("Cannot decrypt contact", ctc.id)
|
|
103
104
|
return Promise.resolve(accessLog);
|
|
104
105
|
}
|
|
105
|
-
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0]
|
|
106
|
+
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0])).then((key) => (0, utils_1.decrypt)(accessLog, (ec) => this.crypto.AES.decrypt(key, ec).then((dec) => {
|
|
106
107
|
const jsonContent = dec && (0, utils_1.ua2utf8)(dec);
|
|
107
108
|
try {
|
|
108
109
|
return JSON.parse(jsonContent);
|
|
@@ -136,9 +137,11 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
136
137
|
: this.initEncryptionKeys(user, accessLog))
|
|
137
138
|
.then((accessLog) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user), accessLog.id, accessLog.encryptionKeys))
|
|
138
139
|
.then((eks) => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(eks.extractedKeys);
|
|
141
|
+
if (!keys.length)
|
|
142
|
+
throw new Error('No valid keys found for calendar item encryption');
|
|
143
|
+
const key = yield this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(keys[0]));
|
|
144
|
+
return (0, utils_1.crypt)(accessLog, (obj) => this.crypto.AES.encrypt(key, (0, utils_1.utf8_2ua)(JSON.stringify(obj)), keys[0]), this.cryptedKeys);
|
|
142
145
|
}))));
|
|
143
146
|
}
|
|
144
147
|
createAccessLog(body) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-accesslog-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-accesslog-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA4C;AAM5C,4BAA2B;AAC3B,mCAAmE;AAEnE,0EAAgG;AAMhG,MAAa,gBAAiB,SAAQ,yBAAe;IAKnD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAA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C,iBAA2B,CAAC,CAAC,IAAI,CACvF,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,gCACI,YAAY,KACf,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GACX,CAAA,CAC/B,CAAA;gBACH,CAAC,CAAC,CACH,CACJ,CAAA;gBAED,MAAM,UAAU,GAA6B,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;qBACpE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC;qBACxF,MAAM,CAAC,CAAC,GAA2B,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;qBACtD,KAAK,EAAE;qBACP,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;gBAEzB,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,UAAU,CAAC,CAAA;gBAErD,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,yBAAyB,EAAE;oBACnD,MAAK;iBACN;qBAAM,IAAI,cAAc,EAAE;oBACzB,WAAW,GAAG,cAAc,CAAA;iBAC7B;qBAAM;oBACL,MAAK;iBACN;aACF;YAED,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;CACF;AAtUD,4CAsUC","sourcesContent":["import { IccAccesslogApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { AccessLog, PaginatedListAccessLog } from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport interface AccessLogWithPatientId extends AccessLog {\n patientId: string\n}\n\nexport class IccAccesslogXApi extends IccAccesslogApi {\n crypto: IccCryptoXApi\n cryptedKeys = ['detail', 'objectId']\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n const accessslog = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.AccessLog',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n date: +new Date(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n user: user.id,\n patientId: patient.id,\n accessType: 'USER_ACCESS',\n },\n h || {}\n )\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(accessslog, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(accessslog, dataOwnerId!)\n\n _.extend(accessslog, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(accessslog)\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then(() =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, accessslog, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return accessslog\n })\n ))\n )\n return promise\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n * @param usingPost\n */\n\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? (usingPost ?\n this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys)) :\n this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(',')))\n : Promise.resolve([])\n )\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n decrypt(hcpId: string, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n accessLogs.map((accessLog) => {\n return accessLog.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n accessLog.id!,\n _.size(accessLog.encryptionKeys) ? accessLog.encryptionKeys! : accessLog.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n //console.log(\"Cannot decrypt contact\", ctc.id)\n return Promise.resolve(accessLog)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n decrypt(accessLog, (ec) =>\n this.crypto.AES.decrypt(key, ec).then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse access log', accessLog.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n )\n )\n })\n : Promise.resolve(accessLog)\n })\n )\n }\n\n initEncryptionKeys(user: models.User, accessLog: models.AccessLog): Promise<models.AccessLog> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(accessLog, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(accessLog, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((accessLog) =>\n this.crypto.appendEncryptionKeys(accessLog, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return Promise.all(\n accessLogs.map((accessLog) =>\n (accessLog.encryptionKeys && Object.keys(accessLog.encryptionKeys).length\n ? Promise.resolve(accessLog)\n : this.initEncryptionKeys(user, accessLog)\n )\n .then((accessLog: AccessLog) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.id!, accessLog.encryptionKeys!)\n )\n .then(async (eks: { extractedKeys: Array<string>; hcpartyId: string }) => {\n const rawKey = eks.extractedKeys[0].replace(/-/g, '')\n const key = await this.crypto.AES.importKey('raw', hex2ua(rawKey))\n return crypt(\n accessLog,\n (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj)), rawKey),\n this.cryptedKeys\n )\n })\n )\n )\n }\n\n createAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n createAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.createAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve()\n }\n\n getAccessLog(accessLogId: string): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n getAccessLogWithUser(user: models.User, accessLogId: string): Promise<models.AccessLog | any> {\n return super\n .getAccessLog(accessLogId)\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n }\n\n listAccessLogs(fromEpoch?: number, toEpoch?: number, startKey?: number, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n listAccessLogsWithUser(\n user: models.User,\n fromEpoch?: number,\n toEpoch?: number,\n startKey?: number,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<PaginatedListAccessLog> {\n return super\n .listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n modifyAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n async modifyAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.modifyAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : null\n }\n\n findByUserAfterDate(\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n findByUserAfterDateWithUser(\n user: models.User,\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<models.AccessLog | any> {\n return super\n .findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n async findLatestAccessLogsOfPatientsWithUser(user: models.User, userId: string, limit = 100, startDate?: number): Promise<models.AccessLog[]> {\n let foundAccessLogs: AccessLogWithPatientId[] = [],\n nextKeyPair: models.PaginatedDocumentKeyIdPairObject | undefined = undefined\n const numberRequestedAccessLogs = 100\n const MAX_WHILE_ITERATIONS = 5\n\n for (let currentIteration = 0; foundAccessLogs.length < limit && currentIteration < MAX_WHILE_ITERATIONS; currentIteration++) {\n const currentLimit = limit - foundAccessLogs.length\n const { rows: logs, nextKeyPair: newNextKeyPair }: models.PaginatedListAccessLog = (await super.findByUserAfterDate(\n userId,\n 'USER_ACCESS',\n startDate,\n nextKeyPair && JSON.stringify(nextKeyPair.startKey!),\n nextKeyPair && nextKeyPair.startKeyDocId!,\n numberRequestedAccessLogs,\n true\n )) as models.PaginatedListAccessLog\n const logsWithPatientId: AccessLogWithPatientId[] = await this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, logs as AccessLog[]).then(\n (decryptedLogs) =>\n Promise.all(\n _.map(decryptedLogs, (decryptedLog) => {\n return this.crypto.extractCryptedFKs(decryptedLog, user.healthcarePartyId as string).then(\n (keys) =>\n ({\n ...decryptedLog,\n patientId: _.head(keys.extractedKeys),\n } as AccessLogWithPatientId)\n )\n })\n )\n )\n\n const uniqueLogs: AccessLogWithPatientId[] = _.chain(logsWithPatientId)\n .reject((log) => _.some(foundAccessLogs, ({ patientId }) => patientId === log.patientId))\n .uniqBy((log: AccessLogWithPatientId) => log.patientId)\n .value()\n .slice(0, currentLimit)\n\n foundAccessLogs = [...foundAccessLogs, ...uniqueLogs]\n\n if ((logs || []).length < numberRequestedAccessLogs) {\n break\n } else if (newNextKeyPair) {\n nextKeyPair = newNextKeyPair\n } else {\n break\n }\n }\n\n return foundAccessLogs\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-accesslog-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-accesslog-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA4C;AAM5C,4BAA2B;AAC3B,mCAAmE;AAEnE,0EAAgG;AAMhG,MAAa,gBAAiB,SAAQ,yBAAe;IAKnD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAfzD,gBAAW,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC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AO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE,IAAI,CAAC,iBAA2B,CAAC,CAAC,IAAI,CACvF,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,gCACI,YAAY,KACf,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GACX,CAAA,CAC/B,CAAA;gBACH,CAAC,CAAC,CACH,CACJ,CAAA;gBAED,MAAM,UAAU,GAA6B,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;qBACpE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC;qBACxF,MAAM,CAAC,CAAC,GAA2B,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;qBACtD,KAAK,EAAE;qBACP,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;gBAEzB,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,UAAU,CAAC,CAAA;gBAErD,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,yBAAyB,EAAE;oBACnD,MAAK;iBACN;qBAAM,IAAI,cAAc,EAAE;oBACzB,WAAW,GAAG,cAAc,CAAA;iBAC7B;qBAAM;oBACL,MAAK;iBACN;aACF;YAED,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;CACF;AAxUD,4CAwUC","sourcesContent":["import { IccAccesslogApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { AccessLog, PaginatedListAccessLog } from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport interface AccessLogWithPatientId extends AccessLog {\n patientId: string\n}\n\nexport class IccAccesslogXApi extends IccAccesslogApi {\n crypto: IccCryptoXApi\n cryptedKeys = ['detail', 'objectId']\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n const accessslog = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.AccessLog',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n date: +new Date(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n user: user.id,\n patientId: patient.id,\n accessType: 'USER_ACCESS',\n },\n h || {}\n )\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(accessslog, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(accessslog, dataOwnerId!)\n\n _.extend(accessslog, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(accessslog)\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then(() =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, accessslog, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return accessslog\n })\n ))\n )\n return promise\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n * @param usingPost\n */\n\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n : Promise.resolve([])\n )\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n decrypt(hcpId: string, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n accessLogs.map((accessLog) => {\n return accessLog.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n accessLog.id!,\n _.size(accessLog.encryptionKeys) ? accessLog.encryptionKeys! : accessLog.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks)\n if (!sfks || !sfks.length) {\n //console.log(\"Cannot decrypt contact\", ctc.id)\n return Promise.resolve(accessLog)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0])).then((key) =>\n decrypt(accessLog, (ec) =>\n this.crypto.AES.decrypt(key, ec).then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse access log', accessLog.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n )\n )\n })\n : Promise.resolve(accessLog)\n })\n )\n }\n\n initEncryptionKeys(user: models.User, accessLog: models.AccessLog): Promise<models.AccessLog> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(accessLog, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(accessLog, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((accessLog) =>\n this.crypto.appendEncryptionKeys(accessLog, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return Promise.all(\n accessLogs.map((accessLog) =>\n (accessLog.encryptionKeys && Object.keys(accessLog.encryptionKeys).length\n ? Promise.resolve(accessLog)\n : this.initEncryptionKeys(user, accessLog)\n )\n .then((accessLog: AccessLog) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.id!, accessLog.encryptionKeys!)\n )\n .then(async (eks: { extractedKeys: Array<string>; hcpartyId: string }) => {\n const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(eks.extractedKeys)\n if (!keys.length) throw new Error('No valid keys found for calendar item encryption')\n const key = await this.crypto.AES.importKey('raw', hex2ua(keys[0]))\n return crypt(\n accessLog,\n (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj)), keys[0]),\n this.cryptedKeys\n )\n })\n )\n )\n }\n\n createAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n createAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.createAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve()\n }\n\n getAccessLog(accessLogId: string): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n getAccessLogWithUser(user: models.User, accessLogId: string): Promise<models.AccessLog | any> {\n return super\n .getAccessLog(accessLogId)\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n }\n\n listAccessLogs(fromEpoch?: number, toEpoch?: number, startKey?: number, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n listAccessLogsWithUser(\n user: models.User,\n fromEpoch?: number,\n toEpoch?: number,\n startKey?: number,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<PaginatedListAccessLog> {\n return super\n .listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n modifyAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n async modifyAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.modifyAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : null\n }\n\n findByUserAfterDate(\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n findByUserAfterDateWithUser(\n user: models.User,\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<models.AccessLog | any> {\n return super\n .findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n async findLatestAccessLogsOfPatientsWithUser(user: models.User, userId: string, limit = 100, startDate?: number): Promise<models.AccessLog[]> {\n let foundAccessLogs: AccessLogWithPatientId[] = [],\n nextKeyPair: models.PaginatedDocumentKeyIdPairObject | undefined = undefined\n const numberRequestedAccessLogs = 100\n const MAX_WHILE_ITERATIONS = 5\n\n for (let currentIteration = 0; foundAccessLogs.length < limit && currentIteration < MAX_WHILE_ITERATIONS; currentIteration++) {\n const currentLimit = limit - foundAccessLogs.length\n const { rows: logs, nextKeyPair: newNextKeyPair }: models.PaginatedListAccessLog = (await super.findByUserAfterDate(\n userId,\n 'USER_ACCESS',\n startDate,\n nextKeyPair && JSON.stringify(nextKeyPair.startKey!),\n nextKeyPair && nextKeyPair.startKeyDocId!,\n numberRequestedAccessLogs,\n true\n )) as models.PaginatedListAccessLog\n const logsWithPatientId: AccessLogWithPatientId[] = await this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, logs as AccessLog[]).then(\n (decryptedLogs) =>\n Promise.all(\n _.map(decryptedLogs, (decryptedLog) => {\n return this.crypto.extractCryptedFKs(decryptedLog, user.healthcarePartyId as string).then(\n (keys) =>\n ({\n ...decryptedLog,\n patientId: _.head(keys.extractedKeys),\n } as AccessLogWithPatientId)\n )\n })\n )\n )\n\n const uniqueLogs: AccessLogWithPatientId[] = _.chain(logsWithPatientId)\n .reject((log) => _.some(foundAccessLogs, ({ patientId }) => patientId === log.patientId))\n .uniqBy((log: AccessLogWithPatientId) => log.patientId)\n .value()\n .slice(0, currentLimit)\n\n foundAccessLogs = [...foundAccessLogs, ...uniqueLogs]\n\n if ((logs || []).length < numberRequestedAccessLogs) {\n break\n } else if (newNextKeyPair) {\n nextKeyPair = newNextKeyPair\n } else {\n break\n }\n }\n\n return foundAccessLogs\n }\n}\n"]}
|
|
@@ -5,7 +5,7 @@ import { IccDocumentXApi } from './icc-document-x-api';
|
|
|
5
5
|
import { IccHelementXApi } from './icc-helement-x-api';
|
|
6
6
|
import { Contact, Document, HealthElement, Service } from '../icc-api/model/models';
|
|
7
7
|
import { AuthenticationProvider } from './auth/AuthenticationProvider';
|
|
8
|
-
export type Patcher = ContactPatcher | HealthElementPatcher | DocumentPatcher | ServicePatcher;
|
|
8
|
+
export declare type Patcher = ContactPatcher | HealthElementPatcher | DocumentPatcher | ServicePatcher;
|
|
9
9
|
export interface ContactPatcher {
|
|
10
10
|
type: 'ContactDto';
|
|
11
11
|
patch: (contacts: Contact[]) => Promise<Contact[]>;
|
|
@@ -74,9 +74,9 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
74
74
|
findBy(hcpartyId, patient, usingPost = false) {
|
|
75
75
|
return this.crypto.extractDelegationsSFKs(patient, hcpartyId).then((secretForeignKeys) => {
|
|
76
76
|
return secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0
|
|
77
|
-
?
|
|
78
|
-
this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys))
|
|
79
|
-
this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys).join(','))
|
|
77
|
+
? usingPost
|
|
78
|
+
? this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys))
|
|
79
|
+
: this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId, _.uniq(secretForeignKeys.extractedKeys).join(','))
|
|
80
80
|
: Promise.resolve([]);
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -84,7 +84,9 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
84
84
|
return super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems));
|
|
85
85
|
}
|
|
86
86
|
findByHCPartyPatientSecretFKeysArray(hcPartyId, secretFKeys) {
|
|
87
|
-
return super
|
|
87
|
+
return super
|
|
88
|
+
.findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)
|
|
89
|
+
.then((calendarItems) => this.decrypt(hcPartyId, calendarItems));
|
|
88
90
|
}
|
|
89
91
|
createCalendarItem(body) {
|
|
90
92
|
throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption');
|
|
@@ -189,7 +191,12 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
189
191
|
? Promise.resolve(calendarItem)
|
|
190
192
|
: this.initEncryptionKeys(user, calendarItem))
|
|
191
193
|
.then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user), calendarItem.id, calendarItem.encryptionKeys))
|
|
192
|
-
.then((eks) =>
|
|
194
|
+
.then((eks) => {
|
|
195
|
+
const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(eks.extractedKeys);
|
|
196
|
+
if (!keys.length)
|
|
197
|
+
throw new Error('No valid keys found for calendar item encryption');
|
|
198
|
+
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(keys[0]));
|
|
199
|
+
})
|
|
193
200
|
.then((key) => (0, utils_1.crypt)(calendarItem, (obj) => this.crypto.AES.encrypt(key, (0, utils_1.utf8_2ua)(JSON.stringify(obj))), this.encryptedKeys))));
|
|
194
201
|
}
|
|
195
202
|
decrypt(hcpId, calendarItems) {
|
|
@@ -199,10 +206,11 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
199
206
|
? this.crypto
|
|
200
207
|
.extractKeysFromDelegationsForHcpHierarchy(hcpId, calendarItem.id, _.size(calendarItem.encryptionKeys) ? calendarItem.encryptionKeys : calendarItem.delegations)
|
|
201
208
|
.then(({ extractedKeys: sfks }) => {
|
|
209
|
+
sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks);
|
|
202
210
|
if (!sfks || !sfks.length) {
|
|
203
211
|
return Promise.resolve(calendarItem);
|
|
204
212
|
}
|
|
205
|
-
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0]
|
|
213
|
+
return this.crypto.AES.importKey('raw', (0, utils_1.hex2ua)(sfks[0])).then((key) => (0, utils_1.decrypt)(calendarItem, (ec) => this.crypto.AES.decrypt(key, ec)
|
|
206
214
|
.then((dec) => {
|
|
207
215
|
const jsonContent = dec && (0, utils_1.ua2utf8)(dec);
|
|
208
216
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-calendar-item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AC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;wBAC/C,OAAO,EAAE,CAAA;oBACX,CAAC,CAAC,CACL,CACF,CAAA;gBACH,CAAC,CAAC;gBACN,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QACnC,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AA1RD,kDA0RC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, delegates: string[] = []) {\n return this.newInstancePatient(user, null, ci, delegates)\n }\n\n newInstancePatient(user: models.User, patient: models.Patient | null, ci: any, delegates: string[] = []): Promise<models.CalendarItem> {\n const calendarItem = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n ci || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient | null,\n calendarItem: models.CalendarItem,\n delegates: string[] = []\n ): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId!).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!)\n\n _.extend(calendarItem, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(calendarItem)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId!, delegateId, dels.secretId, eks.secretId)\n ))\n )\n return promise\n })\n }\n\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto.extractDelegationsSFKs(patient, hcpartyId).then((secretForeignKeys) => {\n return secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? (usingPost ?\n this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys)) :\n this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(',')))\n : Promise.resolve([])\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem> | any> {\n return super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super.findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.modifyCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n initEncryptionKeys(user: models.User, calendarItem: models.CalendarItem): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(calendarItem, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((item) =>\n this.crypto.appendEncryptionKeys(item, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((calendarItem) =>\n (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length\n ? Promise.resolve(calendarItem)\n : this.initEncryptionKeys(user, calendarItem)\n )\n .then((calendarItem: CalendarItem) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(\n this.dataOwnerApi.getDataOwnerOf(user)!,\n calendarItem.id!,\n calendarItem.encryptionKeys!\n )\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(eks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n crypt(calendarItem, (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))), this.encryptedKeys)\n )\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n calendarItems.map((calendarItem) => {\n return calendarItem.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n calendarItem.id!,\n _.size(calendarItem.encryptionKeys) ? calendarItem.encryptionKeys! : calendarItem.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n return Promise.resolve(calendarItem)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n decrypt(calendarItem, (ec) =>\n this.crypto.AES.decrypt(key, ec)\n .then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse calendar item', calendarItem.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n .catch((err) => {\n console.log('Error during AES decryption', err)\n return {}\n })\n )\n )\n })\n : Promise.resolve(calendarItem)\n })\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-calendar-item-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-calendar-item-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA2C;AAE3C,4BAA2B;AAI3B,wCAA+C;AAC/C,mCAAmE;AAEnE,0EAAgG;AAEhG,MAAa,mBAAoB,SAAQ,4BAAkB;IAMzD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,gBAA+B,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,EAChE,yBAAiD,IAAI,iDAAwB,EAAE,EAC/E,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAlBzD,SAAI,GAAQ,IAAI,CAAA;QAGhB,kBAAa,GA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qBACrC;oBACD,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,IAAA,cAAM,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CACpE,IAAA,eAAO,EAAC,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,CAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;yBAC7B,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;wBACZ,MAAM,WAAW,GAAG,GAAG,IAAI,IAAA,eAAO,EAAC,GAAG,CAAC,CAAA;wBACvC,IAAI;4BACF,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;yBAC/B;wBAAC,OAAO,CAAC,EAAE;4BACV,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,YAAY,CAAC,EAAE,EAAE,WAAW,IAAI,iBAAiB,CAAC,CAAA;4BAC5F,OAAO,EAAE,CAAA;yBACV;oBACH,CAAC,CAAC;yBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;wBACb,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;wBAC/C,OAAO,EAAE,CAAA;oBACX,CAAC,CAAC,CACL,CACF,CAAA;gBACH,CAAC,CAAC;gBACN,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QACnC,CAAC,CAAC,CACH,CAAA;IACH,CAAC;CACF;AA/RD,kDA+RC","sourcesContent":["import * as i18n from './rsrc/contact.i18n'\n\nimport * as _ from 'lodash'\nimport * as models from '../icc-api/model/models'\nimport { CalendarItem, User } from '../icc-api/model/models'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\nimport { IccCalendarItemApi } from '../icc-api'\nimport { crypt, decrypt, hex2ua, ua2utf8, utf8_2ua } from './utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\n\nexport class IccCalendarItemXApi extends IccCalendarItemApi {\n i18n: any = i18n\n crypto: IccCryptoXApi\n dataOwnerApi: IccDataOwnerXApi\n encryptedKeys = ['details', 'title', 'patientId']\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n encryptedKeys: Array<string> = ['details', 'title', 'patientId'],\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, authenticationProvider, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n this.encryptedKeys = encryptedKeys\n }\n\n newInstance(user: User, ci: CalendarItem, delegates: string[] = []) {\n return this.newInstancePatient(user, null, ci, delegates)\n }\n\n newInstancePatient(user: models.User, patient: models.Patient | null, ci: any, delegates: string[] = []): Promise<models.CalendarItem> {\n const calendarItem = _.extend(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.CalendarItem',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n responsible: this.dataOwnerApi.getDataOwnerOf(user),\n author: user.id,\n codes: [],\n tags: [],\n },\n ci || {}\n )\n\n return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates)\n }\n\n initDelegationsAndEncryptionKeys(\n user: models.User,\n patient: models.Patient | null,\n calendarItem: models.CalendarItem,\n delegates: string[] = []\n ): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.extractDelegationsSFKs(patient, dataOwnerId!).then(async (secretForeignKeys) => {\n const dels = await this.crypto.initObjectDelegations(calendarItem, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0])\n const eks = await this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!)\n\n _.extend(calendarItem, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(calendarItem)\n _.uniq(\n delegates.concat(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : [])\n ).forEach(\n (delegateId) =>\n (promise = promise.then((contact) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, contact, dataOwnerId!, delegateId, dels.secretId, eks.secretId)\n ))\n )\n return promise\n })\n }\n\n findBy(hcpartyId: string, patient: models.Patient, usingPost: boolean = false) {\n return this.crypto.extractDelegationsSFKs(patient, hcpartyId).then((secretForeignKeys) => {\n return secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? usingPost\n ? this.findByHCPartyPatientSecretFKeysArray(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys))\n : this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n : Promise.resolve([])\n })\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<models.CalendarItem> | any> {\n return super.findCalendarItemsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n findByHCPartyPatientSecretFKeysArray(hcPartyId: string, secretFKeys: string[]): Promise<Array<models.CalendarItem> | any> {\n return super\n .findCalendarItemsByHCPartyPatientForeignKeysUsingPost(hcPartyId, secretFKeys)\n .then((calendarItems) => this.decrypt(hcPartyId, calendarItems))\n }\n\n createCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n async createCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.createCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n getCalendarItemWithUser(user: models.User, calendarItemId: string): Promise<CalendarItem | any> {\n return super\n .getCalendarItem(calendarItemId)\n .then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [calendarItem]))\n .then((cis) => cis[0])\n }\n\n getCalendarItem(calendarItemId: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithUser(user: models.User): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItems(): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsWithIdsWithUser(user: models.User, body?: models.ListOfIds): Promise<Array<CalendarItem> | any> {\n return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsWithIds(body?: models.ListOfIds): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarItemsByPeriodAndHcPartyIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n hcPartyId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarItemsByPeriodAndHcPartyId(startDate?: number, endDate?: number, hcPartyId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n getCalendarsByPeriodAndAgendaIdWithUser(\n user: models.User,\n startDate: number,\n endDate: number,\n agendaId: string\n ): Promise<Array<CalendarItem> | any> {\n return super\n .getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)\n .then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, calendarItems))\n }\n\n getCalendarsByPeriodAndAgendaId(startDate?: number, endDate?: number, agendaId?: string): never {\n throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption')\n }\n\n modifyCalendarItem(body?: CalendarItem): never {\n throw new Error('Cannot call a method that must encrypt a calendar item without providing a user for de/encryption')\n }\n\n /**\n * Remove the following delegation objects from the\n * CalendarItem instance: cryptedForeignKeys, secretForeignKeys.\n *\n * The delegations & encryptionKeys objects are not removed because\n * in the case the CalendarItem is saved in the DB & then encrypted,\n * if later we remove the patient from it, it'd reset the delegations\n * and encryptionKeys thus impossibilitating further access.\n *\n * @param calendarItem The Calendar Item object\n */\n resetCalendarDelegationObjects(calendarItem: models.CalendarItem): models.CalendarItem {\n const { cryptedForeignKeys, secretForeignKeys, ...resetCalendarItem } = calendarItem\n return resetCalendarItem\n }\n\n async modifyCalendarItemWithHcParty(user: models.User, body?: models.CalendarItem): Promise<models.CalendarItem | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((items) => super.modifyCalendarItem(items[0]))\n .then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [ci]))\n .then((cis) => cis[0])\n : null\n }\n\n initEncryptionKeys(user: models.User, calendarItem: models.CalendarItem): Promise<models.CalendarItem> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(calendarItem, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((item) =>\n this.crypto.appendEncryptionKeys(item, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(extraEks.modifiedObject, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n return Promise.all(\n calendarItems.map((calendarItem) =>\n (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length\n ? Promise.resolve(calendarItem)\n : this.initEncryptionKeys(user, calendarItem)\n )\n .then((calendarItem: CalendarItem) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(\n this.dataOwnerApi.getDataOwnerOf(user)!,\n calendarItem.id!,\n calendarItem.encryptionKeys!\n )\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) => {\n const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(eks.extractedKeys)\n if (!keys.length) throw new Error('No valid keys found for calendar item encryption')\n return this.crypto.AES.importKey('raw', hex2ua(keys[0]))\n })\n .then((key: CryptoKey) =>\n crypt(calendarItem, (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))), this.encryptedKeys)\n )\n )\n )\n }\n\n decrypt(hcpId: string, calendarItems: Array<models.CalendarItem>): Promise<Array<models.CalendarItem>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n calendarItems.map((calendarItem) => {\n return calendarItem.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n calendarItem.id!,\n _.size(calendarItem.encryptionKeys) ? calendarItem.encryptionKeys! : calendarItem.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks)\n if (!sfks || !sfks.length) {\n return Promise.resolve(calendarItem)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0])).then((key) =>\n decrypt(calendarItem, (ec) =>\n this.crypto.AES.decrypt(key, ec)\n .then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse calendar item', calendarItem.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n .catch((err) => {\n console.log('Error during AES decryption', err)\n return {}\n })\n )\n )\n })\n : Promise.resolve(calendarItem)\n })\n )\n }\n}\n"]}
|
|
@@ -134,9 +134,9 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
134
134
|
]);
|
|
135
135
|
}, [])
|
|
136
136
|
.filter((l) => l.extractedKeys.length > 0)
|
|
137
|
-
.map(({ hcpartyId, extractedKeys }) => usingPost
|
|
138
|
-
this.findByHCPartyPatientSecretFKeysArray(hcpartyId, _.uniq(extractedKeys))
|
|
139
|
-
this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(',')))).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))
|
|
137
|
+
.map(({ hcpartyId, extractedKeys }) => usingPost
|
|
138
|
+
? this.findByHCPartyPatientSecretFKeysArray(hcpartyId, _.uniq(extractedKeys))
|
|
139
|
+
: this.findByHCPartyPatientSecretFKeys(hcpartyId, _.uniq(extractedKeys).join(',')))).then((results) => _.uniqBy(_.flatMap(results), (x) => x.id))
|
|
140
140
|
: Promise.resolve([]));
|
|
141
141
|
}
|
|
142
142
|
findByPatientSFKs(hcpartyId, patients) {
|
|
@@ -323,22 +323,25 @@ class IccContactXApi extends icc_api_1.IccContactApi {
|
|
|
323
323
|
? ctc
|
|
324
324
|
: yield (ctc.encryptionKeys && Object.keys(ctc.encryptionKeys || {}).length ? Promise.resolve(ctc) : this.initEncryptionKeys(user, ctc));
|
|
325
325
|
const sfks = yield this.crypto.extractKeysFromDelegationsForHcpHierarchy(hcpartyId, initialisedCtc.id, initialisedCtc.encryptionKeys);
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
326
|
+
const keys = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks.extractedKeys);
|
|
327
|
+
if (!keys.length)
|
|
328
|
+
throw new Error('No valid keys found for calendar item encryption');
|
|
329
|
+
const key = yield this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(keys[0]));
|
|
330
|
+
initialisedCtc.services = yield this.encryptServices(key, keys[0], ctc.services || []);
|
|
331
|
+
initialisedCtc.encryptedSelf = (0, binary_utils_1.b2a)((0, binary_utils_1.ua2string)(yield this.crypto.AES.encrypt(key, (0, binary_utils_1.utf8_2ua)(JSON.stringify({ descr: ctc.descr })), keys[0])));
|
|
330
332
|
delete initialisedCtc.descr;
|
|
331
333
|
return initialisedCtc;
|
|
332
334
|
})));
|
|
333
335
|
}
|
|
334
336
|
decrypt(hcpartyId, ctcs) {
|
|
335
337
|
return Promise.all(ctcs.map((ctc) => __awaiter(this, void 0, void 0, function* () {
|
|
336
|
-
|
|
338
|
+
let { extractedKeys: sfks } = yield this.crypto.extractKeysFromDelegationsForHcpHierarchy(hcpartyId, ctc.id, _.size(ctc.encryptionKeys) ? ctc.encryptionKeys : ctc.delegations);
|
|
339
|
+
sfks = this.crypto.filterAndFixValidEntityEncryptionKeyStrings(sfks);
|
|
337
340
|
if (!sfks || !sfks.length) {
|
|
338
341
|
console.log('Cannot decrypt contact', ctc.id);
|
|
339
342
|
return ctc;
|
|
340
343
|
}
|
|
341
|
-
const rawKey = sfks[0]
|
|
344
|
+
const rawKey = sfks[0];
|
|
342
345
|
const key = yield this.crypto.AES.importKey('raw', (0, binary_utils_1.hex2ua)(rawKey));
|
|
343
346
|
ctc.services = yield this.decryptServices(hcpartyId, ctc.services || [], key, rawKey);
|
|
344
347
|
if (ctc.encryptedSelf) {
|