Skip to content

Commit

Permalink
Merge pull request #1029 from matrix-org/travis/lowercase-lookups
Browse files Browse the repository at this point in the history
Do 3pid lookups in lowercase
  • Loading branch information
turt2live authored Sep 9, 2019
2 parents 2f8cc75 + 07af333 commit 3c29963
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/base-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -1916,15 +1916,23 @@ MatrixBaseApis.prototype.identityHashedLookup = async function(
// Abuse the olm hashing
const olmutil = new global.Olm.Utility();
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
// 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];
return hashed;
});
params["algorithm"] = "sha256";
} else if (hashes['algorithms'].includes('none')) {
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 unhashed values to a known (case-sensitive) address. We use
// the case sensitive version because the caller might be expecting that.
localMapping[unhashed] = p[0];
return unhashed;
});
Expand Down

0 comments on commit 3c29963

Please sign in to comment.