Skip to content

Commit 9a750b8

Browse files
committed
Generate mnemophrase
1 parent a41eaa3 commit 9a750b8

11 files changed

+112
-40
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
[submodule "client/3rd/QSimpleCrypto"]
1717
path = client/3rd/QSimpleCrypto
1818
url = https://github.com/amnezia-vpn/QSimpleCrypto.git
19+
[submodule "client/3rd/bip39"]
20+
path = client/3rd/bip39
21+
url = https://github.com/mrfeod/bip39.git

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ if(APPLE AND NOT IOS)
3535
set(CMAKE_OSX_ARCHITECTURES "x86_64")
3636
endif()
3737

38-
# list(APPEND CMAKE_PREFIX_PATH "C:/Qt/6.7.2/msvc2019_64/lib/cmake")
39-
4038
add_subdirectory(client)
4139

4240
if(NOT IOS AND NOT ANDROID)

client/3rd/bip39

Submodule bip39 added at fb21923

client/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ set(HEADERS ${HEADERS}
136136
${CMAKE_CURRENT_LIST_DIR}/core/controllers/vpnConfigurationController.h
137137
${CMAKE_CURRENT_LIST_DIR}/protocols/protocols_defs.h
138138
${CMAKE_CURRENT_LIST_DIR}/protocols/qml_register_protocols.h
139+
${CMAKE_CURRENT_LIST_DIR}/ui/bip39_helper.h
139140
${CMAKE_CURRENT_LIST_DIR}/ui/pages.h
140141
${CMAKE_CURRENT_LIST_DIR}/ui/qautostart.h
141142
${CMAKE_CURRENT_LIST_DIR}/protocols/vpnprotocol.h
@@ -184,6 +185,7 @@ set(SOURCES ${SOURCES}
184185
${CMAKE_CURRENT_LIST_DIR}/core/controllers/serverController.cpp
185186
${CMAKE_CURRENT_LIST_DIR}/core/controllers/vpnConfigurationController.cpp
186187
${CMAKE_CURRENT_LIST_DIR}/protocols/protocols_defs.cpp
188+
${CMAKE_CURRENT_LIST_DIR}/ui/bip39_helper.cpp
187189
${CMAKE_CURRENT_LIST_DIR}/ui/qautostart.cpp
188190
${CMAKE_CURRENT_LIST_DIR}/protocols/vpnprotocol.cpp
189191
${CMAKE_CURRENT_LIST_DIR}/core/sshclient.cpp

client/amnezia_application.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <QLocalServer>
1515

1616
#include "logger.h"
17+
#include "ui/bip39_helper.h"
1718
#include "ui/models/installedAppsModel.h"
1819
#include "version.h"
1920

@@ -218,7 +219,12 @@ void AmneziaApplication::registerTypes()
218219
qmlRegisterSingletonType(QUrl("qrc:/ui/qml/Filters/ContainersModelFilters.qml"), "ContainersModelFilters", 1, 0,
219220
"ContainersModelFilters");
220221

221-
qmlRegisterType<InstalledAppsModel>("InstalledAppsModel", 1, 0, "InstalledAppsModel");
222+
m_bip39Helper.reset(new Bip39Helper());
223+
qmlRegisterSingletonInstance("Bip39Helper", 1, 0, "Bip39Helper",
224+
m_bip39Helper.get());
225+
226+
qmlRegisterType<InstalledAppsModel>("InstalledAppsModel", 1, 0,
227+
"InstalledAppsModel");
222228

223229
Vpn::declareQmlVpnConnectionStateEnum();
224230
PageLoader::declareQmlPageEnum();

client/amnezia_application.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "settings.h"
1616
#include "vpnconnection.h"
1717

18+
#include "ui/bip39_helper.h"
19+
#include "ui/controllers/appSplitTunnelingController.h"
1820
#include "ui/controllers/connectionController.h"
1921
#include "ui/controllers/exportController.h"
2022
#include "ui/controllers/importController.h"
@@ -23,7 +25,6 @@
2325
#include "ui/controllers/settingsController.h"
2426
#include "ui/controllers/sitesController.h"
2527
#include "ui/controllers/systemController.h"
26-
#include "ui/controllers/appSplitTunnelingController.h"
2728
#include "ui/models/containers_model.h"
2829
#include "ui/models/languageModel.h"
2930
#include "ui/models/protocols/cloakConfigModel.h"
@@ -33,6 +34,10 @@
3334
#ifdef Q_OS_WINDOWS
3435
#include "ui/models/protocols/ikev2ConfigModel.h"
3536
#endif
37+
#include "ui/models/apiCountryModel.h"
38+
#include "ui/models/apiServicesModel.h"
39+
#include "ui/models/appSplitTunnelingModel.h"
40+
#include "ui/models/clientManagementModel.h"
3641
#include "ui/models/protocols/awgConfigModel.h"
3742
#include "ui/models/protocols/openvpnConfigModel.h"
3843
#include "ui/models/protocols/shadowsocksConfigModel.h"
@@ -43,10 +48,6 @@
4348
#include "ui/models/services/sftpConfigModel.h"
4449
#include "ui/models/services/socks5ProxyConfigModel.h"
4550
#include "ui/models/sites_model.h"
46-
#include "ui/models/clientManagementModel.h"
47-
#include "ui/models/appSplitTunnelingModel.h"
48-
#include "ui/models/apiServicesModel.h"
49-
#include "ui/models/apiCountryModel.h"
5051

5152
#define amnApp (static_cast<AmneziaApplication *>(QCoreApplication::instance()))
5253

@@ -133,6 +134,8 @@ class AmneziaApplication : public AMNEZIA_BASE_CLASS
133134
QScopedPointer<SystemController> m_systemController;
134135
QScopedPointer<AppSplitTunnelingController> m_appSplitTunnelingController;
135136

137+
QScopedPointer<Bip39Helper> m_bip39Helper;
138+
136139
QNetworkAccessManager *m_nam;
137140

138141
QMetaObject::Connection m_reloadConfigErrorOccurredConnection;

client/cmake/3rdparty.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,18 @@ set(BUILD_WITH_QT6 ON)
7979
add_subdirectory(${CLIENT_ROOT_DIR}/3rd/qtkeychain)
8080
set(LIBS ${LIBS} qt6keychain)
8181

82+
cmake_policy(SET CMP0077 NEW)
83+
add_subdirectory(${CLIENT_ROOT_DIR}/3rd/bip39)
84+
set(LIBS ${LIBS} bip39)
85+
8286
include_directories(
8387
${OPENSSL_INCLUDE_DIR}
8488
${LIBSSH_INCLUDE_DIR}/include
8589
${LIBSSH_ROOT_DIR}/include
8690
${CLIENT_ROOT_DIR}/3rd/libssh/include
8791
${CLIENT_ROOT_DIR}/3rd/QSimpleCrypto/src/include
8892
${CLIENT_ROOT_DIR}/3rd/qtkeychain/qtkeychain
93+
${CLIENT_ROOT_DIR}/3rd/bip39/src/include
8994
${CMAKE_CURRENT_BINARY_DIR}/3rd/qtkeychain
9095
${CMAKE_CURRENT_BINARY_DIR}/3rd/libssh/include
9196
)

client/ui/bip39_helper.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "bip39_helper.h"
2+
3+
#include <iostream> // fix bip39 build
4+
5+
#include <bip39/bip39.h>
6+
7+
#include <QCryptographicHash>
8+
9+
QString Bip39Helper::generatePhrase() {
10+
auto mnemonic = BIP39::generate_mnemonic();
11+
return QString::fromStdString(mnemonic.to_string());
12+
}
13+
14+
bool Bip39Helper::validatePhrase(const QString &phrase) {
15+
BIP39::word_list mnemonic;
16+
auto words = phrase.split(' ');
17+
for (const auto &word : words) {
18+
mnemonic.add(word.toStdString());
19+
}
20+
return BIP39::valid_mnemonic(mnemonic);
21+
}
22+
23+
QString Bip39Helper::generateSha3_512(const QString &input) {
24+
QByteArray byteArray = input.toUtf8();
25+
QByteArray hash =
26+
QCryptographicHash::hash(byteArray, QCryptographicHash::Sha3_512);
27+
return QString(hash.toHex());
28+
}

client/ui/bip39_helper.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef BIP39_HELPER_H
2+
#define BIP39_HELPER_H
3+
4+
#include <QObject>
5+
#include <QString>
6+
7+
class Bip39Helper : public QObject {
8+
Q_OBJECT
9+
public:
10+
Q_INVOKABLE static QString generatePhrase();
11+
Q_INVOKABLE static bool validatePhrase(const QString &phrase);
12+
13+
Q_INVOKABLE static QString generateSha3_512(const QString &input);
14+
};
15+
16+
#endif // BIP39_HELPER_H

client/ui/qml/Pages2/PageSetupWizardStart.qml

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import QtQuick.Layouts
55
import PageEnum 1.0
66
import Style 1.0
77

8+
import Bip39Helper 1.0
9+
810
import "./"
911
import "../Controls2"
1012
import "../Config"
@@ -24,12 +26,13 @@ PageType {
2426

2527
Item {
2628
id: focusItem
27-
KeyNavigation.tab: startButton
29+
KeyNavigation.tab: textKey
2830
}
2931

3032
Header2Type {
3133
Layout.fillWidth: true
3234
Layout.topMargin: 24
35+
Layout.bottomMargin: 10
3336
Layout.rightMargin: 16
3437
Layout.leftMargin: 16
3538

@@ -43,42 +46,46 @@ PageType {
4346
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
4447
Layout.preferredWidth: 180
4548
Layout.preferredHeight: 144
49+
Layout.bottomMargin: 10
4650
}
4751

4852
LabelTextType {
4953
Layout.fillWidth: true
5054
Layout.leftMargin: 16
5155
Layout.rightMargin: 16
56+
Layout.bottomMargin: 10
5257

5358
text: qsTr("FRKN provides complete anonymity without collecting personal data. Upon registration, you will be provided with a unique 12 words mnemophrase.")
5459
}
5560

5661
LabelTextType {
5762
id: warningText
5863
Layout.fillWidth: true
64+
Layout.bottomMargin: 10
5965
Layout.leftMargin: 16
6066
Layout.rightMargin: 16
6167
visible: false
6268

6369
text: qsTr("● Record and securely save your mnemophrase\n\n● Do not share your mnemophrase with anyone\n\n● In case of loss, recovery is impossible")
6470
}
6571

66-
Item
67-
{
68-
Layout.fillHeight: true
69-
}
70-
7172
TextFieldWithHeaderType {
7273
id: textKey
7374

7475
Layout.fillWidth: true
7576
Layout.leftMargin: 16
7677
Layout.rightMargin: 16
78+
Layout.bottomMargin: 10
79+
80+
property bool hasValidPhrase: Bip39Helper.validatePhrase(textField.text)
7781

7882
headerText: qsTr("Your 12 words mnemophrase")
7983
buttonText: qsTr("Insert")
8084
textFieldPlaceholderText: qsTr("frog roof kitchen nature ...")
8185

86+
borderColor: textField.text === "" ? AmneziaStyle.color.slateGray : (hasValidPhrase ? AmneziaStyle.color.goldenApricot : AmneziaStyle.color.vibrantRed)
87+
borderFocusedColor: textField.text === "" ? AmneziaStyle.color.paleGray : (hasValidPhrase ? AmneziaStyle.color.goldenApricot : AmneziaStyle.color.vibrantRed)
88+
8289
clickedFunc: function() {
8390
textField.text = ""
8491
textField.paste()
@@ -87,71 +94,74 @@ PageType {
8794
KeyNavigation.tab: lastItemTabClicked(focusItem)
8895
}
8996

97+
Item
98+
{
99+
Layout.fillHeight: true
100+
}
101+
90102
BasicButtonType {
91103
id: copyButton
92104
Layout.fillWidth: true
93105
Layout.leftMargin: 16
94106
Layout.rightMargin: 16
107+
Layout.bottomMargin: 10
95108
visible: false
96109

110+
property bool phraseCopied: false
111+
97112
text: qsTr("Copy mnemonic phrase")
98113

99114
clickedFunc: function() {
100115
textKey.textField.selectAll()
101116
textKey.textField.copy()
102117
textKey.textField.deselect()
118+
phraseCopied = true
103119
}
104120

105121
Keys.onTabPressed: lastItemTabClicked(focusItem)
106122
}
107123

108124
BasicButtonType {
109-
id: loginButton
125+
id: registerButton
110126
Layout.fillWidth: true
111127
Layout.leftMargin: 16
112128
Layout.rightMargin: 16
113-
Layout.bottomMargin: registerButton.visible ? 0 : 48
129+
Layout.bottomMargin: 10
114130

115-
text: qsTr("Log in")
131+
text: qsTr("Register")
132+
133+
visible: !textKey.hasValidPhrase
116134

117135
clickedFunc: function() {
118-
// TODO Check mnemonic phrase
119-
// TODO If mnemonic phrase is valid - download and add configs
120-
// See how PageSetupWizardConfigSource.qml manages it
136+
textKey.buttonText = ""
137+
textKey.textFieldText = Bip39Helper.generatePhrase()
138+
textKey.textFieldEditable = false
139+
140+
visible = false
141+
copyButton.visible = true
142+
warningText.visible = true
121143
}
122144

123145
Keys.onTabPressed: lastItemTabClicked(focusItem)
124146
}
125147

126148
BasicButtonType {
127-
id: registerButton
149+
id: loginButton
128150
Layout.fillWidth: true
129151
Layout.leftMargin: 16
130152
Layout.rightMargin: 16
131153
Layout.bottomMargin: 48
132154

133-
text: qsTr("Register")
155+
enabled: textKey.hasValidPhrase && (!copyButton.visible || copyButton.phraseCopied)
134156

135-
clickedFunc: function() {
136-
// Generate BIP39 mnemonic phrase
137-
// SHA3_512 hex is the user id
138-
// TODO Receive mnemonic phrase from the server
139-
// TODO Set mnemonic phrase to textKey.textFieldText
140-
// This is valid only for testing purposes
141-
142-
// Redirect to login page with mnemophrase
157+
text: qsTr("Log in")
143158

159+
clickedFunc: function() {
160+
// TODO Request configs
144161
// Auth with SHA3_512 in FRKN and receive configs
145-
146162
// Use mock server to receive configs
147-
148-
textKey.buttonText = ""
149-
textKey.textFieldText = "comfort search stem execute face relief exhaust happy erode movie swing one"
150-
textKey.textFieldEditable = false
151-
152-
visible = false
153-
copyButton.visible = true
154-
warningText.visible = true
163+
// See how PageSetupWizardConfigSource.qml manages it
164+
console.log("User hash: " + Bip39Helper.generateSha3_512(textKey.textFieldText))
155165
}
156166

157167
Keys.onTabPressed: lastItemTabClicked(focusItem)

client/ui/qml/main2.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Window {
3030
PageController.closeWindow()
3131
}
3232

33-
title: "AmneziaVPN"
33+
title: "FRKN"
3434

3535
Connections {
3636
target: PageController

0 commit comments

Comments
 (0)