refactor: root key manager (#2344)
This commit is contained in:
@@ -139,7 +139,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
private deprecatedHttpService!: InternalServices.DeprecatedHttpService
|
||||
private declare httpService: HttpServiceInterface
|
||||
public payloadManager!: InternalServices.PayloadManager
|
||||
public protocolService!: EncryptionService
|
||||
public encryptionService!: EncryptionService
|
||||
private diskStorageService!: InternalServices.DiskStorageService
|
||||
private inMemoryStore!: ExternalServices.KeyValueStoreInterface<string>
|
||||
/**
|
||||
@@ -435,7 +435,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
await this.diskStorageService.initializeFromDisk()
|
||||
await this.notifyEvent(ApplicationEvent.StorageReady)
|
||||
|
||||
await this.protocolService.initialize()
|
||||
await this.encryptionService.initialize()
|
||||
|
||||
await this.handleStage(ExternalServices.ApplicationStage.ReadyForLaunch_05)
|
||||
|
||||
@@ -547,9 +547,9 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
let wrappingKey = response.artifacts?.wrappingKey
|
||||
if (!wrappingKey) {
|
||||
const value = response.getValueForType(ChallengeValidation.LocalPasscode)
|
||||
wrappingKey = await this.protocolService.computeWrappingKey(value.value as string)
|
||||
wrappingKey = await this.encryptionService.computeWrappingKey(value.value as string)
|
||||
}
|
||||
await this.protocolService.unwrapRootKey(wrappingKey)
|
||||
await this.encryptionService.unwrapRootKey(wrappingKey)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -740,22 +740,22 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
}
|
||||
|
||||
public getUserPasswordCreationDate(): Date | undefined {
|
||||
return this.protocolService.getPasswordCreatedDate()
|
||||
return this.encryptionService.getPasswordCreatedDate()
|
||||
}
|
||||
|
||||
public getProtocolEncryptionDisplayName(): Promise<string | undefined> {
|
||||
return this.protocolService.getEncryptionDisplayName()
|
||||
return this.encryptionService.getEncryptionDisplayName()
|
||||
}
|
||||
|
||||
public getUserVersion(): Common.ProtocolVersion | undefined {
|
||||
return this.protocolService.getUserVersion()
|
||||
return this.encryptionService.getUserVersion()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there is an upgrade available for the account or passcode
|
||||
*/
|
||||
public protocolUpgradeAvailable(): Promise<boolean> {
|
||||
return this.protocolService.upgradeAvailable()
|
||||
return this.encryptionService.upgradeAvailable()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -790,7 +790,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
}
|
||||
|
||||
public hasAccount(): boolean {
|
||||
return this.protocolService.hasAccount()
|
||||
return this.encryptionService.hasAccount()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -840,7 +840,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFileForAutomatedDesktopBackups(): Promise<BackupFile | undefined> {
|
||||
return this.protocolService.createEncryptedBackupFile()
|
||||
return this.encryptionService.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
@@ -848,7 +848,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return
|
||||
}
|
||||
|
||||
return this.protocolService.createEncryptedBackupFile()
|
||||
return this.encryptionService.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createDecryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
@@ -856,7 +856,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return
|
||||
}
|
||||
|
||||
return this.protocolService.createDecryptedBackupFile()
|
||||
return this.encryptionService.createDecryptedBackupFile()
|
||||
}
|
||||
|
||||
public isEphemeralSession(): boolean {
|
||||
@@ -1058,7 +1058,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.itemManager,
|
||||
this.syncService,
|
||||
this.protectionService,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.payloadManager,
|
||||
this.challengeService,
|
||||
this.historyManager,
|
||||
@@ -1083,7 +1083,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
}
|
||||
|
||||
public async validateAccountPassword(password: string): Promise<boolean> {
|
||||
const { valid } = await this.protocolService.validateAccountPassword(password)
|
||||
const { valid } = await this.encryptionService.validateAccountPassword(password)
|
||||
return valid
|
||||
}
|
||||
|
||||
@@ -1096,7 +1096,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
}
|
||||
|
||||
public hasPasscode(): boolean {
|
||||
return this.protocolService.hasPasscode()
|
||||
return this.encryptionService.hasPasscode()
|
||||
}
|
||||
|
||||
async isLocked(): Promise<boolean> {
|
||||
@@ -1253,7 +1253,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.createKeySystemKeyManager()
|
||||
this.createProtocolService()
|
||||
|
||||
this.diskStorageService.provideEncryptionProvider(this.protocolService)
|
||||
this.diskStorageService.provideEncryptionProvider(this.encryptionService)
|
||||
this.createChallengeService()
|
||||
this.createLegacyHttpManager()
|
||||
this.createHttpServiceAndApiService()
|
||||
@@ -1308,7 +1308,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
;(this.deprecatedHttpService as unknown) = undefined
|
||||
;(this.httpService as unknown) = undefined
|
||||
;(this.payloadManager as unknown) = undefined
|
||||
;(this.protocolService as unknown) = undefined
|
||||
;(this.encryptionService as unknown) = undefined
|
||||
;(this.diskStorageService as unknown) = undefined
|
||||
;(this.inMemoryStore as unknown) = undefined
|
||||
;(this.apiService as unknown) = undefined
|
||||
@@ -1392,7 +1392,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
private createAsymmetricMessageService() {
|
||||
this.asymmetricMessageService = new ExternalServices.AsymmetricMessageService(
|
||||
this.httpService,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.contacts,
|
||||
this.itemManager,
|
||||
this.mutator,
|
||||
@@ -1410,7 +1410,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.sessionManager,
|
||||
this.options.crypto,
|
||||
this.user,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.singletonManager,
|
||||
this.internalEventBus,
|
||||
)
|
||||
@@ -1424,7 +1424,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.syncService,
|
||||
this.itemManager,
|
||||
this.mutator,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.sessions,
|
||||
this.contactService,
|
||||
this.files,
|
||||
@@ -1440,7 +1440,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.syncService,
|
||||
this.itemManager,
|
||||
this.mutator,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.files,
|
||||
this.alertService,
|
||||
this.internalEventBus,
|
||||
@@ -1468,7 +1468,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.apiService,
|
||||
this.mutator,
|
||||
this.syncService,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.challengeService,
|
||||
this.httpService,
|
||||
this.alertService,
|
||||
@@ -1542,7 +1542,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
|
||||
private createMigrationService() {
|
||||
this.migrationService = new InternalServices.SNMigrationService({
|
||||
protocolService: this.protocolService,
|
||||
encryptionService: this.encryptionService,
|
||||
deviceInterface: this.deviceInterface,
|
||||
storageService: this.diskStorageService,
|
||||
sessionManager: this.sessionManager,
|
||||
@@ -1567,7 +1567,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.syncService,
|
||||
this.diskStorageService,
|
||||
this.itemManager,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.alertService,
|
||||
this.challengeService,
|
||||
this.protectionService,
|
||||
@@ -1720,7 +1720,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
}
|
||||
|
||||
private createProtocolService() {
|
||||
this.protocolService = new EncryptionService(
|
||||
this.encryptionService = new EncryptionService(
|
||||
this.itemManager,
|
||||
this.mutator,
|
||||
this.payloadManager,
|
||||
@@ -1732,13 +1732,13 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.internalEventBus,
|
||||
)
|
||||
this.serviceObservers.push(
|
||||
this.protocolService.addEventObserver(async (event) => {
|
||||
this.encryptionService.addEventObserver(async (event) => {
|
||||
if (event === EncryptionServiceEvent.RootKeyStatusChanged) {
|
||||
await this.notifyEvent(ApplicationEvent.KeyStatusChanged)
|
||||
}
|
||||
}),
|
||||
)
|
||||
this.services.push(this.protocolService)
|
||||
this.services.push(this.encryptionService)
|
||||
}
|
||||
|
||||
private createKeySystemKeyManager() {
|
||||
@@ -1757,7 +1757,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.itemManager,
|
||||
this.payloadManager,
|
||||
this.apiService,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.challengeService,
|
||||
this.alertService,
|
||||
this.diskStorageService,
|
||||
@@ -1774,7 +1774,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.apiService,
|
||||
this.userApiService,
|
||||
this.alertService,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.challengeService,
|
||||
this.webSocketsService,
|
||||
this.httpService,
|
||||
@@ -1789,8 +1789,8 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
case ExternalServices.SessionEvent.Restored: {
|
||||
void (async () => {
|
||||
await this.sync.sync({ sourceDescription: 'Session restored pre key creation' })
|
||||
if (this.protocolService.needsNewRootKeyBasedItemsKey()) {
|
||||
void this.protocolService.createNewDefaultItemsKey().then(() => {
|
||||
if (this.encryptionService.needsNewRootKeyBasedItemsKey()) {
|
||||
void this.encryptionService.createNewDefaultItemsKey().then(() => {
|
||||
void this.sync.sync({ sourceDescription: 'Session restored post key creation' })
|
||||
})
|
||||
}
|
||||
@@ -1816,7 +1816,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.syncService = new InternalServices.SNSyncService(
|
||||
this.itemManager,
|
||||
this.sessionManager,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.diskStorageService,
|
||||
this.payloadManager,
|
||||
this.apiService,
|
||||
@@ -1832,7 +1832,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
const syncEventCallback = async (eventName: ExternalServices.SyncEvent) => {
|
||||
const appEvent = applicationEventForSyncEvent(eventName)
|
||||
if (appEvent) {
|
||||
await this.protocolService.onSyncEvent(eventName)
|
||||
await this.encryptionService.onSyncEvent(eventName)
|
||||
|
||||
await this.notifyEvent(appEvent)
|
||||
|
||||
@@ -1852,7 +1852,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
private createChallengeService() {
|
||||
this.challengeService = new InternalServices.ChallengeService(
|
||||
this.diskStorageService,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.internalEventBus,
|
||||
)
|
||||
this.services.push(this.challengeService)
|
||||
@@ -1860,7 +1860,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
|
||||
private createProtectionService() {
|
||||
this.protectionService = new InternalServices.SNProtectionService(
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.mutator,
|
||||
this.challengeService,
|
||||
this.diskStorageService,
|
||||
@@ -1895,7 +1895,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.deviceInterface,
|
||||
this.deprecatedHttpService,
|
||||
this.payloadManager,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.syncService,
|
||||
this.challengeService,
|
||||
this.listedService,
|
||||
@@ -1953,7 +1953,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
this.filesBackupService = new FilesBackupService(
|
||||
this.itemManager,
|
||||
this.apiService,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
device as FileBackupsDevice,
|
||||
this.statusService,
|
||||
this.options.crypto,
|
||||
@@ -2003,7 +2003,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
private createUseCases() {
|
||||
this._signInWithRecoveryCodes = new SignInWithRecoveryCodes(
|
||||
this.authManager,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.inMemoryStore,
|
||||
this.options.crypto,
|
||||
this.sessionManager,
|
||||
@@ -2030,7 +2030,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
|
||||
this._listRevisions = new ListRevisions(this.revisionManager)
|
||||
|
||||
this._getRevision = new GetRevision(this.revisionManager, this.protocolService)
|
||||
this._getRevision = new GetRevision(this.revisionManager, this.encryptionService)
|
||||
|
||||
this._deleteRevision = new DeleteRevision(this.revisionManager)
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ import { GetRevision } from './GetRevision'
|
||||
|
||||
describe('GetRevision', () => {
|
||||
let revisionManager: RevisionClientInterface
|
||||
let protocolService: EncryptionProviderInterface
|
||||
let encryptionService: EncryptionProviderInterface
|
||||
|
||||
const createUseCase = () => new GetRevision(revisionManager, protocolService)
|
||||
const createUseCase = () => new GetRevision(revisionManager, encryptionService)
|
||||
|
||||
beforeEach(() => {
|
||||
revisionManager = {} as jest.Mocked<RevisionClientInterface>
|
||||
@@ -35,13 +35,13 @@ describe('GetRevision', () => {
|
||||
updated_at: '2021-01-01T00:00:00.000Z'
|
||||
} as jest.Mocked<Revision>)
|
||||
|
||||
protocolService = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
protocolService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: '00000000-0000-0000-0000-000000000000' })
|
||||
encryptionService = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
encryptionService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: '00000000-0000-0000-0000-000000000000' })
|
||||
const encryptedPayload = {
|
||||
content: 'foobar',
|
||||
} as jest.Mocked<EncryptedPayloadInterface>
|
||||
encryptedPayload.copy = jest.fn().mockReturnValue(encryptedPayload)
|
||||
protocolService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
encryptionService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
|
||||
isRemotePayloadAllowed.mockImplementation(() => true)
|
||||
})
|
||||
@@ -59,7 +59,7 @@ describe('GetRevision', () => {
|
||||
})
|
||||
|
||||
it('it should get a revision without uuid from embedded params', async () => {
|
||||
protocolService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: undefined })
|
||||
encryptionService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue({ u: undefined })
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('GetRevision', () => {
|
||||
})
|
||||
|
||||
it('it should get a revision without embedded params', async () => {
|
||||
protocolService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue(undefined)
|
||||
encryptionService.getEmbeddedPayloadAuthenticatedData = jest.fn().mockReturnValue(undefined)
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
@@ -130,7 +130,7 @@ describe('GetRevision', () => {
|
||||
errorDecrypting: true,
|
||||
} as jest.Mocked<EncryptedPayloadInterface>
|
||||
encryptedPayload.copy = jest.fn().mockReturnValue(encryptedPayload)
|
||||
protocolService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
encryptionService.decryptSplitSingle = jest.fn().mockReturnValue(encryptedPayload)
|
||||
|
||||
const useCase = createUseCase()
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ import { EncryptionProviderInterface } from '@standardnotes/encryption'
|
||||
import { GetRevisionDTO } from './GetRevisionDTO'
|
||||
|
||||
export class GetRevision implements UseCaseInterface<HistoryEntry> {
|
||||
constructor(private revisionManager: RevisionClientInterface, private protocolService: EncryptionProviderInterface) {}
|
||||
constructor(
|
||||
private revisionManager: RevisionClientInterface,
|
||||
private encryptionService: EncryptionProviderInterface,
|
||||
) {}
|
||||
|
||||
async execute(dto: GetRevisionDTO): Promise<Result<HistoryEntry>> {
|
||||
const itemUuidOrError = Uuid.create(dto.itemUuid)
|
||||
@@ -63,7 +66,7 @@ export class GetRevision implements UseCaseInterface<HistoryEntry> {
|
||||
* these olders revisions (which have not been mutated after copy) with the source item's
|
||||
* uuid.
|
||||
*/
|
||||
const embeddedParams = this.protocolService.getEmbeddedPayloadAuthenticatedData(serverPayload)
|
||||
const embeddedParams = this.encryptionService.getEmbeddedPayloadAuthenticatedData(serverPayload)
|
||||
const sourceItemUuid = embeddedParams?.u as string | undefined
|
||||
|
||||
const payload = serverPayload.copy({
|
||||
@@ -76,7 +79,7 @@ export class GetRevision implements UseCaseInterface<HistoryEntry> {
|
||||
|
||||
const encryptedPayload = new EncryptedPayload(payload)
|
||||
|
||||
const decryptedPayload = await this.protocolService.decryptSplitSingle<NoteContent>({
|
||||
const decryptedPayload = await this.encryptionService.decryptSplitSingle<NoteContent>({
|
||||
usesItemsKeyWithKeyLookup: { items: [encryptedPayload] },
|
||||
})
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { SignInWithRecoveryCodes } from './SignInWithRecoveryCodes'
|
||||
|
||||
describe('SignInWithRecoveryCodes', () => {
|
||||
let authManager: AuthClientInterface
|
||||
let protocolService: EncryptionProviderInterface
|
||||
let encryptionService: EncryptionProviderInterface
|
||||
let inMemoryStore: KeyValueStoreInterface<string>
|
||||
let crypto: PureCryptoInterface
|
||||
let sessionManager: SessionsClientInterface
|
||||
@@ -22,7 +22,7 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
|
||||
const createUseCase = () => new SignInWithRecoveryCodes(
|
||||
authManager,
|
||||
protocolService,
|
||||
encryptionService,
|
||||
inMemoryStore,
|
||||
crypto,
|
||||
sessionManager,
|
||||
@@ -50,17 +50,17 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
})
|
||||
rootKey.payload = payload
|
||||
|
||||
protocolService = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
protocolService.hasAccount = jest.fn()
|
||||
protocolService.computeRootKey = jest.fn().mockReturnValue(rootKey)
|
||||
protocolService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(true)
|
||||
protocolService.supportedVersions = jest.fn().mockReturnValue([
|
||||
encryptionService = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
encryptionService.hasAccount = jest.fn()
|
||||
encryptionService.computeRootKey = jest.fn().mockReturnValue(rootKey)
|
||||
encryptionService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(true)
|
||||
encryptionService.supportedVersions = jest.fn().mockReturnValue([
|
||||
'001',
|
||||
'002',
|
||||
'003',
|
||||
'004',
|
||||
])
|
||||
protocolService.isVersionNewerThanLibraryVersion = jest.fn()
|
||||
encryptionService.isVersionNewerThanLibraryVersion = jest.fn()
|
||||
|
||||
inMemoryStore = {} as jest.Mocked<KeyValueStoreInterface<string>>
|
||||
inMemoryStore.setValue = jest.fn()
|
||||
@@ -79,7 +79,7 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
})
|
||||
|
||||
it('should fail if an account already exists', async () => {
|
||||
protocolService.hasAccount = jest.fn().mockReturnValue(true)
|
||||
encryptionService.hasAccount = jest.fn().mockReturnValue(true)
|
||||
|
||||
const useCase = createUseCase()
|
||||
const result = await useCase.execute({ recoveryCodes: 'recovery-codes', password: 'foobar', username: 'test@test.te' })
|
||||
@@ -99,7 +99,7 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
})
|
||||
|
||||
it('should fail if key params has unsupported deriviation', async () => {
|
||||
protocolService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(false)
|
||||
encryptionService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(false)
|
||||
|
||||
const useCase = createUseCase()
|
||||
const result = await useCase.execute({ recoveryCodes: 'recovery-codes', password: 'foobar', username: 'test@test.te' })
|
||||
@@ -109,7 +109,7 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
})
|
||||
|
||||
it('should fail if key params has unsupported version', async () => {
|
||||
protocolService.isVersionNewerThanLibraryVersion = jest.fn().mockReturnValue(true)
|
||||
encryptionService.isVersionNewerThanLibraryVersion = jest.fn().mockReturnValue(true)
|
||||
|
||||
authManager.recoveryKeyParams = jest.fn().mockReturnValue({
|
||||
identifier: 'test@test.te',
|
||||
@@ -120,7 +120,7 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
version: '006',
|
||||
})
|
||||
|
||||
protocolService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(false)
|
||||
encryptionService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(false)
|
||||
|
||||
const useCase = createUseCase()
|
||||
const result = await useCase.execute({ recoveryCodes: 'recovery-codes', password: 'foobar', username: 'test@test.te' })
|
||||
@@ -130,7 +130,7 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
})
|
||||
|
||||
it('should fail if key params has expired version', async () => {
|
||||
protocolService.isVersionNewerThanLibraryVersion = jest.fn().mockReturnValue(false)
|
||||
encryptionService.isVersionNewerThanLibraryVersion = jest.fn().mockReturnValue(false)
|
||||
|
||||
authManager.recoveryKeyParams = jest.fn().mockReturnValue({
|
||||
identifier: 'test@test.te',
|
||||
@@ -141,7 +141,7 @@ describe('SignInWithRecoveryCodes', () => {
|
||||
version: '006',
|
||||
})
|
||||
|
||||
protocolService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(false)
|
||||
encryptionService.platformSupportsKeyDerivation = jest.fn().mockReturnValue(false)
|
||||
|
||||
const useCase = createUseCase()
|
||||
const result = await useCase.execute({ recoveryCodes: 'recovery-codes', password: 'foobar', username: 'test@test.te' })
|
||||
|
||||
@@ -20,7 +20,7 @@ import { SignInWithRecoveryCodesDTO } from './SignInWithRecoveryCodesDTO'
|
||||
export class SignInWithRecoveryCodes implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private authManager: AuthClientInterface,
|
||||
private protocolService: EncryptionProviderInterface,
|
||||
private encryptionService: EncryptionProviderInterface,
|
||||
private inMemoryStore: KeyValueStoreInterface<string>,
|
||||
private crypto: PureCryptoInterface,
|
||||
private sessionManager: SessionsClientInterface,
|
||||
@@ -28,7 +28,7 @@ export class SignInWithRecoveryCodes implements UseCaseInterface<void> {
|
||||
) {}
|
||||
|
||||
async execute(dto: SignInWithRecoveryCodesDTO): Promise<Result<void>> {
|
||||
if (this.protocolService.hasAccount()) {
|
||||
if (this.encryptionService.hasAccount()) {
|
||||
return Result.fail('Tried to sign in when an account already exists.')
|
||||
}
|
||||
|
||||
@@ -48,19 +48,19 @@ export class SignInWithRecoveryCodes implements UseCaseInterface<void> {
|
||||
|
||||
const rootKeyParams = CreateAnyKeyParams(recoveryKeyParams)
|
||||
|
||||
if (!this.protocolService.supportedVersions().includes(rootKeyParams.version)) {
|
||||
if (this.protocolService.isVersionNewerThanLibraryVersion(rootKeyParams.version)) {
|
||||
if (!this.encryptionService.supportedVersions().includes(rootKeyParams.version)) {
|
||||
if (this.encryptionService.isVersionNewerThanLibraryVersion(rootKeyParams.version)) {
|
||||
return Result.fail(UNSUPPORTED_PROTOCOL_VERSION)
|
||||
}
|
||||
|
||||
return Result.fail(EXPIRED_PROTOCOL_VERSION)
|
||||
}
|
||||
|
||||
if (!this.protocolService.platformSupportsKeyDerivation(rootKeyParams)) {
|
||||
if (!this.encryptionService.platformSupportsKeyDerivation(rootKeyParams)) {
|
||||
return Result.fail(UNSUPPORTED_KEY_DERIVATION)
|
||||
}
|
||||
|
||||
const rootKey = await this.protocolService.computeRootKey(dto.password, rootKeyParams)
|
||||
const rootKey = await this.encryptionService.computeRootKey(dto.password, rootKeyParams)
|
||||
|
||||
const signInResult = await this.authManager.signInWithRecoveryCodes({
|
||||
codeVerifier,
|
||||
|
||||
@@ -207,13 +207,13 @@ export class BaseMigration extends Migration {
|
||||
this.services.challengeService.addChallengeObserver(challenge, {
|
||||
onNonvalidatedSubmit: async (challengeResponse) => {
|
||||
const password = challengeResponse.values[0].value as string
|
||||
const accountParams = this.services.protocolService.createKeyParams(rawAccountParams)
|
||||
const rootKey = await this.services.protocolService.computeRootKey(password, accountParams)
|
||||
const accountParams = this.services.encryptionService.createKeyParams(rawAccountParams)
|
||||
const rootKey = await this.services.encryptionService.computeRootKey(password, accountParams)
|
||||
|
||||
/** TS can't detect we returned early above if itemToDecrypt is null */
|
||||
assert(itemToDecrypt)
|
||||
|
||||
const decryptedPayload = await this.services.protocolService.decryptSplitSingle({
|
||||
const decryptedPayload = await this.services.encryptionService.decryptSplitSingle({
|
||||
usesRootKey: {
|
||||
items: [itemToDecrypt],
|
||||
key: rootKey,
|
||||
|
||||
@@ -13,7 +13,7 @@ import { ChallengeService, SNSingletonManager, SNFeaturesService, DiskStorageSer
|
||||
import { LegacySession, MapperInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export type MigrationServices = {
|
||||
protocolService: EncryptionService
|
||||
encryptionService: EncryptionService
|
||||
deviceInterface: DeviceInterface
|
||||
storageService: DiskStorageService
|
||||
challengeService: ChallengeService
|
||||
|
||||
@@ -14,8 +14,8 @@ export class Migration2_0_15 extends Migration {
|
||||
}
|
||||
|
||||
private async createNewDefaultItemsKeyIfNecessary() {
|
||||
if (this.services.protocolService.needsNewRootKeyBasedItemsKey()) {
|
||||
await this.services.protocolService.createNewDefaultItemsKey()
|
||||
if (this.services.encryptionService.needsNewRootKeyBasedItemsKey()) {
|
||||
await this.services.encryptionService.createNewDefaultItemsKey()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ export class SNActionsService extends AbstractService {
|
||||
public deviceInterface: DeviceInterface,
|
||||
private httpService: DeprecatedHttpService,
|
||||
private payloadManager: PayloadManager,
|
||||
private protocolService: EncryptionService,
|
||||
private encryptionService: EncryptionService,
|
||||
private syncService: SNSyncService,
|
||||
private challengeService: ChallengeService,
|
||||
private listedService: ListedService,
|
||||
@@ -81,7 +81,7 @@ export class SNActionsService extends AbstractService {
|
||||
;(this.payloadManager as unknown) = undefined
|
||||
;(this.listedService as unknown) = undefined
|
||||
;(this.challengeService as unknown) = undefined
|
||||
;(this.protocolService as unknown) = undefined
|
||||
;(this.encryptionService as unknown) = undefined
|
||||
;(this.syncService as unknown) = undefined
|
||||
this.payloadRequestHandlers.length = 0
|
||||
this.previousPasswords.length = 0
|
||||
@@ -207,7 +207,7 @@ export class SNActionsService extends AbstractService {
|
||||
return
|
||||
}
|
||||
|
||||
let decryptedPayload = await this.protocolService.decryptSplitSingle<ActionExtensionContent>({
|
||||
let decryptedPayload = await this.encryptionService.decryptSplitSingle<ActionExtensionContent>({
|
||||
usesItemsKeyWithKeyLookup: {
|
||||
items: [payload],
|
||||
},
|
||||
@@ -218,7 +218,7 @@ export class SNActionsService extends AbstractService {
|
||||
}
|
||||
|
||||
if (rootKey) {
|
||||
decryptedPayload = await this.protocolService.decryptSplitSingle({
|
||||
decryptedPayload = await this.encryptionService.decryptSplitSingle({
|
||||
usesRootKey: {
|
||||
items: [payload],
|
||||
key: rootKey,
|
||||
@@ -230,7 +230,7 @@ export class SNActionsService extends AbstractService {
|
||||
}
|
||||
|
||||
for (const itemsKey of this.itemManager.getDisplayableItemsKeys()) {
|
||||
const decryptedPayload = await this.protocolService.decryptSplitSingle<ActionExtensionContent>({
|
||||
const decryptedPayload = await this.encryptionService.decryptSplitSingle<ActionExtensionContent>({
|
||||
usesItemsKey: {
|
||||
items: [payload],
|
||||
key: itemsKey,
|
||||
@@ -256,7 +256,7 @@ export class SNActionsService extends AbstractService {
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
const keyParams = this.protocolService.createKeyParams(keyParamsData)
|
||||
const keyParams = this.encryptionService.createKeyParams(keyParamsData)
|
||||
|
||||
/* Try previous passwords */
|
||||
for (const passwordCandidate of this.previousPasswords) {
|
||||
@@ -266,7 +266,7 @@ export class SNActionsService extends AbstractService {
|
||||
|
||||
triedPasswords.push(passwordCandidate)
|
||||
|
||||
const key = await this.protocolService.computeRootKey(passwordCandidate, keyParams)
|
||||
const key = await this.encryptionService.computeRootKey(passwordCandidate, keyParams)
|
||||
if (!key) {
|
||||
continue
|
||||
}
|
||||
@@ -341,7 +341,7 @@ export class SNActionsService extends AbstractService {
|
||||
return item.payload.ejected()
|
||||
}
|
||||
|
||||
const encrypted = await this.protocolService.encryptSplitSingle({
|
||||
const encrypted = await this.encryptionService.encryptSplitSingle({
|
||||
usesItemsKeyWithKeyLookup: { items: [item.payload] },
|
||||
})
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ export class ChallengeService extends AbstractService implements ChallengeServic
|
||||
|
||||
constructor(
|
||||
private storageService: DiskStorageService,
|
||||
private protocolService: EncryptionService,
|
||||
private encryptionService: EncryptionService,
|
||||
protected override internalEventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(internalEventBus)
|
||||
@@ -52,7 +52,7 @@ export class ChallengeService extends AbstractService implements ChallengeServic
|
||||
|
||||
public override deinit() {
|
||||
;(this.storageService as unknown) = undefined
|
||||
;(this.protocolService as unknown) = undefined
|
||||
;(this.encryptionService as unknown) = undefined
|
||||
;(this.sendChallenge as unknown) = undefined
|
||||
;(this.challengeOperations as unknown) = undefined
|
||||
;(this.challengeObservers as unknown) = undefined
|
||||
@@ -79,9 +79,9 @@ export class ChallengeService extends AbstractService implements ChallengeServic
|
||||
public async validateChallengeValue(value: ChallengeValue): Promise<ChallengeValidationResponse> {
|
||||
switch (value.prompt.validation) {
|
||||
case ChallengeValidation.LocalPasscode:
|
||||
return this.protocolService.validatePasscode(value.value as string)
|
||||
return this.encryptionService.validatePasscode(value.value as string)
|
||||
case ChallengeValidation.AccountPassword:
|
||||
return this.protocolService.validateAccountPassword(value.value as string)
|
||||
return this.encryptionService.validateAccountPassword(value.value as string)
|
||||
case ChallengeValidation.Biometric:
|
||||
return { valid: value.value === true }
|
||||
case ChallengeValidation.Authenticator:
|
||||
@@ -104,7 +104,7 @@ export class ChallengeService extends AbstractService implements ChallengeServic
|
||||
}
|
||||
|
||||
async promptForAccountPassword(): Promise<string | null> {
|
||||
if (!this.protocolService.hasAccount()) {
|
||||
if (!this.encryptionService.hasAccount()) {
|
||||
throw Error('Requiring account password for challenge with no account')
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ export class ChallengeService extends AbstractService implements ChallengeServic
|
||||
canceled?: undefined
|
||||
}
|
||||
> {
|
||||
if (!this.protocolService.hasPasscode()) {
|
||||
if (!this.encryptionService.hasPasscode()) {
|
||||
return {}
|
||||
}
|
||||
|
||||
@@ -154,12 +154,12 @@ export class ChallengeService extends AbstractService implements ChallengeServic
|
||||
}
|
||||
}
|
||||
|
||||
const wrappingKey = await this.protocolService.computeWrappingKey(passcode)
|
||||
const wrappingKey = await this.encryptionService.computeWrappingKey(passcode)
|
||||
return { wrappingKey }
|
||||
}
|
||||
|
||||
public isPasscodeLocked() {
|
||||
return this.protocolService.isPasscodeLocked()
|
||||
return this.encryptionService.isPasscodeLocked()
|
||||
}
|
||||
|
||||
public addChallengeObserver(challenge: Challenge, observer: ChallengeObserver): () => void {
|
||||
|
||||
@@ -11,7 +11,7 @@ export class KeyRecoveryOperation {
|
||||
constructor(
|
||||
private queueItem: DecryptionQueueItem,
|
||||
private itemManager: ItemManager,
|
||||
private protocolService: EncryptionProviderInterface,
|
||||
private encryptionService: EncryptionProviderInterface,
|
||||
private challengeService: ChallengeServiceInterface,
|
||||
private clientParams: SNRootKeyParams | undefined,
|
||||
private serverParams: SNRootKeyParams | undefined,
|
||||
@@ -43,7 +43,7 @@ export class KeyRecoveryOperation {
|
||||
|
||||
const decryptionResult = await DecryptItemsKeyByPromptingUser(
|
||||
this.queueItem.encryptedKey,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.challengeService,
|
||||
this.queueItem.keyParams,
|
||||
)
|
||||
|
||||
@@ -87,7 +87,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
private itemManager: ItemManager,
|
||||
private payloadManager: PayloadManager,
|
||||
private apiService: SNApiService,
|
||||
private protocolService: EncryptionService,
|
||||
private encryptionService: EncryptionService,
|
||||
private challengeService: ChallengeService,
|
||||
private alertService: AlertService,
|
||||
private storageService: DiskStorageService,
|
||||
@@ -121,7 +121,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
;(this.itemManager as unknown) = undefined
|
||||
;(this.payloadManager as unknown) = undefined
|
||||
;(this.apiService as unknown) = undefined
|
||||
;(this.protocolService as unknown) = undefined
|
||||
;(this.encryptionService as unknown) = undefined
|
||||
;(this.challengeService as unknown) = undefined
|
||||
;(this.alertService as unknown) = undefined
|
||||
;(this.storageService as unknown) = undefined
|
||||
@@ -251,7 +251,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
}
|
||||
|
||||
private getClientKeyParams() {
|
||||
return this.protocolService.getAccountKeyParams()
|
||||
return this.encryptionService.getAccountKeyParams()
|
||||
}
|
||||
|
||||
private async performServerSignIn(): Promise<SNRootKey | undefined> {
|
||||
@@ -279,7 +279,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
return
|
||||
}
|
||||
|
||||
const rootKey = await this.protocolService.computeRootKey(password, serverParams)
|
||||
const rootKey = await this.encryptionService.computeRootKey(password, serverParams)
|
||||
|
||||
const signInResponse = await this.userService.correctiveSignIn(rootKey)
|
||||
|
||||
@@ -295,7 +295,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
}
|
||||
|
||||
private async getWrappingKeyIfApplicable(): Promise<SNRootKey | undefined> {
|
||||
if (!this.protocolService.hasPasscode()) {
|
||||
if (!this.encryptionService.hasPasscode()) {
|
||||
return undefined
|
||||
}
|
||||
const { wrappingKey, canceled } = await this.challengeService.getWrappingKeyIfApplicable()
|
||||
@@ -312,7 +312,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
|
||||
private addKeysToQueue(keys: EncryptedPayloadInterface[]) {
|
||||
for (const key of keys) {
|
||||
const keyParams = this.protocolService.getKeyEmbeddedKeyParamsFromItemsKey(key)
|
||||
const keyParams = this.encryptionService.getKeyEmbeddedKeyParamsFromItemsKey(key)
|
||||
if (!keyParams) {
|
||||
continue
|
||||
}
|
||||
@@ -356,12 +356,12 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
serverParams = await this.getLatestKeyParamsFromServer(clientParams.identifier)
|
||||
}
|
||||
|
||||
const deallocedAfterNetworkRequest = this.protocolService == undefined
|
||||
const deallocedAfterNetworkRequest = this.encryptionService == undefined
|
||||
if (deallocedAfterNetworkRequest) {
|
||||
return
|
||||
}
|
||||
|
||||
const credentialsMissing = !this.protocolService.hasAccount() && !this.protocolService.hasPasscode()
|
||||
const credentialsMissing = !this.encryptionService.hasAccount() && !this.encryptionService.hasPasscode()
|
||||
|
||||
if (credentialsMissing) {
|
||||
const rootKey = await this.performServerSignIn()
|
||||
@@ -426,7 +426,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
const operation = new KeyRecoveryOperation(
|
||||
queueItem,
|
||||
this.itemManager,
|
||||
this.protocolService,
|
||||
this.encryptionService,
|
||||
this.challengeService,
|
||||
clientParams,
|
||||
serverParams,
|
||||
@@ -460,7 +460,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
if (replacesRootKey) {
|
||||
const wrappingKey = await this.getWrappingKeyIfApplicable()
|
||||
|
||||
await this.protocolService.setRootKey(rootKey, wrappingKey)
|
||||
await this.encryptionService.setRootKey(rootKey, wrappingKey)
|
||||
}
|
||||
|
||||
const clientKeyParams = this.getClientKeyParams()
|
||||
@@ -475,7 +475,7 @@ export class SNKeyRecoveryService extends AbstractService<KeyRecoveryEvent, Decr
|
||||
: qItem.encryptedKey
|
||||
})
|
||||
|
||||
const matchingResults = await this.protocolService.decryptSplit({
|
||||
const matchingResults = await this.encryptionService.decryptSplit({
|
||||
usesRootKey: {
|
||||
items: matchingKeys,
|
||||
key: rootKey,
|
||||
|
||||
@@ -24,14 +24,14 @@ const setupRandomUuid = () => {
|
||||
|
||||
describe('protectionService', () => {
|
||||
let mutator: MutatorClientInterface
|
||||
let protocolService: EncryptionService
|
||||
let encryptionService: EncryptionService
|
||||
let challengeService: ChallengeService
|
||||
let storageService: DiskStorageService
|
||||
let internalEventBus: InternalEventBusInterface
|
||||
let protectionService: SNProtectionService
|
||||
|
||||
const createService = () => {
|
||||
return new SNProtectionService(protocolService, mutator, challengeService, storageService, internalEventBus)
|
||||
return new SNProtectionService(encryptionService, mutator, challengeService, storageService, internalEventBus)
|
||||
}
|
||||
|
||||
const createFile = (name: string, isProtected?: boolean) => {
|
||||
@@ -59,9 +59,9 @@ describe('protectionService', () => {
|
||||
storageService = {} as jest.Mocked<DiskStorageService>
|
||||
storageService.getValue = jest.fn()
|
||||
|
||||
protocolService = {} as jest.Mocked<EncryptionService>
|
||||
protocolService.hasAccount = jest.fn().mockReturnValue(true)
|
||||
protocolService.hasPasscode = jest.fn().mockReturnValue(false)
|
||||
encryptionService = {} as jest.Mocked<EncryptionService>
|
||||
encryptionService.hasAccount = jest.fn().mockReturnValue(true)
|
||||
encryptionService.hasPasscode = jest.fn().mockReturnValue(false)
|
||||
|
||||
mutator = {} as jest.Mocked<MutatorClientInterface>
|
||||
})
|
||||
|
||||
@@ -76,7 +76,7 @@ export class SNProtectionService extends AbstractService<ProtectionEvent> implem
|
||||
private mobileBiometricsTiming: MobileUnlockTiming | undefined = MobileUnlockTiming.OnQuit
|
||||
|
||||
constructor(
|
||||
private protocolService: EncryptionService,
|
||||
private encryptionService: EncryptionService,
|
||||
private mutator: MutatorClientInterface,
|
||||
private challengeService: ChallengeService,
|
||||
private storageService: DiskStorageService,
|
||||
@@ -87,7 +87,7 @@ export class SNProtectionService extends AbstractService<ProtectionEvent> implem
|
||||
|
||||
public override deinit(): void {
|
||||
clearTimeout(this.sessionExpiryTimeout)
|
||||
;(this.protocolService as unknown) = undefined
|
||||
;(this.encryptionService as unknown) = undefined
|
||||
;(this.challengeService as unknown) = undefined
|
||||
;(this.storageService as unknown) = undefined
|
||||
super.deinit()
|
||||
@@ -103,7 +103,7 @@ export class SNProtectionService extends AbstractService<ProtectionEvent> implem
|
||||
}
|
||||
|
||||
public hasProtectionSources(): boolean {
|
||||
return this.protocolService.hasAccount() || this.protocolService.hasPasscode() || this.hasBiometricsEnabled()
|
||||
return this.encryptionService.hasAccount() || this.encryptionService.hasPasscode() || this.hasBiometricsEnabled()
|
||||
}
|
||||
|
||||
public hasUnprotectedAccessSession(): boolean {
|
||||
@@ -148,7 +148,7 @@ export class SNProtectionService extends AbstractService<ProtectionEvent> implem
|
||||
if (this.hasBiometricsEnabled()) {
|
||||
prompts.push(new ChallengePrompt(ChallengeValidation.Biometric))
|
||||
}
|
||||
if (this.protocolService.hasPasscode()) {
|
||||
if (this.encryptionService.hasPasscode()) {
|
||||
prompts.push(new ChallengePrompt(ChallengeValidation.LocalPasscode))
|
||||
}
|
||||
if (prompts.length > 0) {
|
||||
@@ -354,19 +354,19 @@ export class SNProtectionService extends AbstractService<ProtectionEvent> implem
|
||||
prompts.push(new ChallengePrompt(ChallengeValidation.Biometric))
|
||||
}
|
||||
|
||||
if (this.protocolService.hasPasscode()) {
|
||||
if (this.encryptionService.hasPasscode()) {
|
||||
prompts.push(new ChallengePrompt(ChallengeValidation.LocalPasscode))
|
||||
}
|
||||
|
||||
if (requireAccountPassword) {
|
||||
if (!this.protocolService.hasAccount()) {
|
||||
if (!this.encryptionService.hasAccount()) {
|
||||
throw Error('Requiring account password for challenge with no account')
|
||||
}
|
||||
prompts.push(new ChallengePrompt(ChallengeValidation.AccountPassword))
|
||||
}
|
||||
|
||||
if (prompts.length === 0) {
|
||||
if (fallBackToAccountPassword && this.protocolService.hasAccount()) {
|
||||
if (fallBackToAccountPassword && this.encryptionService.hasAccount()) {
|
||||
prompts.push(new ChallengePrompt(ChallengeValidation.AccountPassword))
|
||||
} else {
|
||||
return true
|
||||
|
||||
@@ -93,7 +93,7 @@ export class SNSessionManager
|
||||
private apiService: SNApiService,
|
||||
private userApiService: UserApiServiceInterface,
|
||||
private alertService: AlertService,
|
||||
private protocolService: EncryptionService,
|
||||
private encryptionService: EncryptionService,
|
||||
private challengeService: ChallengeService,
|
||||
private webSocketsService: SNWebSocketsService,
|
||||
private httpService: HttpServiceInterface,
|
||||
@@ -119,7 +119,7 @@ export class SNSessionManager
|
||||
}
|
||||
|
||||
override deinit(): void {
|
||||
;(this.protocolService as unknown) = undefined
|
||||
;(this.encryptionService as unknown) = undefined
|
||||
;(this.diskStorageService as unknown) = undefined
|
||||
;(this.apiService as unknown) = undefined
|
||||
;(this.alertService as unknown) = undefined
|
||||
@@ -205,11 +205,11 @@ export class SNSessionManager
|
||||
}
|
||||
|
||||
public getPublicKey(): string {
|
||||
return this.protocolService.getKeyPair().publicKey
|
||||
return this.encryptionService.getKeyPair().publicKey
|
||||
}
|
||||
|
||||
public getSigningPublicKey(): string {
|
||||
return this.protocolService.getSigningKeyPair().publicKey
|
||||
return this.encryptionService.getSigningKeyPair().publicKey
|
||||
}
|
||||
|
||||
public get userUuid(): string {
|
||||
@@ -285,7 +285,7 @@ export class SNSessionManager
|
||||
onNonvalidatedSubmit: async (challengeResponse) => {
|
||||
const email = challengeResponse.values[0].value as string
|
||||
const password = challengeResponse.values[1].value as string
|
||||
const currentKeyParams = this.protocolService.getAccountKeyParams()
|
||||
const currentKeyParams = this.encryptionService.getAccountKeyParams()
|
||||
const { response } = await this.signIn(
|
||||
email,
|
||||
password,
|
||||
@@ -403,7 +403,7 @@ export class SNSessionManager
|
||||
|
||||
email = cleanedEmailString(email)
|
||||
|
||||
const rootKey = await this.protocolService.createRootKey<RootKeyWithKeyPairsInterface>(
|
||||
const rootKey = await this.encryptionService.createRootKey<RootKeyWithKeyPairsInterface>(
|
||||
email,
|
||||
password,
|
||||
Common.KeyParamsOrigination.Registration,
|
||||
@@ -525,8 +525,8 @@ export class SNSessionManager
|
||||
}
|
||||
}
|
||||
const keyParams = paramsResult.keyParams as SNRootKeyParams
|
||||
if (!this.protocolService.supportedVersions().includes(keyParams.version)) {
|
||||
if (this.protocolService.isVersionNewerThanLibraryVersion(keyParams.version)) {
|
||||
if (!this.encryptionService.supportedVersions().includes(keyParams.version)) {
|
||||
if (this.encryptionService.isVersionNewerThanLibraryVersion(keyParams.version)) {
|
||||
return {
|
||||
response: this.apiService.createErrorResponse(UNSUPPORTED_PROTOCOL_VERSION),
|
||||
}
|
||||
@@ -539,7 +539,7 @@ export class SNSessionManager
|
||||
|
||||
if (Common.isProtocolVersionExpired(keyParams.version)) {
|
||||
/* Cost minimums only apply to now outdated versions (001 and 002) */
|
||||
const minimum = this.protocolService.costMinimumForVersion(keyParams.version)
|
||||
const minimum = this.encryptionService.costMinimumForVersion(keyParams.version)
|
||||
if (keyParams.content002.pw_cost < minimum) {
|
||||
return {
|
||||
response: this.apiService.createErrorResponse(INVALID_PASSWORD_COST),
|
||||
@@ -560,14 +560,14 @@ export class SNSessionManager
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.protocolService.platformSupportsKeyDerivation(keyParams)) {
|
||||
if (!this.encryptionService.platformSupportsKeyDerivation(keyParams)) {
|
||||
return {
|
||||
response: this.apiService.createErrorResponse(UNSUPPORTED_KEY_DERIVATION),
|
||||
}
|
||||
}
|
||||
|
||||
if (strict) {
|
||||
minAllowedVersion = this.protocolService.getLatestVersion()
|
||||
minAllowedVersion = this.encryptionService.getLatestVersion()
|
||||
}
|
||||
|
||||
if (minAllowedVersion != undefined) {
|
||||
@@ -577,7 +577,7 @@ export class SNSessionManager
|
||||
}
|
||||
}
|
||||
}
|
||||
const rootKey = await this.protocolService.computeRootKey(password, keyParams)
|
||||
const rootKey = await this.encryptionService.computeRootKey(password, keyParams)
|
||||
const signInResponse = await this.bypassChecksAndSignInWithRootKey(email, rootKey, ephemeral)
|
||||
|
||||
return {
|
||||
@@ -641,8 +641,8 @@ export class SNSessionManager
|
||||
let oldSigningKeyPair: PkcKeyPair | undefined
|
||||
|
||||
try {
|
||||
oldKeyPair = this.protocolService.getKeyPair()
|
||||
oldSigningKeyPair = this.protocolService.getSigningKeyPair()
|
||||
oldKeyPair = this.encryptionService.getKeyPair()
|
||||
oldSigningKeyPair = this.encryptionService.getSigningKeyPair()
|
||||
} catch (error) {
|
||||
void error
|
||||
}
|
||||
@@ -718,7 +718,7 @@ export class SNSessionManager
|
||||
}
|
||||
|
||||
private decodeDemoShareToken(token: Base64String): ShareToken {
|
||||
const jsonString = this.protocolService.crypto.base64Decode(token)
|
||||
const jsonString = this.encryptionService.crypto.base64Decode(token)
|
||||
return JSON.parse(jsonString)
|
||||
}
|
||||
|
||||
@@ -735,7 +735,7 @@ export class SNSessionManager
|
||||
host: string,
|
||||
wrappingKey?: SNRootKey,
|
||||
) {
|
||||
await this.protocolService.setRootKey(rootKey, wrappingKey)
|
||||
await this.encryptionService.setRootKey(rootKey, wrappingKey)
|
||||
|
||||
this.memoizeUser(user)
|
||||
this.diskStorageService.setValue(StorageKey.User, user)
|
||||
|
||||
@@ -153,7 +153,7 @@ export class SNSyncService
|
||||
constructor(
|
||||
private itemManager: ItemManager,
|
||||
private sessionManager: SNSessionManager,
|
||||
private protocolService: EncryptionService,
|
||||
private encryptionService: EncryptionService,
|
||||
private storageService: DiskStorageService,
|
||||
private payloadManager: PayloadManager,
|
||||
private apiService: SNApiService,
|
||||
@@ -189,7 +189,7 @@ export class SNSyncService
|
||||
this.dealloced = true
|
||||
;(this.sessionManager as unknown) = undefined
|
||||
;(this.itemManager as unknown) = undefined
|
||||
;(this.protocolService as unknown) = undefined
|
||||
;(this.encryptionService as unknown) = undefined
|
||||
;(this.payloadManager as unknown) = undefined
|
||||
;(this.storageService as unknown) = undefined
|
||||
;(this.apiService as unknown) = undefined
|
||||
@@ -250,7 +250,7 @@ export class SNSyncService
|
||||
const encryptionSplit = SplitPayloadsByEncryptionType(encryptedPayloads)
|
||||
const decryptionSplit = CreateDecryptionSplitWithKeyLookup(encryptionSplit)
|
||||
|
||||
const newlyDecryptedPayloads = await this.protocolService.decryptSplit(decryptionSplit)
|
||||
const newlyDecryptedPayloads = await this.encryptionService.decryptSplit(decryptionSplit)
|
||||
|
||||
await this.payloadManager.emitPayloads(
|
||||
[...alreadyDecryptedPayloads, ...newlyDecryptedPayloads],
|
||||
@@ -369,7 +369,7 @@ export class SNSyncService
|
||||
const encryptionSplit = SplitPayloadsByEncryptionType(encrypted)
|
||||
const decryptionSplit = CreateDecryptionSplitWithKeyLookup(encryptionSplit)
|
||||
|
||||
const results = await this.protocolService.decryptSplit(decryptionSplit)
|
||||
const results = await this.encryptionService.decryptSplit(decryptionSplit)
|
||||
|
||||
await this.payloadManager.emitPayloads([...nonencrypted, ...results], PayloadEmitSource.LocalDatabaseLoaded)
|
||||
|
||||
@@ -510,7 +510,7 @@ export class SNSyncService
|
||||
|
||||
const keyLookupSplit = CreateEncryptionSplitWithKeyLookup(encryptionSplit)
|
||||
|
||||
const encryptedResults = await this.protocolService.encryptSplit(keyLookupSplit)
|
||||
const encryptedResults = await this.encryptionService.encryptSplit(keyLookupSplit)
|
||||
|
||||
const contextPayloads = [
|
||||
...encryptedResults.map(CreateEncryptedServerSyncPushPayload),
|
||||
@@ -1138,7 +1138,7 @@ export class SNSyncService
|
||||
},
|
||||
}
|
||||
|
||||
const results = await this.protocolService.decryptSplit<ItemsKeyContent>(rootKeySplit)
|
||||
const results = await this.encryptionService.decryptSplit<ItemsKeyContent>(rootKeySplit)
|
||||
|
||||
results.forEach((result) => {
|
||||
if (isDecryptedPayload<ItemsKeyContent>(result) && result.content_type === ContentType.ItemsKey) {
|
||||
@@ -1168,7 +1168,7 @@ export class SNSyncService
|
||||
},
|
||||
}
|
||||
|
||||
const results = await this.protocolService.decryptSplit<KeySystemItemsKeyContent>(keySystemRootKeySplit)
|
||||
const results = await this.encryptionService.decryptSplit<KeySystemItemsKeyContent>(keySystemRootKeySplit)
|
||||
|
||||
results.forEach((result) => {
|
||||
if (
|
||||
@@ -1213,7 +1213,7 @@ export class SNSyncService
|
||||
}
|
||||
}
|
||||
|
||||
return this.protocolService.decryptSplitSingle(keyedSplit)
|
||||
return this.encryptionService.decryptSplitSingle(keyedSplit)
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -1399,7 +1399,7 @@ export class SNSyncService
|
||||
|
||||
const keyedSplit = CreateDecryptionSplitWithKeyLookup(encryptionSplit)
|
||||
|
||||
const decryptionResults = await this.protocolService.decryptSplit(keyedSplit)
|
||||
const decryptionResults = await this.encryptionService.decryptSplit(keyedSplit)
|
||||
|
||||
this.setInSync(false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user