From 7f6e223c0c2ea0f5f0703e12192848f9a1e88afa Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 23 Mar 2020 18:34:16 +0000 Subject: [PATCH 1/3] Add function for checking cross-signing is ready Aggregate function that checks the various things are in place for cross-signing to work. --- src/client.js | 1 + src/crypto/index.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/client.js b/src/client.js index 776d35bd8..a302ff038 100644 --- a/src/client.js +++ b/src/client.js @@ -1149,6 +1149,7 @@ wrapCryptoFuncs(MatrixClient, [ "checkCrossSigningPrivateKey", "legacyDeviceVerification", "prepareToEncrypt", + "crossSigningReady", ]); /** diff --git a/src/crypto/index.js b/src/crypto/index.js index 27e6982f7..b746e8c4a 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -352,6 +352,37 @@ Crypto.prototype.createRecoveryKeyFromPassphrase = async function(password) { } }; +/** + * Checks whether cross signing: + * - is enabled on this account + * - is trusted by this device + * - has private keys stored in secret storage + * and that the account has a secret storage key + * + * If this function returns false, bootstrapSecretStorage() can be used + * to fix things such that it returns true. That is to say, after + * bootstrapSecretStorage() completes sucessfully, this function should + * return true. + * + * The cross-signing API is currently UNSTABLE and may change without notice. + * + * @return {bool} True if cross-signing is ready to be used on this device + */ +Crypto.prototype.crossSigningReady = async function() { + const publicKeysOnDevice = this._crossSigningInfo.getId(); + const privateKeysInStorage = await this._crossSigningInfo.isStoredInSecretStorage( + this._secretStorage, + ); + const secretStorageKeyInAccount = await this._secretStorage.hasKey(); + + return ( + publicKeysOnDevice && + privateKeysInStorage && + secretStorageKeyInAccount + ); +}; + + /** * Bootstrap Secure Secret Storage if needed by creating a default key and * signing it with the cross-signing master key. If everything is already set From 942ff0c9fd6227df126acfe56f3008c67b800fc1 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 24 Mar 2020 13:00:53 +0000 Subject: [PATCH 2/3] Better name Co-Authored-By: J. Ryan Stinnett --- src/crypto/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/index.js b/src/crypto/index.js index b746e8c4a..47287aa18 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -368,7 +368,7 @@ Crypto.prototype.createRecoveryKeyFromPassphrase = async function(password) { * * @return {bool} True if cross-signing is ready to be used on this device */ -Crypto.prototype.crossSigningReady = async function() { +Crypto.prototype.isCrossSigningReady = async function() { const publicKeysOnDevice = this._crossSigningInfo.getId(); const privateKeysInStorage = await this._crossSigningInfo.isStoredInSecretStorage( this._secretStorage, From 509e4b337d12649cc3de2e275762300e035e3d58 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 24 Mar 2020 13:01:46 +0000 Subject: [PATCH 3/3] Update for new name --- src/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index a302ff038..2abd61cd9 100644 --- a/src/client.js +++ b/src/client.js @@ -1149,7 +1149,7 @@ wrapCryptoFuncs(MatrixClient, [ "checkCrossSigningPrivateKey", "legacyDeviceVerification", "prepareToEncrypt", - "crossSigningReady", + "isCrossSigningReady", ]); /**