Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor encryption code to use bot-sdk #369

Merged
merged 31 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
722a48c
Add quick-lru
Half-Shot Nov 3, 2021
eac28c3
If enabling encryption, always route requests via pan
Half-Shot Nov 3, 2021
092079b
Refactor EncryptedEventBroker to:
Half-Shot Nov 3, 2021
f1e441d
Make ensure registered check the token
Half-Shot Nov 3, 2021
d25bb95
Improve signatures on MembershipCache
Half-Shot Nov 3, 2021
d74a1d0
Tidy up onEventSend
Half-Shot Nov 3, 2021
c7263d3
Tidy up example
Half-Shot Nov 3, 2021
53ff954
Update encryption packages
Half-Shot Nov 3, 2021
42ebee9
Switch encryption example to yarn
Half-Shot Nov 3, 2021
ccfbc3b
Update express dependency to reduce awful errors
Half-Shot Nov 3, 2021
44f8606
Add proper filter setting code
Half-Shot Nov 3, 2021
9839357
Refactor session grabbing code
Half-Shot Nov 3, 2021
d20d9dd
changelog
Half-Shot Nov 3, 2021
d2ebc7a
add a note about ephemeral events
Half-Shot Nov 3, 2021
1d9020a
Avoid races
Half-Shot Nov 3, 2021
bd3bb65
Be more careful about when we engage sync
Half-Shot Nov 3, 2021
e71a61f
Add origianlHomeserver
Half-Shot Nov 3, 2021
112d2f2
more debugging
Half-Shot Nov 3, 2021
a89cf3a
impersonate properly
Half-Shot Nov 3, 2021
9b8ec7f
impersonateUserId
Half-Shot Nov 3, 2021
8cb1bce
Properly wrap the send
Half-Shot Nov 3, 2021
a838451
Tidy up some code
Half-Shot Nov 4, 2021
1c3cbf5
s/pan/pantalaimon
Half-Shot Nov 4, 2021
40e308b
Remove todo
Half-Shot Nov 4, 2021
c149bc4
Fixup room_id
Half-Shot Nov 4, 2021
7861426
Encryption enabled intent
Half-Shot Nov 4, 2021
8242f6f
Refactor out encryption intent code to separate subclass
Half-Shot Nov 4, 2021
53eb846
Reformat changelog
Half-Shot Nov 4, 2021
f412d6d
Depend on intent
Half-Shot Nov 4, 2021
2937c1f
Tweak broker to be less memory intensive.
Half-Shot Nov 4, 2021
159b2b4
Tweaks to code
Half-Shot Nov 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/369.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Refactor Encryption broker code to use the bot-sdk, and generally be more race-resistant when starting new sessions.

**Breaking**: This change drops support for ephemeral events via the encryption broker, so ephemeral events MUST be enabled within the appservice registration to work.
4,546 changes: 0 additions & 4,546 deletions examples/encryption/package-lock.json

This file was deleted.

7 changes: 3 additions & 4 deletions examples/encryption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
"author": "Matrix.org",
"license": "Apache-2.0",
"dependencies": {
"@types/node": "^14",
"@types/request": "^2.48.5",
"matrix-appservice-bridge": "file:../.."
"@types/express": "^4.17.13",
"@types/node": "^14"
},
"devDependencies": {
"typescript": "^4.0.2"
"typescript": "^4.4.4"
}
}
29 changes: 18 additions & 11 deletions examples/encryption/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
// Usage:
// node index.js -r -u "http://localhost:9000" # remember to add the registration!
// node index.js -p 9000
import { Cli, Bridge, AppServiceRegistration, ClientEncryptionSession, ClientEncryptionStore, Logging} from 'matrix-appservice-bridge';
import { Cli, Bridge, AppServiceRegistration, ClientEncryptionSession, ClientEncryptionStore, Logging} from '../../..';

Logging.configure({
console: "debug",
Expand All @@ -31,7 +31,10 @@ const encryptionStore: ClientEncryptionStore = {
async setStoredSession(session: ClientEncryptionSession) {
log.info("Set session", session.userId, session.deviceId);
encMap.set(session.userId, session);
}
},
async updateSyncToken() {
// No-op
},
};

new Cli({
Expand All @@ -44,34 +47,35 @@ new Cli({
reg.addRegexPattern("users", "@enc_.*", true);
callback(reg);
},
run: function (port, config) {
run: function (port, _config, registration) {
let bridge: Bridge;
bridge = new Bridge({
homeserverUrl: "http://localhost:8008",
domain: "halfyxps",
domain: process.env.MATRIX_DOMAIN,
registration: "enc-registration.yaml",
bridgeEncryption: {
homeserverUrl: "http://localhost:8009",
homeserverUrl: "http://localhost:8004",
store: encryptionStore,
},
controller: {
onUserQuery: function (queriedUser) {
onUserQuery: function () {
return {}; // auto-provision users with no additonal data
},

onEvent: async function (request, context) {
const event = request.getData();
const bot = bridge.getBot();
const intent = bridge.getIntentFromLocalpart(`enc_${context.senders.matrix.localpart}`);
console.log(event, bot.getUserId());
console.log(request, bot.getUserId());
if (event.type === "m.room.member" &&
event.content.membership === "invite" &&
event.state_key === "@encbot:halfyxps") {
event.state_key === bot.getUserId()) {
console.log("Joining the room!");
try {
await intent.join(event.room_id);
console.log("Joined the room!");
} catch (ex) {
}
catch (ex) {
console.log("Err joining room:", ex);
}
return;
Expand All @@ -90,7 +94,10 @@ new Cli({
}
}
});
log.info("Matrix-side listening on port %s", port);
bridge.run(port, config);
const splitUrl = registration.getAppServiceUrl().split(":");
const urlPort = parseInt(splitUrl[splitUrl.length-1]);
port = port || urlPort || 8000;
bridge.run(port);
log.info(`Matrix-side listening on port ${port}`);
}
}).run();
Loading