Skip to content

Commit d779433

Browse files
committed
Generate key
1 parent fb3dca7 commit d779433

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

roles/custom/matrix-bridge-appservice-irc/tasks/setup_install.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,41 @@
128128
become: true
129129
become_user: "{{ matrix_user_name }}"
130130

131+
- name: Check if an authenticated media signing key exists
132+
ansible.builtin.stat:
133+
path: "{{ matrix_appservice_irc_data_path }}/auth-media.jwk"
134+
register: matrix_appservice_irc_stat_auth_media_key
135+
136+
- when: not matrix_appservice_irc_stat_auth_media_key.stat.exists
137+
block:
138+
- name: Generate IRC appservice signing key for authenticated media
139+
community.docker.docker_container:
140+
name: "create-auth-media-jwk-key"
141+
image: "{{ matrix_appservice_irc_docker_image }}"
142+
cleanup: yes
143+
network_mode: none
144+
entrypoint: "/usr/local/bin/node"
145+
command: >
146+
-e "const webcrypto = require('node:crypto');
147+
async function main() {
148+
const key = await webcrypto.subtle.generateKey({
149+
name: 'HMAC',
150+
hash: 'SHA-512',
151+
}, true, ['sign', 'verify']);
152+
console.log(JSON.stringify(await webcrypto.subtle.exportKey('jwk', key), undefined, 4));
153+
}
154+
main().then(() => process.exit(0)).catch(err => { throw err });"
155+
detach: false
156+
register: matrix_appservice_irc_jwk_result
157+
158+
- name: Write auth media signing key to file
159+
ansible.builtin.copy:
160+
content: "{{ matrix_appservice_irc_jwk_result.container.Output }}"
161+
dest: "{{ matrix_appservice_irc_data_path }}/auth-media.jwk"
162+
mode: "0644"
163+
owner: "{{ matrix_user_username }}"
164+
group: "{{ matrix_user_groupname }}"
165+
131166
# In the past, we used to generate the passkey.pem file with root, so permissions may not be okay.
132167
# Fix it.
133168
- name: (Migration) Ensure Appservice IRC passkey permissions are okay

roles/custom/matrix-bridge-appservice-irc/templates/config.yaml.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ ircService:
137137
mediaProxy:
138138
# To generate a .jwk file:
139139
# $ node src/generate-signing-key.js > signingkey.jwk
140-
signingKeyPath: "signingkey.jwk"
140+
signingKeyPath: "/data/auth-media.jwk"
141141
# How long should the generated URLs be valid for
142-
ttlSeconds: 3600
142+
ttlSeconds: 604800
143143
# The port for the media proxy to listen on
144-
bindPort: 11111
144+
bindPort: {{ matrix_media_repo_port | to_json }}
145145
# The publically accessible URL to the media proxy
146-
publicUrl: "https://irc.bridge/media"
146+
publicUrl: "{{ matrix_appservice_irc_homeserver_media_url }}"
147147

148148
# Options here are generally only applicable to large-scale bridges and may have
149149
# consequences greater than other options in this configuration file.

0 commit comments

Comments
 (0)