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

Add support for encryption via pantalaimon #231

Merged
merged 33 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
649567b
Add Intent code to setup encryption when registering
Half-Shot Sep 15, 2020
a3157dc
Add bridge opts
Half-Shot Sep 15, 2020
c560409
Export encryption component
Half-Shot Sep 15, 2020
2671a7c
Add encrypted bridges example project
Half-Shot Sep 15, 2020
136f751
Add flag to set js-sdk encryption protection off
Half-Shot Sep 16, 2020
a1af83d
Implement logic for the encrypted event broker
Half-Shot Sep 16, 2020
37a20fe
package tweaks
Half-Shot Sep 16, 2020
2fe081b
changelog
Half-Shot Sep 16, 2020
a503e40
linting
Half-Shot Sep 16, 2020
5e3f185
Apply limited filter to sync
Half-Shot Sep 17, 2020
7b2c111
bridgeEncryption should not be forced
Half-Shot Sep 17, 2020
390323f
oh there is this one too
Half-Shot Sep 17, 2020
26d133a
Split event-types out
Half-Shot Sep 18, 2020
3af1fdd
Fiddle with request to make it return data
Half-Shot Sep 18, 2020
82615b3
Add support for EDUs coming over /sync
Half-Shot Sep 18, 2020
5312c8c
Add explanatory comment
Half-Shot Sep 18, 2020
025e192
Merge remote-tracking branch 'origin/develop' into hs/encryption-pan
Half-Shot Sep 18, 2020
b6fa7d1
linting
Half-Shot Sep 18, 2020
1282637
Ensure homeserver support when running encryption
Half-Shot Sep 23, 2020
d77b219
Tweaks from review
Half-Shot Sep 23, 2020
fcf91ed
Don't include the future login type, until we've merged the spec
Half-Shot Sep 23, 2020
9ef556d
Use matrix-js-sdk 8.3.0
Half-Shot Sep 23, 2020
e3b423a
Merge remote-tracking branch 'origin/develop' into hs/encryption-pan
Half-Shot Sep 23, 2020
a8b819c
We should await the bridge
Half-Shot Sep 23, 2020
84cbc02
Remove TODOs
Half-Shot Sep 23, 2020
654b78b
cast
Half-Shot Sep 23, 2020
7ddd154
remove console line
Half-Shot Sep 23, 2020
22bd557
Ensure bot is also encrypted
Half-Shot Sep 23, 2020
d241e4e
Don't be silly, bots cannot sync
Half-Shot Sep 23, 2020
8593ea8
Do not cull clients that are syncing
Half-Shot Sep 23, 2020
1a48fc4
Allow users to force register
Half-Shot Sep 23, 2020
908331b
Use matrix-js-sdk v8.4.0-rc1
Half-Shot Sep 23, 2020
f14a434
lint
Half-Shot Sep 23, 2020
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
1 change: 1 addition & 0 deletions changelog.d/231.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for bridging encrypted events via [matrix-org/pantalaimon](https://github.com/matrix-org/pantalaimon).
3 changes: 3 additions & 0 deletions examples/encryption/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*.db
/lib
/*registration.yaml
4,546 changes: 4,546 additions & 0 deletions examples/encryption/package-lock.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions examples/encryption/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "matrix-bridge-encryption-example",
"private": "true",
"version": "1.0.0",
"description": "",
"main": "lib/index.js",
"scripts": {
"start": "node ./lib/index.js",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Matrix.org",
"license": "Apache-2.0",
"dependencies": {
"@types/node": "^14",
"@types/request": "^2.48.5",
"matrix-appservice-bridge": "file:../.."
},
"devDependencies": {
"typescript": "^4.0.2"
}
}
96 changes: 96 additions & 0 deletions examples/encryption/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright 2020 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
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';

Logging.configure({
console: "debug",
});
const log = Logging.get("index");

const encMap = new Map<string, ClientEncryptionSession>();
const encryptionStore: ClientEncryptionStore = {
async getStoredSession(userId: string) {
return encMap.get(userId) || null;
},
async setStoredSession(session: ClientEncryptionSession) {
log.info("Set session", session.userId, session.deviceId);
encMap.set(session.userId, session);
}
};

new Cli({
registrationPath: "enc-registration.yaml",
generateRegistration: function (reg, callback) {
reg.setId(AppServiceRegistration.generateToken());
reg.setHomeserverToken(AppServiceRegistration.generateToken());
reg.setAppServiceToken(AppServiceRegistration.generateToken());
reg.setSenderLocalpart("encbot");
reg.addRegexPattern("users", "@enc_.*", true);
callback(reg);
},
run: function (port, config) {
let bridge: Bridge;
bridge = new Bridge({
homeserverUrl: "http://localhost:8008",
domain: "halfyxps",
registration: "enc-registration.yaml",
bridgeEncryption: {
homeserverUrl: "http://localhost:8009",
store: encryptionStore,
},
controller: {
onUserQuery: function (queriedUser) {
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());
if (event.type === "m.room.member" &&
event.content.membership === "invite" &&
event.state_key === "@encbot:halfyxps") {
console.log("Joining the room!");
try {
await intent.join(event.room_id);
console.log("Joined the room!");
} catch (ex) {
console.log("Err joining room:", ex);
}
return;
}

if (event.type === "m.room.encrypted") {
await intent.sendText(event.room_id, "Not encrypted!");
return;
}

if (event.type !== "m.room.message" || !event.content) {
return;
}

await intent.sendText(event.room_id, event.content.body as string);
}
}
});
log.info("Matrix-side listening on port %s", port);
bridge.run(port, config);
}
}).run();
23 changes: 23 additions & 0 deletions examples/encryption/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "./lib",
"sourceMap": true,
"moduleResolution": "Node",
"esModuleInterop": true,
},
"include": [
"src/**/*"
],
"types": [
"node",
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
Loading