//### query management qint64 Session::sendQuery(OutboundPkt &outboundPkt, QueryMethods *methods, const QVariant &extra, const QString &name) { Q_ASSERT (m_sessionId); Q_ASSERT (m_dc->authKeyId()); qint32 *data = outboundPkt.buffer(); qint32 ints = outboundPkt.length(); qCDebug(TG_CORE_SESSION) << "Sending query of size" << 4 * ints << "to DC" << m_dc->id() << "at" << peerName() << ":" << peerPort() << "by session" << QString::number(m_sessionId, 16); Query *q = new Query(this); q->setData(data, ints); q->setMsgId(encryptSendMessage(data, ints, 1)); q->setSeqNo(m_seqNo - 1); qCDebug(TG_CORE_SESSION) << "msgId is" << QString::number(q->msgId(), 16); q->setMethods(methods); q->setAcked(false); q->setExtra(extra); q->setName(name); if (mSettings->resendQueries()) { connect(q, SIGNAL(timeout(Query*)), this, SLOT(resendQuery(Query*)), Qt::UniqueConnection); q->startTimer(QUERY_TIMEOUT); }
//### query management qint64 Session::sendQuery(OutboundPkt &outboundPkt, QueryMethods *methods, const QVariant &extra, const QString &name) { Q_ASSERT (m_sessionId); Q_ASSERT (m_dc->authKeyId()); qint32 *data = outboundPkt.buffer(); qint32 ints = outboundPkt.length(); // prepend init connection header to outboundPkt if initConnectionNeeded // Note: 'wrap' needs to be declare outside of if to persist until encriptSendMessage is completed OutboundPkt wrap(mSettings); if (m_initConnectionNeeded) { wrap.initConnection(); wrap.appendOutboundPkt(outboundPkt); data = wrap.buffer(); ints = wrap.length(); m_initConnectionNeeded = false; } qCDebug(TG_CORE_SESSION) << "Sending query of size" << 4 * ints << "to DC" << m_dc->id() << "at" << peerName() << ":" << peerPort() << "by session" << QString::number(m_sessionId, 16); Query *q = new Query(this); q->setData(data, ints); q->setMsgId(encryptSendMessage(data, ints, 1)); q->setMainMsgId(q->msgId()); q->setSeqNo(m_seqNo - 1); qCDebug(TG_CORE_SESSION) << "msgId is" << QString::number(q->msgId(), 16); q->setMethods(methods); q->setAcked(false); q->setExtra(extra); q->setName(name); if (mSettings->resendQueries()) { connect(q, &Query::timeout, this, &Session::resendQuery, Qt::UniqueConnection); q->startTimer(QUERY_TIMEOUT); } m_pendingQueries.insert(q->msgId(), q); return q->msgId(); }
void OutboundPkt::appendOutboundPkt(OutboundPkt& other) { appendInts(other.buffer(), other.length()); }
qint32 CryptoUtils::encryptPacketBufferAESUnAuth(const char serverNonce[16], const char hiddenClientNonce[32], OutboundPkt &p, void *encryptBuffer) { initAESUnAuth (serverNonce, hiddenClientNonce, AES_ENCRYPT); return padAESEncrypt ((char *) p.buffer(), p.length() * 4, (char *) encryptBuffer, ENCRYPT_BUFFER_INTS * 4); }
qint32 CryptoUtils::encryptPacketBuffer(OutboundPkt &p, void *encryptBuffer) { RSA *pubKey = mSettings->pubKey(); return padRsaEncrypt((char *) p.buffer(), p.length() * 4, (char *) encryptBuffer, ENCRYPT_BUFFER_INTS * 4, pubKey->n, pubKey->e); }