[INJI-699] remove .hmac & .hmace files created due to INJI-612 (#1170)

* [INJI-699] remove .hmac & .hmace files created due to INJI-612

* also bump up secure-keystore to fix INJI-612

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJI-559] remove PoC code added for INji-612

* redundant encryption/decryption over RN bridge was making it slower to
  load VCs, post initial bug-fix this code is removed to improve
  performance

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJI-559] use try-catch for removing redundant files

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

* [INJI-559] skip remove hmac file as its not created

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>

---------

Signed-off-by: Harsh Vardhan <harsh59v@gmail.com>
This commit is contained in:
Harsh Vardhan
2024-01-17 12:09:01 +05:30
committed by GitHub
parent e4593fd0b3
commit f9c6f37450
5 changed files with 12 additions and 110 deletions

View File

@@ -24,7 +24,6 @@ import {
import FileStorage, {
getFilePath,
getFilePathOfEncryptedHmac,
getFilePathOfHmac,
vcDirectoryPath,
} from './fileStorage';
import {__AppId} from './GlobalVariables';
@@ -43,7 +42,7 @@ export const API_CACHED_STORAGE_KEYS = {
fetchIssuerConfig: (issuerId: string) =>
`CACHE_FETCH_ISSUER_CONFIG_${issuerId}`,
fetchIssuerWellknownConfig: (issuerId: string) =>
`CACHE_FETCH_ISSUER_WELLKNOWN_CONFIG_${issuerId}`,
`CACHE_FETCH_ISSUER_WELLKNOWN_CONFIG_${issuerId}`,
};
async function generateHmac(
@@ -164,37 +163,6 @@ class Storage {
encryptionKey,
);
const HMACofVC = await generateHmac(encryptionKey, data);
const hmacStoredinFile = await this.readHmacForVCFromFile(key);
if (HMACofVC !== storedHMACofCurrentVC) {
if (__DEV__) {
sendImpressionEvent(
getImpressionEventData('VC Corruption Event', 'VC Download', {
key: key,
'HMAC stored in MMKV': this.hexEncode(storedHMACofCurrentVC!),
'Length HMAC stored in MMKV': storedHMACofCurrentVC?.length,
'HMAC of VC': this.hexEncode(HMACofVC),
'Length of HMAC of VC': HMACofVC.length,
'HMAC stored in file': this.hexEncode(hmacStoredinFile),
'File vs mmkv data':
hmacStoredinFile === this.hexEncode(storedHMACofCurrentVC!),
}),
);
}
console.log(
`VC corruption Details: ${JSON.stringify({
key: key,
'HMAC stored in MMKV': this.hexEncode(storedHMACofCurrentVC!),
'Length HMAC stored in MMKV': storedHMACofCurrentVC?.length,
'HMAC of VC': this.hexEncode(HMACofVC),
'Length of HMAC of VC': HMACofVC.length,
'HMAC stored in file': this.hexEncode(hmacStoredinFile),
'File vs mmkv data':
hmacStoredinFile === this.hexEncode(storedHMACofCurrentVC!),
})}`,
);
}
return HMACofVC !== storedHMACofCurrentVC;
}
@@ -206,51 +174,11 @@ class Storage {
return null;
}
//TODO: added temporarily for INJI-612
private static async readHmacForVCFromFile(key: string) {
const HMACofCurrentVC = await FileStorage.readFile(getFilePathOfHmac(key));
return HMACofCurrentVC;
}
private static async readHmacForDataCorruptionCheck(
key: string,
encryptionKey: string,
) {
const encryptedHMACofCurrentVC = await MMKV.getItem(key);
const encryptedHMACofCurrentVCFromMMKVFile = await FileStorage.readFile(
getFilePathOfEncryptedHmac(key),
);
if (encryptedHMACofCurrentVC !== encryptedHMACofCurrentVCFromMMKVFile) {
if (__DEV__) {
sendImpressionEvent(
getImpressionEventData('Encrypted HMac Corruption', 'VC Download', {
key: key,
'Encrypted HMAC of Current VC from MMKV store':
encryptedHMACofCurrentVC,
'Encrypted HMAC of Current VC from file':
encryptedHMACofCurrentVCFromMMKVFile,
'encryptedHMACofCurrentVC vs encryptedHMACofCurrentVCFromMMKVFile': `${
encryptedHMACofCurrentVCFromMMKVFile === encryptedHMACofCurrentVC
}`,
}),
);
}
console.log(
`VC corruption Details: ${{
key: key,
'Encrypted HMAC of Current VC from MMKV store':
encryptedHMACofCurrentVC,
'Encrypted HMAC of Current VC from file':
encryptedHMACofCurrentVCFromMMKVFile,
'encryptedHMACofCurrentVC vs encryptedHMACofCurrentVCFromMMKVFile': `${
encryptedHMACofCurrentVCFromMMKVFile === encryptedHMACofCurrentVC
}`,
}}`,
);
}
if (encryptedHMACofCurrentVC) {
return decryptJson(encryptionKey, encryptedHMACofCurrentVC);
}
@@ -267,17 +195,6 @@ class Storage {
return await FileStorage.writeFile(path, data);
}
// TODO: INJI-612 refactor
private static hexEncode(inp: string) {
var hex, i;
var result = '';
for (i = 0; i < inp.length; i++) {
hex = inp.charCodeAt(i).toString(16);
result += ('000' + hex).slice(-4);
}
return result;
}
// TODO: INJI-612 refactor
private static async storeVcHmac(
encryptionKey: string,
@@ -286,12 +203,6 @@ class Storage {
) {
const HMACofVC = await generateHmac(encryptionKey, data);
const encryptedHMACofVC = await encryptJson(encryptionKey, HMACofVC);
const keyOfEncodedHmacStorage = getFilePathOfHmac(key);
const keyOfEncryptedHmacStorage = getFilePathOfEncryptedHmac(key);
const encodedHMACofVC = this.hexEncode(HMACofVC);
await FileStorage.writeFile(keyOfEncodedHmacStorage, encodedHMACofVC);
await FileStorage.writeFile(keyOfEncryptedHmacStorage, encryptedHMACofVC);
await MMKV.setItem(key, encryptedHMACofVC);
}