2023-02-22 01:48:49 +03:00
// SPDX-FileCopyrightText: Nheko Contributors
2021-09-18 01:21:14 +03:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
2021-11-04 01:01:36 +03:00
import "./components/"
2021-09-18 01:21:14 +03:00
import Qt . labs . platform 1.1 as P
import QtQuick 2.15
import QtQuick . Controls 2.15
import QtQuick . Layouts 1.3
import im . nheko 1.0
Item {
enabled: false
2023-06-02 02:45:24 +03:00
visible: false
2021-09-18 01:21:14 +03:00
Dialog {
id: showRecoverKeyDialog
property string recoveryKey: ""
anchors.centerIn: parent
2023-06-02 02:45:24 +03:00
closePolicy: Popup . NoAutoClose
2021-09-18 01:21:14 +03:00
height: content . height + implicitFooterHeight + implicitHeaderHeight
modal: true
2023-06-02 02:45:24 +03:00
padding: 0
2023-06-08 02:51:27 +03:00
// Workaround palettes not inheriting for popups
palette: timelineRoot . palette
2023-06-02 02:45:24 +03:00
parent: Overlay . overlay
2021-09-18 01:21:14 +03:00
standardButtons: Dialog . Ok
2023-06-02 02:45:24 +03:00
width: content . width
background: Rectangle {
border.color: Nheko . theme . separator
border.width: 1
color: palette . window
radius: Nheko . paddingSmall
}
2021-09-18 01:21:14 +03:00
ColumnLayout {
id: content
spacing: 0
Label {
2023-06-02 02:45:24 +03:00
Layout.fillWidth: true
2021-09-18 01:21:14 +03:00
Layout.margins: Nheko . paddingMedium
Layout.maximumWidth: ( Overlay . overlay ? Overlay.overlay.width : 400 ) - Nheko . paddingMedium * 4
2023-06-02 02:29:05 +03:00
color: palette . text
2023-06-02 02:45:24 +03:00
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!" )
2021-09-18 01:21:14 +03:00
wrapMode: Text . Wrap
}
TextEdit {
Layout.alignment: Qt . AlignHCenter
2023-06-02 02:45:24 +03:00
Layout.maximumWidth: ( Overlay . overlay ? Overlay.overlay.width : 400 ) - Nheko . paddingMedium * 4
color: palette . text
font.bold: true
2021-09-18 01:21:14 +03:00
horizontalAlignment: TextEdit . AlignHCenter
readOnly: true
selectByMouse: true
text: showRecoverKeyDialog . recoveryKey
2023-06-02 02:45:24 +03:00
verticalAlignment: TextEdit . AlignVCenter
2021-09-18 01:21:14 +03:00
wrapMode: TextEdit . Wrap
}
}
}
P . MessageDialog {
id: successDialog
buttons: P . MessageDialog . Ok
text: qsTr ( "Encryption setup successfully" )
}
P . MessageDialog {
id: failureDialog
property string errorMessage
buttons: P . MessageDialog . Ok
text: qsTr ( "Failed to setup encryption: %1" ) . arg ( errorMessage )
}
2021-10-17 18:17:29 +03:00
MainWindowDialog {
2021-09-18 01:21:14 +03:00
id: bootstrapCrosssigning
2023-06-08 02:51:27 +03:00
// Workaround palettes not inheriting for popups
palette: timelineRoot . palette
2023-06-02 02:45:24 +03:00
background: Rectangle {
border.color: Nheko . theme . separator
border.width: 1
color: palette . window
radius: Nheko . paddingSmall
}
2021-09-18 01:21:14 +03:00
onAccepted: SelfVerificationStatus . setupCrosssigning ( storeSecretsOnline . checked , usePassword . checked ? passwordField.text : "" , useOnlineKeyBackup . checked )
2021-11-04 01:01:36 +03:00
GridLayout {
id: grid
2021-09-18 01:21:14 +03:00
2023-06-02 02:45:24 +03:00
columnSpacing: 0
2021-11-04 01:01:36 +03:00
columns: 2
rowSpacing: 0
2023-06-02 02:45:24 +03:00
width: bootstrapCrosssigning . useableWidth
2021-10-30 01:22:47 +03:00
z: 1
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
Label {
Layout.alignment: Qt . AlignHCenter
Layout.columnSpan: 2
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
color: palette . text
2021-11-04 01:01:36 +03:00
font.pointSize: fontMetrics . font . pointSize * 2
text: qsTr ( "Setup Encryption" )
wrapMode: Text . Wrap
}
Label {
Layout.alignment: Qt . AlignLeft
Layout.columnSpan: 2
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
2021-11-04 01:01:36 +03:00
Layout.maximumWidth: grid . width - Nheko . paddingMedium * 2
2023-06-02 02:29:05 +03:00
color: palette . text
2023-06-02 02:45:24 +03:00
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!" )
2021-11-04 01:01:36 +03:00
wrapMode: Text . Wrap
}
Label {
Layout.alignment: Qt . AlignLeft
Layout.columnSpan: 1
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
2021-11-04 01:01:36 +03:00
Layout.maximumWidth: Math . floor ( grid . width / 2 ) - Nheko . paddingMedium * 2
2023-06-02 02:29:05 +03:00
color: palette . text
2023-06-02 02:45:24 +03:00
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!"
2021-11-04 01:01:36 +03:00
wrapMode: Text . Wrap
}
Item {
Layout.alignment: Qt . AlignLeft | Qt . AlignVCenter
Layout.fillWidth: true
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
Layout.preferredHeight: storeSecretsOnline . height
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
ToggleButton {
id: storeSecretsOnline
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
checked: true
2023-06-02 02:45:24 +03:00
2021-11-04 01:01:36 +03:00
onClicked: console . log ( "Store secrets toggled: " + checked )
2021-09-18 01:21:14 +03:00
}
2021-11-04 01:01:36 +03:00
}
Label {
Layout.alignment: Qt . AlignLeft
Layout.columnSpan: 1
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
2021-11-04 01:01:36 +03:00
Layout.maximumWidth: Math . floor ( grid . width / 2 ) - Nheko . paddingMedium * 2
2023-06-02 02:45:24 +03:00
Layout.rowSpan: 2
2023-06-02 02:29:05 +03:00
color: palette . text
2023-06-02 02:45:24 +03:00
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.)"
visible: storeSecretsOnline . checked
2021-11-04 01:01:36 +03:00
wrapMode: Text . Wrap
}
Item {
2023-06-02 02:45:24 +03:00
Layout.alignment: Qt . AlignLeft | Qt . AlignTop
Layout.fillWidth: true
2021-11-04 01:01:36 +03:00
Layout.margins: Nheko . paddingMedium
Layout.preferredHeight: storeSecretsOnline . height
Layout.rowSpan: usePassword . checked ? 1 : 2
2023-06-02 02:45:24 +03:00
Layout.topMargin: Nheko . paddingLarge
2021-11-04 01:01:36 +03:00
visible: storeSecretsOnline . checked
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
ToggleButton {
id: usePassword
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
checked: false
2021-09-18 01:21:14 +03:00
}
2021-11-04 01:01:36 +03:00
}
MatrixTextField {
id: passwordField
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
Layout.alignment: Qt . AlignLeft | Qt . AlignTop
Layout.columnSpan: 1
Layout.fillWidth: true
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
Layout.maximumWidth: Math . floor ( grid . width / 2 ) - Nheko . paddingMedium * 2
2021-11-04 01:01:36 +03:00
echoMode: TextInput . Password
2023-06-02 02:45:24 +03:00
visible: storeSecretsOnline . checked && usePassword . checked
2021-11-04 01:01:36 +03:00
}
Label {
Layout.alignment: Qt . AlignLeft
Layout.columnSpan: 1
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
2021-11-04 01:01:36 +03:00
Layout.maximumWidth: Math . floor ( grid . width / 2 ) - Nheko . paddingMedium * 2
2023-06-02 02:29:05 +03:00
color: palette . text
2023-06-02 02:45:24 +03:00
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."
2021-11-04 01:01:36 +03:00
wrapMode: Text . Wrap
}
Item {
Layout.alignment: Qt . AlignLeft | Qt . AlignVCenter
Layout.fillWidth: true
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
Layout.preferredHeight: storeSecretsOnline . height
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
ToggleButton {
id: useOnlineKeyBackup
2021-09-18 01:21:14 +03:00
2021-11-04 01:01:36 +03:00
checked: true
2023-06-02 02:45:24 +03:00
2021-11-04 01:01:36 +03:00
onClicked: console . log ( "Online key backup toggled: " + checked )
2021-09-18 01:21:14 +03:00
}
}
2021-11-04 01:01:36 +03:00
}
2021-09-18 01:21:14 +03:00
}
2021-10-17 18:17:29 +03:00
MainWindowDialog {
id: verifyMasterKey
2023-06-08 02:51:27 +03:00
// Workaround palettes not inheriting for popups
palette: timelineRoot . palette
2021-10-30 01:22:47 +03:00
standardButtons: Dialog . Cancel
2021-10-17 18:17:29 +03:00
GridLayout {
id: masterGrid
2021-10-30 01:22:47 +03:00
columns: 1
2023-06-02 02:45:24 +03:00
width: verifyMasterKey . useableWidth
2021-10-30 01:22:47 +03:00
z: 1
2021-11-04 01:01:36 +03:00
Label {
Layout.alignment: Qt . AlignHCenter
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
color: palette . text
2021-11-04 01:01:36 +03:00
//Layout.columnSpan: 2
font.pointSize: fontMetrics . font . pointSize * 2
text: qsTr ( "Activate Encryption" )
wrapMode: Text . Wrap
}
Label {
Layout.alignment: Qt . AlignLeft
2023-06-02 02:45:24 +03:00
Layout.margins: Nheko . paddingMedium
2021-11-04 01:01:36 +03:00
//Layout.columnSpan: 2
Layout.maximumWidth: grid . width - Nheko . paddingMedium * 2
2023-06-02 02:29:05 +03:00
color: palette . text
2023-06-02 02:45:24 +03:00
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." )
2021-11-04 01:01:36 +03:00
wrapMode: Text . Wrap
}
FlatButton {
Layout.alignment: Qt . AlignHCenter
text: qsTr ( "verify" )
2023-06-02 02:45:24 +03:00
2021-11-04 01:01:36 +03:00
onClicked: {
SelfVerificationStatus . verifyMasterKey ( ) ;
verifyMasterKey . close ( ) ;
}
2021-10-30 01:22:47 +03:00
}
2021-11-04 01:01:36 +03:00
FlatButton {
Layout.alignment: Qt . AlignHCenter
text: qsTr ( "enter passphrase" )
2023-06-02 02:45:24 +03:00
visible: SelfVerificationStatus . hasSSSS
2021-11-04 01:01:36 +03:00
onClicked: {
SelfVerificationStatus . verifyMasterKeyWithPassphrase ( ) ;
verifyMasterKey . close ( ) ;
}
2021-10-30 01:22:47 +03:00
}
}
2021-10-17 18:17:29 +03:00
}
2021-09-18 01:21:14 +03:00
Connections {
2023-06-02 02:45:24 +03:00
function onSetupCompleted ( ) {
successDialog . open ( ) ;
}
function onSetupFailed ( m ) {
failureDialog . errorMessage = m ;
failureDialog . open ( ) ;
}
function onShowRecoveryKey ( key ) {
showRecoverKeyDialog . recoveryKey = key ;
showRecoverKeyDialog . open ( ) ;
}
2021-09-18 01:21:14 +03:00
function onStatusChanged ( ) {
console . log ( "STATUS CHANGED: " + SelfVerificationStatus . status ) ;
2021-11-04 01:01:36 +03:00
if ( SelfVerificationStatus . status == SelfVerificationStatus . NoMasterKey ) {
2021-09-18 01:21:14 +03:00
bootstrapCrosssigning . open ( ) ;
2021-11-04 01:01:36 +03:00
} else if ( SelfVerificationStatus . status == SelfVerificationStatus . UnverifiedMasterKey ) {
2021-10-30 01:22:47 +03:00
verifyMasterKey . open ( ) ;
2021-11-04 01:01:36 +03:00
} else {
2021-11-02 00:20:15 +03:00
bootstrapCrosssigning . close ( ) ;
verifyMasterKey . close ( ) ;
}
2021-09-18 01:21:14 +03:00
}
target: SelfVerificationStatus
}
}