Merge lp:~libqtelegram-team/telegram-app/app-crash-secret-chat-accepted into lp:telegram-app/dev

Proposed by Roberto Mier Escandon
Status: Merged
Approved by: MichaƂ Karnicki
Approved revision: 162
Merged at revision: 161
Proposed branch: lp:~libqtelegram-team/telegram-app/app-crash-secret-chat-accepted
Merge into: lp:telegram-app/dev
Diff against target: 110 lines (+30/-1)
5 files modified
lib/core/settings.cpp (+17/-0)
lib/core/settings.h (+2/-0)
lib/secret/secretchat.cpp (+5/-0)
lib/secret/secretchat.h (+1/-0)
lib/telegram.cpp (+5/-1)
To merge this branch: bzr merge lp:~libqtelegram-team/telegram-app/app-crash-secret-chat-accepted
Reviewer Review Type Date Requested Status
libqtelegram team Pending
Review via email: mp+248572@code.launchpad.net

Description of the change

Stored priv key in settings and loading it when app starts up. This lets secret chat not created yet having that private key to finish the shared key creation if needed (when the peer was offline when we sent the chat creation request and accepts the chat creation after we have shutdown + started again the app)

Tested:

With current app-dev branch in ubuntu, and having the peer on Android:

- Put peer in flight mode
- Send a request of a new secret chat from ubuntu to android
- Stopped Tg
- Started Tg
- Peer flight mode off (secret chat is accepted and created on android)
- Checked that the secret chat is created also in ubuntu and can be used

Second test
- Put peer in flight mode
- Send a request of a new secret chat from ubuntu to android
- Stopped Tg
- Peer flight mode off (secret chat is accepted and created on android)
- Started Tg
- Checked that the secret chat is created on ubuntu and can be used

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/core/settings.cpp'
2--- lib/core/settings.cpp 2015-01-28 10:19:49 +0000
3+++ lib/core/settings.cpp 2015-02-04 16:03:39 +0000
4@@ -29,6 +29,8 @@
5 #include <fcntl.h>
6 #include <unistd.h>
7
8+#include <openssl/bn.h>
9+
10 Q_LOGGING_CATEGORY(TG_INIT_SETTINGS, "tg.init.settings")
11
12 Settings::Settings() :
13@@ -214,9 +216,17 @@
14 secretChat->setAdminId(settings.value(ST_ADMIN_ID, 0).toInt());
15 secretChat->setParticipantId(settings.value(ST_PARTICIPANT_ID, 0).toInt());
16 secretChat->setDate(settings.value(ST_DATE, 0).toInt());
17+ secretChat->setState((SecretChat::State)settings.value(ST_STATE, 0).toInt());
18+
19 QByteArray base64Sk = settings.value(ST_SHARED_KEY).toByteArray();
20 QByteArray parsedSk = QByteArray::fromBase64(base64Sk);
21 memcpy(secretChat->sharedKey(), parsedSk.data(), SHARED_KEY_LENGTH);
22+
23+ QByteArray base64Mk = settings.value(ST_MY_KEY).toByteArray();
24+ QByteArray parsedMk = QByteArray::fromBase64(base64Mk);
25+ BIGNUM *myKey = Utils::bytesToBignum(parsedMk);
26+ secretChat->setMyKey(myKey);
27+
28 secretChat->setLayer(settings.value(ST_LAYER, 0).toInt());
29 secretChat->setInSeqNo(settings.value(ST_IN_SEQ_NO, 0).toInt());
30 secretChat->setOutSeqNo(settings.value(ST_OUT_SEQ_NO, 0).toInt());
31@@ -250,8 +260,15 @@
32 settings.setValue(ST_ADMIN_ID, secretChat->adminId());
33 settings.setValue(ST_PARTICIPANT_ID, secretChat->participantId());
34 settings.setValue(ST_DATE, secretChat->date());
35+ settings.setValue(ST_STATE, secretChat->state());
36+
37+ BIGNUM *myKey = secretChat->myKey();
38+ QByteArray myKeyToSave = Utils::bignumToBytes(myKey);
39+ settings.setValue(ST_MY_KEY, myKeyToSave.toBase64());
40+
41 QByteArray sharedKeyToSave((char *)secretChat->sharedKey(), SHARED_KEY_LENGTH);
42 settings.setValue(ST_SHARED_KEY, sharedKeyToSave.toBase64());
43+
44 settings.setValue(ST_LAYER, secretChat->layer());
45 settings.setValue(ST_IN_SEQ_NO, secretChat->inSeqNo());
46 settings.setValue(ST_OUT_SEQ_NO, secretChat->outSeqNo());
47
48=== modified file 'lib/core/settings.h'
49--- lib/core/settings.h 2015-01-28 10:19:49 +0000
50+++ lib/core/settings.h 2015-02-04 16:03:39 +0000
51@@ -66,6 +66,8 @@
52 #define ST_LAYER "layer"
53 #define ST_IN_SEQ_NO "inSeqNo"
54 #define ST_OUT_SEQ_NO "outSeqNo"
55+#define ST_STATE "state"
56+#define ST_MY_KEY "myKey"
57
58 #define DEFAULT_CONFIG_PATH "~/.libqtelegram"
59 #define DEFAULT_PUBLIC_KEY_FILE "qtelegram.pub"
60
61=== modified file 'lib/secret/secretchat.cpp'
62--- lib/secret/secretchat.cpp 2015-01-30 14:24:53 +0000
63+++ lib/secret/secretchat.cpp 2015-02-04 16:03:39 +0000
64@@ -90,6 +90,11 @@
65 return mMyKey;
66 }
67
68+void SecretChat::setMyKey(BIGNUM *myKey) {
69+ BN_clear_free(mMyKey);
70+ mMyKey = BN_dup(myKey);
71+}
72+
73 qint64 SecretChat::keyFingerprint() {
74 if (!mKeyFingerprint) {
75 mKeyFingerprint = Utils::getKeyFingerprint(mSharedKey);
76
77=== modified file 'lib/secret/secretchat.h'
78--- lib/secret/secretchat.h 2015-01-28 15:50:32 +0000
79+++ lib/secret/secretchat.h 2015-02-04 16:03:39 +0000
80@@ -77,6 +77,7 @@
81 void setParticipantId(qint32 participantId);
82 void setDate(qint32 date);
83 void setGAOrB(QByteArray gAOrB);
84+ void setMyKey(BIGNUM *myKey);
85 void setKeyFingerprint(qint64 keyFingerprint);
86 void setLayer(qint32 layer);
87 void setInSeqNo(qint32 inSeqNo);
88
89=== modified file 'lib/telegram.cpp'
90--- lib/telegram.cpp 2015-02-03 19:13:26 +0000
91+++ lib/telegram.cpp 2015-02-04 16:03:39 +0000
92@@ -536,6 +536,7 @@
93 }
94
95 BN_free(r);
96+ mSecretState.save();
97 }
98
99 void Telegram::onMessagesRequestEncryptionEncryptedChat(qint64, const EncryptedChat &chat) {
100@@ -722,7 +723,10 @@
101 qCDebug(TG_LIB_SECRET) << "received keyFingerprint:" << keyFingerprint;
102
103 SecretChat *secretChat = mSecretState.chats().value(chatId);
104- ASSERT(secretChat);
105+ if (!secretChat) {
106+ qCWarning(TG_LIB_SECRET) << "Could not find secret chat with id" << chatId;
107+ return;
108+ }
109
110 createSharedKey(secretChat, mSecretState.p(), gB);
111

Subscribers

People subscribed via source and target branches

to all changes: