You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-01 04:43:29 +03:00
Fix recovery key format
This commit is contained in:
@@ -53,6 +53,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"another-json": "^0.2.0",
|
"another-json": "^0.2.0",
|
||||||
"babel-runtime": "^6.26.0",
|
"babel-runtime": "^6.26.0",
|
||||||
|
"base58check": "^2.0.0",
|
||||||
"bluebird": "^3.5.0",
|
"bluebird": "^3.5.0",
|
||||||
"browser-request": "^0.3.3",
|
"browser-request": "^0.3.3",
|
||||||
"content-type": "^1.0.2",
|
"content-type": "^1.0.2",
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import {InvalidStoreError} from './errors';
|
|||||||
|
|
||||||
import Crypto from './crypto';
|
import Crypto from './crypto';
|
||||||
import { isCryptoAvailable } from './crypto';
|
import { isCryptoAvailable } from './crypto';
|
||||||
|
import { encodeRecoveryKey, decodeRecoveryKey } from './crypto/recoverykey';
|
||||||
|
|
||||||
const LAZY_LOADING_MESSAGES_FILTER = {
|
const LAZY_LOADING_MESSAGES_FILTER = {
|
||||||
lazy_load_members: true,
|
lazy_load_members: true,
|
||||||
@@ -882,9 +883,7 @@ MatrixClient.prototype.prepareKeyBackupVersion = function() {
|
|||||||
auth_data: {
|
auth_data: {
|
||||||
public_key: publicKey,
|
public_key: publicKey,
|
||||||
},
|
},
|
||||||
// FIXME: pickle isn't the right thing to use, but we don't have
|
recovery_key: encodeRecoveryKey(decryption.get_private_key()),
|
||||||
// anything else yet, so use it for now
|
|
||||||
recovery_key: decryption.pickle("secret_key"),
|
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
decryption.free();
|
decryption.free();
|
||||||
@@ -991,26 +990,17 @@ MatrixClient.prototype.backupAllGroupSessions = function(version) {
|
|||||||
return this._crypto.backupAllGroupSessions(version);
|
return this._crypto.backupAllGroupSessions(version);
|
||||||
};
|
};
|
||||||
|
|
||||||
MatrixClient.prototype.isValidRecoveryKey = function(decryptionKey) {
|
MatrixClient.prototype.isValidRecoveryKey = function(recoveryKey) {
|
||||||
if (this._crypto === null) {
|
|
||||||
throw new Error("End-to-end encryption disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
const decryption = new global.Olm.PkDecryption();
|
|
||||||
try {
|
try {
|
||||||
// FIXME: see the FIXME in createKeyBackupVersion
|
decodeRecoveryKey(recoveryKey);
|
||||||
decryption.unpickle("secret_key", decryptionKey);
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
|
||||||
decryption.free();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MatrixClient.prototype.restoreKeyBackups = function(
|
MatrixClient.prototype.restoreKeyBackups = function(
|
||||||
decryptionKey, targetRoomId, targetSessionId, version,
|
recoveryKey, targetRoomId, targetSessionId, version,
|
||||||
) {
|
) {
|
||||||
if (this._crypto === null) {
|
if (this._crypto === null) {
|
||||||
throw new Error("End-to-end encryption disabled");
|
throw new Error("End-to-end encryption disabled");
|
||||||
@@ -1021,9 +1011,10 @@ MatrixClient.prototype.restoreKeyBackups = function(
|
|||||||
const path = this._makeKeyBackupPath(targetRoomId, targetSessionId, version);
|
const path = this._makeKeyBackupPath(targetRoomId, targetSessionId, version);
|
||||||
|
|
||||||
// FIXME: see the FIXME in createKeyBackupVersion
|
// FIXME: see the FIXME in createKeyBackupVersion
|
||||||
|
const privkey = decodeRecoveryKey(recoveryKey);
|
||||||
const decryption = new global.Olm.PkDecryption();
|
const decryption = new global.Olm.PkDecryption();
|
||||||
try {
|
try {
|
||||||
decryption.unpickle("secret_key", decryptionKey);
|
decryption.init_with_private_key(privkey);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
decryption.free();
|
decryption.free();
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
Reference in New Issue
Block a user