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();
}
// #TODO checked key creation
//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(
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);
_authKeyData->new_nonce,
MTP_int(getProtocolDcId()));
auto dhEncString = encryptPQInnerRSA(p_q_inner, rsaKey);
if (dhEncString.empty()) {
return restart();
@ -2603,11 +2595,8 @@ void ConnectionPrivate::pqAnswered() {
req_DH_params.vnonce = _authKeyData->nonce;
req_DH_params.vserver_nonce = _authKeyData->server_nonce;
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.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.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.vencrypted_data = MTP_bytes(dhEncString);
sendRequestNotSecure(req_DH_params);
}

View File

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

View File

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