Debian Codegraph @

resources/qml/SelfVerificationCheck.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import "./components/"
6 import Qt.labs.platform 1.1 as P
7 import QtQuick 2.15
8 import QtQuick.Controls 2.15
9 import QtQuick.Layouts 1.3
10 import im.nheko 1.0
11
12 Item {
13 enabled: false
14 visible: false
15
16 Dialog {
17 id: showRecoverKeyDialog
18
19 property string recoveryKey: ""
20
21 anchors.centerIn: parent
22 closePolicy: Popup.NoAutoClose
23 height: content.height + implicitFooterHeight + implicitHeaderHeight
24 modal: true
25 padding: 0
26
27 // Workaround palettes not inheriting for popups
28 palette: timelineRoot.palette
29 parent: Overlay.overlay
30 standardButtons: Dialog.Ok
31 width: content.width
32
33 background: Rectangle {
34 border.color: Nheko.theme.separator
35 border.width: 1
36 color: palette.window
37 radius: Nheko.paddingSmall
38 }
39
40 ColumnLayout {
41 id: content
42
43 spacing: 0
44
45 Label {
46 Layout.fillWidth: true
47 Layout.margins: Nheko.paddingMedium
48 Layout.maximumWidth: (showRecoverKeyDialog.Overlay.overlay ? showRecoverKeyDialog.Overlay.overlay.width : 400) - Nheko.paddingMedium * 4
49 color: palette.text
50 text: qsTr("This is your recovery key. You will need it to restore access to your encrypted messages and verification keys. Keep this safe. Don't share it with anyone and don't lose it! Do not pass go! Do not collect $200!")
51 wrapMode: Text.Wrap
52 }
53 TextEdit {
54 Layout.alignment: Qt.AlignHCenter
55 Layout.maximumWidth: (showRecoverKeyDialog.Overlay.overlay ? showRecoverKeyDialog.Overlay.overlay.width : 400) - Nheko.paddingMedium * 4
56 color: palette.text
57 font.bold: true
58 horizontalAlignment: TextEdit.AlignHCenter
59 readOnly: true
60 selectByMouse: true
61 text: showRecoverKeyDialog.recoveryKey
62 verticalAlignment: TextEdit.AlignVCenter
63 wrapMode: TextEdit.Wrap
64 }
65 }
66 }
67 P.MessageDialog {
68 id: successDialog
69
70 buttons: P.MessageDialog.Ok
71 text: qsTr("Encryption setup successfully")
72 }
73 P.MessageDialog {
74 id: failureDialog
75
76 property string errorMessage
77
78 buttons: P.MessageDialog.Ok
79 text: qsTr("Failed to setup encryption: %1").arg(errorMessage)
80 }
81 MainWindowDialog {
82 id: bootstrapCrosssigning
83
84 // Workaround palettes not inheriting for popups
85 palette: timelineRoot.palette
86
87 background: Rectangle {
88 border.color: Nheko.theme.separator
89 border.width: 1
90 color: palette.window
91 radius: Nheko.paddingSmall
92 }
93
94 onAccepted: SelfVerificationStatus.setupCrosssigning(storeSecretsOnline.checked, usePassword.checked ? passwordField.text : "", useOnlineKeyBackup.checked)
95
96 GridLayout {
97 id: grid
98
99 columnSpacing: 0
100 columns: 2
101 rowSpacing: 0
102 width: bootstrapCrosssigning.useableWidth
103 z: 1
104
105 Label {
106 Layout.alignment: Qt.AlignHCenter
107 Layout.columnSpan: 2
108 Layout.margins: Nheko.paddingMedium
109 color: palette.text
110 font.pointSize: fontMetrics.font.pointSize * 2
111 text: qsTr("Setup Encryption")
112 wrapMode: Text.Wrap
113 }
114 Label {
115 Layout.alignment: Qt.AlignLeft
116 Layout.columnSpan: 2
117 Layout.margins: Nheko.paddingMedium
118 Layout.maximumWidth: grid.width - Nheko.paddingMedium * 2
119 color: palette.text
120 text: qsTr("Hello and welcome to Matrix!\nIt seems like you are new. Before you can securely encrypt your messages, we need to setup a few small things. You can either press accept immediately or adjust a few basic options. We also try to explain a few of the basics. You can skip those parts, but they might prove to be helpful!")
121 wrapMode: Text.Wrap
122 }
123 Label {
124 Layout.alignment: Qt.AlignLeft
125 Layout.columnSpan: 1
126 Layout.margins: Nheko.paddingMedium
127 Layout.maximumWidth: Math.floor(grid.width / 2) - Nheko.paddingMedium * 2
128 color: palette.text
129 text: "Store secrets online.\nYou have a few secrets to make all the encryption magic work. While you can keep them stored only locally, we recommend storing them encrypted on the server. Otherwise it will be painful to recover them. Only disable this if you are paranoid and like losing your data!"
130 wrapMode: Text.Wrap
131 }
132 Item {
133 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
134 Layout.fillWidth: true
135 Layout.margins: Nheko.paddingMedium
136 Layout.preferredHeight: storeSecretsOnline.height
137
138 ToggleButton {
139 id: storeSecretsOnline
140
141 checked: true
142
143 onClicked: console.log("Store secrets toggled: " + checked)
144 }
145 }
146 Label {
147 Layout.alignment: Qt.AlignLeft
148 Layout.columnSpan: 1
149 Layout.margins: Nheko.paddingMedium
150 Layout.maximumWidth: Math.floor(grid.width / 2) - Nheko.paddingMedium * 2
151 Layout.rowSpan: 2
152 color: palette.text
153 text: "Set an online backup password.\nWe recommend you DON'T set a password and instead only rely on the recovery key. You will get a recovery key in any case when storing the cross-signing secrets online, but passwords are usually not very random, so they are easier to attack than a completely random recovery key. If you choose to use a password, DON'T make it the same as your login password, otherwise your server can read all your encrypted messages. (You don't want that.)"
154 visible: storeSecretsOnline.checked
155 wrapMode: Text.Wrap
156 }
157 Item {
158 Layout.alignment: Qt.AlignLeft | Qt.AlignTop
159 Layout.fillWidth: true
160 Layout.margins: Nheko.paddingMedium
161 Layout.preferredHeight: storeSecretsOnline.height
162 Layout.rowSpan: usePassword.checked ? 1 : 2
163 Layout.topMargin: Nheko.paddingLarge
164 visible: storeSecretsOnline.checked
165
166 ToggleButton {
167 id: usePassword
168
169 checked: false
170 }
171 }
172 MatrixTextField {
173 id: passwordField
174
175 Layout.alignment: Qt.AlignLeft | Qt.AlignTop
176 Layout.columnSpan: 1
177 Layout.fillWidth: true
178 Layout.margins: Nheko.paddingMedium
179 Layout.maximumWidth: Math.floor(grid.width / 2) - Nheko.paddingMedium * 2
180 echoMode: TextInput.Password
181 visible: storeSecretsOnline.checked && usePassword.checked
182 }
183 Label {
184 Layout.alignment: Qt.AlignLeft
185 Layout.columnSpan: 1
186 Layout.margins: Nheko.paddingMedium
187 Layout.maximumWidth: Math.floor(grid.width / 2) - Nheko.paddingMedium * 2
188 color: palette.text
189 text: "Use online key backup.\nStore the keys for your messages securely encrypted online. In general you do want this, because it protects your messages from becoming unreadable, if you log out by accident. It does however carry a small security risk, if you ever share your recovery key by accident. Currently this also has some other weaknesses, that might allow the server to insert new keys into your backup. The server will however never be able to read your messages."
190 wrapMode: Text.Wrap
191 }
192 Item {
193 Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
194 Layout.fillWidth: true
195 Layout.margins: Nheko.paddingMedium
196 Layout.preferredHeight: storeSecretsOnline.height
197
198 ToggleButton {
199 id: useOnlineKeyBackup
200
201 checked: true
202
203 onClicked: console.log("Online key backup toggled: " + checked)
204 }
205 }
206 }
207 }
208 MainWindowDialog {
209 id: verifyMasterKey
210
211 // Workaround palettes not inheriting for popups
212 palette: timelineRoot.palette
213 standardButtons: Dialog.Cancel
214
215 GridLayout {
216 id: masterGrid
217
218 columns: 1
219 width: verifyMasterKey.useableWidth
220 z: 1
221
222 Label {
223 Layout.alignment: Qt.AlignHCenter
224 Layout.margins: Nheko.paddingMedium
225 color: palette.text
226 //Layout.columnSpan: 2
227 font.pointSize: fontMetrics.font.pointSize * 2
228 text: qsTr("Activate Encryption")
229 wrapMode: Text.Wrap
230 }
231 Label {
232 Layout.alignment: Qt.AlignLeft
233 Layout.margins: Nheko.paddingMedium
234 //Layout.columnSpan: 2
235 Layout.maximumWidth: grid.width - Nheko.paddingMedium * 2
236 color: palette.text
237 text: qsTr("It seems like you have encryption already configured for this account. To be able to access your encrypted messages and make this device appear as trusted, you can either verify an existing device or (if you have one) enter your recovery passphrase. Please select one of the options below.\nIf you choose verify, you need to have the other device available. If you choose \"enter passphrase\", you will need your recovery key or passphrase. If you click cancel, you can choose to verify yourself at a later point.")
238 wrapMode: Text.Wrap
239 }
240 FlatButton {
241 Layout.alignment: Qt.AlignHCenter
242 text: qsTr("verify")
243
244 onClicked: {
245 SelfVerificationStatus.verifyMasterKey();
246 verifyMasterKey.close();
247 }
248 }
249 FlatButton {
250 Layout.alignment: Qt.AlignHCenter
251 text: qsTr("enter passphrase")
252 visible: SelfVerificationStatus.hasSSSS
253
254 onClicked: {
255 SelfVerificationStatus.verifyMasterKeyWithPassphrase();
256 verifyMasterKey.close();
257 }
258 }
259 }
260 }
261 Connections {
262 function onSetupCompleted() {
263 successDialog.open();
264 }
265 function onSetupFailed(m) {
266 failureDialog.errorMessage = m;
267 failureDialog.open();
268 }
269 function onShowRecoveryKey(key) {
270 showRecoverKeyDialog.recoveryKey = key;
271 showRecoverKeyDialog.open();
272 }
273 function onStatusChanged() {
274 console.log("STATUS CHANGED: " + SelfVerificationStatus.status);
275 if (SelfVerificationStatus.status == SelfVerificationStatus.NoMasterKey) {
276 bootstrapCrosssigning.open();
277 } else if (SelfVerificationStatus.status == SelfVerificationStatus.UnverifiedMasterKey) {
278 verifyMasterKey.open();
279 } else {
280 bootstrapCrosssigning.close();
281 verifyMasterKey.close();
282 }
283 }
284
285 target: SelfVerificationStatus
286 }
287 }