use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class XmppConnection method sendBindRequest.
private void sendBindRequest() {
try {
mXmppConnectionService.restoredFromDatabaseLatch.await();
} catch (InterruptedException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": interrupted while waiting for DB restore during bind");
return;
}
clearIqCallbacks();
if (account.getJid().isBareJid()) {
account.setResource(this.createNewResource());
}
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
final String resource = Config.USE_RANDOM_RESOURCE_ON_EVERY_BIND ? nextRandomId() : account.getResource();
iq.addChild("bind", Namespace.BIND).addChild("resource").setContent(resource);
this.sendUnmodifiedIqPacket(iq, (account, packet) -> {
if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
return;
}
final Element bind = packet.findChild("bind");
if (bind != null && packet.getType() == IqPacket.TYPE.RESULT) {
isBound = true;
final Element jid = bind.findChild("jid");
if (jid != null && jid.getContent() != null) {
try {
Jid assignedJid = Jid.fromString(jid.getContent());
if (!account.getJid().getDomainpart().equals(assignedJid.getDomainpart())) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server tried to re-assign domain to " + assignedJid.getDomainpart());
throw new StateChangingError(Account.State.BIND_FAILURE);
}
if (account.setJid(assignedJid)) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": jid changed during bind. updating database");
mXmppConnectionService.databaseBackend.updateAccount(account);
}
if (streamFeatures.hasChild("session") && !streamFeatures.findChild("session").hasChild("optional")) {
sendStartSession();
} else {
sendPostBindInitialization();
}
return;
} catch (final InvalidJidException e) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server reported invalid jid (" + jid.getContent() + ") on bind");
}
} else {
Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure. (no jid)");
}
} else {
Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure (" + packet.toString());
}
final Element error = packet.findChild("error");
if (packet.getType() == IqPacket.TYPE.ERROR && error != null && error.hasChild("conflict")) {
account.setResource(createNewResource());
}
throw new StateChangingError(Account.State.BIND_FAILURE);
}, true);
}
use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class OtrService method sendOtrErrorMessage.
public void sendOtrErrorMessage(SessionID session, String errorText) {
try {
Jid jid = Jid.fromSessionID(session);
Conversation conversation = mXmppConnectionService.find(account, jid);
String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
if (id != null) {
MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid, id, errorText);
packet.setFrom(account.getJid());
mXmppConnectionService.sendMessagePacket(account, packet);
Log.d(Config.LOGTAG, packet.toString());
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": unreadable OTR message in " + conversation.getName());
}
} catch (InvalidJidException e) {
return;
}
}
use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class AxolotlService method verifySessionWithPEP.
private void verifySessionWithPEP(final XmppAxolotlSession session) {
Log.d(Config.LOGTAG, "trying to verify fresh session (" + session.getRemoteAddress().getName() + ") with pep");
final SignalProtocolAddress address = session.getRemoteAddress();
final IdentityKey identityKey = session.getIdentityKey();
try {
IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveVerificationForDevice(Jid.fromString(address.getName()), address.getDeviceId());
mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Pair<X509Certificate[], byte[]> verification = mXmppConnectionService.getIqParser().verification(packet);
if (verification != null) {
try {
Signature verifier = Signature.getInstance("sha256WithRSA");
verifier.initVerify(verification.first[0]);
verifier.update(identityKey.serialize());
if (verifier.verify(verification.second)) {
try {
mXmppConnectionService.getMemorizingTrustManager().getNonInteractive().checkClientTrusted(verification.first, "RSA");
String fingerprint = session.getFingerprint();
Log.d(Config.LOGTAG, "verified session with x.509 signature. fingerprint was: " + fingerprint);
setFingerprintTrust(fingerprint, FingerprintStatus.createActiveVerified(true));
axolotlStore.setFingerprintCertificate(fingerprint, verification.first[0]);
fetchStatusMap.put(address, FetchStatus.SUCCESS_VERIFIED);
Bundle information = CryptoHelper.extractCertificateInformation(verification.first[0]);
try {
final String cn = information.getString("subject_cn");
final Jid jid = Jid.fromString(address.getName());
Log.d(Config.LOGTAG, "setting common name for " + jid + " to " + cn);
account.getRoster().getContact(jid).setCommonName(cn);
} catch (final InvalidJidException ignored) {
// ignored
}
finishBuildingSessionsFromPEP(address);
return;
} catch (Exception e) {
Log.d(Config.LOGTAG, "could not verify certificate");
}
}
} catch (Exception e) {
Log.d(Config.LOGTAG, "error during verification " + e.getMessage());
}
} else {
Log.d(Config.LOGTAG, "no verification found");
}
fetchStatusMap.put(address, FetchStatus.SUCCESS);
finishBuildingSessionsFromPEP(address);
}
});
} catch (InvalidJidException e) {
fetchStatusMap.put(address, FetchStatus.SUCCESS);
finishBuildingSessionsFromPEP(address);
}
}
use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class AbstractParser method parseItem.
public static MucOptions.User parseItem(Conversation conference, Element item, Jid fullJid) {
final String local = conference.getJid().getLocalpart();
final String domain = conference.getJid().getDomainpart();
String affiliation = item.getAttribute("affiliation");
String role = item.getAttribute("role");
String nick = item.getAttribute("nick");
if (nick != null && fullJid == null) {
try {
fullJid = Jid.fromParts(local, domain, nick);
} catch (InvalidJidException e) {
fullJid = null;
}
}
Jid realJid = item.getAttributeAsJid("jid");
MucOptions.User user = new MucOptions.User(conference.getMucOptions(), fullJid);
user.setRealJid(realJid);
user.setAffiliation(affiliation);
user.setRole(role);
return user;
}
use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.
the class PushManagementService method registerPushTokenOnServer.
public void registerPushTokenOnServer(final Account account) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {
@Override
public void onGcmInstanceTokenRetrieved(String token) {
try {
final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID);
IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId);
mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
Element command = packet.findChild("command", "http://jabber.org/protocol/commands");
if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
Element x = command.findChild("x", Namespace.DATA);
if (x != null) {
Data data = Data.parse(x);
try {
String node = data.getValue("node");
String secret = data.getValue("secret");
Jid jid = Jid.fromString(data.getValue("jid"));
if (node != null && secret != null) {
enablePushOnServer(account, jid, node, secret);
}
} catch (InvalidJidException e) {
e.printStackTrace();
}
}
} else {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": invalid response from app server");
}
}
});
} catch (InvalidJidException ignored) {
}
}
});
}
Aggregations