You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Rename backup_password & functions
Not Just For Backups Anymore
This commit is contained in:
@@ -51,7 +51,7 @@ import logger from './logger';
|
|||||||
import Crypto from './crypto';
|
import Crypto from './crypto';
|
||||||
import { isCryptoAvailable } from './crypto';
|
import { isCryptoAvailable } from './crypto';
|
||||||
import { encodeRecoveryKey, decodeRecoveryKey } from './crypto/recoverykey';
|
import { encodeRecoveryKey, decodeRecoveryKey } from './crypto/recoverykey';
|
||||||
import { keyForNewBackup, keyForExistingBackup } from './crypto/backup_password';
|
import { keyFromPassphrase, keyFromAuthData } from './crypto/key_passphrase';
|
||||||
import { randomString } from './randomstring';
|
import { randomString } from './randomstring';
|
||||||
|
|
||||||
// Disable warnings for now: we use deprecated bluebird functions
|
// Disable warnings for now: we use deprecated bluebird functions
|
||||||
@@ -1380,7 +1380,7 @@ MatrixClient.prototype.prepareKeyBackupVersion = async function(password) {
|
|||||||
let publicKey;
|
let publicKey;
|
||||||
const authData = {};
|
const authData = {};
|
||||||
if (password) {
|
if (password) {
|
||||||
const keyInfo = await keyForNewBackup(password);
|
const keyInfo = await keyFromPassphrase(password);
|
||||||
publicKey = decryption.init_with_private_key(keyInfo.key);
|
publicKey = decryption.init_with_private_key(keyInfo.key);
|
||||||
authData.private_key_salt = keyInfo.salt;
|
authData.private_key_salt = keyInfo.salt;
|
||||||
authData.private_key_iterations = keyInfo.iterations;
|
authData.private_key_iterations = keyInfo.iterations;
|
||||||
@@ -1542,7 +1542,7 @@ MatrixClient.RESTORE_BACKUP_ERROR_BAD_KEY = 'RESTORE_BACKUP_ERROR_BAD_KEY';
|
|||||||
MatrixClient.prototype.restoreKeyBackupWithPassword = async function(
|
MatrixClient.prototype.restoreKeyBackupWithPassword = async function(
|
||||||
password, targetRoomId, targetSessionId, backupInfo,
|
password, targetRoomId, targetSessionId, backupInfo,
|
||||||
) {
|
) {
|
||||||
const privKey = await keyForExistingBackup(backupInfo, password);
|
const privKey = await keyFromAuthData(backupInfo.auth_data, password);
|
||||||
return this._restoreKeyBackup(
|
return this._restoreKeyBackup(
|
||||||
privKey, targetRoomId, targetSessionId, backupInfo,
|
privKey, targetRoomId, targetSessionId, backupInfo,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {EventEmitter} from 'events';
|
|||||||
import logger from '../logger';
|
import logger from '../logger';
|
||||||
import olmlib from './olmlib';
|
import olmlib from './olmlib';
|
||||||
import { randomString } from '../randomstring';
|
import { randomString } from '../randomstring';
|
||||||
import { keyForNewBackup } from './backup_password';
|
import { keyFromPassphrase } from './backup_password';
|
||||||
import { encodeRecoveryKey } from './recoverykey';
|
import { encodeRecoveryKey } from './recoverykey';
|
||||||
import { pkVerify } from './olmlib';
|
import { pkVerify } from './olmlib';
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ export default class SecretStorage extends EventEmitter {
|
|||||||
const decryption = new global.Olm.PkDecryption();
|
const decryption = new global.Olm.PkDecryption();
|
||||||
try {
|
try {
|
||||||
if (opts.passphrase) {
|
if (opts.passphrase) {
|
||||||
const key = await keyForNewBackup(opts.passphrase);
|
const key = await keyFromPassphrase(opts.passphrase);
|
||||||
keyData.passphrase = {
|
keyData.passphrase = {
|
||||||
algorithm: "m.pbkdf2",
|
algorithm: "m.pbkdf2",
|
||||||
iterations: key.iterations,
|
iterations: key.iterations,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2018 New Vector Ltd
|
Copyright 2018 New Vector Ltd
|
||||||
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@@ -18,13 +19,11 @@ import { randomString } from '../randomstring';
|
|||||||
|
|
||||||
const DEFAULT_ITERATIONS = 500000;
|
const DEFAULT_ITERATIONS = 500000;
|
||||||
|
|
||||||
export async function keyForExistingBackup(backupData, password) {
|
export async function keyFromAuthData(authData, password) {
|
||||||
if (!global.Olm) {
|
if (!global.Olm) {
|
||||||
throw new Error("Olm is not available");
|
throw new Error("Olm is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
const authData = backupData.auth_data;
|
|
||||||
|
|
||||||
if (!authData.private_key_salt || !authData.private_key_iterations) {
|
if (!authData.private_key_salt || !authData.private_key_iterations) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Salt and/or iterations not found: " +
|
"Salt and/or iterations not found: " +
|
||||||
@@ -33,12 +32,12 @@ export async function keyForExistingBackup(backupData, password) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await deriveKey(
|
return await deriveKey(
|
||||||
password, backupData.auth_data.private_key_salt,
|
password, authData.private_key_salt,
|
||||||
backupData.auth_data.private_key_iterations,
|
authData.private_key_iterations,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function keyForNewBackup(password) {
|
export async function keyFromPassphrase(password) {
|
||||||
if (!global.Olm) {
|
if (!global.Olm) {
|
||||||
throw new Error("Olm is not available");
|
throw new Error("Olm is not available");
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user