Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: display shared vault file usage #2399

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/models": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/utils": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@electron/remote": "^2.0.9",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/electron-clear-data": "1.1.1",
"@standardnotes/web": "workspace:*",
"axios": "^1.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/models": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/sncrypto-common": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/Domain/Keys/ItemsKey/ItemsKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import {
ConflictStrategy,
Expand All @@ -8,6 +7,7 @@ import {
HistoryEntryInterface,
ItemsKeyContent,
ItemsKeyInterface,
ProtocolVersion,
} from '@standardnotes/models'

export function isItemsKey(x: unknown): x is ItemsKeyInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import {
ProtocolVersion,
ConflictStrategy,
DecryptedItem,
DecryptedItemInterface,
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/Domain/Keys/RootKey/Functions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProtocolVersion } from '@standardnotes/common'
import {
ProtocolVersion,
DecryptedPayload,
FillItemContentSpecialized,
PayloadTimestampDefaults,
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/Domain/Keys/RootKey/RootKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProtocolVersion } from '@standardnotes/common'
import {
ProtocolVersion,
DecryptedItem,
DecryptedPayloadInterface,
NamespacedRootKeyInKeychain,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ProtocolVersion } from '@standardnotes/common'
import { DecryptedPayload, ItemContent, ItemsKeyContent, PayloadTimestampDefaults } from '@standardnotes/models'
import {
DecryptedPayload,
ItemContent,
ItemsKeyContent,
PayloadTimestampDefaults,
ProtocolVersion,
} from '@standardnotes/models'
import { SNItemsKey } from '../../Keys/ItemsKey/ItemsKey'
import { SNProtocolOperator004 } from './Operator004'
import { getMockedCrypto } from './MockedCrypto'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
KeySystemItemsKeyContentSpecialized,
KeySystemItemsKeyInterface,
PayloadTimestampDefaults,
ProtocolVersion,
} from '@standardnotes/models'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { V004Algorithm } from '../../../../Algorithm'
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'

export class CreateKeySystemItemsKeyUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
KeySystemRootKeyInterface,
KeySystemRootKeyParamsInterface,
KeySystemPasswordType,
ProtocolVersion,
} from '@standardnotes/models'
import { ProtocolVersion } from '@standardnotes/common'
import { DeriveKeySystemRootKeyUseCase } from './DeriveKeySystemRootKey'

export class CreateRandomKeySystemRootKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
KeySystemRootKeyInterface,
KeySystemRootKeyParamsInterface,
KeySystemPasswordType,
ProtocolVersion,
} from '@standardnotes/models'
import { ProtocolVersion } from '@standardnotes/common'
import { DeriveKeySystemRootKeyUseCase } from './DeriveKeySystemRootKey'

export class CreateUserInputKeySystemRootKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
KeySystemRootKeyInterface,
PayloadTimestampDefaults,
KeySystemRootKeyParamsInterface,
ProtocolVersion,
} from '@standardnotes/models'
import { ProtocolVersion } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'

export class DeriveKeySystemRootKeyUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { splitString, truncateHexString } from '@standardnotes/utils'
import { V004PartitionCharacter } from '../../V004AlgorithmTypes'
import { V004Algorithm } from '../../../../Algorithm'
import { RootKeyInterface } from '@standardnotes/models'
import { RootKeyInterface, ProtocolVersion } from '@standardnotes/models'
import { SNRootKeyParams } from '../../../../Keys/RootKey/RootKeyParams'
import { CreateNewRootKey } from '../../../../Keys/RootKey/Functions'
import { ProtocolVersion } from '@standardnotes/common'

export class DeriveRootKeyUseCase {
constructor(private readonly crypto: PureCryptoInterface) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
isKeySystemRootKey,
ContentTypeUsesRootKeyEncryption,
ContentTypeUsesKeySystemRootKeyEncryption,
ProtocolVersion,
} from '@standardnotes/models'
import { ItemAuthenticatedData } from '../../../../Types/ItemAuthenticatedData'
import { RootKeyEncryptedAuthenticatedData } from '../../../../Types/RootKeyEncryptedAuthenticatedData'
import { KeySystemItemsKeyAuthenticatedData } from '../../../../Types/KeySystemItemsKeyAuthenticatedData'
import { ProtocolVersion } from '@standardnotes/common'
import { isItemsKey } from '../../../../Keys/ItemsKey/ItemsKey'
import { isKeySystemItemsKey } from '../../../../Keys/KeySystemItemsKey/KeySystemItemsKey'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ProtocolVersion } from '@standardnotes/common'
import { PkcKeyPair, PureCryptoInterface } from '@standardnotes/sncrypto-common'
import {
DecryptedPayloadInterface,
ItemsKeyInterface,
KeySystemItemsKeyInterface,
KeySystemRootKeyInterface,
RootKeyInterface,
ProtocolVersion,
} from '@standardnotes/models'
import { CreateConsistentBase64JsonPayloadUseCase } from '../Utils/CreateConsistentBase64JsonPayload'
import { doesPayloadRequireSigning } from '../../V004AlgorithmHelpers'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/models'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'

import { ItemAuthenticatedData } from './../../../../Types/ItemAuthenticatedData'
import { GenerateEncryptedProtocolStringUseCase } from './GenerateEncryptedProtocolString'
import { AdditionalData } from '../../../../Types/EncryptionAdditionalData'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Base64String, HexString, PureCryptoInterface, Utf8String } from '@standardnotes/sncrypto-common'
import { V004PartitionCharacter, V004StringComponents } from '../../V004AlgorithmTypes'
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/models'
import { V004Algorithm } from '../../../../Algorithm'

export class GenerateEncryptedProtocolStringUseCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/models'
import { AnyOperatorInterface } from './OperatorInterface/TypeCheck'

export interface EncryptionOperatorsInterface {
Expand Down
2 changes: 1 addition & 1 deletion packages/encryption/src/Domain/Operator/Functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/models'
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
import { SNProtocolOperator001 } from '../Operator/001/Operator001'
import { SNProtocolOperator002 } from '../Operator/002/Operator002'
Expand Down
8 changes: 6 additions & 2 deletions packages/encryption/src/Domain/Types/EncryptedParameters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ProtocolVersion } from '@standardnotes/common'
import { EncryptedPayloadInterface, DecryptedPayloadInterface, PersistentSignatureData } from '@standardnotes/models'
import {
EncryptedPayloadInterface,
DecryptedPayloadInterface,
PersistentSignatureData,
ProtocolVersion,
} from '@standardnotes/models'
import { DecryptedParameters } from './DecryptedParameters'

export type EncryptedOutputParameters = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/models'

type UserUuid = string
type KeySystemIdentifier = string
Expand Down
2 changes: 1 addition & 1 deletion packages/features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"reflect-metadata": "^0.1.13"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@standardnotes/common": "^1.50.0",
"@standardnotes/domain-core": "^1.24.0",
"@standardnotes/domain-core": "^1.25.0",
"@standardnotes/features": "workspace:*",
"@standardnotes/responses": "workspace:*",
"@standardnotes/sncrypto-common": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,38 @@ function CreateFilteredServerItem(item: ServerItemResponse): FilteredServerItem
}
}

export function FilterDisallowedRemotePayloadsAndMap(payloads: ServerItemResponse[]): FilteredServerItem[] {
return payloads.filter(isRemotePayloadAllowed).map(CreateFilteredServerItem)
export function FilterDisallowedRemotePayloadsAndMap(payloads: ServerItemResponse[]): {
filtered: FilteredServerItem[]
disallowed: ServerItemResponse[]
} {
const filtered = []
const disallowed = []
for (const payload of payloads) {
const result = checkRemotePayloadAllowed(payload)
if (result.allowed === undefined) {
disallowed.push(payload)
} else {
filtered.push(CreateFilteredServerItem(result.allowed))
}
}

return {
filtered,
disallowed,
}
}

export function isRemotePayloadAllowed(payload: ServerItemResponse): boolean {
export function checkRemotePayloadAllowed(payload: ServerItemResponse): {
allowed?: ServerItemResponse
disallowed?: ServerItemResponse
} {
if (isCorruptTransferPayload(payload)) {
return false
return { disallowed: payload }
}

return isEncryptedTransferPayload(payload) || payload.content == undefined
if (isEncryptedTransferPayload(payload) || payload.content == undefined) {
return { allowed: payload }
} else {
return { disallowed: payload }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '../../../Local/Protocol/ProtocolVersion'
import { EncryptedPayloadInterface } from '../../Payload/Interfaces/EncryptedPayload'
import { ItemInterface } from './ItemInterface'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ProtocolVersion, protocolVersionFromEncryptedString } from '@standardnotes/common'
import { ProtocolVersion } from '../../../Local/Protocol/ProtocolVersion'
import { ProtocolVersionFromEncryptedString } from '../../../Local/Protocol/ProtocolVersionFromEncryptedString'
import { SyncResolvedParams, SyncResolvedPayload } from '../../../Runtime/Deltas/Utilities/SyncResolvedPayload'
import { EncryptedTransferPayload } from '../../TransferPayload/Interfaces/EncryptedTransferPayload'
import { EncryptedPayloadInterface } from '../Interfaces/EncryptedPayload'
Expand All @@ -18,13 +19,18 @@ export class EncryptedPayload extends PurePayload<EncryptedTransferPayload> impl
constructor(rawPayload: EncryptedTransferPayload, source = PayloadSource.Constructor) {
super(rawPayload, source)

const versionResult = ProtocolVersionFromEncryptedString(rawPayload.content)
if (versionResult.isFailed()) {
throw new Error('EncryptedPayload constructor versionResult is failed')
}

this.auth_hash = rawPayload.auth_hash
this.content = rawPayload.content
this.deleted = false
this.enc_item_key = rawPayload.enc_item_key
this.errorDecrypting = rawPayload.errorDecrypting
this.items_key_id = rawPayload.items_key_id
this.version = protocolVersionFromEncryptedString(this.content)
this.version = versionResult.getValue()
this.waitingForKey = rawPayload.waitingForKey
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '../../../Local/Protocol/ProtocolVersion'
import { EncryptedTransferPayload } from '../../TransferPayload/Interfaces/EncryptedTransferPayload'
import { PayloadInterface } from './PayloadInterface'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('type check', () => {
expect(
isCorruptTransferPayload({
uuid: '123',
content_type: ContentType.TYPES.Unknown,
content_type: 'Unknown',
content: '123',
...PayloadTimestampDefaults(),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export function isDeletedTransferPayload(payload: TransferPayload): payload is D
export function isCorruptTransferPayload(payload: TransferPayload): boolean {
const invalidDeletedState = payload.deleted === true && payload.content != undefined

return payload.uuid == undefined || invalidDeletedState || payload.content_type === ContentType.TYPES.Unknown
const contenTypeOrError = ContentType.create(payload.content_type)

return payload.uuid == undefined || invalidDeletedState || contenTypeOrError.isFailed()
}
1 change: 1 addition & 0 deletions packages/models/src/Domain/Local/ApplicationIdentifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ApplicationIdentifier = string
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProtocolVersion } from '@standardnotes/common'
import { KeySystemIdentifier } from '../../Syncable/KeySystemRootKey/KeySystemIdentifier'
import { ProtocolVersion } from '../Protocol/ProtocolVersion'
import { KeySystemPasswordType } from './KeySystemPasswordType'

/**
Expand Down
47 changes: 47 additions & 0 deletions packages/models/src/Domain/Local/Protocol/ProtocolVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export enum ProtocolVersion {
V001 = '001',
V002 = '002',
V003 = '003',
V004 = '004',
}

export const ProtocolVersionLatest = ProtocolVersion.V004

/** The last protocol version to not use root-key based items keys */
export const ProtocolVersionLastNonrootItemsKey = ProtocolVersion.V003

export const ProtocolExpirationDates: Partial<Record<ProtocolVersion, number>> = Object.freeze({
[ProtocolVersion.V001]: Date.parse('2018-01-01'),
[ProtocolVersion.V002]: Date.parse('2020-01-01'),
})

export function isProtocolVersionExpired(version: ProtocolVersion) {
const expireDate = ProtocolExpirationDates[version]
if (!expireDate) {
return false
}

const expired = new Date().getTime() > expireDate
return expired
}

export const ProtocolVersionLength = 3

/**
* -1 if a < b
* 0 if a == b
* 1 if a > b
*/
export function compareVersions(a: ProtocolVersion, b: ProtocolVersion): number {
const aNum = Number(a)
const bNum = Number(b)
return aNum - bNum
}

export function leftVersionGreaterThanOrEqualToRight(a: ProtocolVersion, b: ProtocolVersion): boolean {
return compareVersions(a, b) >= 0
}

export function isVersionLessThanOrEqualTo(input: ProtocolVersion, compareTo: ProtocolVersion): boolean {
return compareVersions(input, compareTo) <= 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Result } from '@standardnotes/domain-core'
import { ProtocolVersion, ProtocolVersionLength } from './ProtocolVersion'

export function ProtocolVersionFromEncryptedString(string: string): Result<ProtocolVersion> {
try {
const version = string.substring(0, ProtocolVersionLength) as ProtocolVersion
if (Object.values(ProtocolVersion).includes(version)) {
return Result.ok(version)
}
} catch (error) {
return Result.fail(JSON.stringify(error))
}

return Result.fail(`Invalid encrypted string ${string}`)
}
Loading
Loading