-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
ElementR: Add CryptoApi.getCrossSigningStatus
#3452
Merged
florianduros
merged 18 commits into
develop
from
florianduros/element-r/add-cross-signing-status
Jun 9, 2023
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b9e6b2b
Add `crypto.getCrossSigningStatus`
florianduros d149f3a
Merge branch 'develop' into florianduros/element-r/add-cross-signing-…
florianduros 704eac5
Fix imports and boolean casting
florianduros 3b2be80
Moved `isStoredInSecretStorage` into a single function
florianduros 698d8ce
Review changes `CrossSigningStatus`
florianduros e561b04
Review changes for `cross-signing.spec.ts`
florianduros 952f191
Add test in case when cross signing is not setup
florianduros 1994f98
Handle when the `crossSigningStatus` returned by the olmMachine is null
florianduros 9b1e525
Review changes for `crypto-api` documentation
florianduros 295dc45
Update `cross-signing.spec.ts` according to review changes
florianduros f8a0107
Moved and renamed `isStoredInSecretStorage`
florianduros c8cf9c3
Remove noise in `CrossSigning.ts` imports
florianduros 25350c5
Fix `returns` sentence in `secretStorageContainsCrossSigningKeys`
florianduros 2070dac
Fix typos
florianduros adb2423
Add test for `secret-storage.ts`
florianduros f8647d0
Merge branch 'develop' into florianduros/element-r/add-cross-signing-…
florianduros ae8c86a
Improve documentation
florianduros f8317d3
Add doc about fetch mock request name
florianduros 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 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 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,69 @@ | ||
/* | ||
Copyright 2023 The Matrix.org Foundation C.I.C. | ||
|
||
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 { secretStorageContainsCrossSigningKeys } from "../../../src/rust-crypto/secret-storage"; | ||
import { ServerSideSecretStorage } from "../../../src/secret-storage"; | ||
|
||
describe("secret-storage", () => { | ||
describe("secretStorageContainsCrossSigningKeys", () => { | ||
it("should return false when there is no secret storage master key", async () => { | ||
florianduros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const secretStorage = { | ||
isStored: jest.fn().mockReturnValue(false), | ||
} as unknown as ServerSideSecretStorage; | ||
|
||
const result = await secretStorageContainsCrossSigningKeys(secretStorage); | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it("should return false when there is no shared secret storage key between master, user signing and self signing keys", async () => { | ||
const secretStorage = { | ||
isStored: (type: string) => { | ||
// Return different storage keys | ||
if (type === "m.cross_signing.master") return { secretStorageKey: {} }; | ||
else return { secretStorageKey2: {} }; | ||
}, | ||
} as unknown as ServerSideSecretStorage; | ||
|
||
const result = await secretStorageContainsCrossSigningKeys(secretStorage); | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it("should return false when the secret storage master key is only shared by user signing the secret storage", async () => { | ||
florianduros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const secretStorage = { | ||
isStored: (type: string) => { | ||
// Return different storage keys | ||
if (type === "m.cross_signing.master" || type === "m.cross_signing.user_signing") { | ||
return { secretStorageKey: {} }; | ||
} else { | ||
return { secretStorageKey2: {} }; | ||
} | ||
}, | ||
} as unknown as ServerSideSecretStorage; | ||
|
||
const result = await secretStorageContainsCrossSigningKeys(secretStorage); | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it("should return true when there is shared secret storage key between master, user signing and self signing keys", async () => { | ||
const secretStorage = { | ||
isStored: jest.fn().mockReturnValue({ secretStorageKey: {} }), | ||
} as unknown as ServerSideSecretStorage; | ||
|
||
const result = await secretStorageContainsCrossSigningKeys(secretStorage); | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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 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,42 @@ | ||
/* | ||
Copyright 2023 The Matrix.org Foundation C.I.C. | ||
|
||
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 { ServerSideSecretStorage } from "../secret-storage"; | ||
|
||
/** | ||
* Check that the private cross signing keys (master, self signing, user signing) are stored into the secret storage and encrypted with the secret storage key. | ||
florianduros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param secretStorage - The secret store using account data | ||
* @returns True if one of the secret storage master keys is shared with the secret storage user signing and self signing keys. | ||
florianduros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
export async function secretStorageContainsCrossSigningKeys(secretStorage: ServerSideSecretStorage): Promise<boolean> { | ||
// Get the secret storage keys stored into the secret storage | ||
florianduros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const secretStorageMasterKeys = await secretStorage.isStored("m.cross_signing.master"); | ||
|
||
// Not stored keys | ||
florianduros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!secretStorageMasterKeys) return false; | ||
|
||
// Get the user signing keys stored into the secret storage | ||
const secretStorageUserSigningKeys = (await secretStorage.isStored(`m.cross_signing.user_signing`)) || {}; | ||
// Get the self signing keys stored into the secret storage | ||
const secretStorageSelfSigningKeys = (await secretStorage.isStored(`m.cross_signing.self_signing`)) || {}; | ||
|
||
// Check that one of the secret storage master keys is shared with the secret storage user signing and self signing keys | ||
florianduros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return Object.keys(secretStorageMasterKeys).some( | ||
(secretStorageKey) => | ||
secretStorageUserSigningKeys[secretStorageKey] && secretStorageSelfSigningKeys[secretStorageKey], | ||
); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to document these endpoint names, in the doc-comments for
mockCrossSigningRequest
. They form part of the interface of those functions, which the test is relying on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear, by "endpoint names", I mean things like
upload-sigs
.