Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5638 from uhoreg/use_default_ssss_key
Browse files Browse the repository at this point in the history
Use the default SSSS key if the default is set
  • Loading branch information
uhoreg authored Feb 25, 2021
2 parents 0f0e6c3 + 5f74fac commit f1330b7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/SecurityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,27 @@ async function getSecretStorageKey(
{ keys: keyInfos }: { keys: Record<string, ISecretStorageKeyInfo> },
ssssItemName,
): Promise<[string, Uint8Array]> {
const keyInfoEntries = Object.entries(keyInfos);
if (keyInfoEntries.length > 1) {
throw new Error("Multiple storage key requests not implemented");
const cli = MatrixClientPeg.get();
let keyId = await cli.getDefaultSecretStorageKeyId();
let keyInfo;
if (keyId) {
// use the default SSSS key if set
keyInfo = keyInfos[keyId];
if (!keyInfo) {
// if the default key is not available, pretend the default key
// isn't set
keyId = undefined;
}
}
if (!keyId) {
// if no default SSSS key is set, fall back to a heuristic of using the
// only available key, if only one key is set
const keyInfoEntries = Object.entries(keyInfos);
if (keyInfoEntries.length > 1) {
throw new Error("Multiple storage key requests not implemented");
}
[keyId, keyInfo] = keyInfoEntries[0];
}
const [keyId, keyInfo] = keyInfoEntries[0];

// Check the in-memory cache
if (isCachingAllowed() && secretStorageKeys[keyId]) {
Expand Down

0 comments on commit f1330b7

Please sign in to comment.