bool ConsoleWidget::xmppStanzaIn(IXmppStream *AXmppStream, Stanza &AStanza, int AOrder) { if (AOrder == XSHO_CONSOLE) showElement(AXmppStream,AStanza.element(),false); return false; }
void Gateways::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza) { Q_UNUSED(AStreamJid); if (FPromptRequests.contains(AStanza.id())) { if (AStanza.type() == "result") { LOG_STRM_DEBUG(AStreamJid,QString("Legacy user prompt received, id=%1").arg(AStanza.id())); QString desc = AStanza.firstElement("query",NS_JABBER_GATEWAY).firstChildElement("desc").text(); QString prompt = AStanza.firstElement("query",NS_JABBER_GATEWAY).firstChildElement("prompt").text(); emit promptReceived(AStanza.id(),desc,prompt); } else { XmppStanzaError err(AStanza); LOG_STRM_WARNING(AStreamJid,QString("Failed to receive legacy user prompt, id=%1: %2").arg(AStanza.id(),err.condition())); emit errorReceived(AStanza.id(),err); } FPromptRequests.removeAll(AStanza.id()); } else if (FUserJidRequests.contains(AStanza.id())) { if (AStanza.type() == "result") { LOG_STRM_DEBUG(AStreamJid,QString("Legacy user JID received, id=%1").arg(AStanza.id())); Jid userJid = AStanza.firstElement("query",NS_JABBER_GATEWAY).firstChildElement("jid").text(); emit userJidReceived(AStanza.id(),userJid); } else { XmppStanzaError err(AStanza); LOG_STRM_WARNING(AStreamJid,QString("Failed to receive legacy user JID, id=%1: %2").arg(AStanza.id(),err.condition())); emit errorReceived(AStanza.id(),err); } FUserJidRequests.removeAll(AStanza.id()); } }
bool IqAuthFeature::xmppStanzaIn(IXmppStream *AXmppStream, Stanza &AStanza, int AOrder) { if (AXmppStream==FXmppStream && AOrder==XSHO_XMPP_FEATURE) { if (AStanza.id() == "getIqAuth") { if (AStanza.isResult()) { Stanza auth(STANZA_KIND_IQ); auth.setType(STANZA_TYPE_SET).setTo(FXmppStream->streamJid().domain()).setId("setIqAuth"); QDomElement query = auth.addElement("query",NS_JABBER_IQ_AUTH); query.appendChild(auth.createElement("username")).appendChild(auth.createTextNode(FXmppStream->streamJid().pNode())); query.appendChild(auth.createElement("resource")).appendChild(auth.createTextNode(FXmppStream->streamJid().resource())); QDomElement reqElem = AStanza.firstElement("query",NS_JABBER_IQ_AUTH); if (!reqElem.firstChildElement("digest").isNull()) { QByteArray shaData = FXmppStream->streamId().toUtf8()+FXmppStream->password().toUtf8(); QByteArray shaDigest = QCryptographicHash::hash(shaData,QCryptographicHash::Sha1).toHex(); query.appendChild(auth.createElement("digest")).appendChild(auth.createTextNode(shaDigest.toLower().trimmed())); FXmppStream->sendStanza(auth); LOG_STRM_INFO(AXmppStream->streamJid(),"Username and encrypted password sent"); } else if (!reqElem.firstChildElement("password").isNull()) { if (FXmppStream->connection()->isEncrypted()) { query.appendChild(auth.createElement("password")).appendChild(auth.createTextNode(FXmppStream->password())); FXmppStream->sendStanza(auth); LOG_STRM_INFO(AXmppStream->streamJid(),"Username and plain text password sent"); } else { LOG_STRM_ERROR(AXmppStream->streamJid(),"Failed to send username and plain text password: Connection not encrypted"); emit error(XmppError(IERR_XMPPSTREAM_NOT_SECURE)); } } } else { XmppStanzaError err(AStanza); LOG_STRM_ERROR(AXmppStream->streamJid(),QString("Failed to receive authentication initialization: %1").arg(err.condition())); emit error(err); } return true; } else if (AStanza.id() == "setIqAuth") { FXmppStream->removeXmppStanzaHandler(XSHO_XMPP_FEATURE,this); if (AStanza.isResult()) { LOG_STRM_INFO(AXmppStream->streamJid(),"Username and password accepted"); deleteLater(); emit finished(false); } else { XmppStanzaError err(AStanza); LOG_STRM_WARNING(AXmppStream->streamJid(),QString("Username and password rejected: %1").arg(err.condition())); emit error(XmppStanzaError(AStanza)); } return true; } } return false; }
bool SASLAuthFeature::xmppStanzaIn(IXmppStream *AXmppStream, Stanza &AStanza, int AOrder) { if (AXmppStream==FXmppStream && AOrder==XSHO_XMPP_FEATURE) { if (AStanza.kind() == "challenge") { QByteArray challengeData = QByteArray::fromBase64(AStanza.element().text().toLatin1()); LOG_STRM_DEBUG(FXmppStream->streamJid(),QString("SASL auth challenge received: %1").arg(QString::fromUtf8(challengeData))); QMap<QByteArray, QByteArray> responseMap; QMap<QByteArray, QByteArray> challengeMap = parseChallenge(challengeData); if (challengeMap.value("qop") == "auth") { QByteArray randBytes(32,' '); for (int i=0; i<randBytes.size(); i++) randBytes[i] = (char) (256.0 * qrand() / (RAND_MAX + 1.0)); responseMap["cnonce"] = randBytes.toHex(); if (challengeMap.contains("realm")) responseMap["realm"] = challengeMap.value("realm"); else responseMap["realm"] = FXmppStream->streamJid().pDomain().toUtf8(); responseMap["username"] = FXmppStream->streamJid().pNode().toUtf8(); responseMap["nonce"] = challengeMap.value("nonce"); responseMap["nc"] = "00000001"; responseMap["qop"] = "auth"; responseMap["digest-uri"] = QString("xmpp/%1").arg(FXmppStream->streamJid().pDomain()).toUtf8(); responseMap["charset"] = "utf-8"; responseMap["response"] = getResponseValue(responseMap,FXmppStream->password()); } QByteArray responseData = serializeResponse(responseMap); Stanza response("response",NS_FEATURE_SASL); response.element().appendChild(response.createTextNode(responseData.toBase64())); FXmppStream->sendStanza(response); LOG_STRM_DEBUG(FXmppStream->streamJid(),QString("SASL auth response sent: %1").arg(QString::fromUtf8(responseData))); } else { FXmppStream->removeXmppStanzaHandler(XSHO_XMPP_FEATURE,this); if (AStanza.kind() == "success") { LOG_STRM_INFO(FXmppStream->streamJid(),"Authorization successes"); deleteLater(); emit finished(true); } else if (AStanza.kind() == "failure") { XmppSaslError err(AStanza.element()); LOG_STRM_WARNING(FXmppStream->streamJid(),QString("Authorization failed: %1").arg(err.condition())); emit error(err); } else { XmppError err(IERR_SASL_AUTH_INVALID_RESPONSE); LOG_STRM_WARNING(FXmppStream->streamJid(),QString("Authorization error: Invalid stanza kind=%1").arg(AStanza.kind())); emit error(err); } } return true; } return false; }
bool Roster::stanzaReadWrite(int AHandlerId, const Jid &AStreamJid, Stanza &AStanza, bool &AAccept) { if (AHandlerId == FSHIRosterPush) { if (isOpen() && AStanza.isFromServer()) { AAccept = true; LOG_STRM_DEBUG(streamJid(),"Roster items push received"); processItemsElement(AStanza.firstElement("query",NS_JABBER_ROSTER),false); Stanza result = FStanzaProcessor->makeReplyResult(AStanza); FStanzaProcessor->sendStanzaOut(AStreamJid,result); } else if (!isOpen()) { REPORT_ERROR("Failed to process roster items push: Roster is closed"); } else if (!AStanza.isFromServer()) { REPORT_ERROR("Failed to process roster items push: Invalid stanza sender"); } } else if (AHandlerId == FSHISubscription) { Jid contactJid = AStanza.from(); QString status = AStanza.firstElement("status").text(); if (AStanza.type() == SUBSCRIPTION_SUBSCRIBE) { AAccept = true; FSubscriptionRequests += contactJid.bare(); LOG_STRM_INFO(streamJid(),QString("Subscribe presence received from=%1, status=%2").arg(contactJid.full(),status)); emit subscriptionReceived(AStanza.from(),IRoster::Subscribe,status); } else if (AStanza.type() == SUBSCRIPTION_SUBSCRIBED) { AAccept = true; LOG_STRM_INFO(streamJid(),QString("Subscribed presence received from=%1, status=%2").arg(contactJid.full(),status)); emit subscriptionReceived(AStanza.from(),IRoster::Subscribed,status); } else if (AStanza.type() == SUBSCRIPTION_UNSUBSCRIBE) { AAccept = true; FSubscriptionRequests -= contactJid.bare(); LOG_STRM_INFO(streamJid(),QString("Unsubscribe presence received from=%1, status=%2").arg(contactJid.full(),status)); emit subscriptionReceived(AStanza.from(),IRoster::Unsubscribe,status); } else if (AStanza.type() == SUBSCRIPTION_UNSUBSCRIBED) { AAccept = true; LOG_STRM_INFO(streamJid(),QString("Unsubscribed presence received from=%1, status=%2").arg(contactJid.full(),status)); emit subscriptionReceived(AStanza.from(),IRoster::Unsubscribed,status); } } return false; }