Merge lp:~libqtelegram-team/telegram-app/dev-401 into lp:telegram-app/dev
- dev-401
- Merge into libqtelegram-dev
Proposed by
Roberto Mier Escandon
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Michał Karnicki | ||||
Approved revision: | 139 | ||||
Merged at revision: | 140 | ||||
Proposed branch: | lp:~libqtelegram-team/telegram-app/dev-401 | ||||
Merge into: | lp:telegram-app/dev | ||||
Diff against target: |
402 lines (+118/-114) 8 files modified
lib/core/constants.h (+7/-2) lib/core/dcauth.cpp (+10/-89) lib/core/dcprovider.cpp (+24/-19) lib/core/settings.cpp (+2/-1) lib/core/tlvalues.h (+1/-0) lib/core/utils.cpp (+66/-3) lib/core/utils.h (+7/-0) qmlplugin/models/dialogsmodel.cpp (+1/-0) |
||||
To merge this branch: | bzr merge lp:~libqtelegram-team/telegram-app/dev-401 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michał Karnicki (community) | Approve | ||
Review via email: mp+245323@code.launchpad.net |
Commit message
Description of the change
Changed default DC from 1 to 4. This is a workaround to fix the problem. Not known exactly the cause of the bug but this fixes it
Also simplified the process of processResPQAnswer in DcAuth class. This way code is better to be figured out if needed to be changed (and avoids original telegram-cli code way)
To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) : | # |
- 138. By Roberto Mier Escandon
-
fixed as review comments
- 139. By Roberto Mier Escandon
-
merged dev
Revision history for this message
Roberto Mier Escandon (rmescandon) wrote : | # |
Revision history for this message
Michał Karnicki (karni) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/core/constants.h' | |||
2 | --- lib/core/constants.h 2014-12-09 17:28:59 +0000 | |||
3 | +++ lib/core/constants.h 2015-01-07 16:21:39 +0000 | |||
4 | @@ -28,8 +28,6 @@ | |||
5 | 28 | #define ENCRYPT_BUFFER_INTS 16384 | 28 | #define ENCRYPT_BUFFER_INTS 16384 |
6 | 29 | #define DECRYPT_BUFFER_INTS 16384 | 29 | #define DECRYPT_BUFFER_INTS 16384 |
7 | 30 | 30 | ||
8 | 31 | #define LIBQTELEGRAM_SERVER "173.240.5.1" | ||
9 | 32 | #define LIBQTELEGRAM_SERVER_TEST "173.240.5.253" | ||
10 | 33 | // These are the the original | 31 | // These are the the original |
11 | 34 | #define LIBQTELEGRAM_APP_HASH "c68fd5e560aa84dd4b6ad6f489164790" | 32 | #define LIBQTELEGRAM_APP_HASH "c68fd5e560aa84dd4b6ad6f489164790" |
12 | 35 | #define LIBQTELEGRAM_APP_ID 12433 | 33 | #define LIBQTELEGRAM_APP_ID 12433 |
13 | @@ -40,6 +38,13 @@ | |||
14 | 40 | //#define LIBQTELEGRAM_APP_HASH "4b7f87d44de5e0a22248597939c848ae" | 38 | //#define LIBQTELEGRAM_APP_HASH "4b7f87d44de5e0a22248597939c848ae" |
15 | 41 | //#define LIBQTELEGRAM_APP_ID 11986 | 39 | //#define LIBQTELEGRAM_APP_ID 11986 |
16 | 42 | 40 | ||
17 | 41 | #define PRODUCTION_DEFAULT_DC_ID 4 | ||
18 | 42 | #define PRODUCTION_DEFAULT_DC_HOST "149.154.167.91" | ||
19 | 43 | #define PRODUCTION_DEFAULT_DC_PORT 443 | ||
20 | 44 | #define TEST_DEFAULT_DC_ID 1 | ||
21 | 45 | #define TEST_DEFAULT_DC_HOST "173.240.5.253" | ||
22 | 46 | #define TEST_DEFAULT_DC_PORT 80 | ||
23 | 47 | |||
24 | 43 | #define LIBQTELEGRAM_BUILD "001" | 48 | #define LIBQTELEGRAM_BUILD "001" |
25 | 44 | #define LIBQTELEGRAM_VERSION "1.0.0-SNAPSHOT" | 49 | #define LIBQTELEGRAM_VERSION "1.0.0-SNAPSHOT" |
26 | 45 | 50 | ||
27 | 46 | 51 | ||
28 | === modified file 'lib/core/dcauth.cpp' | |||
29 | --- lib/core/dcauth.cpp 2014-12-02 13:01:22 +0000 | |||
30 | +++ lib/core/dcauth.cpp 2015-01-07 16:21:39 +0000 | |||
31 | @@ -107,44 +107,9 @@ | |||
32 | 107 | 107 | ||
33 | 108 | uint p1 = 0, p2 = 0; | 108 | uint p1 = 0, p2 = 0; |
34 | 109 | 109 | ||
73 | 110 | qCDebug(TG_AUTH_DCAUTH) << what << "received"; | 110 | qCDebug(TG_AUTH_DCAUTH) << "received pq =" << what; |
74 | 111 | 111 | ||
75 | 112 | qint32 it = 0; | 112 | qint64 g = Utils::findDivider(what); |
38 | 113 | quint64 g = 0; | ||
39 | 114 | for (i = 0; i < 3 || it < 1000; i++) { | ||
40 | 115 | qint32 q = ((lrand48() & 15) + 17) % what; | ||
41 | 116 | quint64 x = (qint64)lrand48 () % (what - 1) + 1, y = x; | ||
42 | 117 | qint32 lim = 1 << (i + 18); | ||
43 | 118 | qint32 j; | ||
44 | 119 | for (j = 1; j < lim; j++) { | ||
45 | 120 | ++it; | ||
46 | 121 | quint64 a = x, b = x, c = q; | ||
47 | 122 | while (b) { | ||
48 | 123 | if (b & 1) { | ||
49 | 124 | c += a; | ||
50 | 125 | if (c >= what) { | ||
51 | 126 | c -= what; | ||
52 | 127 | } | ||
53 | 128 | } | ||
54 | 129 | a += a; | ||
55 | 130 | if (a >= what) { | ||
56 | 131 | a -= what; | ||
57 | 132 | } | ||
58 | 133 | b >>= 1; | ||
59 | 134 | } | ||
60 | 135 | x = c; | ||
61 | 136 | quint64 z = x < y ? what + x - y : x - y; | ||
62 | 137 | g = Utils::gcd (z, what); | ||
63 | 138 | if (g != 1) { | ||
64 | 139 | break; | ||
65 | 140 | } | ||
66 | 141 | if (!(j & (j - 1))) { | ||
67 | 142 | y = x; | ||
68 | 143 | } | ||
69 | 144 | } | ||
70 | 145 | if (g > 1 && g < what) break; | ||
71 | 146 | } | ||
72 | 147 | |||
76 | 148 | mAsserter.check(g > 1 && g < what); | 113 | mAsserter.check(g > 1 && g < what); |
77 | 149 | p1 = g; | 114 | p1 = g; |
78 | 150 | p2 = what / g; | 115 | p2 = what / g; |
79 | @@ -152,7 +117,7 @@ | |||
80 | 152 | uint t = p1; p1 = p2; p2 = t; | 117 | uint t = p1; p1 = p2; p2 = t; |
81 | 153 | } | 118 | } |
82 | 154 | 119 | ||
84 | 155 | qCDebug(TG_AUTH_DCAUTH) << "p1=" << p1 << ", p2=" << p2 << ", " << it << "iterations"; | 120 | qCDebug(TG_AUTH_DCAUTH) << "p1 =" << p1 << ", p2 =" << p2; |
85 | 156 | 121 | ||
86 | 157 | mAsserter.check(*(qint32 *) (from) == TL_Vector); | 122 | mAsserter.check(*(qint32 *) (from) == TL_Vector); |
87 | 158 | qint32 fingerprints_num = *(qint32 *)(from + 4); | 123 | qint32 fingerprints_num = *(qint32 *)(from + 4); |
88 | @@ -175,31 +140,11 @@ | |||
89 | 175 | p.appendInt(TL_PQInnerData); | 140 | p.appendInt(TL_PQInnerData); |
90 | 176 | p.appendCString(buffer + 57, clen); | 141 | p.appendCString(buffer + 57, clen); |
91 | 177 | 142 | ||
104 | 178 | if (p1 < 256) { | 143 | QByteArray p1BigEndianBytes = Utils::pToBigEndian(p1); |
105 | 179 | clen = 1; | 144 | p.appendBytes(p1BigEndianBytes); |
94 | 180 | } else if (p1 < 65536) { | ||
95 | 181 | clen = 2; | ||
96 | 182 | } else if (p1 < 16777216) { | ||
97 | 183 | clen = 3; | ||
98 | 184 | } else { | ||
99 | 185 | clen = 4; | ||
100 | 186 | } | ||
101 | 187 | p1 = __builtin_bswap32 (p1); | ||
102 | 188 | p.appendCString((char *)&p1 + 4 - clen, clen); | ||
103 | 189 | p1 = __builtin_bswap32 (p1); | ||
106 | 190 | 145 | ||
119 | 191 | if (p2 < 256) { | 146 | QByteArray p2BigEndianBytes = Utils::pToBigEndian(p2); |
120 | 192 | clen = 1; | 147 | p.appendBytes(p2BigEndianBytes); |
109 | 193 | } else if (p2 < 65536) { | ||
110 | 194 | clen = 2; | ||
111 | 195 | } else if (p2 < 16777216) { | ||
112 | 196 | clen = 3; | ||
113 | 197 | } else { | ||
114 | 198 | clen = 4; | ||
115 | 199 | } | ||
116 | 200 | p2 = __builtin_bswap32 (p2); | ||
117 | 201 | p.appendCString((char *)&p2 + 4 - clen, clen); | ||
118 | 202 | p2 = __builtin_bswap32 (p2); | ||
121 | 203 | 148 | ||
122 | 204 | p.appendInts((qint32 *) m_nonce, 4); | 149 | p.appendInts((qint32 *) m_nonce, 4); |
123 | 205 | p.appendInts((qint32 *) m_serverNonce, 4); | 150 | p.appendInts((qint32 *) m_serverNonce, 4); |
124 | @@ -215,32 +160,8 @@ | |||
125 | 215 | p.appendInt(TL_ReqDHParams); | 160 | p.appendInt(TL_ReqDHParams); |
126 | 216 | p.appendInts((qint32 *) m_nonce, 4); | 161 | p.appendInts((qint32 *) m_nonce, 4); |
127 | 217 | p.appendInts((qint32 *) m_serverNonce, 4); | 162 | p.appendInts((qint32 *) m_serverNonce, 4); |
154 | 218 | 163 | p.appendBytes(p1BigEndianBytes); | |
155 | 219 | if (p1 < 256) { | 164 | p.appendBytes(p2BigEndianBytes); |
130 | 220 | clen = 1; | ||
131 | 221 | } else if (p1 < 65536) { | ||
132 | 222 | clen = 2; | ||
133 | 223 | } else if (p1 < 16777216) { | ||
134 | 224 | clen = 3; | ||
135 | 225 | } else { | ||
136 | 226 | clen = 4; | ||
137 | 227 | } | ||
138 | 228 | p1 = __builtin_bswap32 (p1); | ||
139 | 229 | p.appendCString((char *)&p1 + 4 - clen, clen); | ||
140 | 230 | p1 = __builtin_bswap32 (p1); | ||
141 | 231 | if (p2 < 256) { | ||
142 | 232 | clen = 1; | ||
143 | 233 | } else if (p2 < 65536) { | ||
144 | 234 | clen = 2; | ||
145 | 235 | } else if (p2 < 16777216) { | ||
146 | 236 | clen = 3; | ||
147 | 237 | } else { | ||
148 | 238 | clen = 4; | ||
149 | 239 | } | ||
150 | 240 | p2 = __builtin_bswap32 (p2); | ||
151 | 241 | p.appendCString((char *)&p2 + 4 - clen, clen); | ||
152 | 242 | p2 = __builtin_bswap32 (p2); | ||
153 | 243 | |||
156 | 244 | p.appendLong(Settings::getInstance()->pkFingerprint()); | 165 | p.appendLong(Settings::getInstance()->pkFingerprint()); |
157 | 245 | p.appendCString((char *) encryptBuffer, l); | 166 | p.appendCString((char *) encryptBuffer, l); |
158 | 246 | 167 | ||
159 | 247 | 168 | ||
160 | === modified file 'lib/core/dcprovider.cpp' | |||
161 | --- lib/core/dcprovider.cpp 2014-11-18 17:13:16 +0000 | |||
162 | +++ lib/core/dcprovider.cpp 2015-01-07 16:21:39 +0000 | |||
163 | @@ -1,8 +1,5 @@ | |||
164 | 1 | /* | 1 | /* |
165 | 2 | * Copyright 2014 Canonical Ltd. | 2 | * Copyright 2014 Canonical Ltd. |
166 | 3 | * Authors: | ||
167 | 4 | * Roberto Mier | ||
168 | 5 | * Tiago Herrmann | ||
169 | 6 | * | 3 | * |
170 | 7 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
171 | 8 | * it under the terms of the GNU General Public License as published by | 5 | * it under the terms of the GNU General Public License as published by |
172 | @@ -87,46 +84,54 @@ | |||
173 | 87 | */ | 84 | */ |
174 | 88 | 85 | ||
175 | 89 | // 1.- Get the settings dcs, fullfill m_dcs map and current dc num | 86 | // 1.- Get the settings dcs, fullfill m_dcs map and current dc num |
178 | 90 | Settings *s = Settings::getInstance(); | 87 | Settings *settings = Settings::getInstance(); |
179 | 91 | QList<DC *> dcsList = s->dcsList(); | 88 | QList<DC *> dcsList = settings->dcsList(); |
180 | 92 | 89 | ||
181 | 93 | Q_FOREACH (DC *dc, dcsList) { | 90 | Q_FOREACH (DC *dc, dcsList) { |
182 | 94 | mDcs.insert(dc->id(), dc); | 91 | mDcs.insert(dc->id(), dc); |
183 | 95 | } | 92 | } |
184 | 96 | 93 | ||
185 | 94 | qint32 defaultDcId = settings->testMode() ? TEST_DEFAULT_DC_ID : PRODUCTION_DEFAULT_DC_ID; | ||
186 | 95 | |||
187 | 97 | // 2.- connect to working DC | 96 | // 2.- connect to working DC |
192 | 98 | if (s->workingDcNum() == 1) { | 97 | if (settings->workingDcNum() == defaultDcId) { |
193 | 99 | // If dcId == 1, it's the default one, so call default host and port | 98 | // If dcId == defaultDcId, it's the default one, so call default host and port |
194 | 100 | if (!mDcs.value(1, 0)) { | 99 | if (!mDcs.value(defaultDcId, 0)) { |
195 | 101 | mDcs[1] = new DC(1); | 100 | mDcs[defaultDcId] = new DC(defaultDcId); |
196 | 102 | } | 101 | } |
197 | 103 | // if dc hasn't key created, create it | 102 | // if dc hasn't key created, create it |
199 | 104 | if (mDcs[1]->state() < DC::authKeyCreated) { | 103 | if (mDcs[defaultDcId]->state() < DC::authKeyCreated) { |
200 | 104 | QString defaultDcHost = PRODUCTION_DEFAULT_DC_HOST; | ||
201 | 105 | qint32 defaultDcPort = PRODUCTION_DEFAULT_DC_PORT; | ||
202 | 106 | if (settings->testMode()) { | ||
203 | 107 | defaultDcHost = TEST_DEFAULT_DC_HOST; | ||
204 | 108 | defaultDcPort = TEST_DEFAULT_DC_PORT; | ||
205 | 109 | } | ||
206 | 105 | // create a dc authenticator based in dc info | 110 | // create a dc authenticator based in dc info |
211 | 106 | s->testMode() ? mDcs[1]->setHost(LIBQTELEGRAM_SERVER_TEST) : mDcs[1]->setHost(LIBQTELEGRAM_SERVER); | 111 | mDcs[defaultDcId]->setHost(defaultDcHost); |
212 | 107 | mDcs[1]->setPort(443); | 112 | mDcs[defaultDcId]->setPort(defaultDcPort); |
213 | 108 | DCAuth *dcAuth = new DCAuth(mDcs[1], this); | 113 | DCAuth *dcAuth = new DCAuth(mDcs[defaultDcId], this); |
214 | 109 | mDcAuths.insert(1, dcAuth); | 114 | mDcAuths.insert(defaultDcId, dcAuth); |
215 | 110 | connect(dcAuth, SIGNAL(fatalError()), this, SLOT(logOut())); | 115 | connect(dcAuth, SIGNAL(fatalError()), this, SLOT(logOut())); |
216 | 111 | connect(dcAuth, SIGNAL(fatalError()), this, SIGNAL(fatalError())); | 116 | connect(dcAuth, SIGNAL(fatalError()), this, SIGNAL(fatalError())); |
217 | 112 | connect(dcAuth, SIGNAL(dcReady(DC*)), this, SLOT(onDcReady(DC*))); | 117 | connect(dcAuth, SIGNAL(dcReady(DC*)), this, SLOT(onDcReady(DC*))); |
218 | 113 | dcAuth->createAuthKey(); | 118 | dcAuth->createAuthKey(); |
219 | 114 | } else { | 119 | } else { |
221 | 115 | onDcReady(mDcs[1]); | 120 | onDcReady(mDcs[defaultDcId]); |
222 | 116 | } | 121 | } |
223 | 117 | 122 | ||
224 | 118 | } else { | 123 | } else { |
225 | 119 | // In any other case, the host and port have been retrieved from auth file settings and the DC object is already created | 124 | // In any other case, the host and port have been retrieved from auth file settings and the DC object is already created |
227 | 120 | if (mDcs[s->workingDcNum()]->state() < DC::authKeyCreated) { | 125 | if (mDcs[settings->workingDcNum()]->state() < DC::authKeyCreated) { |
228 | 121 | // create a dc authenticator based in dc info | 126 | // create a dc authenticator based in dc info |
231 | 122 | DCAuth *dcAuth = new DCAuth(mDcs[s->workingDcNum()]); | 127 | DCAuth *dcAuth = new DCAuth(mDcs[settings->workingDcNum()]); |
232 | 123 | mDcAuths.insert(s->workingDcNum(), dcAuth); | 128 | mDcAuths.insert(settings->workingDcNum(), dcAuth); |
233 | 124 | connect(dcAuth, SIGNAL(fatalError()), this, SLOT(logOut())); | 129 | connect(dcAuth, SIGNAL(fatalError()), this, SLOT(logOut())); |
234 | 125 | connect(dcAuth, SIGNAL(fatalError()), this, SIGNAL(fatalError())); | 130 | connect(dcAuth, SIGNAL(fatalError()), this, SIGNAL(fatalError())); |
235 | 126 | connect(dcAuth, SIGNAL(dcReady(DC*)), this, SLOT(onDcReady(DC*))); | 131 | connect(dcAuth, SIGNAL(dcReady(DC*)), this, SLOT(onDcReady(DC*))); |
236 | 127 | dcAuth->createAuthKey(); | 132 | dcAuth->createAuthKey(); |
237 | 128 | } else { | 133 | } else { |
239 | 129 | onDcReady(mDcs[s->workingDcNum()]); | 134 | onDcReady(mDcs[settings->workingDcNum()]); |
240 | 130 | } | 135 | } |
241 | 131 | } | 136 | } |
242 | 132 | } | 137 | } |
243 | 133 | 138 | ||
244 | === modified file 'lib/core/settings.cpp' | |||
245 | --- lib/core/settings.cpp 2014-11-18 17:13:16 +0000 | |||
246 | +++ lib/core/settings.cpp 2015-01-07 16:21:39 +0000 | |||
247 | @@ -144,7 +144,8 @@ | |||
248 | 144 | void Settings::readAuthFile() { | 144 | void Settings::readAuthFile() { |
249 | 145 | QSettings settings(m_authFilename, QSettings::IniFormat); | 145 | QSettings settings(m_authFilename, QSettings::IniFormat); |
250 | 146 | Settings::getInstance()->testMode() ? settings.beginGroup(ST_TEST) : settings.beginGroup(ST_PRODUCTION); | 146 | Settings::getInstance()->testMode() ? settings.beginGroup(ST_TEST) : settings.beginGroup(ST_PRODUCTION); |
252 | 147 | m_workingDcNum = settings.value(ST_WORKING_DC_NUM, 1).toInt(); | 147 | qint32 defaultDcId = m_testMode ? TEST_DEFAULT_DC_ID : PRODUCTION_DEFAULT_DC_ID; |
253 | 148 | m_workingDcNum = settings.value(ST_WORKING_DC_NUM, defaultDcId).toInt(); | ||
254 | 148 | m_ourId = settings.value(ST_OUR_ID).toInt(); | 149 | m_ourId = settings.value(ST_OUR_ID).toInt(); |
255 | 149 | 150 | ||
256 | 150 | qCDebug(TG_INIT_SETTINGS) << "workingDcNum:" << m_workingDcNum; | 151 | qCDebug(TG_INIT_SETTINGS) << "workingDcNum:" << m_workingDcNum; |
257 | 151 | 152 | ||
258 | === modified file 'lib/core/tlvalues.h' | |||
259 | --- lib/core/tlvalues.h 2014-11-18 17:13:16 +0000 | |||
260 | +++ lib/core/tlvalues.h 2015-01-07 16:21:39 +0000 | |||
261 | @@ -27,6 +27,7 @@ | |||
262 | 27 | TL_ResPQ = 0x05162463, | 27 | TL_ResPQ = 0x05162463, |
263 | 28 | TL_ReqDHParams = 0xd712e4be, | 28 | TL_ReqDHParams = 0xd712e4be, |
264 | 29 | TL_PQInnerData = 0x83c95aec, | 29 | TL_PQInnerData = 0x83c95aec, |
265 | 30 | TL_PQInnerDataTemp = 0x3c6a84d4, | ||
266 | 30 | TL_ServerDHParamsOK = 0xd0e8075c, | 31 | TL_ServerDHParamsOK = 0xd0e8075c, |
267 | 31 | TL_ServerDHParamsFail = 0x79cb045d, | 32 | TL_ServerDHParamsFail = 0x79cb045d, |
268 | 32 | TL_ServerDHInnerData = 0xb5890dba, | 33 | TL_ServerDHInnerData = 0xb5890dba, |
269 | 33 | 34 | ||
270 | === modified file 'lib/core/utils.cpp' | |||
271 | --- lib/core/utils.cpp 2014-11-17 20:28:24 +0000 | |||
272 | +++ lib/core/utils.cpp 2015-01-07 16:21:39 +0000 | |||
273 | @@ -33,6 +33,11 @@ | |||
274 | 33 | #include <QtMultimedia/QMediaResource> | 33 | #include <QtMultimedia/QMediaResource> |
275 | 34 | #include <QProcess> | 34 | #include <QProcess> |
276 | 35 | #include <QStringList> | 35 | #include <QStringList> |
277 | 36 | #include <QtCore> | ||
278 | 37 | |||
279 | 38 | |||
280 | 39 | Q_LOGGING_CATEGORY(TG_UTILS, "tg.utils") | ||
281 | 40 | |||
282 | 36 | 41 | ||
283 | 37 | Utils::Utils(QObject *parent) : | 42 | Utils::Utils(QObject *parent) : |
284 | 38 | QObject(parent) | 43 | QObject(parent) |
285 | @@ -157,16 +162,16 @@ | |||
286 | 157 | RSA *pubKey = NULL; | 162 | RSA *pubKey = NULL; |
287 | 158 | FILE *f = fopen (publicKeyName.toLocal8Bit().data(), "r"); | 163 | FILE *f = fopen (publicKeyName.toLocal8Bit().data(), "r"); |
288 | 159 | if (f == NULL) { | 164 | if (f == NULL) { |
290 | 160 | qWarning() << "Couldn't open public key file" << publicKeyName; | 165 | qCWarning(TG_UTILS) << "Couldn't open public key file" << publicKeyName; |
291 | 161 | return NULL; | 166 | return NULL; |
292 | 162 | } | 167 | } |
293 | 163 | pubKey = PEM_read_RSAPublicKey (f, NULL, NULL, NULL); | 168 | pubKey = PEM_read_RSAPublicKey (f, NULL, NULL, NULL); |
294 | 164 | fclose (f); | 169 | fclose (f); |
295 | 165 | if (pubKey == NULL) { | 170 | if (pubKey == NULL) { |
297 | 166 | qWarning() << "PEM_read_RSAPublicKey returns NULL"; | 171 | qCWarning(TG_UTILS) << "PEM_read_RSAPublicKey returns NULL"; |
298 | 167 | return NULL; | 172 | return NULL; |
299 | 168 | } | 173 | } |
301 | 169 | qDebug() << "public key" << publicKeyName << "loaded successfully"; | 174 | qCDebug(TG_UTILS) << "public key" << publicKeyName << "loaded successfully"; |
302 | 170 | return pubKey; | 175 | return pubKey; |
303 | 171 | } | 176 | } |
304 | 172 | 177 | ||
305 | @@ -312,3 +317,61 @@ | |||
306 | 312 | 317 | ||
307 | 313 | return filteredChars; | 318 | return filteredChars; |
308 | 314 | } | 319 | } |
309 | 320 | |||
310 | 321 | QByteArray Utils::pToBigEndian(quint32 p) {; | ||
311 | 322 | qint32 pLength; | ||
312 | 323 | if (p < (1 << 8)) { | ||
313 | 324 | pLength = 1; | ||
314 | 325 | } else if (p < (1 << 16)) { | ||
315 | 326 | pLength = 2; | ||
316 | 327 | } else if (p < (1 << 24)) { | ||
317 | 328 | pLength = 3; | ||
318 | 329 | } else { | ||
319 | 330 | pLength = 4; | ||
320 | 331 | } | ||
321 | 332 | |||
322 | 333 | uchar beP[4]; | ||
323 | 334 | qToBigEndian(p, beP); | ||
324 | 335 | |||
325 | 336 | return QByteArray((const char *)beP, pLength); | ||
326 | 337 | } | ||
327 | 338 | |||
328 | 339 | qint64 Utils::findDivider(qint64 pq) { | ||
329 | 340 | qint32 it = 0; | ||
330 | 341 | quint64 g = 0; | ||
331 | 342 | for (int i = 0; i < 3 || it < 1000; i++) { | ||
332 | 343 | qint32 q = ((lrand48() & 15) + 17) % pq; | ||
333 | 344 | quint64 x = (qint64)lrand48 () % (pq - 1) + 1, y = x; | ||
334 | 345 | qint32 lim = 1 << (i + 18); | ||
335 | 346 | qint32 j; | ||
336 | 347 | for (j = 1; j < lim; j++) { | ||
337 | 348 | ++it; | ||
338 | 349 | quint64 a = x, b = x, c = q; | ||
339 | 350 | while (b) { | ||
340 | 351 | if (b & 1) { | ||
341 | 352 | c += a; | ||
342 | 353 | if (c >= pq) { | ||
343 | 354 | c -= pq; | ||
344 | 355 | } | ||
345 | 356 | } | ||
346 | 357 | a += a; | ||
347 | 358 | if (a >= pq) { | ||
348 | 359 | a -= pq; | ||
349 | 360 | } | ||
350 | 361 | b >>= 1; | ||
351 | 362 | } | ||
352 | 363 | x = c; | ||
353 | 364 | quint64 z = x < y ? pq + x - y : x - y; | ||
354 | 365 | g = Utils::gcd(z, pq); | ||
355 | 366 | if (g != 1) { | ||
356 | 367 | break; | ||
357 | 368 | } | ||
358 | 369 | if (!(j & (j - 1))) { | ||
359 | 370 | y = x; | ||
360 | 371 | } | ||
361 | 372 | } | ||
362 | 373 | if (g > 1 && g < pq) break; | ||
363 | 374 | } | ||
364 | 375 | qCDebug(TG_UTILS) << "got" << g << "divider after" << it << "iterations"; | ||
365 | 376 | return g; | ||
366 | 377 | } | ||
367 | 315 | 378 | ||
368 | === modified file 'lib/core/utils.h' | |||
369 | --- lib/core/utils.h 2014-11-17 11:31:25 +0000 | |||
370 | +++ lib/core/utils.h 2015-01-07 16:21:39 +0000 | |||
371 | @@ -35,6 +35,10 @@ | |||
372 | 35 | #include <QObject> | 35 | #include <QObject> |
373 | 36 | #include <openssl/bn.h> | 36 | #include <openssl/bn.h> |
374 | 37 | #include "constants.h" | 37 | #include "constants.h" |
375 | 38 | #include <QLoggingCategory> | ||
376 | 39 | |||
377 | 40 | Q_DECLARE_LOGGING_CATEGORY(TG_UTILS) | ||
378 | 41 | |||
379 | 38 | 42 | ||
380 | 39 | class Utils : public QObject | 43 | class Utils : public QObject |
381 | 40 | { | 44 | { |
382 | @@ -76,6 +80,9 @@ | |||
383 | 76 | static QString createThumbnail(const QString &resource); | 80 | static QString createThumbnail(const QString &resource); |
384 | 77 | 81 | ||
385 | 78 | static QString parsePhoneNumberDigits(const QString &phoneNumber); | 82 | static QString parsePhoneNumberDigits(const QString &phoneNumber); |
386 | 83 | |||
387 | 84 | static QByteArray pToBigEndian(quint32 p); | ||
388 | 85 | static qint64 findDivider(qint64 pq); | ||
389 | 79 | }; | 86 | }; |
390 | 80 | 87 | ||
391 | 81 | #endif // UTILS_H | 88 | #endif // UTILS_H |
392 | 82 | 89 | ||
393 | === modified file 'qmlplugin/models/dialogsmodel.cpp' | |||
394 | --- qmlplugin/models/dialogsmodel.cpp 2014-12-15 15:56:52 +0000 | |||
395 | +++ qmlplugin/models/dialogsmodel.cpp 2015-01-07 16:21:39 +0000 | |||
396 | @@ -268,6 +268,7 @@ | |||
397 | 268 | } | 268 | } |
398 | 269 | 269 | ||
399 | 270 | qCDebug(TG_PLUGIN_LOGIC) << "fetch more:" << mCanFetchMore; | 270 | qCDebug(TG_PLUGIN_LOGIC) << "fetch more:" << mCanFetchMore; |
400 | 271 | |||
401 | 271 | return mCanFetchMore; | 272 | return mCanFetchMore; |
402 | 272 | } | 273 | } |
403 | 273 | 274 |
- Modified pToBigEndian way of compare to know the length
- removed not well formated blank space
NOTE: findDivider() method searches for a divider for pq value so that
p = divider
q = pq / divider
or reverse if p < q