Skip to content

Commit 6482c7e

Browse files
Handle RSA token handling in Rust (#915)
* Split out queue and cache config * Update usages of cache config, * Update default * Cleanup * Make queue optional. * config updates. * changelog * update spec config * Update tests * tweak import * Update default config. * fixup test * Update config.sample.yml Co-authored-by: Andrew Ferrazzutti <[email protected]> Signed-off-by: Will Hunt <[email protected]> * Update encryption.md Signed-off-by: Will Hunt <[email protected]> * Clear up worker config Signed-off-by: Will Hunt <[email protected]> * Update src/config/Config.ts Co-authored-by: Andrew Ferrazzutti <[email protected]> Signed-off-by: Will Hunt <[email protected]> * update helm config * move UserTokenStore.ts * Port all the imports to new path. * Port RSA handling to rust. * Add tests. * linting * lint rust * Remove unwraps / panics * fix build script * Ensure we store and check with algorithm and key was used. * quieten false deadcode warnings * changelog * fix test imports * lazy mock out UTS * Refactor so that UserTokenStore is initiated by the time Bridge is created. * update defaults * replace if with match * Use the magic of ? * fmt --------- Signed-off-by: Will Hunt <[email protected]> Co-authored-by: Andrew Ferrazzutti <[email protected]>
1 parent 6618ab6 commit 6482c7e

33 files changed

+413
-69
lines changed

Cargo.lock

+167
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ atom_syndication = "0.12"
2222
ruma = { version = "0.9", features = ["events", "html"] }
2323
reqwest = "0.11"
2424
rand = "0.8.5"
25-
25+
rsa = "0.9.6"
26+
base64ct = { version = "1.6.0", features = ["alloc"] }
2627
[build-dependencies]
2728
napi-build = "2"

changelog.d/915.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Track which key was used to encrypt secrets in storage, and encrypt/decrypt secrets in Rust.

config.sample.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bridge:
1010
passFile:
1111
# A passkey used to encrypt tokens stored inside the bridge.
1212
# Run openssl genpkey -out passkey.pem -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096 to generate
13-
passkey.pem
13+
./passkey.pem
1414
logging:
1515
# Logging settings. You can have a severity debug,info,warn,error
1616
level: info

scripts/build-app.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# exit when any command fails
44
set -e

spec/basic.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ describe('Basic test setup', () => {
1919
const user = testEnv.getUser('user');
2020
const roomId = await user.createRoom({ name: 'Test room', invite:[testEnv.botMxid] });
2121
await user.waitForRoomJoin({sender: testEnv.botMxid, roomId });
22-
await user.sendText(roomId, "!hookshot help");
23-
const msg = await user.waitForRoomEvent<MessageEventContent>({
22+
const msg = user.waitForRoomEvent<MessageEventContent>({
2423
eventType: 'm.room.message', sender: testEnv.botMxid, roomId
2524
});
25+
await user.sendText(roomId, "!hookshot help");
2626
// Expect help text.
27-
expect(msg.data.content.body).to.include('!hookshot help` - This help text\n');
27+
expect((await msg).data.content.body).to.include('!hookshot help` - This help text\n');
2828
});
2929

3030
// TODO: Move test to it's own generic connections file.

src/AdminRoom.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Intent } from "matrix-bot-sdk";
1616
import { JiraBotCommands } from "./jira/AdminCommands";
1717
import { NotifFilter, NotificationFilterStateContent } from "./NotificationFilters";
1818
import { ProjectsListResponseData } from "./github/Types";
19-
import { UserTokenStore } from "./UserTokenStore";
19+
import { UserTokenStore } from "./tokens/UserTokenStore";
2020
import { Logger } from "matrix-appservice-bridge";
2121
import markdown from "markdown-it";
2222
type ProjectsListForRepoResponseData = Endpoints["GET /repos/{owner}/{repo}/projects"]["response"];

src/AdminRoomCommandHandler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import EventEmitter from "events";
22
import { Intent } from "matrix-bot-sdk";
33
import { BridgeConfig } from "./config/Config";
4-
import { UserTokenStore } from "./UserTokenStore";
4+
import { UserTokenStore } from "./tokens/UserTokenStore";
55

66

77
export enum Category {

src/App/BridgeApp.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { getAppservice } from "../appservice";
99
import BotUsersManager from "../Managers/BotUsersManager";
1010
import * as Sentry from '@sentry/node';
1111
import { GenericHookConnection } from "../Connections";
12+
import { UserTokenStore } from "../tokens/UserTokenStore";
1213

1314
Logger.configure({console: "info"});
1415
const log = new Logger("App");
@@ -50,7 +51,8 @@ export async function start(config: BridgeConfig, registration: IAppserviceRegis
5051

5152
const botUsersManager = new BotUsersManager(config, appservice);
5253

53-
const bridgeApp = new Bridge(config, listener, appservice, storage, botUsersManager);
54+
const tokenStore = await UserTokenStore.fromKeyPath(config.passFile , appservice.botIntent, config);
55+
const bridgeApp = new Bridge(config, tokenStore, listener, appservice, storage, botUsersManager);
5456

5557
process.once("SIGTERM", () => {
5658
log.error("Got SIGTERM");

0 commit comments

Comments
 (0)