1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

All the linting

This commit is contained in:
David Baker
2019-02-05 13:03:27 +00:00
parent b3513dc8f8
commit 7f5584e4f5
4 changed files with 60 additions and 28 deletions

View File

@@ -917,13 +917,17 @@ async function _updateStoredSelfSigningKeyForUser(
return; return;
} }
if (!userResult || !userResult.usage.includes('self_signing')) { if (!userResult || !userResult.usage.includes('self_signing')) {
logger.warn("Self-signing key for " + userId + " does not include 'self_signing' usage: ignoring"); logger.warn(
"Self-signing key for " + userId +
" does not include 'self_signing' usage: ignoring",
);
return; return;
} }
const keyCount = Object.keys(userResult.keys).length; const keyCount = Object.keys(userResult.keys).length;
if (keyCount !== 1) { if (keyCount !== 1) {
logger.warn( logger.warn(
"Self-signing key block for " + userId + " has " + keyCount + " keys: expected exactly 1. Ignoring.", "Self-signing key block for " + userId + " has " +
keyCount + " keys: expected exactly 1. Ignoring.",
); );
return; return;
} }
@@ -937,7 +941,10 @@ async function _updateStoredSelfSigningKeyForUser(
const newKey = userResult.keys[newKeyId]; const newKey = userResult.keys[newKeyId];
if (oldKeyId !== newKeyId || oldKey !== newKey) { if (oldKeyId !== newKeyId || oldKey !== newKey) {
updated = true; updated = true;
logger.info("New self-signing key detected for " + userId + ": " + newKeyId + ", was previously " + oldKeyId); logger.info(
"New self-signing key detected for " + userId +
": " + newKeyId + ", was previously " + oldKeyId,
);
userStore.user_id = userResult.user_id; userStore.user_id = userResult.user_id;
userStore.usage = userResult.usage; userStore.usage = userResult.usage;

View File

@@ -18,9 +18,9 @@ const anotherjson = require('another-json');
/** /**
* Higher level wrapper around olm.PkSigning that signs JSON objects * Higher level wrapper around olm.PkSigning that signs JSON objects
* @param obj {Object} Object to sign * @param {Object} obj Object to sign
* @param seed {Uint8Array} The private key seed (32 bytes) * @param {Uint8Array} seed The private key seed (32 bytes)
* @param userId {string} The user ID who owns the signing key * @param {string} userId The user ID who owns the signing key
*/ */
export function pkSign(obj, seed, userId) { export function pkSign(obj, seed, userId) {
const signing = new global.Olm.PkSigning(); const signing = new global.Olm.PkSigning();

View File

@@ -286,27 +286,37 @@ Crypto.prototype.checkOwnSskTrust = async function() {
// First, get the pubkey of the one we can see // First, get the pubkey of the one we can see
const seenSsk = this._deviceList.getStoredSskForUser(userId); const seenSsk = this._deviceList.getStoredSskForUser(userId);
if (!seenSsk) { if (!seenSsk) {
logger.error("Got SSK update event for user " + userId + " but no new SSK found!"); logger.error(
"Got SSK update event for user " + userId +
" but no new SSK found!",
);
return; return;
} }
const seenPubkey = seenSsk.getFingerprint(); const seenPubkey = seenSsk.getFingerprint();
// Now dig out the account keys and get the pubkey of the one in there // Now dig out the account keys and get the pubkey of the one in there
let accountKeys = null; let accountKeys = null;
await this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { await this._cryptoStore.doTxn(
this._cryptoStore.getAccountKeys(txn, keys => { 'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT],
accountKeys = keys; (txn) => {
}); this._cryptoStore.getAccountKeys(txn, keys => {
}); accountKeys = keys;
});
},
);
if (!accountKeys || !accountKeys.self_signing_key_seed) { if (!accountKeys || !accountKeys.self_signing_key_seed) {
logger.info("Ignoring new self-signing key for us because we have no private part stored"); logger.info(
"Ignoring new self-signing key for us because we have no private part stored",
);
return; return;
} }
let signing; let signing;
let localPubkey; let localPubkey;
try { try {
signing = new global.Olm.PkSigning(); signing = new global.Olm.PkSigning();
localPubkey = signing.init_with_seed(Buffer.from(accountKeys.self_signing_key_seed, 'base64')); localPubkey = signing.init_with_seed(
Buffer.from(accountKeys.self_signing_key_seed, 'base64'),
);
} finally { } finally {
if (signing) signing.free(); if (signing) signing.free();
signing = null; signing = null;
@@ -468,7 +478,8 @@ Crypto.prototype.isKeyBackupTrusted = async function(backupInfo) {
ret.usable = ret.sigs.some((s) => { ret.usable = ret.sigs.some((s) => {
return ( return (
s.valid && ( s.valid && (
(s.device && s.device.isVerified()) || (s.self_signing_key && s.self_signing_key.isVerified()) (s.device && s.device.isVerified()) ||
(s.self_signing_key && s.self_signing_key.isVerified())
) )
); );
}); });
@@ -568,15 +579,22 @@ Crypto.prototype.uploadDeviceKeys = function() {
let accountKeys; let accountKeys;
return crypto._signObject(deviceKeys).then(() => { return crypto._signObject(deviceKeys).then(() => {
return this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { return this._cryptoStore.doTxn(
this._cryptoStore.getAccountKeys(txn, keys => { 'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT],
accountKeys = keys; (txn) => {
}); this._cryptoStore.getAccountKeys(txn, keys => {
}); accountKeys = keys;
});
},
);
}).then(() => { }).then(() => {
if (accountKeys && accountKeys.self_signing_key_seed) { if (accountKeys && accountKeys.self_signing_key_seed) {
// if we have an SSK, sign the key with the SSK too // if we have an SSK, sign the key with the SSK too
pkSign(deviceKeys, Buffer.from(accountKeys.self_signing_key_seed, 'base64'), userId); pkSign(
deviceKeys,
Buffer.from(accountKeys.self_signing_key_seed, 'base64'),
userId,
);
} }
return crypto._baseApis.uploadKeysRequest({ return crypto._baseApis.uploadKeysRequest({
@@ -608,15 +626,22 @@ Crypto.prototype.uploadDeviceKeySignatures = async function() {
user_id: userId, user_id: userId,
}; };
let accountKeys; let accountKeys;
await this._cryptoStore.doTxn('readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => { await this._cryptoStore.doTxn(
this._cryptoStore.getAccountKeys(txn, keys => { 'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT],
accountKeys = keys; (txn) => {
}); this._cryptoStore.getAccountKeys(txn, keys => {
accountKeys = keys;
},
);
}); });
if (!accountKeys || !accountKeys.self_signing_key_seed) return false; if (!accountKeys || !accountKeys.self_signing_key_seed) return false;
// Sign this device with the SSK // Sign this device with the SSK
pkSign(thisDeviceKey, Buffer.from(accountKeys.self_signing_key_seed, 'base64'), userId); pkSign(
thisDeviceKey,
Buffer.from(accountKeys.self_signing_key_seed, 'base64'),
userId,
);
const content = { const content = {
[userId]: { [userId]: {

View File

@@ -72,9 +72,9 @@ export default class SskInfo {
isVerified() { isVerified() {
return this.verified == SskInfo.SskVerification.VERIFIED; return this.verified == SskInfo.SskVerification.VERIFIED;
}; }
isUnverified() { isUnverified() {
return this.verified == SskInfo.SskVerification.UNVERIFIED; return this.verified == SskInfo.SskVerification.UNVERIFIED;
}; }
} }