You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-05 17:02:07 +03:00
[CONFLICT CHUNKS] Merge branch 'develop' into travis/sourcemaps-dev
This commit is contained in:
150
src/client.js
150
src/client.js
@@ -22,6 +22,7 @@ limitations under the License.
|
||||
* This is an internal module. See {@link MatrixClient} for the public class.
|
||||
* @module client
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
|
||||
import url from "url";
|
||||
import {EventEmitter} from "events";
|
||||
@@ -47,6 +48,37 @@ import {decodeRecoveryKey} from './crypto/recoverykey';
|
||||
import {keyFromAuthData} from './crypto/key_passphrase';
|
||||
import {randomString} from './randomstring';
|
||||
import {PushProcessor} from "./pushprocessor";
|
||||
=======
|
||||
const EventEmitter = require("events").EventEmitter;
|
||||
const url = require('url');
|
||||
|
||||
const httpApi = require("./http-api");
|
||||
const MatrixEvent = require("./models/event").MatrixEvent;
|
||||
const EventStatus = require("./models/event").EventStatus;
|
||||
const EventTimeline = require("./models/event-timeline");
|
||||
const SearchResult = require("./models/search-result");
|
||||
const StubStore = require("./store/stub");
|
||||
const webRtcCall = require("./webrtc/call");
|
||||
const utils = require("./utils");
|
||||
const contentRepo = require("./content-repo");
|
||||
const Filter = require("./filter");
|
||||
const SyncApi = require("./sync");
|
||||
const MatrixBaseApis = require("./base-apis");
|
||||
const MatrixError = httpApi.MatrixError;
|
||||
const ContentHelpers = require("./content-helpers");
|
||||
const olmlib = require("./crypto/olmlib");
|
||||
|
||||
import ReEmitter from './ReEmitter';
|
||||
import RoomList from './crypto/RoomList';
|
||||
import logger from './logger';
|
||||
|
||||
import Crypto from './crypto';
|
||||
import { isCryptoAvailable } from './crypto';
|
||||
import { decodeRecoveryKey } from './crypto/recoverykey';
|
||||
import { keyFromAuthData } from './crypto/key_passphrase';
|
||||
import { randomString } from './randomstring';
|
||||
import { encodeBase64, decodeBase64 } from '../lib/crypto/olmlib';
|
||||
>>>>>>> develop
|
||||
|
||||
const SCROLLBACK_DELAY_MS = 3000;
|
||||
export const CRYPTO_ENABLED = isCryptoAvailable();
|
||||
@@ -666,7 +698,7 @@ MatrixClient.prototype.initCrypto = async function() {
|
||||
"crypto.warning",
|
||||
"crypto.devicesUpdated",
|
||||
"deviceVerificationChanged",
|
||||
"userVerificationChanged",
|
||||
"userTrustStatusChanged",
|
||||
"crossSigning.keysChanged",
|
||||
]);
|
||||
|
||||
@@ -1431,7 +1463,7 @@ MatrixClient.prototype.disableKeyBackup = function() {
|
||||
* when restoring the backup as an alternative to entering the recovery key.
|
||||
* Optional.
|
||||
* @param {boolean} [opts.secureSecretStorage = false] Whether to use Secure
|
||||
* Secret Storage (MSC1946) to store the key encrypting key backups.
|
||||
* Secret Storage to store the key encrypting key backups.
|
||||
* Optional, defaults to false.
|
||||
*
|
||||
* @returns {Promise<object>} Object that can be passed to createKeyBackupVersion and
|
||||
@@ -1445,32 +1477,37 @@ MatrixClient.prototype.prepareKeyBackupVersion = async function(
|
||||
throw new Error("End-to-end encryption disabled");
|
||||
}
|
||||
|
||||
if (secureSecretStorage) {
|
||||
logger.log("Preparing key backup version with Secure Secret Storage");
|
||||
|
||||
// Ensure Secure Secret Storage is ready for use
|
||||
if (!this.hasSecretStorageKey()) {
|
||||
throw new Error("Secure Secret Storage has no keys, needs bootstrapping");
|
||||
}
|
||||
|
||||
throw new Error("Not yet implemented");
|
||||
}
|
||||
|
||||
const [keyInfo, encodedPrivateKey] =
|
||||
const [keyInfo, encodedPrivateKey, privateKey] =
|
||||
await this.createRecoveryKeyFromPassphrase(password);
|
||||
|
||||
if (secureSecretStorage) {
|
||||
await this.storeSecret("m.megolm_backup.v1", encodeBase64(privateKey));
|
||||
logger.info("Key backup private key stored in secret storage");
|
||||
}
|
||||
|
||||
// Reshape objects into form expected for key backup
|
||||
const authData = {
|
||||
public_key: keyInfo.pubkey,
|
||||
};
|
||||
if (keyInfo.passphrase) {
|
||||
authData.private_key_salt = keyInfo.passphrase.salt;
|
||||
authData.private_key_iterations = keyInfo.passphrase.iterations;
|
||||
}
|
||||
return {
|
||||
algorithm: olmlib.MEGOLM_BACKUP_ALGORITHM,
|
||||
auth_data: {
|
||||
public_key: keyInfo.pubkey,
|
||||
private_key_salt: keyInfo.passphrase.salt,
|
||||
private_key_iterations: keyInfo.passphrase.iterations,
|
||||
},
|
||||
auth_data: authData,
|
||||
recovery_key: encodedPrivateKey,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether the key backup private key is stored in secret storage.
|
||||
* @return {Promise<boolean>} Whether the backup key is stored.
|
||||
*/
|
||||
MatrixClient.prototype.isKeyBackupKeyStored = async function() {
|
||||
return this.isSecretStored("m.megolm_backup.v1", false /* checkKey */);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new key backup version and enable it, using the information return
|
||||
* from prepareKeyBackupVersion.
|
||||
@@ -1488,13 +1525,19 @@ MatrixClient.prototype.createKeyBackupVersion = async function(info) {
|
||||
auth_data: info.auth_data,
|
||||
};
|
||||
|
||||
// Now sign the backup auth data. Do it as this device first because crypto._signObject
|
||||
// is dumb and bluntly replaces the whole signatures block...
|
||||
// this can probably go away very soon in favour of just signing with the SSK.
|
||||
// Sign the backup auth data with the device key for backwards compat with
|
||||
// older devices with cross-signing. This can probably go away very soon in
|
||||
// favour of just signing with the cross-singing master key.
|
||||
await this._crypto._signObject(data.auth_data);
|
||||
|
||||
if (this._crypto._crossSigningInfo.getId()) {
|
||||
// now also sign the auth data with the master key
|
||||
if (
|
||||
this._cryptoCallbacks.getCrossSigningKey &&
|
||||
this._crypto._crossSigningInfo.getId()
|
||||
) {
|
||||
// now also sign the auth data with the cross-signing master key
|
||||
// we check for the callback explicitly here because we still want to be able
|
||||
// to create an un-cross-signed key backup if there is a cross-signing key but
|
||||
// no callback supplied.
|
||||
await this._crypto._crossSigningInfo.signObject(data.auth_data, "master");
|
||||
}
|
||||
|
||||
@@ -1502,11 +1545,15 @@ MatrixClient.prototype.createKeyBackupVersion = async function(info) {
|
||||
undefined, "POST", "/room_keys/version", undefined, data,
|
||||
{prefix: PREFIX_UNSTABLE},
|
||||
);
|
||||
this.enableKeyBackup({
|
||||
algorithm: info.algorithm,
|
||||
auth_data: info.auth_data,
|
||||
version: res.version,
|
||||
});
|
||||
|
||||
// We could assume everything's okay and enable directly, but this ensures
|
||||
// we run the same signature verification that will be used for future
|
||||
// sessions.
|
||||
await this.checkKeyBackup();
|
||||
if (!this.getKeyBackupEnabled()) {
|
||||
logger.error("Key backup not usable even though we just created it");
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
@@ -1610,6 +1657,18 @@ MatrixClient.prototype.isValidRecoveryKey = function(recoveryKey) {
|
||||
|
||||
MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY = 'RESTORE_BACKUP_ERROR_BAD_KEY';
|
||||
|
||||
/**
|
||||
* Restore from an existing key backup via a passphrase.
|
||||
*
|
||||
* @param {string} password Passphrase
|
||||
* @param {string} [targetRoomId] Room ID to target a specific room.
|
||||
* Restores all rooms if omitted.
|
||||
* @param {string} [targetSessionId] Session ID to target a specific session.
|
||||
* Restores all sessions if omitted.
|
||||
* @param {object} backupInfo Backup metadata from `checkKeyBackup`
|
||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||
* key counts.
|
||||
*/
|
||||
MatrixClient.prototype.restoreKeyBackupWithPassword = async function(
|
||||
password, targetRoomId, targetSessionId, backupInfo,
|
||||
) {
|
||||
@@ -1619,6 +1678,39 @@ MatrixClient.prototype.restoreKeyBackupWithPassword = async function(
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Restore from an existing key backup via a private key stored in secret
|
||||
* storage.
|
||||
*
|
||||
* @param {object} backupInfo Backup metadata from `checkKeyBackup`
|
||||
* @param {string} [targetRoomId] Room ID to target a specific room.
|
||||
* Restores all rooms if omitted.
|
||||
* @param {string} [targetSessionId] Session ID to target a specific session.
|
||||
* Restores all sessions if omitted.
|
||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||
* key counts.
|
||||
*/
|
||||
MatrixClient.prototype.restoreKeyBackupWithSecretStorage = async function(
|
||||
backupInfo, targetRoomId, targetSessionId,
|
||||
) {
|
||||
const privKey = decodeBase64(await this.getSecret("m.megolm_backup.v1"));
|
||||
return this._restoreKeyBackup(
|
||||
privKey, targetRoomId, targetSessionId, backupInfo,
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Restore from an existing key backup via an encoded recovery key.
|
||||
*
|
||||
* @param {string} recoveryKey Encoded recovery key
|
||||
* @param {string} [targetRoomId] Room ID to target a specific room.
|
||||
* Restores all rooms if omitted.
|
||||
* @param {string} [targetSessionId] Session ID to target a specific session.
|
||||
* Restores all sessions if omitted.
|
||||
* @param {object} backupInfo Backup metadata from `checkKeyBackup`
|
||||
* @return {Promise<object>} Status of restoration with `total` and `imported`
|
||||
* key counts.
|
||||
*/
|
||||
MatrixClient.prototype.restoreKeyBackupWithRecoveryKey = function(
|
||||
recoveryKey, targetRoomId, targetSessionId, backupInfo,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user