This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Add extension mechanism, and extension points to replace deprecated Security customisations. #31
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8bdb23c
Added mechanism to create extension points for method calls. Implemen…
thoraj 9f0a318
Bumped version to 2.4.0
thoraj 547e779
Re-add changes to runtime module
thoraj b3796e9
Whitespace
thoraj 7eeb743
ran lint:js-fix to have prettier to fix whitespace
thoraj 25718bb
Remove 'I' prefix in interface names
thoraj 5a758d6
Added links back to the origin files for copied types. Rename enum na…
thoraj 0fc320f
Whitespace fix from linter
thoraj 57f45b4
Merge branch 'main' of https://github.com/verji/matrix-react-sdk-modu…
thoraj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| /* | ||
thoraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Copyright 2023 Verji Tech AS | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| /* | ||
| * Types copied (and renamed) from matrix-js-sdk | ||
| */ | ||
|
|
||
| /** | ||
| * Copied from https://github.com/matrix-org/matrix-js-sdk/blob/2337d5a7af6265bbcabbd42c1594cd8b1829b00b/src/secret-storage.ts#L39-L50 | ||
| */ | ||
| export interface SecretStorageKeyDescriptionCommon { | ||
| /** A human-readable name for this key. */ | ||
| // XXX: according to the spec, this is optional | ||
thoraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| name: string; | ||
|
|
||
| /** The encryption algorithm used with this key. */ | ||
| algorithm: string; | ||
|
|
||
| /** Information for deriving this key from a passphrase. */ | ||
| // XXX: according to the spec, this is optional | ||
thoraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| passphrase: PassphraseInfo; | ||
| } | ||
|
|
||
| /** | ||
| * Copied from https://github.com/matrix-org/matrix-js-sdk/blob/2337d5a7af6265bbcabbd42c1594cd8b1829b00b/src/secret-storage.ts#L59-L71 | ||
| */ | ||
| export interface SecretStorageKeyDescriptionAesV1 extends SecretStorageKeyDescriptionCommon { | ||
| // XXX: strictly speaking, we should be able to enforce the algorithm here. But | ||
| // this interface ends up being incorrectly used where other algorithms are in use (notably | ||
| // in device-dehydration support), and unpicking that is too much like hard work | ||
| // at the moment. | ||
| // algorithm: "m.secret_storage.v1.aes-hmac-sha2"; | ||
|
|
||
| /** The 16-byte AES initialization vector, encoded as base64. */ | ||
| iv: string; | ||
|
|
||
| /** The MAC of the result of encrypting 32 bytes of 0, encoded as base64. */ | ||
| mac: string; | ||
| } | ||
|
|
||
| /** | ||
| * Copied from https://github.com/matrix-org/matrix-js-sdk/blob/2337d5a7af6265bbcabbd42c1594cd8b1829b00b/src/secret-storage.ts#L78 | ||
| */ | ||
| export type SecretStorageKeyDescription = SecretStorageKeyDescriptionAesV1; | ||
|
|
||
| /** | ||
| * Copied from https://github.com/matrix-org/matrix-js-sdk/blob/2337d5a7af6265bbcabbd42c1594cd8b1829b00b/src/secret-storage.ts#L85-L97 | ||
| */ | ||
| export interface PassphraseInfo { | ||
| /** The algorithm to be used to derive the key. */ | ||
| algorithm: "m.pbkdf2"; | ||
|
|
||
| /** The number of PBKDF2 iterations to use. */ | ||
| iterations: number; | ||
|
|
||
| /** The salt to be used for PBKDF2. */ | ||
| salt: string; | ||
|
|
||
| /** The number of bits to generate. Defaults to 256. */ | ||
| bits?: number; | ||
| } | ||
|
|
||
| /* | ||
| * Copied from https://github.com/matrix-org/matrix-react-sdk/blob/11096b207a1510569f5c54182e328f6148a6475c/src/MatrixClientPeg.ts#L57-L67 | ||
| */ | ||
| export interface ExamineLoginResponseCreds { | ||
| homeserverUrl: string; | ||
| identityServerUrl?: string; | ||
| userId: string; | ||
| deviceId?: string; | ||
| accessToken: string; | ||
| refreshToken?: string; | ||
| guest?: boolean; | ||
| pickleKey?: string; | ||
| freshLogin?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Copied from https://github.com/matrix-org/matrix-react-sdk/blob/11096b207a1510569f5c54182e328f6148a6475c/src/toasts/SetupEncryptionToast.ts#L71-L75 | ||
| */ | ||
| export enum SetupEncryptionKind { | ||
| SetUpEncryption = "set_up_encryption", | ||
| UpgradeEncryption = "upgrade_encryption", | ||
| VerifyThisSessions = "verify_this_session", | ||
| } | ||
|
|
||
| export interface ExtendedMatrixClientCreds extends ExamineLoginResponseCreds { | ||
| secureBackupKey?: string; | ||
| } | ||
|
|
||
| export interface ProvideCryptoSetupStore { | ||
| getInstance: () => SetupEncryptionStoreProjection; | ||
| } | ||
|
|
||
| export interface SetupEncryptionStoreProjection { | ||
| usePassPhrase(): Promise<void>; | ||
| } | ||
|
|
||
| export interface ProvideCryptoSetupExtensions { | ||
| examineLoginResponse(response: any, credentials: ExtendedMatrixClientCreds): void; | ||
| persistCredentials(credentials: ExtendedMatrixClientCreds): void; | ||
| getSecretStorageKey(): Uint8Array | null; | ||
| createSecretStorageKey(): Uint8Array | null; | ||
| catchAccessSecretStorageError(e: Error): void; | ||
| setupEncryptionNeeded: (args: CryptoSetupArgs) => boolean; | ||
| getDehydrationKeyCallback(): | ||
| | ((keyInfo: SecretStorageKeyDescription, checkFunc: (key: Uint8Array) => void) => Promise<Uint8Array>) | ||
| | null; | ||
| SHOW_ENCRYPTION_SETUP_UI: boolean; | ||
| } | ||
|
|
||
| export abstract class CryptoSetupExtensionsBase implements ProvideCryptoSetupExtensions { | ||
| public abstract examineLoginResponse(response: any, credentials: ExtendedMatrixClientCreds): void; | ||
| public abstract persistCredentials(credentials: ExtendedMatrixClientCreds): void; | ||
| public abstract getSecretStorageKey(): Uint8Array | null; | ||
| public abstract createSecretStorageKey(): Uint8Array | null; | ||
| public abstract catchAccessSecretStorageError(e: Error): void; | ||
| public abstract setupEncryptionNeeded(args: CryptoSetupArgs): boolean; | ||
| public abstract getDehydrationKeyCallback(): | ||
| | ((keyInfo: SecretStorageKeyDescription, checkFunc: (key: Uint8Array) => void) => Promise<Uint8Array>) | ||
| | null; | ||
| public abstract SHOW_ENCRYPTION_SETUP_UI: boolean; | ||
| } | ||
|
|
||
| /* Define an interface for setupEncryptionNeeded to help enforce mandatory arguments */ | ||
| export interface CryptoSetupArgs { | ||
| kind: SetupEncryptionKind; | ||
| storeProvider: ProvideCryptoSetupStore; | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * The default/empty crypto-extensions | ||
| * Can (and will) be used if none of the modules has an implementaion of IProvideCryptoSetupExtensions | ||
| * | ||
| * */ | ||
| export class DefaultCryptoSetupExtensions extends CryptoSetupExtensionsBase { | ||
| public SHOW_ENCRYPTION_SETUP_UI = true; | ||
|
|
||
| public examineLoginResponse(response: any, credentials: ExtendedMatrixClientCreds): void { | ||
| console.log("Default empty examineLoginResponse() => void"); | ||
| } | ||
| public persistCredentials(credentials: ExtendedMatrixClientCreds): void { | ||
| console.log("Default empty persistCredentials() => void"); | ||
| } | ||
|
|
||
| public getSecretStorageKey(): Uint8Array | null { | ||
| console.log("Default empty getSecretStorageKey() => null"); | ||
| return null; | ||
| } | ||
|
|
||
| public createSecretStorageKey(): Uint8Array | null { | ||
| console.log("Default empty createSecretStorageKey() => null"); | ||
| return null; | ||
| } | ||
|
|
||
| public catchAccessSecretStorageError(e: Error): void { | ||
| console.log("Default catchAccessSecretStorageError() => void"); | ||
| } | ||
|
|
||
| public setupEncryptionNeeded(args: CryptoSetupArgs): boolean { | ||
| console.log("Default setupEncryptionNeeded() => false"); | ||
| return false; | ||
| } | ||
|
|
||
| public getDehydrationKeyCallback(): | ||
| | ((keyInfo: SecretStorageKeyDescription, checkFunc: (key: Uint8Array) => void) => Promise<Uint8Array>) | ||
| | null { | ||
| console.log("Default empty getDehydrationKeyCallback() => null"); | ||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
thoraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Copyright 2023 Verji Tech AS | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Mostly for test. To ensure we handle more than one module having extensions | ||
| * Can possibly also be useful for PoC development | ||
| */ | ||
| export interface ProvideExperimentalExtensions { | ||
| experimentalMethod(args?: any): any; | ||
| } | ||
|
|
||
| export abstract class ExperimentalExtensionsBase implements ProvideExperimentalExtensions { | ||
| public abstract experimentalMethod(args?: any): any; | ||
| } | ||
|
|
||
| export class DefaultExperimentalExtensions extends ExperimentalExtensionsBase { | ||
| public experimentalMethod(args?: any): any { | ||
| return null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| Copyright 2023 Verji Tech AS | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { ProvideCryptoSetupExtensions } from "../lifecycles/CryptoSetupExtensions"; | ||
| import { ProvideExperimentalExtensions } from "../lifecycles/ExperimentalExtensions"; | ||
|
|
||
| export type AllExtensions = { | ||
| cryptoSetup?: ProvideCryptoSetupExtensions; | ||
| experimental?: ProvideExperimentalExtensions; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.