Skip to content

Commit c3e5ffc

Browse files
authored
BE-6553 a new method unloadUserKeys to remove all keys except user keys from the local cache (#80)
* a new method unloadNonUserKeys to remove all keys except user keys * v16.0.80
1 parent fa798e0 commit c3e5ffc

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

keeperapi/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

keeperapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@keeper-security/keeperapi",
33
"description": "Keeper API Javascript SDK",
4-
"version": "16.0.79",
4+
"version": "16.0.80",
55
"browser": "dist/index.es.js",
66
"main": "dist/index.cjs.js",
77
"types": "dist/node/index.d.ts",

keeperapi/src/browser/platform.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ export const browserPlatform: Platform = class {
133133
keyBytesCache = {}
134134
}
135135

136+
static unloadNonUserKeys(): void {
137+
cryptoKeysCache = {
138+
cbc: {
139+
data: cryptoKeysCache.cbc.data
140+
},
141+
gcm: {
142+
data: cryptoKeysCache.gcm.data
143+
},
144+
ecc: {
145+
pk_ecc: cryptoKeysCache.ecc.pk_ecc
146+
},
147+
}
148+
keyBytesCache = {
149+
pk_rsa: keyBytesCache.pk_rsa
150+
}
151+
}
152+
136153
static getStorageKeyId(keyId: string, keyType: EncryptionType): string {
137154
switch (keyType) {
138155
case 'cbc':

keeperapi/src/node/platform.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ export const nodePlatform: Platform = class {
7979
keyCache = {}
8080
}
8181

82+
static unloadNonUserKeys(): void {
83+
keyCache = {
84+
data: keyCache.data,
85+
pk_ecc: keyCache.pk_ecc,
86+
pk_rsa: keyCache.pk_rsa,
87+
}
88+
}
89+
8290
static async unwrapKeys(keys: UnwrapKeyMap, storage?: KeyStorage): Promise<void> {
8391
for (const task of Object.values(keys)) {
8492
try {

keeperapi/src/platform.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ export interface Platform {
2727

2828
importKeyRSA(keyId: string, key: Uint8Array, storage?: KeyStorage, canExport?: boolean): Promise<void>
2929

30+
// Removes all keys stored in the local cache, including user keys, record keys, etc.
31+
// A typical use case is during logout, when you want to completely clear the cached keys.
3032
unloadKeys(): void
3133

34+
// Clears all cached keys except user keys.
35+
// A good use case is a manual full sync while the user is still logged in.
36+
unloadNonUserKeys(): void
37+
3238
unwrapKey(key: Uint8Array, keyId: string, unwrappingKeyId: string, encryptionType: EncryptionType, unwrappedType: UnwrappedKeyType, storage?: KeyStorage, canExport?: boolean): Promise<void>
3339

3440
unwrapKeys(keys: UnwrapKeyMap, storage?: KeyStorage): Promise<void>

keeperapi/src/vault.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ export const syncDown = async (options: SyncDownOptions): Promise<SyncResult> =>
10571057
addCounts(totalCounts, counts)
10581058
logProtobuf(resp, options.logFormat || '!', result.pageCount, counts)
10591059
if (resp.cacheStatus == CacheStatus.CLEAR) {
1060+
platform.unloadNonUserKeys()
10601061
await storage.clear()
10611062
result.fullSync = true
10621063
}

0 commit comments

Comments
 (0)