use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class ConversationActivity method handleViewConversationIntent.
private void handleViewConversationIntent(final Intent intent) {
final String uuid = intent.getStringExtra(CONVERSATION);
final String downloadUuid = intent.getStringExtra(EXTRA_DOWNLOAD_UUID);
final String text = intent.getStringExtra(TEXT);
final String nick = intent.getStringExtra(NICK);
final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false);
if (selectConversationByUuid(uuid)) {
this.mConversationFragment.reInit(getSelectedConversation());
if (nick != null) {
if (pm) {
Jid jid = getSelectedConversation().getJid();
try {
Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
this.mConversationFragment.privateMessageWith(next);
} catch (final InvalidJidException ignored) {
//do nothing
}
} else {
this.mConversationFragment.highlightInConference(nick);
}
} else {
this.mConversationFragment.appendText(text);
}
hideConversationsOverview();
mUnprocessedNewIntent = false;
openConversation();
if (mContentView instanceof SlidingPaneLayout) {
//fixes bug where slp isn't properly closed yet
updateActionBarTitle(true);
}
if (downloadUuid != null) {
final Message message = mSelectedConversation.findMessageWithFileAndUuid(downloadUuid);
if (message != null) {
startDownloadable(message);
}
}
} else {
mUnprocessedNewIntent = false;
}
}
use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class XmppConnectionService method createAdhocConference.
public boolean createAdhocConference(final Account account, final String subject, final Iterable<Jid> jids, final UiCallback<Conversation> callback) {
Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": creating adhoc conference with " + jids.toString());
if (account.getStatus() == Account.State.ONLINE) {
try {
String server = findConferenceServer(account);
if (server == null) {
if (callback != null) {
callback.error(R.string.no_conference_server_found, null);
}
return false;
}
final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true, false);
joinMuc(conversation, new OnConferenceJoined() {
@Override
public void onConferenceJoined(final Conversation conversation) {
pushConferenceConfiguration(conversation, IqGenerator.defaultRoomConfiguration(), new OnConfigurationPushed() {
@Override
public void onPushSucceeded() {
if (subject != null && !subject.trim().isEmpty()) {
pushSubjectToConference(conversation, subject.trim());
}
for (Jid invite : jids) {
invite(conversation, invite);
}
if (account.countPresences() > 1) {
directInvite(conversation, account.getJid().toBareJid());
}
saveConversationAsBookmark(conversation, subject);
if (callback != null) {
callback.success(conversation);
}
}
@Override
public void onPushFailed() {
archiveConversation(conversation);
if (callback != null) {
callback.error(R.string.conference_creation_failed, conversation);
}
}
});
}
});
return true;
} catch (InvalidJidException e) {
if (callback != null) {
callback.error(R.string.conference_creation_failed, null);
}
return false;
}
} else {
if (callback != null) {
callback.error(R.string.not_connected_try_again, null);
}
return false;
}
}
use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class XmppConnectionService method onOtrSessionEstablished.
public void onOtrSessionEstablished(Conversation conversation) {
final Account account = conversation.getAccount();
final Session otrSession = conversation.getOtrSession();
Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {
@Override
public void onMessageFound(Message message) {
SessionID id = otrSession.getSessionID();
try {
message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
} catch (InvalidJidException e) {
return;
}
if (message.needsUploading()) {
mJingleConnectionManager.createNewConnection(message);
} else {
MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
if (outPacket != null) {
mMessageGenerator.addDelay(outPacket, message.getTimeSent());
message.setStatus(Message.STATUS_SEND);
databaseBackend.updateMessage(message);
sendMessagePacket(account, outPacket);
}
}
updateConversationUi();
}
});
}
use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
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 AxolotlAddress 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 eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class OtrService method injectMessage.
@Override
public void injectMessage(SessionID session, String body) throws OtrException {
MessagePacket packet = new MessagePacket();
packet.setFrom(account.getJid());
if (session.getUserID().isEmpty()) {
packet.setAttribute("to", session.getAccountID());
} else {
packet.setAttribute("to", session.getAccountID() + "/" + session.getUserID());
}
packet.setBody(body);
MessageGenerator.addMessageHints(packet);
try {
Jid jid = Jid.fromSessionID(session);
Conversation conversation = mXmppConnectionService.find(account, jid);
if (conversation != null && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
if (mXmppConnectionService.sendChatStates()) {
packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
}
}
} catch (final InvalidJidException ignored) {
}
packet.setType(MessagePacket.TYPE_CHAT);
packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "urn:xmpp:otr:0");
account.getXmppConnection().sendMessagePacket(packet);
}
Aggregations