Add secret storage cache callback to avoid prompts
This supplies a cache callback to the JS SDK so that we can be notified if a new storage key is created e.g. by resetting secret storage. This allows it to be supplied automatically in case it's needed in the same user operation, as it is when resetting both secret storage and cross-signing together.
This commit is contained in:
parent
3a98b4b4e9
commit
f634c3a71e
2 changed files with 20 additions and 15 deletions
|
@ -69,19 +69,19 @@ async function getSecretStorageKey({ keys: keyInfos }, ssssItemName) {
|
||||||
if (keyInfoEntries.length > 1) {
|
if (keyInfoEntries.length > 1) {
|
||||||
throw new Error("Multiple storage key requests not implemented");
|
throw new Error("Multiple storage key requests not implemented");
|
||||||
}
|
}
|
||||||
const [name, info] = keyInfoEntries[0];
|
const [keyId, keyInfo] = keyInfoEntries[0];
|
||||||
|
|
||||||
// Check the in-memory cache
|
// Check the in-memory cache
|
||||||
if (isCachingAllowed() && secretStorageKeys[name]) {
|
if (isCachingAllowed() && secretStorageKeys[keyId]) {
|
||||||
return [name, secretStorageKeys[name]];
|
return [keyId, secretStorageKeys[keyId]];
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputToKey = async ({ passphrase, recoveryKey }) => {
|
const inputToKey = async ({ passphrase, recoveryKey }) => {
|
||||||
if (passphrase) {
|
if (passphrase) {
|
||||||
return deriveKey(
|
return deriveKey(
|
||||||
passphrase,
|
passphrase,
|
||||||
info.passphrase.salt,
|
keyInfo.passphrase.salt,
|
||||||
info.passphrase.iterations,
|
keyInfo.passphrase.iterations,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return decodeRecoveryKey(recoveryKey);
|
return decodeRecoveryKey(recoveryKey);
|
||||||
|
@ -93,10 +93,10 @@ async function getSecretStorageKey({ keys: keyInfos }, ssssItemName) {
|
||||||
AccessSecretStorageDialog,
|
AccessSecretStorageDialog,
|
||||||
/* props= */
|
/* props= */
|
||||||
{
|
{
|
||||||
keyInfo: info,
|
keyInfo,
|
||||||
checkPrivateKey: async (input) => {
|
checkPrivateKey: async (input) => {
|
||||||
const key = await inputToKey(input);
|
const key = await inputToKey(input);
|
||||||
return await MatrixClientPeg.get().checkSecretStorageKey(key, info);
|
return await MatrixClientPeg.get().checkSecretStorageKey(key, keyInfo);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* className= */ null,
|
/* className= */ null,
|
||||||
|
@ -118,11 +118,15 @@ async function getSecretStorageKey({ keys: keyInfos }, ssssItemName) {
|
||||||
const key = await inputToKey(input);
|
const key = await inputToKey(input);
|
||||||
|
|
||||||
// Save to cache to avoid future prompts in the current session
|
// Save to cache to avoid future prompts in the current session
|
||||||
if (isCachingAllowed()) {
|
cacheSecretStorageKey(keyId, key);
|
||||||
secretStorageKeys[name] = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [name, key];
|
return [keyId, key];
|
||||||
|
}
|
||||||
|
|
||||||
|
function cacheSecretStorageKey(keyId, key) {
|
||||||
|
if (isCachingAllowed()) {
|
||||||
|
secretStorageKeys[keyId] = key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onSecretRequested = async function({
|
const onSecretRequested = async function({
|
||||||
|
@ -170,6 +174,7 @@ const onSecretRequested = async function({
|
||||||
|
|
||||||
export const crossSigningCallbacks = {
|
export const crossSigningCallbacks = {
|
||||||
getSecretStorageKey,
|
getSecretStorageKey,
|
||||||
|
cacheSecretStorageKey,
|
||||||
onSecretRequested,
|
onSecretRequested,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -282,15 +282,15 @@ export default class CreateSecretStorageDialog extends React.PureComponent {
|
||||||
try {
|
try {
|
||||||
if (forceReset) {
|
if (forceReset) {
|
||||||
console.log("Forcing cross-signing and secret storage reset");
|
console.log("Forcing cross-signing and secret storage reset");
|
||||||
await cli.bootstrapCrossSigning({
|
|
||||||
authUploadDeviceSigningKeys: this._doBootstrapUIAuth,
|
|
||||||
setupNewCrossSigning: true,
|
|
||||||
});
|
|
||||||
await cli.bootstrapSecretStorage({
|
await cli.bootstrapSecretStorage({
|
||||||
createSecretStorageKey: async () => this._recoveryKey,
|
createSecretStorageKey: async () => this._recoveryKey,
|
||||||
setupNewKeyBackup: true,
|
setupNewKeyBackup: true,
|
||||||
setupNewSecretStorage: true,
|
setupNewSecretStorage: true,
|
||||||
});
|
});
|
||||||
|
await cli.bootstrapCrossSigning({
|
||||||
|
authUploadDeviceSigningKeys: this._doBootstrapUIAuth,
|
||||||
|
setupNewCrossSigning: true,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
await cli.bootstrapCrossSigning({
|
await cli.bootstrapCrossSigning({
|
||||||
authUploadDeviceSigningKeys: this._doBootstrapUIAuth,
|
authUploadDeviceSigningKeys: this._doBootstrapUIAuth,
|
||||||
|
|
Loading…
Reference in a new issue