Skip to content

Commit

Permalink
make workspaceKeyBox mandator
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Apr 28, 2023
1 parent e3e8ff4 commit ccdb87d
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apps/app/components/page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default function Page({
snapshot: {
keyDerivationTrace: snapshotKeyData.keyDerivationTrace,
},
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
});

return {
Expand Down
12 changes: 6 additions & 6 deletions apps/app/components/sidebarFolder/SidebarFolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default function SidebarFolder(props: Props) {
try {
const parentKeyChainData = deriveKeysFromKeyDerivationTrace({
keyDerivationTrace: props.keyDerivationTrace,
workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox,
activeDevice: {
signingPublicKey: activeDevice.signingPublicKey,
signingPrivateKey: activeDevice.signingPrivateKey!,
Expand Down Expand Up @@ -201,7 +201,7 @@ export default function SidebarFolder(props: Props) {
encryptionPublicKeySignature:
activeDevice.encryptionPublicKeySignature!,
},
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
});
const parentChainItem =
parentFolderKeyChainData.trace[parentFolderKeyChainData.trace.length - 1];
Expand Down Expand Up @@ -270,7 +270,7 @@ export default function SidebarFolder(props: Props) {
}
const folderKeyTrace = deriveKeysFromKeyDerivationTrace({
keyDerivationTrace: props.keyDerivationTrace,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
activeDevice: {
signingPublicKey: activeDevice.signingPublicKey,
signingPrivateKey: activeDevice.signingPrivateKey!,
Expand Down Expand Up @@ -327,7 +327,7 @@ export default function SidebarFolder(props: Props) {
snapshot: {
keyDerivationTrace: snapshot.publicData.keyDerivationTrace,
},
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
});
const result = await runCreateDocumentMutation(
{
Expand Down Expand Up @@ -399,7 +399,7 @@ export default function SidebarFolder(props: Props) {
if (!workspace) {
throw new Error("Workspace not found");
}
if (!workspace.currentWorkspaceKey!.workspaceKeyBox) {
if (!workspace.currentWorkspaceKey?.workspaceKeyBox) {
throw new Error("no workspace key boxes for this workspace");
}
const workspaceKeyData = await deriveWorkspaceKey({
Expand All @@ -418,7 +418,7 @@ export default function SidebarFolder(props: Props) {
encryptionPublicKeySignature:
activeDevice.encryptionPublicKeySignature!,
},
workspaceKeyBox: workspace.currentWorkspaceKey!.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
});
// ignore the last chain item as it's the key for the old folder name
let parentKey = workspaceKey;
Expand Down
2 changes: 1 addition & 1 deletion apps/app/components/sidebarPage/SidebarPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function SidebarPage(props: Props) {
snapshot: {
keyDerivationTrace: snapshot.keyDerivationTrace,
},
workspaceKeyBox: documentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: documentWorkspaceKey.workspaceKeyBox,
});
setDocumentTitle(documentTitle);
documentTitleStore.updateDocumentTitle({
Expand Down
10 changes: 5 additions & 5 deletions apps/app/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ export type WorkspaceKey = {
generation: Scalars['Int'];
id: Scalars['String'];
workspaceId: Scalars['String'];
workspaceKeyBox?: Maybe<WorkspaceKeyBox>;
workspaceKeyBox: WorkspaceKeyBox;
workspaceKeyBoxes?: Maybe<Array<WorkspaceKeyBox>>;
};

Expand Down Expand Up @@ -1387,7 +1387,7 @@ export type AttachDeviceToWorkspacesMutationVariables = Exact<{
}>;


export type AttachDeviceToWorkspacesMutation = { __typename?: 'Mutation', attachDeviceToWorkspaces?: { __typename?: 'AttachDeviceToWorkspacesResult', workspaceKeys: Array<{ __typename?: 'WorkspaceKey', id: string, generation: number, workspaceId: string, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, deviceSigningPublicKey: string, creatorDeviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null }> } | null };
export type AttachDeviceToWorkspacesMutation = { __typename?: 'Mutation', attachDeviceToWorkspaces?: { __typename?: 'AttachDeviceToWorkspacesResult', workspaceKeys: Array<{ __typename?: 'WorkspaceKey', id: string, generation: number, workspaceId: string, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, deviceSigningPublicKey: string, creatorDeviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } }> } | null };

export type AttachDevicesToWorkspacesMutationVariables = Exact<{
input: AttachDevicesToWorkspacesInput;
Expand Down Expand Up @@ -1436,7 +1436,7 @@ export type CreateInitialWorkspaceStructureMutationVariables = Exact<{
}>;


export type CreateInitialWorkspaceStructureMutation = { __typename?: 'Mutation', createInitialWorkspaceStructure?: { __typename?: 'CreateInitialWorkspaceStructureResult', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null } | null } | null, folder?: { __typename?: 'Folder', id: string, nameCiphertext: string, nameNonce: string, parentFolderId?: string | null, rootFolderId?: string | null, workspaceId?: string | null, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null, document?: { __typename?: 'Document', id: string } | null, snapshot?: { __typename?: 'Snapshot', id: string, latestVersion: number, data: string, documentId: string, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null } | null };
export type CreateInitialWorkspaceStructureMutation = { __typename?: 'Mutation', createInitialWorkspaceStructure?: { __typename?: 'CreateInitialWorkspaceStructureResult', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } } | null } | null, folder?: { __typename?: 'Folder', id: string, nameCiphertext: string, nameNonce: string, parentFolderId?: string | null, rootFolderId?: string | null, workspaceId?: string | null, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null, document?: { __typename?: 'Document', id: string } | null, snapshot?: { __typename?: 'Snapshot', id: string, latestVersion: number, data: string, documentId: string, keyDerivationTrace: { __typename?: 'KeyDerivationTrace', workspaceKeyId: string, trace: Array<{ __typename?: 'KeyDerivationTraceEntry', entryId: string, subkeyId: number, parentId?: string | null, context: string }> } } | null } | null };

export type CreateWorkspaceInvitationMutationVariables = Exact<{
input: CreateWorkspaceInvitationInput;
Expand Down Expand Up @@ -1752,7 +1752,7 @@ export type WorkspaceQueryVariables = Exact<{
}>;


export type WorkspaceQuery = { __typename?: 'Query', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, username?: string | null, role: Role, devices?: Array<{ __typename?: 'MinimalDevice', signingPublicKey: string, encryptionPublicKey: string, encryptionPublicKeySignature: string }> | null }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null }> | null } | null };
export type WorkspaceQuery = { __typename?: 'Query', workspace?: { __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, username?: string | null, role: Role, devices?: Array<{ __typename?: 'MinimalDevice', signingPublicKey: string, encryptionPublicKey: string, encryptionPublicKeySignature: string }> | null }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } }> | null } | null };

export type WorkspaceDevicesQueryVariables = Exact<{
workspaceId: Scalars['ID'];
Expand Down Expand Up @@ -1780,7 +1780,7 @@ export type WorkspacesQueryVariables = Exact<{
}>;


export type WorkspacesQuery = { __typename?: 'Query', workspaces?: { __typename?: 'WorkspaceConnection', nodes?: Array<{ __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox?: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } | null }> | null } | null> | null } | null };
export type WorkspacesQuery = { __typename?: 'Query', workspaces?: { __typename?: 'WorkspaceConnection', nodes?: Array<{ __typename?: 'Workspace', id: string, name?: string | null, members?: Array<{ __typename?: 'WorkspaceMember', userId: string, role: Role }> | null, currentWorkspaceKey?: { __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } } | null, workspaceKeys?: Array<{ __typename?: 'WorkspaceKey', id: string, workspaceId: string, generation: number, workspaceKeyBox: { __typename?: 'WorkspaceKeyBox', id: string, workspaceKeyId: string, deviceSigningPublicKey: string, ciphertext: string, nonce: string, creatorDevice: { __typename?: 'CreatorDevice', signingPublicKey: string, encryptionPublicKey: string } } }> | null } | null> | null } | null };


export const AcceptWorkspaceInvitationDocument = gql`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const createNewSnapshotKey = async ({
encryptionPrivateKey: activeDevice.encryptionPrivateKey!,
encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!,
},
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
});

const parentFolderChainItem =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const deriveExistingSnapshotKey = async (
encryptionPrivateKey: activeDevice.encryptionPrivateKey!,
encryptionPublicKeySignature: activeDevice.encryptionPublicKeySignature!,
},
workspaceKeyBox: workspace?.currentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
});
const folderChainItem =
folderKeyChainData.trace[folderKeyChainData.trace.length - 2];
Expand Down
2 changes: 1 addition & 1 deletion apps/app/utils/document/documentPathStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const useDocumentPathStore = create<DocumentPathState>((set, get) => ({
encryptionPublicKeySignature:
activeDevice.encryptionPublicKeySignature!,
},
workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: folderWorkspaceKey.workspaceKeyBox,
});
// since decryptFolderName also derives the folder subkey,
// we can pass the parentKeyTrace's parent key to it
Expand Down
1 change: 0 additions & 1 deletion apps/app/utils/document/updateDocumentName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const updateDocumentName = async ({
const encryptedDocumentTitle = encryptDocumentTitle({
title: name,
activeDevice,
// @ts-expect-error
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
snapshot: snapshotResult.data.snapshot,
});
Expand Down
2 changes: 1 addition & 1 deletion apps/app/utils/folder/folderKeyStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const useFolderKeyStore = create<FolderKeyState>((set, get) => ({
encryptionPublicKeySignature:
activeDevice.encryptionPublicKeySignature!,
},
workspaceKeyBox: workspace!.currentWorkspaceKey.workspaceKeyBox!,
workspaceKeyBox: workspace.currentWorkspaceKey.workspaceKeyBox,
});
folderKey =
derivedFolderKeyData.trace[derivedFolderKeyData.trace.length - 1].key;
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/graphql/types/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const WorkspaceKey = objectType({
t.nonNull.string("id");
t.nonNull.string("workspaceId");
t.nonNull.int("generation");
t.field("workspaceKeyBox", {
t.nonNull.field("workspaceKeyBox", {
type: WorkspaceKeyBox,
});
t.list.nonNull.field("workspaceKeyBoxes", {
Expand Down

0 comments on commit ccdb87d

Please sign in to comment.