Enable checked auth key creation.

This commit is contained in:
John Preston 2018-05-20 21:23:50 +03:00
parent c43dcf0567
commit 8e442563f2
3 changed files with 23 additions and 32 deletions

View File

@ -2572,22 +2572,14 @@ void ConnectionPrivate::pqAnswered() {
return restart(); return restart();
} }
// #TODO checked key creation auto p_q_inner = MTP_p_q_inner_data_dc(
//auto p_q_inner = MTP_p_q_inner_data_dc(
// res_pq_data.vpq,
// MTP_bytes(std::move(p)),
// MTP_bytes(std::move(q)),
// _authKeyData->nonce,
// _authKeyData->server_nonce,
// _authKeyData->new_nonce,
// MTP_int(getProtocolDcId()));
auto p_q_inner = MTP_p_q_inner_data(
res_pq_data.vpq, res_pq_data.vpq,
MTP_bytes(std::move(p)), MTP_bytes(std::move(p)),
MTP_bytes(std::move(q)), MTP_bytes(std::move(q)),
_authKeyData->nonce, _authKeyData->nonce,
_authKeyData->server_nonce, _authKeyData->server_nonce,
_authKeyData->new_nonce); _authKeyData->new_nonce,
MTP_int(getProtocolDcId()));
auto dhEncString = encryptPQInnerRSA(p_q_inner, rsaKey); auto dhEncString = encryptPQInnerRSA(p_q_inner, rsaKey);
if (dhEncString.empty()) { if (dhEncString.empty()) {
return restart(); return restart();
@ -2603,11 +2595,8 @@ void ConnectionPrivate::pqAnswered() {
req_DH_params.vnonce = _authKeyData->nonce; req_DH_params.vnonce = _authKeyData->nonce;
req_DH_params.vserver_nonce = _authKeyData->server_nonce; req_DH_params.vserver_nonce = _authKeyData->server_nonce;
req_DH_params.vpublic_key_fingerprint = MTP_long(rsaKey.getFingerPrint()); req_DH_params.vpublic_key_fingerprint = MTP_long(rsaKey.getFingerPrint());
// #TODO checked key creation req_DH_params.vp = p_q_inner.c_p_q_inner_data_dc().vp;
//req_DH_params.vp = p_q_inner.c_p_q_inner_data_dc().vp; req_DH_params.vq = p_q_inner.c_p_q_inner_data_dc().vq;
//req_DH_params.vq = p_q_inner.c_p_q_inner_data_dc().vq;
req_DH_params.vp = p_q_inner.c_p_q_inner_data().vp;
req_DH_params.vq = p_q_inner.c_p_q_inner_data().vq;
req_DH_params.vencrypted_data = MTP_bytes(dhEncString); req_DH_params.vencrypted_data = MTP_bytes(dhEncString);
sendRequestNotSecure(req_DH_params); sendRequestNotSecure(req_DH_params);
} }

View File

@ -22,7 +22,7 @@ ResolvingConnection::ResolvingConnection(
ConnectionPointer &&child) ConnectionPointer &&child)
: AbstractConnection(thread, proxy) : AbstractConnection(thread, proxy)
, _instance(instance) , _instance(instance)
, _timeoutTimer([=] { handleError(); }) { , _timeoutTimer([=] { handleError(kErrorCodeOther); }) {
setChild(std::move(child)); setChild(std::move(child));
if (proxy.resolvedExpireAt < getms(true)) { if (proxy.resolvedExpireAt < getms(true)) {
const auto host = proxy.host; const auto host = proxy.host;
@ -104,7 +104,7 @@ void ResolvingConnection::domainResolved(
if (index < _proxy.resolvedIPs.size()) { if (index < _proxy.resolvedIPs.size()) {
_proxy.resolvedIPs.resize(index); _proxy.resolvedIPs.resize(index);
if (_ipIndex >= index) { if (_ipIndex >= index) {
emitError(); emitError(kErrorCodeOther);
} }
} }
if (_ipIndex < 0) { if (_ipIndex < 0) {
@ -112,28 +112,30 @@ void ResolvingConnection::domainResolved(
} }
} }
void ResolvingConnection::refreshChild() { bool ResolvingConnection::refreshChild() {
if (!_child) { if (!_child) {
return; return true;
} else if (++_ipIndex >= _proxy.resolvedIPs.size()) { } else if (++_ipIndex >= _proxy.resolvedIPs.size()) {
emitError(); return false;
return;
} }
setChild(_child->clone(ToDirectIpProxy(_proxy, _ipIndex))); setChild(_child->clone(ToDirectIpProxy(_proxy, _ipIndex)));
_timeoutTimer.callOnce(kOneConnectionTimeout); _timeoutTimer.callOnce(kOneConnectionTimeout);
return true;
} }
void ResolvingConnection::emitError() { void ResolvingConnection::emitError(int errorCode) {
_ipIndex = -1; _ipIndex = -1;
_child = nullptr; _child = nullptr;
emit error(kErrorCodeOther); emit error(errorCode);
} }
void ResolvingConnection::handleError() { void ResolvingConnection::handleError(int errorCode) {
if (_connected) { if (_connected) {
emitError(); emitError(errorCode);
} else if (!_proxy.resolvedIPs.empty()) { } else if (!_proxy.resolvedIPs.empty()) {
refreshChild(); if (!refreshChild()) {
emitError(errorCode);
}
} else { } else {
// Wait for the domain to be resolved. // Wait for the domain to be resolved.
} }
@ -143,7 +145,7 @@ void ResolvingConnection::handleDisconnected() {
if (_connected) { if (_connected) {
emit disconnected(); emit disconnected();
} else { } else {
handleError(); handleError(kErrorCodeOther);
} }
} }
@ -204,7 +206,7 @@ void ResolvingConnection::connectToServer(
const bytes::vector &protocolSecret, const bytes::vector &protocolSecret,
int16 protocolDcId) { int16 protocolDcId) {
if (!_child) { if (!_child) {
InvokeQueued(this, [=] { emitError(); }); InvokeQueued(this, [=] { emitError(kErrorCodeOther); });
return; return;
} }
_address = address; _address = address;

View File

@ -42,14 +42,14 @@ public:
private: private:
void setChild(ConnectionPointer &&child); void setChild(ConnectionPointer &&child);
void refreshChild(); bool refreshChild();
void emitError(); void emitError(int errorCode);
void domainResolved( void domainResolved(
const QString &host, const QString &host,
const QStringList &ips, const QStringList &ips,
qint64 expireAt); qint64 expireAt);
void handleError(); void handleError(int errorCode);
void handleConnected(); void handleConnected();
void handleDisconnected(); void handleDisconnected();
void handleReceivedData(); void handleReceivedData();