chore: remove phased out storage encryption policy (#2323)

This commit is contained in:
Mo
2023-05-03 07:56:01 -05:00
committed by GitHub
parent e3f8b81139
commit 9f937f217b
8 changed files with 14 additions and 235 deletions

View File

@@ -1,7 +1,5 @@
import { DiskStorageService } from './DiskStorageService'
import { InternalEventBus, DeviceInterface, InternalEventBusInterface } from '@standardnotes/services'
import { Environment } from '@standardnotes/models'
describe('diskStorageService', () => {
let storageService: DiskStorageService
@@ -12,7 +10,7 @@ describe('diskStorageService', () => {
internalEventBus = {} as jest.Mocked<InternalEventBus>
device = {} as jest.Mocked<DeviceInterface>
storageService = new DiskStorageService(device, 'test', Environment.Desktop, internalEventBus)
storageService = new DiskStorageService(device, 'test', internalEventBus)
})
it('setInitialValues should set unwrapped values as wrapped value if wrapped value is not encrypted', async () => {

View File

@@ -19,7 +19,6 @@ import {
DeletedPayloadInterface,
PayloadTimestampDefaults,
LocalStorageEncryptedContextualPayload,
Environment,
FullyFormedTransferPayload,
} from '@standardnotes/models'
@@ -37,7 +36,6 @@ export class DiskStorageService extends Services.AbstractService implements Serv
private encryptionProvider!: Encryption.EncryptionProviderInterface
private storagePersistable = false
private persistencePolicy!: Services.StoragePersistencePolicies
private encryptionPolicy!: Services.StorageEncryptionPolicy
private needsPersist = false
private currentPersistPromise?: Promise<Services.StorageValuesObject>
@@ -46,12 +44,10 @@ export class DiskStorageService extends Services.AbstractService implements Serv
constructor(
private deviceInterface: Services.DeviceInterface,
private identifier: string,
private environment: Environment,
protected override internalEventBus: Services.InternalEventBusInterface,
) {
super(internalEventBus)
void this.setPersistencePolicy(Services.StoragePersistencePolicies.Default)
void this.setEncryptionPolicy(Services.StorageEncryptionPolicy.Default, false)
}
public provideEncryptionProvider(provider: Encryption.EncryptionProviderInterface): void {
@@ -73,11 +69,6 @@ export class DiskStorageService extends Services.AbstractService implements Serv
if (this.needsPersist) {
void this.persistValuesToDisk()
}
} else if (stage === Services.ApplicationStage.StorageDecrypted_09) {
const persistedPolicy = await this.getValue(Services.StorageKey.StorageEncryptionPolicy)
if (persistedPolicy) {
void this.setEncryptionPolicy(persistedPolicy as Services.StorageEncryptionPolicy, false)
}
}
}
@@ -90,21 +81,6 @@ export class DiskStorageService extends Services.AbstractService implements Serv
}
}
public setEncryptionPolicy(encryptionPolicy: Services.StorageEncryptionPolicy, persist = true): void {
if (
encryptionPolicy === Services.StorageEncryptionPolicy.Disabled &&
![Environment.Mobile].includes(this.environment)
) {
throw Error('Disabling storage encryption is only available on mobile.')
}
this.encryptionPolicy = encryptionPolicy
if (persist) {
this.setValue(Services.StorageKey.StorageEncryptionPolicy, encryptionPolicy)
}
}
public isEphemeralSession() {
return this.persistencePolicy === Services.StoragePersistencePolicies.Ephemeral
}
@@ -329,10 +305,6 @@ export class DiskStorageService extends Services.AbstractService implements Serv
}
}
public getStorageEncryptionPolicy() {
return this.encryptionPolicy
}
/**
* Default persistence key. Platforms can override as needed.
*/
@@ -393,36 +365,29 @@ export class DiskStorageService extends Services.AbstractService implements Serv
const { encrypted, decrypted, deleted, discardable } = CreatePayloadSplitWithDiscardables(payloads)
const encryptionEnabled = this.encryptionPolicy === Services.StorageEncryptionPolicy.Default
const rootKeyEncryptionAvailable = this.encryptionProvider.hasRootKeyEncryptionSource()
const encryptable: DecryptedPayloadInterface[] = []
const unencryptable: DecryptedPayloadInterface[] = []
if (encryptionEnabled) {
const split = Encryption.SplitPayloadsByEncryptionType(decrypted)
const split = Encryption.SplitPayloadsByEncryptionType(decrypted)
if (split.itemsKeyEncryption) {
extendArray(encryptable, split.itemsKeyEncryption)
}
if (split.itemsKeyEncryption) {
extendArray(encryptable, split.itemsKeyEncryption)
if (split.rootKeyEncryption) {
if (!rootKeyEncryptionAvailable) {
extendArray(unencryptable, split.rootKeyEncryption)
} else {
extendArray(encryptable, split.rootKeyEncryption)
}
if (split.rootKeyEncryption) {
if (!rootKeyEncryptionAvailable) {
extendArray(unencryptable, split.rootKeyEncryption)
} else {
extendArray(encryptable, split.rootKeyEncryption)
}
}
} else {
extendArray(unencryptable, encryptable)
extendArray(unencryptable, decrypted)
}
await this.deletePayloads(discardable)
const split = Encryption.SplitPayloadsByEncryptionType(encryptable)
const encryptableSplit = Encryption.SplitPayloadsByEncryptionType(encryptable)
const keyLookupSplit = Encryption.CreateEncryptionSplitWithKeyLookup(split)
const keyLookupSplit = Encryption.CreateEncryptionSplitWithKeyLookup(encryptableSplit)
const encryptedResults = await this.encryptionProvider.encryptSplit(keyLookupSplit)
@@ -478,7 +443,6 @@ export class DiskStorageService extends Services.AbstractService implements Serv
storage: {
storagePersistable: this.storagePersistable,
persistencePolicy: Services.StoragePersistencePolicies[this.persistencePolicy],
encryptionPolicy: Services.StorageEncryptionPolicy[this.encryptionPolicy],
needsPersist: this.needsPersist,
currentPersistPromise: this.currentPersistPromise != undefined,
isStorageWrapped: this.isStorageWrapped(),