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

Commit f1330b7

Browse files
authored
Merge pull request #5638 from uhoreg/use_default_ssss_key
Use the default SSSS key if the default is set
2 parents 0f0e6c3 + 5f74fac commit f1330b7

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/SecurityManager.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,27 @@ async function getSecretStorageKey(
9898
{ keys: keyInfos }: { keys: Record<string, ISecretStorageKeyInfo> },
9999
ssssItemName,
100100
): Promise<[string, Uint8Array]> {
101-
const keyInfoEntries = Object.entries(keyInfos);
102-
if (keyInfoEntries.length > 1) {
103-
throw new Error("Multiple storage key requests not implemented");
101+
const cli = MatrixClientPeg.get();
102+
let keyId = await cli.getDefaultSecretStorageKeyId();
103+
let keyInfo;
104+
if (keyId) {
105+
// use the default SSSS key if set
106+
keyInfo = keyInfos[keyId];
107+
if (!keyInfo) {
108+
// if the default key is not available, pretend the default key
109+
// isn't set
110+
keyId = undefined;
111+
}
112+
}
113+
if (!keyId) {
114+
// if no default SSSS key is set, fall back to a heuristic of using the
115+
// only available key, if only one key is set
116+
const keyInfoEntries = Object.entries(keyInfos);
117+
if (keyInfoEntries.length > 1) {
118+
throw new Error("Multiple storage key requests not implemented");
119+
}
120+
[keyId, keyInfo] = keyInfoEntries[0];
104121
}
105-
const [keyId, keyInfo] = keyInfoEntries[0];
106122

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

0 commit comments

Comments
 (0)