internal: incomplete vault systems behind feature flag (#2340)

This commit is contained in:
Mo
2023-06-30 09:01:56 -05:00
committed by GitHub
parent d16e401bb9
commit b032eb9c9b
638 changed files with 20321 additions and 4813 deletions

View File

@@ -1,8 +1,10 @@
import {
DecryptedPayloadInterface,
EncryptedPayloadInterface,
KeySystemRootKeyInterface,
ItemsKeyInterface,
RootKeyInterface,
KeySystemItemsKeyInterface,
} from '@standardnotes/models'
export interface AbstractKeySplit<T = EncryptedPayloadInterface | DecryptedPayloadInterface> {
@@ -10,13 +12,20 @@ export interface AbstractKeySplit<T = EncryptedPayloadInterface | DecryptedPaylo
items: T[]
key: RootKeyInterface
}
usesKeySystemRootKey?: {
items: T[]
key: KeySystemRootKeyInterface
}
usesItemsKey?: {
items: T[]
key: ItemsKeyInterface
key: ItemsKeyInterface | KeySystemItemsKeyInterface
}
usesRootKeyWithKeyLookup?: {
items: T[]
}
usesKeySystemRootKeyWithKeyLookup?: {
items: T[]
}
usesItemsKeyWithKeyLookup?: {
items: T[]
}

View File

@@ -12,6 +12,10 @@ export function CreateEncryptionSplitWithKeyLookup(
result.usesRootKeyWithKeyLookup = { items: payloadSplit.rootKeyEncryption }
}
if (payloadSplit.keySystemRootKeyEncryption) {
result.usesKeySystemRootKeyWithKeyLookup = { items: payloadSplit.keySystemRootKeyEncryption }
}
if (payloadSplit.itemsKeyEncryption) {
result.usesItemsKeyWithKeyLookup = { items: payloadSplit.itemsKeyEncryption }
}
@@ -28,6 +32,10 @@ export function CreateDecryptionSplitWithKeyLookup(
result.usesRootKeyWithKeyLookup = { items: payloadSplit.rootKeyEncryption }
}
if (payloadSplit.keySystemRootKeyEncryption) {
result.usesKeySystemRootKeyWithKeyLookup = { items: payloadSplit.keySystemRootKeyEncryption }
}
if (payloadSplit.itemsKeyEncryption) {
result.usesItemsKeyWithKeyLookup = { items: payloadSplit.itemsKeyEncryption }
}
@@ -46,6 +54,11 @@ export function FindPayloadInEncryptionSplit(uuid: string, split: KeyedEncryptio
return inUsesRootKey
}
const inUsesKeySystemRootKey = split.usesKeySystemRootKey?.items.find((item) => item.uuid === uuid)
if (inUsesKeySystemRootKey) {
return inUsesKeySystemRootKey
}
const inUsesItemsKeyWithKeyLookup = split.usesItemsKeyWithKeyLookup?.items.find((item) => item.uuid === uuid)
if (inUsesItemsKeyWithKeyLookup) {
return inUsesItemsKeyWithKeyLookup
@@ -56,6 +69,13 @@ export function FindPayloadInEncryptionSplit(uuid: string, split: KeyedEncryptio
return inUsesRootKeyWithKeyLookup
}
const inUsesKeySystemRootKeyWithKeyLookup = split.usesKeySystemRootKeyWithKeyLookup?.items.find(
(item) => item.uuid === uuid,
)
if (inUsesKeySystemRootKeyWithKeyLookup) {
return inUsesKeySystemRootKeyWithKeyLookup
}
throw Error('Cannot find payload in encryption split')
}
@@ -70,6 +90,11 @@ export function FindPayloadInDecryptionSplit(uuid: string, split: KeyedDecryptio
return inUsesRootKey
}
const inUsesKeySystemRootKey = split.usesKeySystemRootKey?.items.find((item) => item.uuid === uuid)
if (inUsesKeySystemRootKey) {
return inUsesKeySystemRootKey
}
const inUsesItemsKeyWithKeyLookup = split.usesItemsKeyWithKeyLookup?.items.find((item) => item.uuid === uuid)
if (inUsesItemsKeyWithKeyLookup) {
return inUsesItemsKeyWithKeyLookup
@@ -80,5 +105,12 @@ export function FindPayloadInDecryptionSplit(uuid: string, split: KeyedDecryptio
return inUsesRootKeyWithKeyLookup
}
const inUsesKeySystemRootKeyWithKeyLookup = split.usesKeySystemRootKeyWithKeyLookup?.items.find(
(item) => item.uuid === uuid,
)
if (inUsesKeySystemRootKeyWithKeyLookup) {
return inUsesKeySystemRootKeyWithKeyLookup
}
throw Error('Cannot find payload in encryption split')
}

View File

@@ -2,5 +2,6 @@ import { DecryptedPayloadInterface, EncryptedPayloadInterface } from '@standardn
export interface EncryptionTypeSplit<T = EncryptedPayloadInterface | DecryptedPayloadInterface> {
rootKeyEncryption?: T[]
keySystemRootKeyEncryption?: T[]
itemsKeyEncryption?: T[]
}

View File

@@ -1,5 +1,9 @@
import { DecryptedPayloadInterface, EncryptedPayloadInterface } from '@standardnotes/models'
import { ItemContentTypeUsesRootKeyEncryption } from '../Keys/RootKey/Functions'
import {
DecryptedPayloadInterface,
EncryptedPayloadInterface,
ContentTypeUsesKeySystemRootKeyEncryption,
ContentTypeUsesRootKeyEncryption,
} from '@standardnotes/models'
import { EncryptionTypeSplit } from './EncryptionTypeSplit'
export function SplitPayloadsByEncryptionType<T extends EncryptedPayloadInterface | DecryptedPayloadInterface>(
@@ -7,10 +11,13 @@ export function SplitPayloadsByEncryptionType<T extends EncryptedPayloadInterfac
): EncryptionTypeSplit<T> {
const usesRootKey: T[] = []
const usesItemsKey: T[] = []
const usesKeySystemRootKey: T[] = []
for (const item of payloads) {
if (ItemContentTypeUsesRootKeyEncryption(item.content_type)) {
if (ContentTypeUsesRootKeyEncryption(item.content_type)) {
usesRootKey.push(item)
} else if (ContentTypeUsesKeySystemRootKeyEncryption(item.content_type)) {
usesKeySystemRootKey.push(item)
} else {
usesItemsKey.push(item)
}
@@ -19,5 +26,6 @@ export function SplitPayloadsByEncryptionType<T extends EncryptedPayloadInterfac
return {
rootKeyEncryption: usesRootKey.length > 0 ? usesRootKey : undefined,
itemsKeyEncryption: usesItemsKey.length > 0 ? usesItemsKey : undefined,
keySystemRootKeyEncryption: usesKeySystemRootKey.length > 0 ? usesKeySystemRootKey : undefined,
}
}