Skip to content

Commit

Permalink
Support receiving the security score data from the sync down routine (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hleekeeper authored Jan 17, 2025
1 parent e3b9119 commit 6f48498
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions keeperapi/src/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export type VaultStorage = KeyStorage & {
delete(kind: VaultStorageKind, uid: string): Promise<void>
}

export type VaultStorageData = DProfilePic | DContinuationToken | DRecord | DRecordMetadata | DRecordNonSharedData | DTeam | DSharedFolder | DSharedFolderUser | DSharedFolderTeam | DSharedFolderRecord | DSharedFolderFolder | DUserFolder | DProfile | DReusedPasswords | DBWRecord | DBWSecurityData
export type VaultStorageData = DProfilePic | DContinuationToken | DRecord | DRecordMetadata | DRecordNonSharedData | DTeam | DSharedFolder | DSharedFolderUser | DSharedFolderTeam | DSharedFolderRecord | DSharedFolderFolder | DUserFolder | DProfile | DReusedPasswords | DBWRecord | DBWSecurityData | DSecurityScoreData

export type VaultStorageKind = 'profilePic' | 'record' | 'metadata' | 'non_shared_data' | 'team' | 'shared_folder' | 'shared_folder_user' | 'shared_folder_team' | 'shared_folder_record' | 'shared_folder_folder' | 'user_folder' | 'profile' | 'continuationToken' | 'reused_passwords' | 'bw_record' | 'bw_security_data'
export type VaultStorageKind = 'profilePic' | 'record' | 'metadata' | 'non_shared_data' | 'team' | 'shared_folder' | 'shared_folder_user' | 'shared_folder_team' | 'shared_folder_record' | 'shared_folder_folder' | 'user_folder' | 'profile' | 'continuationToken' | 'reused_passwords' | 'bw_record' | 'bw_security_data' | 'security_score_data'

export type VaultStorageResult<T extends VaultStorageKind> = (
T extends 'continuationToken' ? DContinuationToken :
Expand Down Expand Up @@ -194,6 +194,13 @@ export type DBWSecurityData = {
revision: number
}

export type DSecurityScoreData = {
kind: 'security_score_data',
uid: string,
data: any,
revision: number,
}

export type DContinuationToken = {
kind?: 'continuationToken'
token: string
Expand Down Expand Up @@ -885,6 +892,32 @@ const processBreachWatchSecurityData = async (securityData: IBreachWatchSecurity
}
}

const processSecurityScoreData = async (securityScoreDataList: Vault.ISecurityScoreData[], storage: VaultStorage) => {
for (const securityScoreData of securityScoreDataList) {
if (
!securityScoreData.recordUid
|| !securityScoreData.data
|| typeof securityScoreData.revision !== 'number'
) continue

const recUid = webSafe64FromBytes(securityScoreData.recordUid)
try {
const decrypted = await platform.decrypt(securityScoreData.data, recUid, 'gcm', storage)
const securityScoreDataObj = JSON.parse(platform.bytesToString(decrypted))
await storage.put({
kind: 'security_score_data',
uid: recUid,
revision: securityScoreData.revision,
data: securityScoreDataObj,
})
} catch (e: any) {
console.error(
`The security score data ${recUid} cannot be decrypted (${e.message})`
)
}
}
}

export type SyncLogFormat = '!' | 'raw' | 'obj' | 'str' | 'cnt' | 'cnt_t'

const logProtobuf = (data: any, format: SyncLogFormat, seqNo: number, counts: any) => {
Expand Down Expand Up @@ -1053,6 +1086,8 @@ export const syncDown = async (options: SyncDownOptions): Promise<SyncResult> =>

await processBreachWatchSecurityData(resp.breachWatchSecurityData, storage)

await processSecurityScoreData(resp.securityScoreData, storage)

await storage.addDependencies(dependencies)

const removedDependencies = {}
Expand Down

0 comments on commit 6f48498

Please sign in to comment.