Merge pull request #1279 from matrix-org/dbkr/unify_cross_signing_checks

Add function for checking cross-signing is ready
This commit is contained in:
David Baker
2020-03-24 13:34:19 +00:00
committed by GitHub
2 changed files with 32 additions and 0 deletions
+1
View File
@@ -1151,6 +1151,7 @@ wrapCryptoFuncs(MatrixClient, [
"checkCrossSigningPrivateKey",
"legacyDeviceVerification",
"prepareToEncrypt",
"isCrossSigningReady",
]);
/**
+31
View File
@@ -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.isCrossSigningReady = 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