refactor: root key manager (#2344)

This commit is contained in:
Mo
2023-07-04 07:31:50 -05:00
committed by GitHub
parent b4a90025c4
commit b06999d25b
56 changed files with 1400 additions and 1231 deletions

View File

@@ -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)
}

View File

@@ -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()

View File

@@ -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] },
})

View File

@@ -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' })

View File

@@ -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,

View File

@@ -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,

View File

@@ -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

View File

@@ -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()
}
}
}

View File

@@ -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] },
})

View File

@@ -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 {

View File

@@ -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,
)

View File

@@ -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,

View File

@@ -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>
})

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -31,7 +31,7 @@ describe('001 protocol operations', () => {
})
it('cost minimum', () => {
expect(application.protocolService.costMinimumForVersion('001')).to.equal(3000)
expect(application.encryptionService.costMinimumForVersion('001')).to.equal(3000)
})
it('generates valid keys for registration', async () => {
@@ -46,7 +46,7 @@ describe('001 protocol operations', () => {
it('generates valid keys from existing params and decrypts', async () => {
const password = 'password'
const keyParams = await application.protocolService.createKeyParams({
const keyParams = await application.encryptionService.createKeyParams({
pw_func: 'pbkdf2',
pw_alg: 'sha512',
pw_key_size: 512,
@@ -67,7 +67,7 @@ describe('001 protocol operations', () => {
'sVuHmG0XAp1PRDE8r8XqFXijjP8Pqdwal9YFRrXK4hKLt1yyq8MwQU+1Z95Tz/b7ajYdidwFE0iDwd8Iu8281VtJsQ4yhh2tJiAzBy6newyHfhA5nH93yZ3iXRJaG87bgNQE9lsXzTV/OHAvqMuQtw/QVSWI3Qy1Pyu1Tn72q7FPKKhRRkzEEZ+Ax0BA1fHg',
uuid: '54001a6f-7c22-4b34-8316-fadf9b1fc255',
})
const decrypted = await application.protocolService.decryptSplitSingle({
const decrypted = await application.encryptionService.decryptSplitSingle({
usesRootKey: {
items: [payload],
key: key,

View File

@@ -30,7 +30,7 @@ describe('002 protocol operations', () => {
})
it('cost minimum', () => {
expect(application.protocolService.costMinimumForVersion('002')).to.equal(3000)
expect(application.encryptionService.costMinimumForVersion('002')).to.equal(3000)
})
it('generates valid keys for registration', async () => {
@@ -46,7 +46,7 @@ describe('002 protocol operations', () => {
it('generates valid keys from existing params and decrypts', async () => {
const password = 'password'
const keyParams = await application.protocolService.createKeyParams({
const keyParams = await application.encryptionService.createKeyParams({
pw_salt: '8d381ef44cdeab1489194f87066b747b46053a833ee24956e846e7b40440f5f4',
pw_cost: 101000,
version: '002',
@@ -64,7 +64,7 @@ describe('002 protocol operations', () => {
'002:24a8e8f7728bbe06605d8209d87ad338d3d15ef81154bb64d3967c77daa01333:959b042a-3892-461e-8c50-477c10c7c40a:f1d294388742dca34f6f266a01483a4e:VdlEDyjhZ35GbJDg8ruSZv3Tp6WtMME3T5LLvcBYLHIMhrMi0RlPK83lK6F0aEaZvY82pZ0ntU+XpAX7JMSEdKdPXsACML7WeFrqKb3z2qHnA7NxgnIC0yVT/Z2mRrvlY3NNrUPGwJbfRcvfS7FVyw87MemT9CSubMZRviXvXETx82t7rsgjV/AIwOOeWhFi',
uuid: '959b042a-3892-461e-8c50-477c10c7c40a',
})
const decrypted = await application.protocolService.decryptSplitSingle({
const decrypted = await application.encryptionService.decryptSplitSingle({
usesRootKey: {
items: [payload],
key: key,

View File

@@ -39,7 +39,7 @@ describe('003 protocol operations', () => {
it('cost minimum should throw', () => {
expect(() => {
sharedApplication.protocolService.costMinimumForVersion('003')
sharedApplication.encryptionService.costMinimumForVersion('003')
}).to.throw('Cost minimums only apply to versions <= 002')
})
@@ -59,7 +59,7 @@ describe('003 protocol operations', () => {
it('computes proper keys for sign in', async () => {
const identifier = 'foo@bar.com'
const password = 'very_secure'
const keyParams = sharedApplication.protocolService.createKeyParams({
const keyParams = sharedApplication.encryptionService.createKeyParams({
pw_nonce: 'baaec0131d677cf993381367eb082fe377cefe70118c1699cb9b38f0bc850e7b',
identifier: identifier,
version: '003',
@@ -73,7 +73,7 @@ describe('003 protocol operations', () => {
it('can decrypt item generated with web version 3.3.6', async () => {
const identifier = 'demo@standardnotes.org'
const password = 'password'
const keyParams = sharedApplication.protocolService.createKeyParams({
const keyParams = sharedApplication.encryptionService.createKeyParams({
pw_nonce: '31107837b44d86179140b7c602a55d694243e2e9ced0c4c914ac21ad90215055',
identifier: identifier,
version: '003',

View File

@@ -25,12 +25,12 @@ describe('004 protocol operations', function () {
it('cost minimum should throw', function () {
expect(function () {
application.protocolService.costMinimumForVersion('004')
application.encryptionService.costMinimumForVersion('004')
}).to.throw('Cost minimums only apply to versions <= 002')
})
it('generates valid keys for registration', async function () {
const key = await application.protocolService.createRootKey(
const key = await application.encryptionService.createRootKey(
_identifier,
_password,
KeyParamsOrigination.Registration,
@@ -51,7 +51,7 @@ describe('004 protocol operations', function () {
it('computes proper keys for sign in', async function () {
const identifier = 'foo@bar.com'
const password = 'very_secure'
const keyParams = application.protocolService.createKeyParams({
const keyParams = application.encryptionService.createKeyParams({
pw_nonce: 'baaec0131d677cf993381367eb082fe377cefe70118c1699cb9b38f0bc850e7b',
identifier: identifier,
version: '004',
@@ -64,7 +64,7 @@ describe('004 protocol operations', function () {
it('generates random key', async function () {
const length = 96
const key = await application.protocolService.crypto.generateRandomKey(length)
const key = await application.encryptionService.crypto.generateRandomKey(length)
expect(key.length).to.equal(length / 4)
})
@@ -78,7 +78,7 @@ describe('004 protocol operations', function () {
}),
})
const operator = application.protocolService.operatorManager.operatorForVersion(ProtocolVersion.V004)
const operator = application.encryptionService.operators.operatorForVersion(ProtocolVersion.V004)
const encrypted = await operator.generateEncryptedParameters(payload, rootKey)
const decrypted = await operator.generateDecryptedParameters(encrypted, rootKey)
@@ -97,7 +97,7 @@ describe('004 protocol operations', function () {
}),
})
const operator = application.protocolService.operatorManager.operatorForVersion(ProtocolVersion.V004)
const operator = application.encryptionService.operators.operatorForVersion(ProtocolVersion.V004)
const encrypted = await operator.generateEncryptedParameters(payload, rootKey)
const decrypted = await operator.generateDecryptedParameters(
@@ -112,7 +112,7 @@ describe('004 protocol operations', function () {
})
it('generates existing keys for key params', async function () {
const key = await application.protocolService.computeRootKey(_password, rootKeyParams)
const key = await application.encryptionService.computeRootKey(_password, rootKeyParams)
expect(key.compare(rootKey)).to.be.true
})

View File

@@ -25,7 +25,7 @@ describe('actions service', () => {
password: this.password,
})
const rootKey = await this.application.protocolService.createRootKey(
const rootKey = await this.application.encryptionService.createRootKey(
this.email,
this.password,
KeyParamsOrigination.Registration,
@@ -117,7 +117,7 @@ describe('actions service', () => {
})
const encryptedPayload = CreateEncryptedServerSyncPushPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -359,14 +359,14 @@ describe('actions service', () => {
const response = await this.actionsManager.runAction(this.encryptedPostAction, this.noteItem)
expect(response.items[0].enc_item_key).to.satisfy((string) => {
return string.startsWith(this.application.protocolService.getLatestVersion())
return string.startsWith(this.application.encryptionService.getLatestVersion())
})
expect(response.items[0].uuid).to.eq(this.noteItem.uuid)
expect(response.items[0].auth_hash).to.not.be.ok
expect(response.items[0].content_type).to.be.ok
expect(response.items[0].created_at).to.be.ok
expect(response.items[0].content).to.satisfy((string) => {
return string.startsWith(this.application.protocolService.getLatestVersion())
return string.startsWith(this.application.encryptionService.getLatestVersion())
})
})

View File

@@ -31,7 +31,7 @@ describe('basic auth', function () {
it('successfully register new account', async function () {
const response = await this.application.register(this.email, this.password)
expect(response).to.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
})
it('fails register new account with short password', async function () {
@@ -49,18 +49,18 @@ describe('basic auth', function () {
'For your security, please choose a longer password or, ideally, a passphrase, and try again.',
)
expect(await this.application.protocolService.getRootKey()).to.not.be.ok
expect(await this.application.encryptionService.getRootKey()).to.not.be.ok
})
it('successfully signs out of account', async function () {
await this.application.register(this.email, this.password)
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
expect(await this.application.protocolService.getRootKey()).to.not.be.ok
expect(this.application.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.RootKeyNone)
expect(await this.application.encryptionService.getRootKey()).to.not.be.ok
expect(this.application.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.RootKeyNone)
})
it('successfully signs in to registered account', async function () {
@@ -69,7 +69,7 @@ describe('basic auth', function () {
const response = await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
expect(response).to.be.ok
expect(response.data.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
}).timeout(20000)
it('cannot sign while already signed in', async function () {
@@ -79,7 +79,7 @@ describe('basic auth', function () {
const response = await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
expect(response).to.be.ok
expect(response.data.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
let error
try {
@@ -99,7 +99,7 @@ describe('basic auth', function () {
error = e
}
expect(error).to.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
}).timeout(20000)
it('cannot perform two sign-ins at the same time', async function () {
@@ -111,7 +111,7 @@ describe('basic auth', function () {
const response = await this.application.signIn(this.email, this.password, undefined, undefined, undefined, true)
expect(response).to.be.ok
expect(response.data.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
})(),
(async () => {
/** Make sure the first function runs first */
@@ -134,7 +134,7 @@ describe('basic auth', function () {
const response = await this.application.register(this.email, this.password)
expect(response).to.be.ok
expect(response.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
})(),
(async () => {
/** Make sure the first function runs first */
@@ -204,7 +204,7 @@ describe('basic auth', function () {
const response = await this.application.signIn(uppercase, this.password, undefined, undefined, undefined, true)
expect(response).to.be.ok
expect(response.data.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
}).timeout(20000)
it('can sign into account regardless of whitespace', async function () {
@@ -220,7 +220,7 @@ describe('basic auth', function () {
const response = await this.application.signIn(withspace, this.password, undefined, undefined, undefined, true)
expect(response).to.be.ok
expect(response.data.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
}).timeout(20000)
it('fails login with wrong password', async function () {
@@ -229,7 +229,7 @@ describe('basic auth', function () {
const response = await this.application.signIn(this.email, 'wrongpassword', undefined, undefined, undefined, true)
expect(response).to.be.ok
expect(response.data.error).to.be.ok
expect(await this.application.protocolService.getRootKey()).to.not.be.ok
expect(await this.application.encryptionService.getRootKey()).to.not.be.ok
}).timeout(20000)
it('fails to change to short password', async function () {
@@ -339,7 +339,7 @@ describe('basic auth', function () {
expect(signinResponse).to.be.ok
expect(signinResponse.data.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
expect(this.application.itemManager.items.length).to.equal(this.expectedItemCount)
expect(this.application.payloadManager.invalidPayloads.length).to.equal(0)
@@ -421,7 +421,7 @@ describe('basic auth', function () {
expect(signinResponse).to.be.ok
expect(signinResponse.data.error).to.not.be.ok
expect(await this.application.protocolService.getRootKey()).to.be.ok
expect(await this.application.encryptionService.getRootKey()).to.be.ok
}
}).timeout(80000)

View File

@@ -27,10 +27,10 @@ describe('backups', function () {
it('backup file should have a version number', async function () {
let data = await this.application.createDecryptedBackupFile()
expect(data.version).to.equal(this.application.protocolService.getLatestVersion())
expect(data.version).to.equal(this.application.encryptionService.getLatestVersion())
await this.application.addPasscode('passcode')
data = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups()
expect(data.version).to.equal(this.application.protocolService.getLatestVersion())
expect(data.version).to.equal(this.application.encryptionService.getLatestVersion())
})
it('no passcode + no account backup file should have correct number of items', async function () {
@@ -143,7 +143,7 @@ describe('backups', function () {
const note = await Factory.createSyncedNote(this.application)
const encrypted = await this.application.protocolService.encryptSplitSingle({
const encrypted = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [note.payload],
},

View File

@@ -22,7 +22,7 @@ describe('device authentication', function () {
await application.addPasscode(passcode)
expect(await application.hasPasscode()).to.equal(true)
expect(await application.protectionService.createLaunchChallenge()).to.be.ok
expect(application.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.WrapperOnly)
expect(application.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.WrapperOnly)
await Factory.safeDeinit(application)
/** Recreate application and initialize */
@@ -49,10 +49,10 @@ describe('device authentication', function () {
tmpApplication.submitValuesForChallenge(challenge, initialValues)
}
await tmpApplication.prepareForLaunch({ receiveChallenge })
expect(await tmpApplication.protocolService.getRootKey()).to.not.be.ok
expect(await tmpApplication.encryptionService.getRootKey()).to.not.be.ok
await tmpApplication.launch(true)
expect(await tmpApplication.protocolService.getRootKey()).to.be.ok
expect(tmpApplication.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.WrapperOnly)
expect(await tmpApplication.encryptionService.getRootKey()).to.be.ok
expect(tmpApplication.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.WrapperOnly)
await Factory.safeDeinit(tmpApplication)
}).timeout(10000)
@@ -65,7 +65,7 @@ describe('device authentication', function () {
await application.protections.enableBiometrics()
expect(await application.hasPasscode()).to.equal(true)
expect((await application.protectionService.createLaunchChallenge()).prompts.length).to.equal(2)
expect(application.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.WrapperOnly)
expect(application.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.WrapperOnly)
await Factory.safeDeinit(application)
/** Recreate application and initialize */
@@ -98,11 +98,11 @@ describe('device authentication', function () {
}
await tmpApplication.prepareForLaunch({ receiveChallenge })
expect(await tmpApplication.protocolService.getRootKey()).to.not.be.ok
expect(await tmpApplication.encryptionService.getRootKey()).to.not.be.ok
expect((await tmpApplication.protectionService.createLaunchChallenge()).prompts.length).to.equal(2)
await tmpApplication.launch(true)
expect(await tmpApplication.protocolService.getRootKey()).to.be.ok
expect(tmpApplication.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.WrapperOnly)
expect(await tmpApplication.encryptionService.getRootKey()).to.be.ok
expect(tmpApplication.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.WrapperOnly)
await Factory.safeDeinit(tmpApplication)
}).timeout(Factory.TwentySecondTimeout)
@@ -119,11 +119,11 @@ describe('device authentication', function () {
const sampleStorageKey = 'foo'
const sampleStorageValue = 'bar'
await application.diskStorageService.setValue(sampleStorageKey, sampleStorageValue)
expect(application.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.RootKeyOnly)
expect(application.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.RootKeyOnly)
const passcode = 'foobar'
Factory.handlePasswordChallenges(application, password)
await application.addPasscode(passcode)
expect(application.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.RootKeyPlusWrapper)
expect(application.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.RootKeyPlusWrapper)
expect(await application.hasPasscode()).to.equal(true)
await Factory.safeDeinit(application)
@@ -154,11 +154,11 @@ describe('device authentication', function () {
await tmpApplication.prepareForLaunch({
receiveChallenge: receiveChallenge,
})
expect(await tmpApplication.protocolService.getRootKey()).to.not.be.ok
expect(await tmpApplication.encryptionService.getRootKey()).to.not.be.ok
await tmpApplication.launch(true)
expect(await tmpApplication.diskStorageService.getValue(sampleStorageKey)).to.equal(sampleStorageValue)
expect(await tmpApplication.protocolService.getRootKey()).to.be.ok
expect(tmpApplication.protocolService.rootKeyEncryption.keyMode).to.equal(KeyMode.RootKeyPlusWrapper)
expect(await tmpApplication.encryptionService.getRootKey()).to.be.ok
expect(tmpApplication.encryptionService.rootKeyManager.getKeyMode()).to.equal(KeyMode.RootKeyPlusWrapper)
await Factory.safeDeinit(tmpApplication)
}).timeout(Factory.TwentySecondTimeout)
})

View File

@@ -37,21 +37,21 @@ describe('key recovery service', function () {
await context.register()
const randomRootKey = await application.protocolService.createRootKey(
const randomRootKey = await application.encryptionService.createRootKey(
unassociatedIdentifier,
unassociatedPassword,
KeyParamsOrigination.Registration,
)
const randomItemsKey = await application.protocolService.operatorManager.defaultOperator().createItemsKey()
const randomItemsKey = await application.encryptionService.operators.defaultOperator().createItemsKey()
const encrypted = await application.protocolService.encryptSplitSingle({
const encrypted = await application.encryptionService.encryptSplitSingle({
usesRootKey: {
items: [randomItemsKey.payload],
key: randomRootKey,
},
})
const errored = await application.protocolService.decryptSplitSingle({
const errored = await application.encryptionService.decryptSplitSingle({
usesRootKeyWithKeyLookup: {
items: [encrypted],
},
@@ -89,13 +89,13 @@ describe('key recovery service', function () {
})
await context.register()
const randomRootKey = await application.protocolService.createRootKey(
const randomRootKey = await application.encryptionService.createRootKey(
unassociatedIdentifier,
unassociatedPassword,
KeyParamsOrigination.Registration,
)
const randomItemsKey = await application.protocolService.operatorManager.defaultOperator().createItemsKey()
const randomItemsKey = await application.encryptionService.operators.defaultOperator().createItemsKey()
await application.payloadManager.emitPayload(
randomItemsKey.payload.copy({ dirty: true, dirtyIndex: getIncrementedDirtyIndex() }),
@@ -106,14 +106,14 @@ describe('key recovery service', function () {
const originalSyncTime = application.payloadManager.findOne(randomItemsKey.uuid).lastSyncEnd.getTime()
const encrypted = await application.protocolService.encryptSplitSingle({
const encrypted = await application.encryptionService.encryptSplitSingle({
usesRootKey: {
items: [randomItemsKey.payload],
key: randomRootKey,
},
})
const errored = await application.protocolService.decryptSplitSingle({
const errored = await application.encryptionService.decryptSplitSingle({
usesRootKeyWithKeyLookup: {
items: [encrypted],
},
@@ -214,15 +214,15 @@ describe('key recovery service', function () {
})
/** Create items key associated with a random root key */
const randomRootKey = await application.protocolService.createRootKey(
const randomRootKey = await application.encryptionService.createRootKey(
unassociatedIdentifier,
unassociatedPassword,
KeyParamsOrigination.Registration,
)
const randomItemsKey = await application.protocolService.operatorManager.defaultOperator().createItemsKey()
const randomItemsKey2 = await application.protocolService.operatorManager.defaultOperator().createItemsKey()
const randomItemsKey = await application.encryptionService.operators.defaultOperator().createItemsKey()
const randomItemsKey2 = await application.encryptionService.operators.defaultOperator().createItemsKey()
const encrypted = await application.protocolService.encryptSplit({
const encrypted = await application.encryptionService.encryptSplit({
usesRootKey: {
items: [randomItemsKey.payload, randomItemsKey2.payload],
key: randomRootKey,
@@ -230,7 +230,7 @@ describe('key recovery service', function () {
})
/** Attempt decryption and insert into rotation in errored state */
const decrypted = await application.protocolService.decryptSplit({
const decrypted = await application.encryptionService.decryptSplit({
usesRootKeyWithKeyLookup: {
items: encrypted,
},
@@ -293,8 +293,8 @@ describe('key recovery service', function () {
expect(key.errorDecrypting).to.not.be.ok
}
const aKey = await contextA.application.protocolService.getRootKey()
const bKey = await contextB.application.protocolService.getRootKey()
const aKey = await contextA.application.encryptionService.getRootKey()
const bKey = await contextB.application.encryptionService.getRootKey()
expect(aKey.compare(bKey)).to.equal(true)
expect(contextA.application.items.findItem(note.uuid).errorDecrypting).to.not.be.ok
@@ -379,7 +379,7 @@ describe('key recovery service', function () {
await application.launch(true)
await context.register()
const correctRootKey = await application.protocolService.getRootKey()
const correctRootKey = await application.encryptionService.getRootKey()
/**
* 1. Change our root key locally so that its keys params doesn't match the server's
@@ -390,7 +390,7 @@ describe('key recovery service', function () {
const unassociatedIdentifier = 'foorand'
/** Create items key associated with a random root key */
const randomRootKey = await application.protocolService.createRootKey(
const randomRootKey = await application.encryptionService.createRootKey(
unassociatedIdentifier,
unassociatedPassword,
KeyParamsOrigination.Registration,
@@ -398,11 +398,11 @@ describe('key recovery service', function () {
const signInFunction = sinon.spy(application.keyRecoveryService, 'performServerSignIn')
await application.protocolService.setRootKey(randomRootKey)
await application.encryptionService.setRootKey(randomRootKey)
const correctItemsKey = await application.protocolService.operatorManager.defaultOperator().createItemsKey()
const correctItemsKey = await application.encryptionService.operators.defaultOperator().createItemsKey()
const encrypted = await application.protocolService.encryptSplitSingle({
const encrypted = await application.encryptionService.encryptSplitSingle({
usesRootKey: {
items: [correctItemsKey.payload],
key: randomRootKey,
@@ -428,7 +428,7 @@ describe('key recovery service', function () {
expect(signInFunction.callCount).to.equal(1)
const clientRootKey = await application.protocolService.getRootKey()
const clientRootKey = await application.encryptionService.getRootKey()
expect(clientRootKey.compare(correctRootKey)).to.equal(true)
const decryptedKey = application.items.findItem(correctItemsKey.uuid)
@@ -448,8 +448,8 @@ describe('key recovery service', function () {
await context.register()
/** Create and emit errored encrypted items key payload */
const itemsKey = await application.protocolService.getSureDefaultItemsKey()
const encrypted = await application.protocolService.encryptSplitSingle({
const itemsKey = await application.encryptionService.getSureDefaultItemsKey()
const encrypted = await application.encryptionService.encryptSplitSingle({
usesRootKeyWithKeyLookup: {
items: [itemsKey.payload],
},
@@ -485,8 +485,8 @@ describe('key recovery service', function () {
await context.launch()
await context.register()
const itemsKey = await application.protocolService.getSureDefaultItemsKey()
const encrypted = await application.protocolService.encryptSplitSingle({
const itemsKey = await application.encryptionService.getSureDefaultItemsKey()
const encrypted = await application.encryptionService.encryptSplitSingle({
usesRootKeyWithKeyLookup: {
items: [itemsKey.payload],
},
@@ -524,8 +524,8 @@ describe('key recovery service', function () {
await context.register()
/** Create and emit errored encrypted items key payload */
const itemsKey = await application.protocolService.getSureDefaultItemsKey()
const encrypted = await application.protocolService.encryptSplitSingle({
const itemsKey = await application.encryptionService.getSureDefaultItemsKey()
const encrypted = await application.encryptionService.encryptSplitSingle({
usesRootKeyWithKeyLookup: {
items: [itemsKey.payload],
},
@@ -589,17 +589,17 @@ describe('key recovery service', function () {
})
/** Create items key associated with a random root key */
const randomRootKey = await application.protocolService.createRootKey(
const randomRootKey = await application.encryptionService.createRootKey(
unassociatedIdentifier,
unassociatedPassword,
KeyParamsOrigination.Registration,
ProtocolVersion.V003,
)
const randomItemsKey = await application.protocolService.operatorManager
const randomItemsKey = await application.encryptionService.operators
.operatorForVersion(ProtocolVersion.V003)
.createItemsKey()
const encrypted = await application.protocolService.encryptSplitSingle({
const encrypted = await application.encryptionService.encryptSplitSingle({
usesRootKey: {
items: [randomItemsKey.payload],
key: randomRootKey,
@@ -607,7 +607,7 @@ describe('key recovery service', function () {
})
/** Attempt decryption and insert into rotation in errored state */
const decrypted = await application.protocolService.decryptSplitSingle({
const decrypted = await application.encryptionService.decryptSplitSingle({
usesRootKeyWithKeyLookup: {
items: [encrypted],
},
@@ -653,9 +653,9 @@ describe('key recovery service', function () {
contextA.password = newPassword
await appB.sync.sync()
const newDefaultKey = appB.protocolService.getSureDefaultItemsKey()
const newDefaultKey = appB.encryptionService.getSureDefaultItemsKey()
const encrypted = await appB.protocolService.encryptSplitSingle({
const encrypted = await appB.encryptionService.encryptSplitSingle({
usesRootKeyWithKeyLookup: {
items: [newDefaultKey.payload],
},
@@ -676,13 +676,13 @@ describe('key recovery service', function () {
const stored = (await appA.deviceInterface.getAllDatabaseEntries(appA.identifier)).find(
(payload) => payload.uuid === newDefaultKey.uuid,
)
const storedParams = await appA.protocolService.getKeyEmbeddedKeyParamsFromItemsKey(new EncryptedPayload(stored))
const storedParams = await appA.encryptionService.getKeyEmbeddedKeyParamsFromItemsKey(new EncryptedPayload(stored))
const correctStored = (await appB.deviceInterface.getAllDatabaseEntries(appB.identifier)).find(
(payload) => payload.uuid === newDefaultKey.uuid,
)
const correctParams = await appB.protocolService.getKeyEmbeddedKeyParamsFromItemsKey(
const correctParams = await appB.encryptionService.getKeyEmbeddedKeyParamsFromItemsKey(
new EncryptedPayload(correctStored),
)

View File

@@ -29,7 +29,7 @@ describe('keys', function () {
})
it('should not have root key by default', async function () {
expect(await this.application.protocolService.getRootKey()).to.not.be.ok
expect(await this.application.encryptionService.getRootKey()).to.not.be.ok
})
it('validates content types requiring root encryption', function () {
@@ -43,7 +43,7 @@ describe('keys', function () {
/** Items key available by default */
const payload = Factory.createNotePayload()
const processedPayload = CreateEncryptedLocalStorageContextPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -54,44 +54,44 @@ describe('keys', function () {
it('has root key and one items key after registering user', async function () {
await Factory.registerUserToApplication({ application: this.application })
expect(this.application.protocolService.getRootKey()).to.be.ok
expect(this.application.encryptionService.getRootKey()).to.be.ok
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(1)
})
it('changing root key with passcode should re-wrap root key', async function () {
const email = 'foo'
const password = 'bar'
const key = await this.application.protocolService.createRootKey(email, password, KeyParamsOrigination.Registration)
await this.application.protocolService.setRootKey(key)
const key = await this.application.encryptionService.createRootKey(email, password, KeyParamsOrigination.Registration)
await this.application.encryptionService.setRootKey(key)
Factory.handlePasswordChallenges(this.application, password)
await this.application.addPasscode(password)
/** We should be able to decrypt wrapped root key with passcode */
const wrappingKeyParams = await this.application.protocolService.rootKeyEncryption.getRootKeyWrapperKeyParams()
const wrappingKey = await this.application.protocolService.computeRootKey(password, wrappingKeyParams)
await this.application.protocolService.unwrapRootKey(wrappingKey).catch((error) => {
const wrappingKeyParams = await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()
const wrappingKey = await this.application.encryptionService.computeRootKey(password, wrappingKeyParams)
await this.application.encryptionService.unwrapRootKey(wrappingKey).catch((error) => {
expect(error).to.not.be.ok
})
const newPassword = 'bar'
const newKey = await this.application.protocolService.createRootKey(
const newKey = await this.application.encryptionService.createRootKey(
email,
newPassword,
KeyParamsOrigination.Registration,
)
await this.application.protocolService.setRootKey(newKey, wrappingKey)
await this.application.protocolService.unwrapRootKey(wrappingKey).catch((error) => {
await this.application.encryptionService.setRootKey(newKey, wrappingKey)
await this.application.encryptionService.unwrapRootKey(wrappingKey).catch((error) => {
expect(error).to.not.be.ok
})
})
it('items key should be encrypted with root key', async function () {
await Factory.registerUserToApplication({ application: this.application })
const itemsKey = await this.application.protocolService.getSureDefaultItemsKey()
const rootKey = await this.application.protocolService.getRootKey()
const itemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
const rootKey = await this.application.encryptionService.getRootKey()
/** Encrypt items key */
const encryptedPayload = await this.application.protocolService.encryptSplitSingle({
const encryptedPayload = await this.application.encryptionService.encryptSplitSingle({
usesRootKey: {
items: [itemsKey.payloadRepresentation()],
key: rootKey,
@@ -102,7 +102,7 @@ describe('keys', function () {
expect(encryptedPayload.items_key_id).to.not.be.ok
/** Attempt to decrypt with root key. Should succeed. */
const decryptedPayload = await this.application.protocolService.decryptSplitSingle({
const decryptedPayload = await this.application.encryptionService.decryptSplitSingle({
usesRootKey: {
items: [encryptedPayload],
key: rootKey,
@@ -142,35 +142,35 @@ describe('keys', function () {
it('should use items key for encryption of note', async function () {
const notePayload = Factory.createNotePayload()
const keyToUse = await this.application.protocolService.itemsEncryption.keyToUseForItemEncryption(notePayload)
const keyToUse = await this.application.encryptionService.itemsEncryption.keyToUseForItemEncryption(notePayload)
expect(keyToUse.content_type).to.equal(ContentType.ItemsKey)
})
it('encrypting an item should associate an items key to it', async function () {
const note = Factory.createNotePayload()
const encryptedPayload = await this.application.protocolService.encryptSplitSingle({
const encryptedPayload = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [note],
},
})
const itemsKey = this.application.protocolService.itemsKeyForEncryptedPayload(encryptedPayload)
const itemsKey = this.application.encryptionService.itemsKeyForEncryptedPayload(encryptedPayload)
expect(itemsKey).to.be.ok
})
it('decrypt encrypted item with associated key', async function () {
const note = Factory.createNotePayload()
const title = note.content.title
const encryptedPayload = await this.application.protocolService.encryptSplitSingle({
const encryptedPayload = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [note],
},
})
const itemsKey = this.application.protocolService.itemsKeyForEncryptedPayload(encryptedPayload)
const itemsKey = this.application.encryptionService.itemsKeyForEncryptedPayload(encryptedPayload)
expect(itemsKey).to.be.ok
const decryptedPayload = await this.application.protocolService.decryptSplitSingle({
const decryptedPayload = await this.application.encryptionService.decryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [encryptedPayload],
},
@@ -182,17 +182,17 @@ describe('keys', function () {
it('decrypts items waiting for keys', async function () {
const notePayload = Factory.createNotePayload()
const title = notePayload.content.title
const encryptedPayload = await this.application.protocolService.encryptSplitSingle({
const encryptedPayload = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [notePayload],
},
})
const itemsKey = this.application.protocolService.itemsKeyForEncryptedPayload(encryptedPayload)
const itemsKey = this.application.encryptionService.itemsKeyForEncryptedPayload(encryptedPayload)
await this.application.itemManager.removeItemLocally(itemsKey)
const erroredPayload = await this.application.protocolService.decryptSplitSingle({
const erroredPayload = await this.application.encryptionService.decryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [encryptedPayload],
},
@@ -208,7 +208,7 @@ describe('keys', function () {
await this.application.mutator.emitItemsFromPayloads([keyPayload], PayloadEmitSource.LocalChanged)
/**
* Sleeping is required to trigger asyncronous protocolService.decryptItemsWaitingForKeys,
* Sleeping is required to trigger asyncronous encryptionService.decryptItemsWaitingForKeys,
* which occurs after keys are mapped above.
*/
await Factory.sleep(0.2)
@@ -223,7 +223,7 @@ describe('keys', function () {
it('attempting to emit errored items key for which there exists a non errored master copy should ignore it', async function () {
await Factory.registerUserToApplication({ application: this.application })
const itemsKey = await this.application.protocolService.getSureDefaultItemsKey()
const itemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
expect(itemsKey.errorDecrypting).to.not.be.ok
@@ -250,13 +250,13 @@ describe('keys', function () {
it('generating export params with logged in account should produce encrypted payload', async function () {
await Factory.registerUserToApplication({ application: this.application })
const payload = Factory.createNotePayload()
const encryptedPayload = await this.application.protocolService.encryptSplitSingle({
const encryptedPayload = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
})
expect(typeof encryptedPayload.content).to.equal('string')
expect(encryptedPayload.content.substring(0, 3)).to.equal(this.application.protocolService.getLatestVersion())
expect(encryptedPayload.content.substring(0, 3)).to.equal(this.application.encryptionService.getLatestVersion())
})
it('When setting passcode, should encrypt items keys', async function () {
@@ -276,7 +276,7 @@ describe('keys', function () {
const itemsKeyPayload = new EncryptedPayload(itemsKeyRawPayload)
const authenticatedData = this.context.encryption.getEmbeddedPayloadAuthenticatedData(itemsKeyPayload)
const rootKeyParams = await this.application.protocolService.getRootKeyParams()
const rootKeyParams = await this.application.encryptionService.getRootKeyParams()
expect(authenticatedData.kp).to.be.ok
expect(authenticatedData.kp).to.eql(rootKeyParams.getPortableValue())
@@ -286,8 +286,8 @@ describe('keys', function () {
it('correctly validates local passcode', async function () {
const passcode = 'foo'
await this.application.addPasscode('foo')
expect((await this.application.protocolService.validatePasscode('wrong')).valid).to.equal(false)
expect((await this.application.protocolService.validatePasscode(passcode)).valid).to.equal(true)
expect((await this.application.encryptionService.validatePasscode('wrong')).valid).to.equal(false)
expect((await this.application.encryptionService.validatePasscode(passcode)).valid).to.equal(true)
})
it('signing into 003 account should delete latest offline items key and create 003 items key', async function () {
@@ -296,8 +296,8 @@ describe('keys', function () {
* Upon signing into an 003 account, the application should delete any neverSynced items keys,
* and create a new default items key that is the default for a given protocol version.
*/
const defaultItemsKey = await this.application.protocolService.getSureDefaultItemsKey()
const latestVersion = this.application.protocolService.getLatestVersion()
const defaultItemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
const latestVersion = this.application.encryptionService.getLatestVersion()
expect(defaultItemsKey.keyVersion).to.equal(latestVersion)
/** Register with 003 version */
@@ -312,7 +312,7 @@ describe('keys', function () {
expect(itemsKeys.length).to.equal(1)
const newestItemsKey = itemsKeys[0]
expect(newestItemsKey.keyVersion).to.equal(ProtocolVersion.V003)
const rootKey = await this.application.protocolService.getRootKey()
const rootKey = await this.application.encryptionService.getRootKey()
expect(newestItemsKey.itemsKey).to.equal(rootKey.masterKey)
expect(newestItemsKey.dataAuthenticationKey).to.equal(rootKey.dataAuthenticationKey)
})
@@ -347,12 +347,12 @@ describe('keys', function () {
expect(itemsKeys.length).to.equal(1)
const originalItemsKey = itemsKeys[0]
const originalRootKey = await this.application.protocolService.getRootKey()
const originalRootKey = await this.application.encryptionService.getRootKey()
/** Expect that we can decrypt raw payload with current root key */
const rawPayloads = await this.application.diskStorageService.getAllRawPayloads()
const itemsKeyRawPayload = rawPayloads.find((p) => p.uuid === originalItemsKey.uuid)
const itemsKeyPayload = new EncryptedPayload(itemsKeyRawPayload)
const decrypted = await this.application.protocolService.decryptSplitSingle({
const decrypted = await this.application.encryptionService.decryptSplitSingle({
usesRootKey: {
items: [itemsKeyPayload],
key: originalRootKey,
@@ -366,7 +366,7 @@ describe('keys', function () {
Factory.handlePasswordChallenges(this.application, passcode)
await this.application.changePasscode('bar')
const newRootKey = await this.application.protocolService.getRootKey()
const newRootKey = await this.application.encryptionService.getRootKey()
expect(newRootKey).to.not.equal(originalRootKey)
expect(newRootKey.masterKey).to.not.equal(originalRootKey.masterKey)
@@ -379,7 +379,7 @@ describe('keys', function () {
expect(itemsKeyRawPayload2.content).to.not.equal(itemsKeyRawPayload.content)
const itemsKeyPayload2 = new EncryptedPayload(itemsKeyRawPayload2)
const decrypted2 = await this.application.protocolService.decryptSplitSingle({
const decrypted2 = await this.application.encryptionService.decryptSplitSingle({
usesRootKey: {
items: [itemsKeyPayload2],
key: originalRootKey,
@@ -388,7 +388,7 @@ describe('keys', function () {
expect(decrypted2.errorDecrypting).to.equal(true)
/** Should be able to decrypt with new root key */
const decrypted3 = await this.application.protocolService.decryptSplitSingle({
const decrypted3 = await this.application.encryptionService.decryptSplitSingle({
usesRootKey: {
items: [itemsKeyPayload2],
key: newRootKey,
@@ -405,17 +405,17 @@ describe('keys', function () {
})
const itemsKeys = this.application.itemManager.getDisplayableItemsKeys()
expect(itemsKeys.length).to.equal(1)
const defaultItemsKey = await this.application.protocolService.getSureDefaultItemsKey()
const defaultItemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
const result = await this.application.changePassword(this.password, 'foobarfoo')
expect(result.error).to.not.be.ok
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(2)
const newDefaultItemsKey = await this.application.protocolService.getSureDefaultItemsKey()
const newDefaultItemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
expect(newDefaultItemsKey.uuid).to.not.equal(defaultItemsKey.uuid)
const note = await Factory.createSyncedNote(this.application)
const payload = await this.application.protocolService.encryptSplitSingle({
const payload = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [note.payload],
},
@@ -432,18 +432,18 @@ describe('keys', function () {
})
const itemsKeys = application.itemManager.getDisplayableItemsKeys()
expect(itemsKeys.length).to.equal(1)
const defaultItemsKey = application.protocolService.getSureDefaultItemsKey()
const defaultItemsKey = application.encryptionService.getSureDefaultItemsKey()
const newEmail = UuidGenerator.GenerateUuid()
const result = await application.changeEmail(newEmail, password)
expect(result.error).to.not.be.ok
expect(application.itemManager.getDisplayableItemsKeys().length).to.equal(2)
const newDefaultItemsKey = application.protocolService.getSureDefaultItemsKey()
const newDefaultItemsKey = application.encryptionService.getSureDefaultItemsKey()
expect(newDefaultItemsKey.uuid).to.not.equal(defaultItemsKey.uuid)
const note = await Factory.createSyncedNote(application)
const payload = await application.protocolService.encryptSplitSingle({
const payload = await application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [note.payload],
},
@@ -480,7 +480,7 @@ describe('keys', function () {
it('loading the keychain root key should also load its key params', async function () {
await Factory.registerUserToApplication({ application: this.application })
const rootKey = await this.application.protocolService.rootKeyEncryption.getRootKeyFromKeychain()
const rootKey = await this.application.encryptionService.rootKeyManager.getRootKeyFromKeychain()
expect(rootKey.keyParams).to.be.ok
})
@@ -497,7 +497,7 @@ describe('keys', function () {
it('persisted key params should exactly equal in memory rootKey.keyParams', async function () {
await Factory.registerUserToApplication({ application: this.application })
const rootKey = await this.application.protocolService.getRootKey()
const rootKey = await this.application.encryptionService.getRootKey()
const rawKeyParams = await this.application.diskStorageService.getValue(
StorageKey.RootKeyParams,
StorageValueModes.Nonwrapped,
@@ -507,7 +507,7 @@ describe('keys', function () {
it('key params should have expected values', async function () {
await Factory.registerUserToApplication({ application: this.application })
const keyParamsObject = await this.application.protocolService.getRootKeyParams()
const keyParamsObject = await this.application.encryptionService.getRootKeyParams()
const keyParams = keyParamsObject.content
expect(keyParams.identifier).to.be.ok
expect(keyParams.pw_nonce).to.be.ok
@@ -533,7 +533,7 @@ describe('keys', function () {
email,
password,
})
const keyParamsObject = await this.application.protocolService.getRootKeyParams()
const keyParamsObject = await this.application.encryptionService.getRootKeyParams()
const keyParams = keyParamsObject.content
expect(keyParams.created).to.be.ok
@@ -551,7 +551,7 @@ describe('keys', function () {
password: this.password,
version: ProtocolVersion.V003,
})
const keyParamsObject = await this.application.protocolService.getRootKeyParams()
const keyParamsObject = await this.application.encryptionService.getRootKeyParams()
const keyParams = keyParamsObject.content
expect(keyParams.created).to.be.ok
@@ -566,12 +566,12 @@ describe('keys', function () {
password: this.password,
version: ProtocolVersion.V003,
})
expect(await this.application.protocolService.getEncryptionDisplayName()).to.equal('AES-256')
expect(await this.application.encryptionService.getEncryptionDisplayName()).to.equal('AES-256')
this.application = await Factory.signOutApplicationAndReturnNew(this.application)
/** Register with 004 account */
await this.application.register(this.email + 'new', this.password)
expect(await this.application.protocolService.getEncryptionDisplayName()).to.equal('XChaCha20-Poly1305')
expect(await this.application.encryptionService.getEncryptionDisplayName()).to.equal('XChaCha20-Poly1305')
})
it('when launching app with no keychain but data, should present account recovery challenge', async function () {
@@ -599,7 +599,7 @@ describe('keys', function () {
await recreatedApp.prepareForLaunch({ receiveChallenge })
await recreatedApp.launch(true)
expect(recreatedApp.protocolService.getRootKey()).to.be.ok
expect(recreatedApp.encryptionService.getRootKey()).to.be.ok
expect(totalChallenges).to.equal(expectedChallenges)
await Factory.safeDeinit(recreatedApp)
})
@@ -684,11 +684,11 @@ describe('keys', function () {
/** Change password through session manager directly instead of application,
* as not to create any items key (to simulate 003 client behavior) */
const currentRootKey = await oldClient.protocolService.computeRootKey(
const currentRootKey = await oldClient.encryptionService.computeRootKey(
this.password,
await oldClient.protocolService.getRootKeyParams(),
await oldClient.encryptionService.getRootKeyParams(),
)
const operator = oldClient.protocolService.operatorManager.operatorForVersion(ProtocolVersion.V003)
const operator = oldClient.encryptionService.operators.operatorForVersion(ProtocolVersion.V003)
const newRootKey = await operator.createRootKey(this.email, this.password)
Object.defineProperty(oldClient.apiService, 'apiVersion', {
get: function () {
@@ -734,11 +734,11 @@ describe('keys', function () {
/** Change password through session manager directly instead of application,
* as not to create any items key (to simulate 003 client behavior) */
const currentRootKey = await this.application.protocolService.computeRootKey(
const currentRootKey = await this.application.encryptionService.computeRootKey(
this.password,
await this.application.protocolService.getRootKeyParams(),
await this.application.encryptionService.getRootKeyParams(),
)
const operator = this.application.protocolService.operatorManager.operatorForVersion(ProtocolVersion.V003)
const operator = this.application.encryptionService.operators.operatorForVersion(ProtocolVersion.V003)
const newRootKeyTemplate = await operator.createRootKey(this.email, this.password)
const newRootKey = CreateNewRootKey({
...newRootKeyTemplate.content,
@@ -761,7 +761,7 @@ describe('keys', function () {
currentServerPassword: currentRootKey.serverPassword,
newRootKey,
})
await this.application.protocolService.reencryptApplicableItemsAfterUserRootKeyChange()
await this.application.encryptionService.reencryptApplicableItemsAfterUserRootKeyChange()
/** Note: this may result in a deadlock if features_service syncs and results in an error */
await this.application.sync.sync({ awaitAll: true })
@@ -786,7 +786,7 @@ describe('keys', function () {
* will have an updated_at value, which tell our protocol service that this key has been
* synced before, which sort of "lies" to the protocol service because now it thinks it doesnt
* need to create a new items key because one has already been synced with the account.
* The corrective action was to do a final check in protocolService.handleDownloadFirstSyncCompletion
* The corrective action was to do a final check in encryptionService.handleDownloadFirstSyncCompletion
* to ensure there exists an items key corresponding to the user's account version.
*/
const promise = this.context.awaitNextSucessfulSync()
@@ -794,7 +794,7 @@ describe('keys', function () {
await promise
await this.application.itemManager.removeAllItemsFromMemory()
expect(this.application.protocolService.getSureDefaultItemsKey()).to.not.be.ok
expect(this.application.encryptionService.getSureDefaultItemsKey()).to.not.be.ok
const protocol003 = new SNProtocolOperator003(new SNWebCrypto())
const key = await protocol003.createItemsKey()
@@ -810,14 +810,14 @@ describe('keys', function () {
}),
)
const defaultKey = this.application.protocolService.getSureDefaultItemsKey()
const defaultKey = this.application.encryptionService.getSureDefaultItemsKey()
expect(defaultKey.keyVersion).to.equal(ProtocolVersion.V003)
expect(defaultKey.uuid).to.equal(key.uuid)
await Factory.registerUserToApplication({ application: this.application })
const notePayload = Factory.createNotePayload()
expect(await this.application.protocolService.itemsEncryption.keyToUseForItemEncryption(notePayload)).to.be.ok
expect(await this.application.encryptionService.itemsEncryption.keyToUseForItemEncryption(notePayload)).to.be.ok
})
it('having unsynced items keys should resync them upon download first sync completion', async function () {
@@ -856,7 +856,7 @@ describe('keys', function () {
email: this.email,
password: this.password,
})
const defaultKeys = otherClient.protocolService.itemsEncryption.getItemsKeys().filter((key) => {
const defaultKeys = otherClient.encryptionService.itemsEncryption.getItemsKeys().filter((key) => {
return key.isDefault
})
expect(defaultKeys.length).to.equal(1)

View File

@@ -70,7 +70,7 @@ export class AppContext {
}
get encryption() {
return this.application.protocolService
return this.application.encryptionService
}
get contacts() {

View File

@@ -112,10 +112,10 @@ export function registerUserToApplication({ application, email, password, epheme
}
export async function setOldVersionPasscode({ application, passcode, version }) {
const identifier = await application.protocolService.crypto.generateUUID()
const operator = application.protocolService.operatorManager.operatorForVersion(version)
const identifier = await application.encryptionService.crypto.generateUUID()
const operator = application.encryptionService.operators.operatorForVersion(version)
const key = await operator.createRootKey(identifier, passcode, KeyParamsOrigination.PasscodeCreate)
await application.protocolService.setNewRootKeyWrapper(key)
await application.encryptionService.setNewRootKeyWrapper(key)
await application.userService.rewriteItemsKeys()
await application.syncService.sync(syncOptions)
}
@@ -127,7 +127,7 @@ export async function setOldVersionPasscode({ application, passcode, version })
export async function registerOldUser({ application, email, password, version }) {
if (!email) email = Utils.generateUuid()
if (!password) password = Utils.generateUuid()
const operator = application.protocolService.operatorManager.operatorForVersion(version)
const operator = application.encryptionService.operators.operatorForVersion(version)
const accountKey = await operator.createRootKey(email, password, KeyParamsOrigination.Registration)
const response = await application.userApiService.register({
@@ -145,7 +145,7 @@ export async function registerOldUser({ application, email, password, version })
mode: SyncMode.DownloadFirst,
...syncOptions,
})
await application.protocolService.decryptErroredPayloads()
await application.encryptionService.decryptErroredPayloads()
}
export function createStorageItemPayload(contentType) {

View File

@@ -282,7 +282,7 @@ describe('app models', () => {
const itemsKey = this.application.itemManager.getDisplayableItemsKeys()[0]
/** Encrypt item1 and emit as errored so it persists with items_key_id */
const encrypted = await this.application.protocolService.encryptSplitSingle({
const encrypted = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [item1.payload],
},
@@ -297,7 +297,7 @@ describe('app models', () => {
expect(this.application.payloadManager.findOne(item1.uuid).errorDecrypting).to.equal(true)
expect(this.application.payloadManager.findOne(item1.uuid).items_key_id).to.equal(itemsKey.uuid)
sinon.stub(this.application.protocolService.itemsEncryption, 'decryptErroredItemPayloads').callsFake(() => {
sinon.stub(this.application.encryptionService.itemsEncryption, 'decryptErroredItemPayloads').callsFake(() => {
// prevent auto decryption
})

View File

@@ -40,7 +40,7 @@ describe('payload encryption', function () {
lastSyncBegan: new Date(),
})
const encryptedPayload = await this.application.protocolService.encryptSplitSingle({
const encryptedPayload = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [notePayload],
},
@@ -114,7 +114,7 @@ describe('payload encryption', function () {
it('returns valid encrypted params for syncing', async function () {
const payload = Factory.createNotePayload()
const encryptedPayload = CreateEncryptedServerSyncPushPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -126,7 +126,7 @@ describe('payload encryption', function () {
expect(encryptedPayload.content_type).to.be.ok
expect(encryptedPayload.created_at).to.be.ok
expect(encryptedPayload.content).to.satisfy((string) => {
return string.startsWith(this.application.protocolService.getLatestVersion())
return string.startsWith(this.application.encryptionService.getLatestVersion())
})
}).timeout(5000)
@@ -134,7 +134,7 @@ describe('payload encryption', function () {
const payload = Factory.createNotePayload()
const encryptedPayload = CreateEncryptedLocalStorageContextPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -150,14 +150,14 @@ describe('payload encryption', function () {
expect(encryptedPayload.deleted).to.not.be.ok
expect(encryptedPayload.errorDecrypting).to.not.be.ok
expect(encryptedPayload.content).to.satisfy((string) => {
return string.startsWith(this.application.protocolService.getLatestVersion())
return string.startsWith(this.application.encryptionService.getLatestVersion())
})
})
it('omits deleted for export file', async function () {
const payload = Factory.createNotePayload()
const encryptedPayload = CreateEncryptedBackupFileContextPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -170,7 +170,7 @@ describe('payload encryption', function () {
expect(encryptedPayload.created_at).to.be.ok
expect(encryptedPayload.deleted).to.not.be.ok
expect(encryptedPayload.content).to.satisfy((string) => {
return string.startsWith(this.application.protocolService.getLatestVersion())
return string.startsWith(this.application.encryptionService.getLatestVersion())
})
})

View File

@@ -19,43 +19,43 @@ describe('protocol', function () {
})
it('checks version to make sure its 004', function () {
expect(this.application.protocolService.getLatestVersion()).to.equal('004')
expect(this.application.encryptionService.getLatestVersion()).to.equal('004')
})
it('checks supported versions to make sure it includes 001, 002, 003, 004', function () {
expect(this.application.protocolService.supportedVersions()).to.eql(['001', '002', '003', '004'])
expect(this.application.encryptionService.supportedVersions()).to.eql(['001', '002', '003', '004'])
})
it('platform derivation support', function () {
expect(
this.application.protocolService.platformSupportsKeyDerivation({
this.application.encryptionService.platformSupportsKeyDerivation({
version: '001',
}),
).to.equal(true)
expect(
this.application.protocolService.platformSupportsKeyDerivation({
this.application.encryptionService.platformSupportsKeyDerivation({
version: '002',
}),
).to.equal(true)
expect(
this.application.protocolService.platformSupportsKeyDerivation({
this.application.encryptionService.platformSupportsKeyDerivation({
version: '003',
}),
).to.equal(true)
expect(
this.application.protocolService.platformSupportsKeyDerivation({
this.application.encryptionService.platformSupportsKeyDerivation({
version: '004',
}),
).to.equal(true)
expect(
this.application.protocolService.platformSupportsKeyDerivation({
this.application.encryptionService.platformSupportsKeyDerivation({
version: '005',
}),
).to.equal(true)
})
it('key params versions <= 002 should include pw_cost in portable value', function () {
const keyParams002 = this.application.protocolService.createKeyParams({
const keyParams002 = this.application.encryptionService.createKeyParams({
version: '002',
pw_cost: 5000,
})
@@ -63,15 +63,15 @@ describe('protocol', function () {
})
it('version comparison of 002 should be older than library version', function () {
expect(this.application.protocolService.isVersionNewerThanLibraryVersion('002')).to.equal(false)
expect(this.application.encryptionService.isVersionNewerThanLibraryVersion('002')).to.equal(false)
})
it('version comparison of 005 should be newer than library version', function () {
expect(this.application.protocolService.isVersionNewerThanLibraryVersion('005')).to.equal(true)
expect(this.application.encryptionService.isVersionNewerThanLibraryVersion('005')).to.equal(true)
})
it('library version should not be outdated', function () {
var currentVersion = this.application.protocolService.getLatestVersion()
var currentVersion = this.application.encryptionService.getLatestVersion()
expect(isProtocolVersionExpired(currentVersion)).to.equal(false)
})
@@ -91,7 +91,7 @@ describe('protocol', function () {
const payload = Factory.createNotePayload()
let error
try {
await this.application.protocolService.decryptSplitSingle({
await this.application.encryptionService.decryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -106,7 +106,7 @@ describe('protocol', function () {
await this.application.addPasscode('123')
const payload = Factory.createNotePayload()
const result = CreateEncryptedServerSyncPushPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -121,7 +121,7 @@ describe('protocol', function () {
it('encrypted payload for server should include duplicate_of field', async function () {
const payload = Factory.createNotePayload('Test')
const encryptedPayload = CreateEncryptedServerSyncPushPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -134,7 +134,7 @@ describe('protocol', function () {
it('ejected payload for server should include duplicate_of field', async function () {
const payload = Factory.createNotePayload('Test')
const encryptedPayload = CreateEncryptedServerSyncPushPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -147,7 +147,7 @@ describe('protocol', function () {
it('encrypted payload for storage should include duplicate_of field', async function () {
const payload = Factory.createNotePayload('Test')
const encryptedPayload = CreateEncryptedLocalStorageContextPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -160,7 +160,7 @@ describe('protocol', function () {
it('ejected payload for storage should include duplicate_of field', async function () {
const payload = Factory.createNotePayload('Test')
const encryptedPayload = CreateEncryptedLocalStorageContextPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -173,7 +173,7 @@ describe('protocol', function () {
it('encrypted payload for file should include duplicate_of field', async function () {
const payload = Factory.createNotePayload('Test')
const encryptedPayload = CreateEncryptedBackupFileContextPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},
@@ -186,7 +186,7 @@ describe('protocol', function () {
it('ejected payload for file should include duplicate_of field', async function () {
const payload = Factory.createNotePayload('Test')
const encryptedPayload = CreateEncryptedBackupFileContextPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [payload],
},

View File

@@ -44,7 +44,7 @@ describe('account recovery', function () {
application = await context.signout()
expect(await application.protocolService.getRootKey()).to.not.be.ok
expect(await application.encryptionService.getRootKey()).to.not.be.ok
await application.signInWithRecoveryCodes.execute({
recoveryCodes: generatedRecoveryCodes.getValue(),
@@ -52,7 +52,7 @@ describe('account recovery', function () {
password: context.password,
})
expect(await application.protocolService.getRootKey()).to.be.ok
expect(await application.encryptionService.getRootKey()).to.be.ok
})
it('should automatically generate new recovery code after recovery sign in', async () => {
@@ -96,7 +96,7 @@ describe('account recovery', function () {
application = await context.signout()
expect(await application.protocolService.getRootKey()).to.not.be.ok
expect(await application.encryptionService.getRootKey()).to.not.be.ok
await application.signInWithRecoveryCodes.execute({
recoveryCodes: generatedRecoveryCodes.getValue(),
@@ -104,7 +104,7 @@ describe('account recovery', function () {
password: 'foobar',
})
expect(await application.protocolService.getRootKey()).to.not.be.ok
expect(await application.encryptionService.getRootKey()).to.not.be.ok
})
it('should not allow to sign in with invalid recovery code', async () => {
@@ -112,7 +112,7 @@ describe('account recovery', function () {
application = await context.signout()
expect(await application.protocolService.getRootKey()).to.not.be.ok
expect(await application.encryptionService.getRootKey()).to.not.be.ok
await application.signInWithRecoveryCodes.execute({
recoveryCodes: 'invalid recovery code',
@@ -120,13 +120,13 @@ describe('account recovery', function () {
password: context.paswword,
})
expect(await application.protocolService.getRootKey()).to.not.be.ok
expect(await application.encryptionService.getRootKey()).to.not.be.ok
})
it('should not allow to sign in with recovery code if user has none', async () => {
application = await context.signout()
expect(await application.protocolService.getRootKey()).to.not.be.ok
expect(await application.encryptionService.getRootKey()).to.not.be.ok
await application.signInWithRecoveryCodes.execute({
recoveryCodes: 'foo bar',
@@ -134,6 +134,6 @@ describe('account recovery', function () {
password: context.paswword,
})
expect(await application.protocolService.getRootKey()).to.not.be.ok
expect(await application.encryptionService.getRootKey()).to.not.be.ok
})
})

View File

@@ -574,7 +574,7 @@ describe('server session', function () {
password: password,
})
const oldRootKey = await appA.protocolService.getRootKey()
const oldRootKey = await appA.encryptionService.getRootKey()
/** Set the session as nonsense */
appA.diskStorageService.setValue(StorageKey.Session, {
@@ -597,7 +597,7 @@ describe('server session', function () {
expect(appA.apiService.session.refreshToken.value).to.not.equal('bar')
/** Expect that the session recovery replaces the global root key */
const newRootKey = await appA.protocolService.getRootKey()
const newRootKey = await appA.encryptionService.getRootKey()
expect(oldRootKey).to.not.equal(newRootKey)
await Factory.safeDeinit(appA)

View File

@@ -171,7 +171,7 @@ describe('storage manager', function () {
password: this.password,
ephemeral: true,
})
const accountKey = await this.application.protocolService.getRootKey()
const accountKey = await this.application.encryptionService.getRootKey()
expect(await this.application.diskStorageService.canDecryptWithKey(accountKey)).to.equal(true)
})
@@ -201,7 +201,7 @@ describe('storage manager', function () {
})
/** Should not be wrapped root key yet */
expect(await this.application.protocolService.rootKeyEncryption.getWrappedRootKey()).to.not.be.ok
expect(await this.application.encryptionService.rootKeyManager.getWrappedRootKey()).to.not.be.ok
const passcode = '123'
Factory.handlePasswordChallenges(this.application, this.password)
@@ -209,15 +209,15 @@ describe('storage manager', function () {
await this.application.diskStorageService.setValueAndAwaitPersist('bar', 'foo')
/** Root key should now be wrapped */
expect(await this.application.protocolService.rootKeyEncryption.getWrappedRootKey()).to.be.ok
expect(await this.application.encryptionService.rootKeyManager.getWrappedRootKey()).to.be.ok
const accountKey = await this.application.protocolService.getRootKey()
const accountKey = await this.application.encryptionService.getRootKey()
expect(await this.application.diskStorageService.canDecryptWithKey(accountKey)).to.equal(true)
const passcodeKey = await this.application.protocolService.computeWrappingKey(passcode)
const wrappedRootKey = await this.application.protocolService.rootKeyEncryption.getWrappedRootKey()
const passcodeKey = await this.application.encryptionService.computeWrappingKey(passcode)
const wrappedRootKey = await this.application.encryptionService.rootKeyManager.getWrappedRootKey()
/** Expect that we can decrypt wrapped root key with passcode key */
const payload = new EncryptedPayload(wrappedRootKey)
const decrypted = await this.application.protocolService.decryptSplitSingle({
const decrypted = await this.application.encryptionService.decryptSplitSingle({
usesRootKey: {
items: [payload],
key: passcodeKey,

View File

@@ -90,7 +90,7 @@ describe('offline syncing', () => {
const payload = rawPayloads2[0]
expect(typeof payload.content).to.equal('string')
expect(payload.content.startsWith(this.application.protocolService.getLatestVersion())).to.equal(true)
expect(payload.content.startsWith(this.application.encryptionService.getLatestVersion())).to.equal(true)
})
it('signing out while offline should succeed', async function () {

View File

@@ -277,7 +277,7 @@ describe('online syncing', function () {
await this.application.syncService.sync(syncOptions)
const encrypted = CreateEncryptedServerSyncPushPayload(
await this.application.protocolService.encryptSplitSingle({
await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [note.payloadRepresentation()],
},
@@ -295,7 +295,7 @@ describe('online syncing', function () {
expect(typeof mappedItem.content).to.equal('string')
const decryptedPayload = await this.application.protocolService.decryptSplitSingle({
const decryptedPayload = await this.application.encryptionService.decryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [errorred],
},
@@ -515,7 +515,7 @@ describe('online syncing', function () {
const keyedSplit = CreateDecryptionSplitWithKeyLookup(encryptionSplit)
const decryptionResults = await this.application.protocolService.decryptSplit(keyedSplit)
const decryptionResults = await this.application.encryptionService.decryptSplit(keyedSplit)
await this.application.mutator.emitItemsFromPayloads(decryptionResults, PayloadEmitSource.LocalChanged)
@@ -918,7 +918,7 @@ describe('online syncing', function () {
const lastSyncBegan = note.lastSyncBegan
const lastSyncEnd = note.lastSyncEnd
const encrypted = await this.application.protocolService.encryptSplitSingle({
const encrypted = await this.application.encryptionService.encryptSplitSingle({
usesItemsKeyWithKeyLookup: {
items: [note.payload],
},

View File

@@ -92,11 +92,11 @@ describe('upgrading', () => {
version: oldVersion,
})
expect((await this.application.protocolService.rootKeyEncryption.getRootKeyWrapperKeyParams()).version).to.equal(
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
oldVersion,
)
expect((await this.application.protocolService.getRootKeyParams()).version).to.equal(oldVersion)
expect((await this.application.protocolService.getRootKey()).keyVersion).to.equal(oldVersion)
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(oldVersion)
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(oldVersion)
this.application.setLaunchCallback({
receiveChallenge: this.receiveChallenge,
@@ -104,15 +104,15 @@ describe('upgrading', () => {
const result = await this.application.upgradeProtocolVersion()
expect(result).to.deep.equal({ success: true })
const wrappedRootKey = await this.application.protocolService.rootKeyEncryption.getWrappedRootKey()
const wrappedRootKey = await this.application.encryptionService.rootKeyManager.getWrappedRootKey()
const payload = new EncryptedPayload(wrappedRootKey)
expect(payload.version).to.equal(newVersion)
expect((await this.application.protocolService.rootKeyEncryption.getRootKeyWrapperKeyParams()).version).to.equal(
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
newVersion,
)
expect((await this.application.protocolService.getRootKeyParams()).version).to.equal(newVersion)
expect((await this.application.protocolService.getRootKey()).keyVersion).to.equal(newVersion)
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(newVersion)
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(newVersion)
/**
* Immediately logging out ensures we don't rely on subsequent
@@ -172,7 +172,7 @@ describe('upgrading', () => {
it('protocol version should be upgraded on password change', async function () {
/** Delete default items key that is created on launch */
const itemsKey = await this.application.protocolService.getSureDefaultItemsKey()
const itemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
await this.application.mutator.setItemToBeDeleted(itemsKey)
expect(Uuids(this.application.itemManager.getDisplayableItemsKeys()).includes(itemsKey.uuid)).to.equal(false)
@@ -188,8 +188,8 @@ describe('upgrading', () => {
expect(this.application.itemManager.getDisplayableItemsKeys().length).to.equal(1)
expect((await this.application.protocolService.getRootKeyParams()).version).to.equal(ProtocolVersion.V003)
expect((await this.application.protocolService.getRootKey()).keyVersion).to.equal(ProtocolVersion.V003)
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(ProtocolVersion.V003)
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(ProtocolVersion.V003)
/** Ensure note is encrypted with 003 */
const notePayloads = await Factory.getStoragePayloadsOfType(this.application, ContentType.Note)
@@ -199,11 +199,11 @@ describe('upgrading', () => {
const { error } = await this.application.changePassword(this.password, 'foobarfoo')
expect(error).to.not.exist
const latestVersion = this.application.protocolService.getLatestVersion()
expect((await this.application.protocolService.getRootKeyParams()).version).to.equal(latestVersion)
expect((await this.application.protocolService.getRootKey()).keyVersion).to.equal(latestVersion)
const latestVersion = this.application.encryptionService.getLatestVersion()
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(latestVersion)
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(latestVersion)
const defaultItemsKey = await this.application.protocolService.getSureDefaultItemsKey()
const defaultItemsKey = await this.application.encryptionService.getSureDefaultItemsKey()
expect(defaultItemsKey.keyVersion).to.equal(latestVersion)
/** After change, note should now be encrypted with latest protocol version */
@@ -247,19 +247,19 @@ describe('upgrading', () => {
this.application.setLaunchCallback({
receiveChallenge: this.receiveChallenge,
})
expect((await this.application.protocolService.rootKeyEncryption.getRootKeyWrapperKeyParams()).version).to.equal(
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
oldVersion,
)
const errors = await this.application.upgradeProtocolVersion()
expect(errors).to.not.be.empty
/** Ensure we're still on 003 */
expect((await this.application.protocolService.rootKeyEncryption.getRootKeyWrapperKeyParams()).version).to.equal(
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
oldVersion,
)
expect((await this.application.protocolService.getRootKeyParams()).version).to.equal(oldVersion)
expect((await this.application.protocolService.getRootKey()).keyVersion).to.equal(oldVersion)
expect((await this.application.protocolService.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(oldVersion)
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(oldVersion)
expect((await this.application.encryptionService.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
})
it('rolls back the local protocol upgrade if the server responds with an error', async function () {
@@ -268,19 +268,19 @@ describe('upgrading', () => {
this.application.setLaunchCallback({
receiveChallenge: this.receiveChallenge,
})
expect((await this.application.protocolService.rootKeyEncryption.getRootKeyWrapperKeyParams()).version).to.equal(
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
oldVersion,
)
const errors = await this.application.upgradeProtocolVersion()
expect(errors).to.not.be.empty
/** Ensure we're still on 003 */
expect((await this.application.protocolService.rootKeyEncryption.getRootKeyWrapperKeyParams()).version).to.equal(
expect((await this.application.encryptionService.rootKeyManager.getRootKeyWrapperKeyParams()).version).to.equal(
oldVersion,
)
expect((await this.application.protocolService.getRootKeyParams()).version).to.equal(oldVersion)
expect((await this.application.protocolService.getRootKey()).keyVersion).to.equal(oldVersion)
expect((await this.application.protocolService.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
expect((await this.application.encryptionService.getRootKeyParams()).version).to.equal(oldVersion)
expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(oldVersion)
expect((await this.application.encryptionService.getSureDefaultItemsKey()).keyVersion).to.equal(oldVersion)
})
})
})