1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Do 3pid lookups in lowercase

Fixes https://github.com/vector-im/riot-web/issues/10754
This commit is contained in:
Travis Ralston
2019-09-07 14:04:30 -06:00
parent 2f8cc75432
commit 0bbc781d0c

View File

@@ -1916,15 +1916,23 @@ MatrixBaseApis.prototype.identityHashedLookup = async function(
// Abuse the olm hashing // Abuse the olm hashing
const olmutil = new global.Olm.Utility(); const olmutil = new global.Olm.Utility();
params["addresses"] = addressPairs.map(p => { params["addresses"] = addressPairs.map(p => {
const hashed = olmutil.sha256(`${p[0]} ${p[1]} ${params['pepper']}`) const addr = p[0].toLowerCase(); // lowercase to get consistent hashes
const med = p[1].toLowerCase();
const hashed = olmutil.sha256(`${addr} ${med} ${params['pepper']}`)
.replace(/\+/g, '-').replace(/\//g, '_'); // URL-safe base64 .replace(/\+/g, '-').replace(/\//g, '_'); // URL-safe base64
// Map the hash to a known (case-sensitive) address. We use the case
// sensitive version because the caller might be expecting that.
localMapping[hashed] = p[0]; localMapping[hashed] = p[0];
return hashed; return hashed;
}); });
params["algorithm"] = "sha256"; params["algorithm"] = "sha256";
} else if (hashes['algorithms'].includes('none')) { } else if (hashes['algorithms'].includes('none')) {
params["addresses"] = addressPairs.map(p => { params["addresses"] = addressPairs.map(p => {
const unhashed = `${p[0]} ${p[1]}`; const addr = p[0].toLowerCase(); // lowercase to get consistent hashes
const med = p[1].toLowerCase();
const unhashed = `${addr} ${med}`;
// Map the ""hash"" to a known (case-sensitive) address. We use the case
// sensitive version because the caller might be expecting that.
localMapping[unhashed] = p[0]; localMapping[unhashed] = p[0];
return unhashed; return unhashed;
}); });