1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Publicise method testing for secret storage key existence

This commit is contained in:
J. Ryan Stinnett
2019-12-04 13:51:43 +00:00
parent eeffe208ec
commit c0dbf2df7f
2 changed files with 17 additions and 2 deletions

View File

@@ -1073,6 +1073,16 @@ MatrixClient.prototype.checkEventSenderTrust = async function(event) {
* @return {string} the name of the key * @return {string} the name of the key
*/ */
/**
* Check whether we have a key with a given ID.
* The Secure Secret Storage API is currently UNSTABLE and may change without notice.
*
* @function module:client~MatrixClient#hasSecretStorageKey
* @param {string} [keyId = default key's ID] The ID of the key to check
* for. Defaults to the default key ID if not provided.
* @return {boolean} Whether we have the key.
*/
/** /**
* Store an encrypted secret on the server * Store an encrypted secret on the server
* The Secure Secret Storage API is currently UNSTABLE and may change without notice. * The Secure Secret Storage API is currently UNSTABLE and may change without notice.
@@ -1137,6 +1147,7 @@ MatrixClient.prototype.checkEventSenderTrust = async function(event) {
wrapCryptoFuncs(MatrixClient, [ wrapCryptoFuncs(MatrixClient, [
"bootstrapSecretStorage", "bootstrapSecretStorage",
"addSecretStorageKey", "addSecretStorageKey",
"hasSecretStorageKey",
"storeSecret", "storeSecret",
"getSecret", "getSecret",
"isSecretStored", "isSecretStored",
@@ -1401,7 +1412,7 @@ MatrixClient.prototype.prepareKeyBackupVersion = async function(
logger.log("Preparing key backup version with Secure Secret Storage"); logger.log("Preparing key backup version with Secure Secret Storage");
// Ensure Secure Secret Storage is ready for use // Ensure Secure Secret Storage is ready for use
if (!this._secretStorage.hasKey()) { if (!this.hasSecretStorageKey()) {
throw new Error("Secure Secret Storage has no keys, needs bootstrapping"); throw new Error("Secure Secret Storage has no keys, needs bootstrapping");
} }
} }

View File

@@ -369,7 +369,7 @@ Crypto.prototype.bootstrapSecretStorage = async function({
// Check if Secure Secret Storage has a default key. If we don't have one, create the // Check if Secure Secret Storage has a default key. If we don't have one, create the
// default key (which will also be signed by the cross-signing master key). // default key (which will also be signed by the cross-signing master key).
if (!this._secretStorage.hasKey()) { if (!this.hasSecretStorageKey()) {
logger.log("Secret storage default key not found, creating new key"); logger.log("Secret storage default key not found, creating new key");
const keyOptions = await createSecretStorageKey(); const keyOptions = await createSecretStorageKey();
const newKeyId = await this.addSecretStorageKey( const newKeyId = await this.addSecretStorageKey(
@@ -400,6 +400,10 @@ Crypto.prototype.addSecretStorageKey = function(algorithm, opts, keyID) {
return this._secretStorage.addKey(algorithm, opts, keyID); return this._secretStorage.addKey(algorithm, opts, keyID);
}; };
Crypto.prototype.hasSecretStorageKey = function(keyID) {
return this._secretStorage.hasKey(keyID);
};
Crypto.prototype.storeSecret = function(name, secret, keys) { Crypto.prototype.storeSecret = function(name, secret, keys) {
return this._secretStorage.store(name, secret, keys); return this._secretStorage.store(name, secret, keys);
}; };