code cleanup + logging of spoofed iq packets

This commit is contained in:
Daniel Gultsch 2015-01-04 15:40:09 +01:00
parent d64496eab6
commit 0d6d09b7e9
1 changed files with 33 additions and 35 deletions

View File

@ -430,42 +430,40 @@ public class XmppConnection implements Runnable {
return element; return element;
} }
private void processIq(final Tag currentTag) throws XmlPullParserException, private void processIq(final Tag currentTag) throws XmlPullParserException, IOException {
IOException { final IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
final IqPacket packet = (IqPacket) processPacket(currentTag, PACKET_IQ);
if (packet.getId() == null) { if (packet.getId() == null) {
return; // an iq packet without id is definitely invalid return; // an iq packet without id is definitely invalid
} }
if (packet instanceof JinglePacket) { if (packet instanceof JinglePacket) {
if (this.jingleListener != null) { if (this.jingleListener != null) {
this.jingleListener.onJinglePacketReceived(account, this.jingleListener.onJinglePacketReceived(account,(JinglePacket) packet);
(JinglePacket) packet); }
} } else {
} else { if (packetCallbacks.containsKey(packet.getId())) {
if (packetCallbacks.containsKey(packet.getId())) { final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId());
final Pair<IqPacket, OnIqPacketReceived> packetCallbackDuple = packetCallbacks.get(packet.getId()); // Packets to the server should have responses from the server
// Packets to the server should have responses from the server if (packetCallbackDuple.first.toServer(account)) {
if (packetCallbackDuple.first.toServer(account)) { if (packet.fromServer(account)) {
if (packet.fromServer(account)) { packetCallbackDuple.second.onIqPacketReceived(account, packet);
packetCallbackDuple.second packetCallbacks.remove(packet.getId());
.onIqPacketReceived(account, packet); } else {
packetCallbacks.remove(packet.getId()); Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
} }
} else { } else {
if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) { if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) {
packetCallbackDuple.second packetCallbackDuple.second.onIqPacketReceived(account, packet);
.onIqPacketReceived(account, packet); packetCallbacks.remove(packet.getId());
packetCallbacks.remove(packet.getId()); } else {
} Log.e(Config.LOGTAG,account.getJid().toBareJid().toString()+": ignoring spoofed iq packet");
} }
} else if ((packet.getType() == IqPacket.TYPE.GET || packet }
.getType() == IqPacket.TYPE.SET) } else if (packet.getType() == IqPacket.TYPE.GET|| packet.getType() == IqPacket.TYPE.SET) {
&& this.unregisteredIqListener != null) { this.unregisteredIqListener.onIqPacketReceived(account, packet);
this.unregisteredIqListener.onIqPacketReceived(account, packet); }
} }
}
} }
private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException { private void processMessage(final Tag currentTag) throws XmlPullParserException, IOException {
@ -836,7 +834,7 @@ public class XmppConnection implements Runnable {
} }
private void sendUnmodifiedIqPacket(final IqPacket packet, final OnIqPacketReceived callback) { private synchronized void sendUnmodifiedIqPacket(final IqPacket packet, final OnIqPacketReceived callback) {
if (packet.getId() == null) { if (packet.getId() == null) {
final String id = nextRandomId(); final String id = nextRandomId();
packet.setAttribute("id", id); packet.setAttribute("id", id);