Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Keeper-Security/keeper-sdk-javascri…
Browse files Browse the repository at this point in the history
…pt into TH_rsa_to_ecc
  • Loading branch information
THeflinKeeper committed Oct 25, 2024
2 parents 4c90ec3 + 8d230bb commit d7786ad
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 24 deletions.
44 changes: 22 additions & 22 deletions keeperapi/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion keeperapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@keeper-security/keeperapi",
"description": "Keeper API Javascript SDK",
"version": "16.0.59",
"version": "16.0.63",
"browser": "dist/index.es.js",
"main": "dist/index.cjs.js",
"types": "dist/node/index.d.ts",
Expand Down
30 changes: 30 additions & 0 deletions keeperapi/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,36 @@ export type RecordAddRequest = {

export const recordAddCommand = (request: RecordAddRequest): RestCommand<RecordAddRequest, KeeperResponse> => createCommand(request, 'record_add')

export type RecordPreDeleteObject = {
object_uid: string
object_type: 'record'
from_uid: string
from_type: string
delete_resolution: 'unlink'
}
export type RecordPreDeleteRequest = {
objects: RecordPreDeleteObject[]
}
export type DeletionSummary = {
deletion_summary: string[]
}
export type PreDeleteResponse = {
pre_delete_token: string
would_delete: DeletionSummary
}
export type KeeperPreDeleteResponse = {
result: string
result_code: string
message?: string
pre_delete_response: PreDeleteResponse
}
export type RecordDeleteRequest = {
pre_delete_token: string
}

export const recordPreDeleteCommand = (request: RecordPreDeleteRequest): RestCommand<RecordPreDeleteRequest, KeeperPreDeleteResponse> => createCommand(request, 'pre_delete')
export const recordDeleteCommand = (request: RecordDeleteRequest): RestCommand<RecordDeleteRequest, KeeperResponse> => createCommand(request, 'delete')

export type EnterpriseSettingInclude =
| "AuditSyncConfig"
| "AuditSyncContext"
Expand Down
20 changes: 20 additions & 0 deletions keeperapi/src/restMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ export const recordTypeDeleteMessage = (data: Records.IRecordType): RestMessage<
export const recordsGetMessage = (data: Records.IRecordsGetRequest): RestMessage<Records.IRecordsGetRequest, Records.IRecordsGetResponse> =>
createMessage(data, 'vault/records_get', Records.RecordsGetRequest, Records.RecordsGetResponse)

export const getRecordsDetailsMessage = (data: Records.IGetRecordDataWithAccessInfoRequest): RestMessage<Records.IGetRecordDataWithAccessInfoRequest, Records.IGetRecordDataWithAccessInfoResponse> =>
createMessage(data, 'vault/get_records_details', Records.GetRecordDataWithAccessInfoRequest, Records.GetRecordDataWithAccessInfoResponse)

export const recordsAddMessage = (data: Records.IRecordsAddRequest): RestMessage<Records.IRecordsAddRequest, Records.IRecordsModifyResponse> =>
createMessage(data, 'vault/records_add', Records.RecordsAddRequest, Records.RecordsModifyResponse)

Expand Down Expand Up @@ -290,6 +293,23 @@ export const setReusedPasswords = (data: Authentication.IReusedPasswordsRequest)
export const changeToKeyTypeOne = (data: Authentication.IChangeToKeyTypeOne): RestInMessage<Authentication.IChangeToKeyTypeOne> =>
createInMessage(data, 'vault/change_to_key_type_one', Authentication.ChangeToKeyTypeOne)

/* -- BreachWatch -- */

export const breachWatchInitialize = (): RestOutMessage<BreachWatch.IBreachWatchTokenRequest> =>
createOutMessage('breachwatch/initialize', BreachWatch.BreachWatchTokenResponse)

export const breachWatchSaveToken = (data: BreachWatch.IBreachWatchTokenRequest): RestInMessage<BreachWatch.IBreachWatchTokenRequest> =>
createInMessage(data,'breachwatch/save_token', BreachWatch.BreachWatchTokenRequest)

export const breachWatchAnonymizeToken = (data: BreachWatch.IBreachWatchTokenRequest): RestMessage<BreachWatch.IBreachWatchTokenRequest, BreachWatch.IAnonymizedTokenResponse> =>
createMessage(data, 'breachwatch/anonymize_token', BreachWatch.BreachWatchTokenRequest, BreachWatch.AnonymizedTokenResponse)

export const breachWatchStatus = (data: BreachWatch.IBreachWatchStatusRequest): RestMessage<BreachWatch.IBreachWatchStatusRequest, BreachWatch.IBreachWatchStatusResponse> =>
createMessage(data, 'breachwatch/status', BreachWatch.BreachWatchStatusRequest, BreachWatch.BreachWatchStatusResponse)

export const breachWatchUpdateRecordData = (data: BreachWatch.IBreachWatchUpdateRequest): RestMessage<BreachWatch.IBreachWatchUpdateRequest, BreachWatch.IBreachWatchUpdateResponse> =>
createMessage(data, 'breachwatch/update_record_data', BreachWatch.BreachWatchUpdateRequest, BreachWatch.BreachWatchUpdateResponse)

/* -- SERVICE LOGGER -- */

export const serviceLoggerGetMessage = (data: ServiceLogger.IServiceLogGetRequest): RestMessage<ServiceLogger.IServiceLogGetRequest, ServiceLogger.IServiceLogResponse> =>
Expand Down
24 changes: 23 additions & 1 deletion keeperapi/src/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export type SyncResult = {
fullSync?: boolean
}

export type Udata = {
file_ids?: string[]
}

export type DRecord = {
kind: 'record'
uid: string
Expand All @@ -73,6 +77,7 @@ export type DRecord = {
shared: boolean
clientModifiedTime: number
extra?: any
udata?: Udata
}

export type DRecordMetadata = {
Expand Down Expand Up @@ -613,6 +618,7 @@ const processRecords = async (records: IRecord[], storage: VaultStorage) => {
const encryptionType: EncryptionType = rec.version >= 3 ? 'gcm' : 'cbc'

let extra: any
let udata: Udata | undefined
try {
if (rec.extra.byteLength > 0) {
const decryptedExtra = await platform.decrypt(rec.extra, recUid, encryptionType, storage)
Expand All @@ -621,7 +627,13 @@ const processRecords = async (records: IRecord[], storage: VaultStorage) => {
} catch (e: any) {
console.error(`The record extra data ${recUid} cannot be decrypted (${e.message})`)
}

try {
if (!!rec.udata) {
udata = JSON.parse(rec.udata)
}
} catch {
console.error('failed to parse the udata')
}
try {
const decryptedData = await platform.decrypt(rec.data, recUid, encryptionType, storage)
const recordData = JSON.parse(platform.bytesToString(decryptedData))
Expand All @@ -634,6 +646,7 @@ const processRecords = async (records: IRecord[], storage: VaultStorage) => {
shared: rec.shared,
extra,
clientModifiedTime: <number>rec.clientModifiedTime,
udata,
})
} catch (e: any) {
console.error(`The record ${recUid} cannot be decrypted (${e.message})`)
Expand Down Expand Up @@ -809,6 +822,14 @@ const processRemovedSharedFolderRecords = async (records: ISharedFolderRecord[],
}
}

const processRemovedSharedFolderFolderRecords = async (records: ISharedFolderFolderRecord[], storage: VaultStorage, dependencies: RemovedDependencies) => {
for (const record of records as NN<ISharedFolderFolderRecord>[]) {
const sharedFolderFolderUid = webSafe64FromBytes(record.folderUid)
const recordUid = webSafe64FromBytes(record.recordUid)
addRemovedDependencies(dependencies, sharedFolderFolderUid, recordUid)
}
}

const processMetadata = async (recordMetaData: IRecordMetaData[], storage: VaultStorage) => {
const recordKeys: UnwrapKeyMap = {}

Expand Down Expand Up @@ -1077,6 +1098,7 @@ export const syncDown = async (options: SyncDownOptions): Promise<SyncResult> =>
await processRemovedSharedFolderTeams(resp.removedSharedFolderTeams, removedDependencies)
processRemovedSharedFolderUsers(resp.removedSharedFolderUsers, removedDependencies)
await processRemovedSharedFolderRecords(resp.removedSharedFolderRecords, storage, removedDependencies)
await processRemovedSharedFolderFolderRecords(resp.removedSharedFolderFolderRecords, storage, removedDependencies)

const removedSFDependencies: Dependency[] = []
for await (const folder of resp.removedSharedFolders) {
Expand Down

0 comments on commit d7786ad

Please sign in to comment.