From d0b8bd0f8a0cb10c93d45d6900ff1fdb62db80b7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 24 Aug 2015 18:18:01 +0200 Subject: catch invalid base64 in axolotl key parsing --- src/main/java/eu/siacs/conversations/parser/IqParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/parser/IqParser.java b/src/main/java/eu/siacs/conversations/parser/IqParser.java index cef5b03d9..44e4bc089 100644 --- a/src/main/java/eu/siacs/conversations/parser/IqParser.java +++ b/src/main/java/eu/siacs/conversations/parser/IqParser.java @@ -138,7 +138,7 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived { } try { publicKey = Curve.decodePoint(Base64.decode(signedPreKeyPublic.getContent(),Base64.DEFAULT), 0); - } catch (InvalidKeyException e) { + } catch (InvalidKeyException | IllegalArgumentException e) { Log.e(Config.LOGTAG, AxolotlService.LOGPREFIX+" : "+"Invalid signedPreKeyPublic in PEP: " + e.getMessage()); } return publicKey; -- cgit v1.2.3 From fb0b4bb4453568b10a830ff14f751318cbcd85d7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 24 Aug 2015 20:56:25 +0200 Subject: added setting to allow for white backgrounds in incoming message bubbles --- .../conversations/ui/ConversationActivity.java | 11 ++- .../conversations/ui/ConversationFragment.java | 1 + .../conversations/ui/adapter/MessageAdapter.java | 85 +++++++++++++--------- 3 files changed, 61 insertions(+), 36 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 219a4fcac..e7f453994 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -966,6 +966,9 @@ public class ConversationActivity extends XmppActivity mPendingGeoUri = null; setSelectedConversation(conversationList.get(0)); this.mConversationFragment.reInit(getSelectedConversation()); + } else { + this.mConversationFragment.messageListAdapter.updatePreferences(); + this.mConversationFragment.messagesView.invalidateViews(); } if(!forbidProcessingPendings) { @@ -1144,7 +1147,7 @@ public class ConversationActivity extends XmppActivity } prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG); prepareFileToast.show(); - xmppConnectionService.attachFileToConversation(conversation,uri, new UiCallback() { + xmppConnectionService.attachFileToConversation(conversation, uri, new UiCallback() { @Override public void success(Message message) { hidePrepareFileToast(); @@ -1174,7 +1177,7 @@ public class ConversationActivity extends XmppActivity @Override public void userInputRequried(PendingIntent pi, - Message object) { + Message object) { hidePrepareFileToast(); } @@ -1256,6 +1259,10 @@ public class ConversationActivity extends XmppActivity return getPreferences().getBoolean("indicate_received", false); } + public boolean useWhiteBackground() { + return getPreferences().getBoolean("use_white_background",false); + } + protected boolean trustKeysIfNeeded(int requestCode) { return trustKeysIfNeeded(requestCode, ATTACHMENT_CHOICE_INVALID); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index de758efc1..541e1533b 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -662,6 +662,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa this.mEditMessage.setText(""); this.mEditMessage.append(this.conversation.getNextMessage()); this.mEditMessage.setKeyboardListener(this); + messageListAdapter.updatePreferences(); this.messagesView.setAdapter(messageListAdapter); updateMessages(); this.messagesLoaded = true; diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 1ddd6c44a..8cdcb585f 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -60,11 +60,14 @@ public class MessageAdapter extends ArrayAdapter { return true; } }; + private boolean mIndicateReceived = false; + private boolean mUseWhiteBackground = false; public MessageAdapter(ConversationActivity activity, List messages) { super(activity, 0, messages); this.activity = activity; metrics = getContext().getResources().getDisplayMetrics(); + updatePreferences(); } public void setOnContactPictureClicked(OnContactPictureClicked listener) { @@ -96,15 +99,15 @@ public class MessageAdapter extends ArrayAdapter { return this.getItemViewType(getItem(position)); } - private int getMessageTextColor(int type, boolean primary) { - if (type == SENT) { - return activity.getResources().getColor(primary ? R.color.black87 : R.color.black54); - } else { + private int getMessageTextColor(boolean onDark, boolean primary) { + if (onDark) { return activity.getResources().getColor(primary ? R.color.white : R.color.white70); + } else { + return activity.getResources().getColor(primary ? R.color.black87 : R.color.black54); } } - private void displayStatus(ViewHolder viewHolder, Message message, int type) { + private void displayStatus(ViewHolder viewHolder, Message message, int type, boolean darkBackground) { String filesize = null; String info = null; boolean error = false; @@ -140,12 +143,12 @@ public class MessageAdapter extends ArrayAdapter { info = getContext().getString(R.string.offering); break; case Message.STATUS_SEND_RECEIVED: - if (activity.indicateReceived()) { + if (mIndicateReceived) { viewHolder.indicatorReceived.setVisibility(View.VISIBLE); } break; case Message.STATUS_SEND_DISPLAYED: - if (activity.indicateReceived()) { + if (mIndicateReceived) { viewHolder.indicatorReceived.setVisibility(View.VISIBLE); } break; @@ -162,11 +165,12 @@ public class MessageAdapter extends ArrayAdapter { if (error && type == SENT) { viewHolder.time.setTextColor(activity.getWarningTextColor()); } else { - viewHolder.time.setTextColor(this.getMessageTextColor(type,false)); + viewHolder.time.setTextColor(this.getMessageTextColor(darkBackground,false)); } if (message.getEncryption() == Message.ENCRYPTION_NONE) { viewHolder.indicator.setVisibility(View.GONE); } else { + viewHolder.indicator.setImageResource(darkBackground ? R.drawable.ic_secure_indicator_white : R.drawable.ic_secure_indicator); viewHolder.indicator.setVisibility(View.VISIBLE); if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { XmppAxolotlSession.Trust trust = message.getConversation() @@ -178,18 +182,18 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.indicator.setAlpha(1.0f); } else { viewHolder.indicator.clearColorFilter(); - if (type == SENT) { - viewHolder.indicator.setAlpha(0.57f); - } else { + if (darkBackground) { viewHolder.indicator.setAlpha(0.7f); + } else { + viewHolder.indicator.setAlpha(0.57f); } } } else { viewHolder.indicator.clearColorFilter(); - if (type == SENT) { - viewHolder.indicator.setAlpha(0.57f); - } else { + if (darkBackground) { viewHolder.indicator.setAlpha(0.7f); + } else { + viewHolder.indicator.setAlpha(0.57f); } } } @@ -223,19 +227,19 @@ public class MessageAdapter extends ArrayAdapter { } } - private void displayInfoMessage(ViewHolder viewHolder, String text, int type) { + private void displayInfoMessage(ViewHolder viewHolder, String text, boolean darkBackground) { if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } viewHolder.image.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.VISIBLE); viewHolder.messageBody.setText(text); - viewHolder.messageBody.setTextColor(getMessageTextColor(type,false)); + viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false)); viewHolder.messageBody.setTypeface(null, Typeface.ITALIC); viewHolder.messageBody.setTextIsSelectable(false); } - private void displayDecryptionFailed(ViewHolder viewHolder, int type) { + private void displayDecryptionFailed(ViewHolder viewHolder, boolean darkBackground) { if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } @@ -243,7 +247,7 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.messageBody.setVisibility(View.VISIBLE); viewHolder.messageBody.setText(getContext().getString( R.string.decryption_failed)); - viewHolder.messageBody.setTextColor(getMessageTextColor(type,false)); + viewHolder.messageBody.setTextColor(getMessageTextColor(darkBackground, false)); viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); viewHolder.messageBody.setTextIsSelectable(false); } @@ -261,7 +265,7 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.messageBody.setText(span); } - private void displayTextMessage(final ViewHolder viewHolder, final Message message, int type) { + private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground) { if (viewHolder.download_button != null) { viewHolder.download_button.setVisibility(View.GONE); } @@ -303,7 +307,7 @@ public class MessageAdapter extends ArrayAdapter { } final Spannable span = new SpannableString(privateMarker + " " + formattedBody); - span.setSpan(new ForegroundColorSpan(getMessageTextColor(type,false)), 0, privateMarker + span.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground,false)), 0, privateMarker .length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new StyleSpan(Typeface.BOLD), 0, privateMarker.length(), @@ -318,7 +322,8 @@ public class MessageAdapter extends ArrayAdapter { } else { viewHolder.messageBody.setText(""); } - viewHolder.messageBody.setTextColor(this.getMessageTextColor(type,true)); + viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); + viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground,true)); viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); viewHolder.messageBody.setTextIsSelectable(true); } @@ -388,7 +393,7 @@ public class MessageAdapter extends ArrayAdapter { scalledH = (int) (params.height / ((double) params.width / target)); } LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scalledW, scalledH); - layoutParams.setMargins(0, (int)(metrics.density * 4), 0, (int)(metrics.density * 4)); + layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4)); viewHolder.image.setLayoutParams(layoutParams); activity.loadBitmap(message, viewHolder.image); viewHolder.image.setOnClickListener(new OnClickListener() { @@ -404,6 +409,7 @@ public class MessageAdapter extends ArrayAdapter { @Override public View getView(int position, View view, ViewGroup parent) { final Message message = getItem(position); + final boolean isInValidSession = message.isValidInSession(); final Conversation conversation = message.getConversation(); final Account account = conversation.getAccount(); final int type = getItemViewType(position); @@ -468,6 +474,8 @@ public class MessageAdapter extends ArrayAdapter { } } + boolean darkBackground = (type == RECEIVED && (!isInValidSession || !mUseWhiteBackground)); + if (type == STATUS) { if (conversation.getMode() == Conversation.MODE_SINGLE) { viewHolder.contact_picture.setImageBitmap(activity @@ -497,7 +505,7 @@ public class MessageAdapter extends ArrayAdapter { public void onClick(View v) { if (MessageAdapter.this.mOnContactPictureClickedListener != null) { MessageAdapter.this.mOnContactPictureClickedListener - .onContactPictureClicked(message); + .onContactPictureClicked(message); } } @@ -509,7 +517,7 @@ public class MessageAdapter extends ArrayAdapter { public boolean onLongClick(View v) { if (MessageAdapter.this.mOnContactPictureLongClickedListener != null) { MessageAdapter.this.mOnContactPictureLongClickedListener - .onContactPictureLongClicked(message); + .onContactPictureLongClicked(message); return true; } else { return false; @@ -524,7 +532,7 @@ public class MessageAdapter extends ArrayAdapter { } else if (transferable.getStatus() == Transferable.STATUS_OFFER_CHECK_FILESIZE) { displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message))); } else { - displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first,type); + displayInfoMessage(viewHolder, UIHelper.getMessagePreview(activity, message).first,darkBackground); } } else if (message.getType() == Message.TYPE_IMAGE && message.getEncryption() != Message.ENCRYPTION_PGP && message.getEncryption() != Message.ENCRYPTION_DECRYPTION_FAILED) { displayImageMessage(viewHolder, message); @@ -536,9 +544,9 @@ public class MessageAdapter extends ArrayAdapter { } } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (activity.hasPgp()) { - displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message),type); + displayInfoMessage(viewHolder,activity.getString(R.string.encrypted_message),darkBackground); } else { - displayInfoMessage(viewHolder,activity.getString(R.string.install_openkeychain),type); + displayInfoMessage(viewHolder,activity.getString(R.string.install_openkeychain),darkBackground); if (viewHolder != null) { viewHolder.message_box .setOnClickListener(new OnClickListener() { @@ -551,7 +559,7 @@ public class MessageAdapter extends ArrayAdapter { } } } else if (message.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) { - displayDecryptionFailed(viewHolder,type); + displayDecryptionFailed(viewHolder,darkBackground); } else { if (GeoHelper.isGeoUri(message.getBody())) { displayLocationMessage(viewHolder,message); @@ -560,19 +568,23 @@ public class MessageAdapter extends ArrayAdapter { } else if (message.treatAsDownloadable() == Message.Decision.MUST) { displayDownloadableMessage(viewHolder, message, activity.getString(R.string.check_x_filesize, UIHelper.getFileDescriptionString(activity, message))); } else { - displayTextMessage(viewHolder, message, type); + displayTextMessage(viewHolder, message, darkBackground); } } if (type == RECEIVED) { - if(message.isValidInSession()) { - viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received); + if(isInValidSession) { + if (mUseWhiteBackground) { + viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_white); + } else { + viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received); + } } else { viewHolder.message_box.setBackgroundResource(R.drawable.message_bubble_received_warning); } } - displayStatus(viewHolder, message, type); + displayStatus(viewHolder, message, type, darkBackground); return view; } @@ -616,12 +628,17 @@ public class MessageAdapter extends ArrayAdapter { Toast.makeText(activity,R.string.no_application_found_to_display_location,Toast.LENGTH_SHORT).show(); } + public void updatePreferences() { + this.mIndicateReceived = activity.indicateReceived(); + this.mUseWhiteBackground = activity.useWhiteBackground(); + } + public interface OnContactPictureClicked { - public void onContactPictureClicked(Message message); + void onContactPictureClicked(Message message); } public interface OnContactPictureLongClicked { - public void onContactPictureLongClicked(Message message); + void onContactPictureLongClicked(Message message); } private static class ViewHolder { -- cgit v1.2.3 From 865e08401b3b6642a761b720f69ea26d04992384 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 24 Aug 2015 20:56:36 +0200 Subject: fixed regression with mlinks stream managment. fixes #1206 --- src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 376858323..ddc3158ce 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -954,7 +954,7 @@ public class XmppConnection implements Runnable { AbstractAcknowledgeableStanza stanza = (AbstractAcknowledgeableStanza) packet; ++stanzasSent; this.mStanzaQueue.put(stanzasSent, stanza); - if (stanza instanceof MessagePacket && stanza.getId() != null && this.streamId != null) { + if (stanza instanceof MessagePacket && stanza.getId() != null && getFeatures().sm()) { if (Config.EXTENDED_SM_LOGGING) { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": requesting ack for message stanza #" + stanzasSent); } -- cgit v1.2.3 From 730a5c644bbacea3189479ef067b3ebbd7dcffd6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 24 Aug 2015 21:15:47 +0200 Subject: renamed plain text to unencrypted. fixes #1331 --- src/main/java/eu/siacs/conversations/ui/ConversationFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 541e1533b..2d6288714 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -327,7 +327,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa switch (conversation.getNextEncryption()) { case Message.ENCRYPTION_NONE: mEditMessage - .setHint(getString(R.string.send_plain_text_message)); + .setHint(getString(R.string.send_unencrypted_message)); break; case Message.ENCRYPTION_OTR: mEditMessage.setHint(getString(R.string.send_otr_message)); -- cgit v1.2.3 From f6374f466b52d7d6465449ce3bd8e50128f9878e Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 24 Aug 2015 21:25:04 +0200 Subject: increased carbon grace period to 90s --- src/main/java/eu/siacs/conversations/Config.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index f3cbffe68..2b84e75e6 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -18,7 +18,7 @@ public final class Config { public static final int PING_TIMEOUT = 10; public static final int SOCKET_TIMEOUT = 15; public static final int CONNECT_TIMEOUT = 90; - public static final int CARBON_GRACE_PERIOD = 60; + public static final int CARBON_GRACE_PERIOD = 90; public static final int MINI_GRACE_PERIOD = 750; public static final int AVATAR_SIZE = 192; -- cgit v1.2.3 From 476db24c10180c0100bbd9a2cfbc34b672464b74 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 25 Aug 2015 11:11:32 +0200 Subject: fixed session time --- src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index ddc3158ce..6a94a5f3e 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -318,7 +318,6 @@ public class XmppConnection implements Runnable { Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": stream management(" + smVersion + ") enabled"); } - this.lastSessionStarted = SystemClock.elapsedRealtime(); this.stanzasReceived = 0; final RequestPacket r = new RequestPacket(smVersion); tagWriter.writeStanzaAsync(r); @@ -784,6 +783,7 @@ public class XmppConnection implements Runnable { sendServiceDiscoveryInfo(account.getJid().toBareJid()); sendServiceDiscoveryItems(account.getServer()); Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": online with resource " + account.getResource()); + this.lastSessionStarted = SystemClock.elapsedRealtime(); changeStatus(Account.State.ONLINE); if (bindListener != null) { bindListener.onBind(account); @@ -1100,12 +1100,7 @@ public class XmppConnection implements Runnable { } public long getLastSessionEstablished() { - final long diff; - if (this.lastSessionStarted == 0) { - diff = SystemClock.elapsedRealtime() - this.lastConnect; - } else { - diff = SystemClock.elapsedRealtime() - this.lastSessionStarted; - } + final long diff = SystemClock.elapsedRealtime() - this.lastSessionStarted; return System.currentTimeMillis() - diff; } -- cgit v1.2.3 From 7617a19280d7d7c6d716ce366419db5993cc3254 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 25 Aug 2015 11:11:53 +0200 Subject: additonal null checks in file backend --- src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 9381ba1d8..628f56303 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -137,6 +137,9 @@ public class FileBackend { options.inJustDecodeBounds = true; try { BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(uri), null, options); + if (options == null || options.outMimeType == null) { + return false; + } return (options.outWidth <= Config.IMAGE_SIZE && options.outHeight <= Config.IMAGE_SIZE && options.outMimeType.contains(Config.IMAGE_FORMAT.name().toLowerCase())); } catch (FileNotFoundException e) { return false; -- cgit v1.2.3 From 25c49d5e34a842ddbe0a7430c87ea46065468245 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 25 Aug 2015 11:12:10 +0200 Subject: catch some db query exceptions --- src/main/java/eu/siacs/conversations/utils/FileUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/utils/FileUtils.java b/src/main/java/eu/siacs/conversations/utils/FileUtils.java index a13300d43..c29841112 100644 --- a/src/main/java/eu/siacs/conversations/utils/FileUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/FileUtils.java @@ -104,15 +104,17 @@ public class FileUtils { }; try { - cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, - null); + cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } + } catch(Exception e) { + return null; } finally { - if (cursor != null) + if (cursor != null) { cursor.close(); + } } return null; } -- cgit v1.2.3 From 5eae1e52d264ac78f5e902fc647009cde5337946 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 25 Aug 2015 11:43:10 +0200 Subject: cleared up some error messages in axolotl service and execute publishOwnDevicesWhenNeeded() only if processing our own jid --- .../eu/siacs/conversations/crypto/axolotl/AxolotlService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index d700b644b..21b49b10b 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -282,7 +282,9 @@ public class AxolotlService { XmppAxolotlSession.Trust.UNTRUSTED); this.deviceIds.put(jid, deviceIds); mXmppConnectionService.keyStatusUpdated(); - publishOwnDeviceIdIfNeeded(); + if (account.getJid().toBareJid().equals(jid.toBareJid())) { + publishOwnDeviceIdIfNeeded(); + } } public void wipeOtherPepDevices() { @@ -320,12 +322,14 @@ public class AxolotlService { mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - // TODO: implement this! + if (packet.getType() != IqPacket.TYPE.RESULT) { + Log.d(Config.LOGTAG, getLogprefix(account)+ "Error received while publishing own device id" + packet.findChild("error")); + } } }); } } else { - Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing device ID:" + packet.findChild("error")); + Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while retrieving Device Ids" + packet.findChild("error")); } } }); -- cgit v1.2.3 From b84fecf51abd0f6e02d49307827622b5aa6f4044 Mon Sep 17 00:00:00 2001 From: Andreas Straub Date: Tue, 25 Aug 2015 12:17:09 +0200 Subject: Pass through device IDs when updating own list --- .../crypto/axolotl/AxolotlService.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 21b49b10b..816264eae 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -257,6 +257,8 @@ public class AxolotlService { if (jid.toBareJid().equals(account.getJid().toBareJid())) { if (deviceIds.contains(getOwnDeviceId())) { deviceIds.remove(getOwnDeviceId()); + } else { + publishOwnDeviceId(deviceIds); } for (Integer deviceId : deviceIds) { AxolotlAddress ownDeviceAddress = new AxolotlAddress(jid.toBareJid().toString(), deviceId); @@ -282,9 +284,6 @@ public class AxolotlService { XmppAxolotlSession.Trust.UNTRUSTED); this.deviceIds.put(jid, deviceIds); mXmppConnectionService.keyStatusUpdated(); - if (account.getJid().toBareJid().equals(jid.toBareJid())) { - publishOwnDeviceIdIfNeeded(); - } } public void wipeOtherPepDevices() { @@ -312,21 +311,8 @@ public class AxolotlService { if (packet.getType() == IqPacket.TYPE.RESULT) { Element item = mXmppConnectionService.getIqParser().getItem(packet); Set deviceIds = mXmppConnectionService.getIqParser().deviceIds(item); - if (deviceIds == null) { - deviceIds = new HashSet(); - } if (!deviceIds.contains(getOwnDeviceId())) { - deviceIds.add(getOwnDeviceId()); - IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds); - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Own device " + getOwnDeviceId() + " not in PEP devicelist. Publishing: " + publish); - mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() != IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG, getLogprefix(account)+ "Error received while publishing own device id" + packet.findChild("error")); - } - } - }); + publishOwnDeviceId(deviceIds); } } else { Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while retrieving Device Ids" + packet.findChild("error")); @@ -335,6 +321,20 @@ public class AxolotlService { }); } + public void publishOwnDeviceId(Set deviceIds) { + deviceIds.add(getOwnDeviceId()); + IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds); + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Own device " + getOwnDeviceId() + " not in PEP devicelist. Publishing: " + publish); + mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() != IqPacket.TYPE.RESULT) { + Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error")); + } + } + }); + } + public void publishBundlesIfNeeded() { IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(account.getJid().toBareJid(), getOwnDeviceId()); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { -- cgit v1.2.3 From ae9de26f597b63733e584e65e51adbfd1df755ad Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 25 Aug 2015 12:40:22 +0200 Subject: remove unused imports. --- .../conversations/persistance/FileBackend.java | 2 -- .../services/XmppConnectionService.java | 2 +- .../conversations/ui/adapter/MessageAdapter.java | 1 - .../conversations/xmpp/jingle/JingleTransport.java | 26 ---------------------- 4 files changed, 1 insertion(+), 30 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 628f56303..d5e4645ea 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -1,6 +1,5 @@ package eu.siacs.conversations.persistance; -import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -8,7 +7,6 @@ import android.graphics.Matrix; import android.graphics.RectF; import android.net.Uri; import android.os.Environment; -import android.provider.MediaStore; import android.util.Base64; import android.util.Base64OutputStream; import android.util.Log; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b08a71bfa..ef0c84d54 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -84,9 +84,9 @@ import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.OnBindListener; import eu.siacs.conversations.xmpp.OnContactStatusChanged; import eu.siacs.conversations.xmpp.OnIqPacketReceived; +import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.OnMessageAcknowledged; import eu.siacs.conversations.xmpp.OnMessagePacketReceived; -import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.OnPresencePacketReceived; import eu.siacs.conversations.xmpp.OnStatusChanged; import eu.siacs.conversations.xmpp.OnUpdateBlocklist; diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 8cdcb585f..d20761b22 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -3,7 +3,6 @@ package eu.siacs.conversations.ui.adapter; import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.graphics.Color; import android.graphics.Typeface; import android.net.Uri; import android.text.Spannable; diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleTransport.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleTransport.java index b32111584..e832d3f58 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleTransport.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleTransport.java @@ -1,31 +1,5 @@ package eu.siacs.conversations.xmpp.jingle; -import android.util.Log; -import android.util.Pair; - -import org.bouncycastle.crypto.engines.AESEngine; -import org.bouncycastle.crypto.modes.AEADBlockCipher; -import org.bouncycastle.crypto.modes.GCMBlockCipher; -import org.bouncycastle.crypto.params.AEADParameters; -import org.bouncycastle.crypto.params.KeyParameter; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.security.InvalidAlgorithmParameterException; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; - -import javax.crypto.Cipher; -import javax.crypto.CipherInputStream; -import javax.crypto.CipherOutputStream; -import javax.crypto.NoSuchPaddingException; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.SecretKeySpec; - -import eu.siacs.conversations.Config; import eu.siacs.conversations.entities.DownloadableFile; public abstract class JingleTransport { -- cgit v1.2.3 From eafcf38ec9efc635ce81b8dd7d867eba67072873 Mon Sep 17 00:00:00 2001 From: Andreas Straub Date: Tue, 25 Aug 2015 18:41:30 +0200 Subject: Limit number of PEP publish tries If PEP publish tries are repeatedly triggered by empty PEP updates, stop attempting to publish after 3 tries. This should work around broken PEP implementations in older ejabberd and OpenFire versions. --- .../crypto/axolotl/AxolotlService.java | 51 ++++++++++++++++++---- 1 file changed, 42 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 816264eae..a724429dd 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -50,6 +50,7 @@ public class AxolotlService { public static final String LOGPREFIX = "AxolotlService"; public static final int NUM_KEYS_TO_PUBLISH = 100; + public static final int publishTriesThreshold = 3; private final Account account; private final XmppConnectionService mXmppConnectionService; @@ -59,6 +60,8 @@ public class AxolotlService { private final Map messageCache; private final FetchStatusMap fetchStatusMap; private final SerialSingleThreadExecutor executor; + private int numPublishTriesOnEmptyPep = 0; + private boolean pepBroken = false; private static class AxolotlAddressMap { protected Map> map; @@ -255,6 +258,10 @@ public class AxolotlService { public void registerDevices(final Jid jid, @NonNull final Set deviceIds) { if (jid.toBareJid().equals(account.getJid().toBareJid())) { + if (!deviceIds.isEmpty()) { + pepBroken = false; + numPublishTriesOnEmptyPep = 0; + } if (deviceIds.contains(getOwnDeviceId())) { deviceIds.remove(getOwnDeviceId()); } else { @@ -287,6 +294,10 @@ public class AxolotlService { } public void wipeOtherPepDevices() { + if (pepBroken) { + Log.d(Config.LOGTAG, getLogprefix(account) + "wipeOtherPepDevices called, but PEP is broken. Ignoring... "); + return; + } Set deviceIds = new HashSet<>(); deviceIds.add(getOwnDeviceId()); IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds); @@ -304,6 +315,10 @@ public class AxolotlService { } public void publishOwnDeviceIdIfNeeded() { + if (pepBroken) { + Log.d(Config.LOGTAG, getLogprefix(account) + "publishOwnDeviceIdIfNeeded called, but PEP is broken. Ignoring... "); + return; + } IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(account.getJid().toBareJid()); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override @@ -322,20 +337,38 @@ public class AxolotlService { } public void publishOwnDeviceId(Set deviceIds) { - deviceIds.add(getOwnDeviceId()); - IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds); - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Own device " + getOwnDeviceId() + " not in PEP devicelist. Publishing: " + publish); - mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() != IqPacket.TYPE.RESULT) { - Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error")); + if (!deviceIds.contains(getOwnDeviceId())) { + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Own device " + getOwnDeviceId() + " not in PEP devicelist."); + if (deviceIds.isEmpty()) { + if (numPublishTriesOnEmptyPep >= publishTriesThreshold) { + Log.w(Config.LOGTAG, getLogprefix(account) + "Own device publish attempt threshold exceeded, aborting..."); + pepBroken = true; + return; + } else { + numPublishTriesOnEmptyPep++; + Log.w(Config.LOGTAG, getLogprefix(account) + "Own device list empty, attempting to publish (try " + numPublishTriesOnEmptyPep + ")"); } + } else { + numPublishTriesOnEmptyPep = 0; } - }); + deviceIds.add(getOwnDeviceId()); + IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds); + mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + if (packet.getType() != IqPacket.TYPE.RESULT) { + Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error")); + } + } + }); + } } public void publishBundlesIfNeeded() { + if (!pepBroken) { + Log.d(Config.LOGTAG, getLogprefix(account) + "publishBundlesIfNeeded called, but PEP is broken. Ignoring... "); + return; + } IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(account.getJid().toBareJid(), getOwnDeviceId()); mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override -- cgit v1.2.3 From 25a9d59412690528c86df6fb7d73a3bfba12825c Mon Sep 17 00:00:00 2001 From: Andreas Straub Date: Tue, 25 Aug 2015 18:52:36 +0200 Subject: Add more logging to pep attemp counter logic --- src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index a724429dd..42e87494c 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -259,6 +259,7 @@ public class AxolotlService { public void registerDevices(final Jid jid, @NonNull final Set deviceIds) { if (jid.toBareJid().equals(account.getJid().toBareJid())) { if (!deviceIds.isEmpty()) { + Log.d(Config.LOGTAG, getLogprefix(account) + "Received non-empty own device list. Resetting publish attemps and pepBroken status."); pepBroken = false; numPublishTriesOnEmptyPep = 0; } -- cgit v1.2.3 From 0eeaccd974a123b656f5e0affde88dbbc3173821 Mon Sep 17 00:00:00 2001 From: Andreas Straub Date: Wed, 26 Aug 2015 00:27:39 +0200 Subject: Fix key publishing Remove invalid check for result code, which prevented publishing if the node was empty to begin with. Fix pepBroken check --- .../crypto/axolotl/AxolotlService.java | 140 ++++++++++----------- 1 file changed, 68 insertions(+), 72 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 42e87494c..4452fcc4c 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -366,7 +366,7 @@ public class AxolotlService { } public void publishBundlesIfNeeded() { - if (!pepBroken) { + if (pepBroken) { Log.d(Config.LOGTAG, getLogprefix(account) + "publishBundlesIfNeeded called, but PEP is broken. Ignoring... "); return; } @@ -374,92 +374,88 @@ public class AxolotlService { mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - if (packet.getType() == IqPacket.TYPE.RESULT) { - PreKeyBundle bundle = mXmppConnectionService.getIqParser().bundle(packet); - Map keys = mXmppConnectionService.getIqParser().preKeyPublics(packet); - boolean flush = false; - if (bundle == null) { - Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received invalid bundle:" + packet); - bundle = new PreKeyBundle(-1, -1, -1, null, -1, null, null, null); - flush = true; - } - if (keys == null) { - Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received invalid prekeys:" + packet); + PreKeyBundle bundle = mXmppConnectionService.getIqParser().bundle(packet); + Map keys = mXmppConnectionService.getIqParser().preKeyPublics(packet); + boolean flush = false; + if (bundle == null) { + Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received invalid bundle:" + packet); + bundle = new PreKeyBundle(-1, -1, -1, null, -1, null, null, null); + flush = true; + } + if (keys == null) { + Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received invalid prekeys:" + packet); + } + try { + boolean changed = false; + // Validate IdentityKey + IdentityKeyPair identityKeyPair = axolotlStore.getIdentityKeyPair(); + if (flush || !identityKeyPair.getPublicKey().equals(bundle.getIdentityKey())) { + Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding own IdentityKey " + identityKeyPair.getPublicKey() + " to PEP."); + changed = true; } - try { - boolean changed = false; - // Validate IdentityKey - IdentityKeyPair identityKeyPair = axolotlStore.getIdentityKeyPair(); - if (flush || !identityKeyPair.getPublicKey().equals(bundle.getIdentityKey())) { - Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding own IdentityKey " + identityKeyPair.getPublicKey() + " to PEP."); - changed = true; - } - // Validate signedPreKeyRecord + ID - SignedPreKeyRecord signedPreKeyRecord; - int numSignedPreKeys = axolotlStore.loadSignedPreKeys().size(); - try { - signedPreKeyRecord = axolotlStore.loadSignedPreKey(bundle.getSignedPreKeyId()); - if (flush - || !bundle.getSignedPreKey().equals(signedPreKeyRecord.getKeyPair().getPublicKey()) - || !Arrays.equals(bundle.getSignedPreKeySignature(), signedPreKeyRecord.getSignature())) { - Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding new signedPreKey with ID " + (numSignedPreKeys + 1) + " to PEP."); - signedPreKeyRecord = KeyHelper.generateSignedPreKey(identityKeyPair, numSignedPreKeys + 1); - axolotlStore.storeSignedPreKey(signedPreKeyRecord.getId(), signedPreKeyRecord); - changed = true; - } - } catch (InvalidKeyIdException e) { + // Validate signedPreKeyRecord + ID + SignedPreKeyRecord signedPreKeyRecord; + int numSignedPreKeys = axolotlStore.loadSignedPreKeys().size(); + try { + signedPreKeyRecord = axolotlStore.loadSignedPreKey(bundle.getSignedPreKeyId()); + if (flush + || !bundle.getSignedPreKey().equals(signedPreKeyRecord.getKeyPair().getPublicKey()) + || !Arrays.equals(bundle.getSignedPreKeySignature(), signedPreKeyRecord.getSignature())) { Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding new signedPreKey with ID " + (numSignedPreKeys + 1) + " to PEP."); signedPreKeyRecord = KeyHelper.generateSignedPreKey(identityKeyPair, numSignedPreKeys + 1); axolotlStore.storeSignedPreKey(signedPreKeyRecord.getId(), signedPreKeyRecord); changed = true; } + } catch (InvalidKeyIdException e) { + Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding new signedPreKey with ID " + (numSignedPreKeys + 1) + " to PEP."); + signedPreKeyRecord = KeyHelper.generateSignedPreKey(identityKeyPair, numSignedPreKeys + 1); + axolotlStore.storeSignedPreKey(signedPreKeyRecord.getId(), signedPreKeyRecord); + changed = true; + } - // Validate PreKeys - Set preKeyRecords = new HashSet<>(); - if (keys != null) { - for (Integer id : keys.keySet()) { - try { - PreKeyRecord preKeyRecord = axolotlStore.loadPreKey(id); - if (preKeyRecord.getKeyPair().getPublicKey().equals(keys.get(id))) { - preKeyRecords.add(preKeyRecord); - } - } catch (InvalidKeyIdException ignored) { + // Validate PreKeys + Set preKeyRecords = new HashSet<>(); + if (keys != null) { + for (Integer id : keys.keySet()) { + try { + PreKeyRecord preKeyRecord = axolotlStore.loadPreKey(id); + if (preKeyRecord.getKeyPair().getPublicKey().equals(keys.get(id))) { + preKeyRecords.add(preKeyRecord); } + } catch (InvalidKeyIdException ignored) { } } - int newKeys = NUM_KEYS_TO_PUBLISH - preKeyRecords.size(); - if (newKeys > 0) { - List newRecords = KeyHelper.generatePreKeys( - axolotlStore.getCurrentPreKeyId() + 1, newKeys); - preKeyRecords.addAll(newRecords); - for (PreKeyRecord record : newRecords) { - axolotlStore.storePreKey(record.getId(), record); - } - changed = true; - Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding " + newKeys + " new preKeys to PEP."); + } + int newKeys = NUM_KEYS_TO_PUBLISH - preKeyRecords.size(); + if (newKeys > 0) { + List newRecords = KeyHelper.generatePreKeys( + axolotlStore.getCurrentPreKeyId() + 1, newKeys); + preKeyRecords.addAll(newRecords); + for (PreKeyRecord record : newRecords) { + axolotlStore.storePreKey(record.getId(), record); } + changed = true; + Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Adding " + newKeys + " new preKeys to PEP."); + } - if (changed) { - IqPacket publish = mXmppConnectionService.getIqGenerator().publishBundles( - signedPreKeyRecord, axolotlStore.getIdentityKeyPair().getPublicKey(), - preKeyRecords, getOwnDeviceId()); - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + ": Bundle " + getOwnDeviceId() + " in PEP not current. Publishing: " + publish); - mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { - @Override - public void onIqPacketReceived(Account account, IqPacket packet) { - // TODO: implement this! - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Published bundle, got: " + packet); - } - }); - } - } catch (InvalidKeyException e) { - Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Failed to publish bundle " + getOwnDeviceId() + ", reason: " + e.getMessage()); - return; + if (changed) { + IqPacket publish = mXmppConnectionService.getIqGenerator().publishBundles( + signedPreKeyRecord, axolotlStore.getIdentityKeyPair().getPublicKey(), + preKeyRecords, getOwnDeviceId()); + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + ": Bundle " + getOwnDeviceId() + " in PEP not current. Publishing: " + publish); + mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { + @Override + public void onIqPacketReceived(Account account, IqPacket packet) { + // TODO: implement this! + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Published bundle, got: " + packet); + } + }); } - } else { - Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing Bundle:" + packet.findChild("error")); + } catch (InvalidKeyException e) { + Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Failed to publish bundle " + getOwnDeviceId() + ", reason: " + e.getMessage()); + return; } } }); -- cgit v1.2.3 From 3e0636367a733285526c709138110ddb86899196 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 26 Aug 2015 11:39:18 +0200 Subject: Revert "improved compatibility with muc components that change the message id" This reverts commit df86b0fc47cb7af8e97826f97d0e202405cff414. --- src/main/java/eu/siacs/conversations/parser/MessageParser.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 025ed1e7e..ec900de4d 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -311,10 +311,9 @@ public class MessageParser extends AbstractParser implements status = Message.STATUS_SEND_RECEIVED; if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) { return; - } else { - Message message = conversation.findSentMessageWithBody(body); + } else if (remoteMsgId == null) { + Message message = conversation.findSentMessageWithBody(packet.getBody()); if (message != null) { - message.setRemoteMsgId(remoteMsgId); mXmppConnectionService.markMessage(message, status); return; } -- cgit v1.2.3 From ea2ce78d6e0b37db21ebffd9f0f991ab25e17f1a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 26 Aug 2015 12:11:12 +0200 Subject: be more restrictive about marking messages as sent_received in muc parser --- .../siacs/conversations/entities/Conversation.java | 21 ++++++++++++++++----- .../services/XmppConnectionService.java | 5 ++--- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 36d6b43b0..e6c044a1c 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -201,14 +201,25 @@ public class Conversation extends AbstractEntity implements Blockable { } } - public Message findSentMessageWithUuid(String uuid) { + public Message findSentMessageWithUuidOrRemoteId(String id) { synchronized (this.messages) { for (Message message : this.messages) { - if (uuid.equals(message.getUuid()) - || (message.getStatus() >= Message.STATUS_SEND && uuid - .equals(message.getRemoteMsgId()))) { + if (id.equals(message.getUuid()) + || (message.getStatus() >= Message.STATUS_SEND + && id.equals(message.getRemoteMsgId()))) { return message; - } + } + } + } + return null; + } + + public Message findSentMessageWithUuid(String id) { + synchronized (this.messages) { + for (Message message : this.messages) { + if (id.equals(message.getUuid())) { + return message; + } } } return null; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index ef0c84d54..a2b101bbe 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2216,7 +2216,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa } for (Conversation conversation : getConversations()) { if (conversation.getJid().toBareJid().equals(recipient) && conversation.getAccount() == account) { - final Message message = conversation.findSentMessageWithUuid(uuid); + final Message message = conversation.findSentMessageWithUuidOrRemoteId(uuid); if (message != null) { markMessage(message, status); } @@ -2226,8 +2226,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return null; } - public boolean markMessage(Conversation conversation, String uuid, - int status) { + public boolean markMessage(Conversation conversation, String uuid, int status) { if (uuid == null) { return false; } else { -- cgit v1.2.3 From f6b7a25e290d3ddfa46a5e704b05abe0e6b50dd5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 26 Aug 2015 14:01:37 +0200 Subject: moved actual iq callback out of synchronized find callback block --- src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 6a94a5f3e..bb0c3987b 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -472,29 +472,33 @@ public class XmppConnection implements Runnable { this.jingleListener.onJinglePacketReceived(account,(JinglePacket) packet); } } else { + OnIqPacketReceived callback = null; synchronized (this.packetCallbacks) { if (packetCallbacks.containsKey(packet.getId())) { final Pair packetCallbackDuple = packetCallbacks.get(packet.getId()); // Packets to the server should have responses from the server if (packetCallbackDuple.first.toServer(account)) { if (packet.fromServer(account)) { - packetCallbackDuple.second.onIqPacketReceived(account, packet); + callback = packetCallbackDuple.second; packetCallbacks.remove(packet.getId()); } else { Log.e(Config.LOGTAG, account.getJid().toBareJid().toString() + ": ignoring spoofed iq packet"); } } else { if (packet.getFrom().equals(packetCallbackDuple.first.getTo())) { - packetCallbackDuple.second.onIqPacketReceived(account, packet); + callback = packetCallbackDuple.second; 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) { - this.unregisteredIqListener.onIqPacketReceived(account, packet); + callback = this.unregisteredIqListener; } } + if (callback != null) { + callback.onIqPacketReceived(account,packet); + } } } -- cgit v1.2.3 From c4a548ada00f5abd175e28ac1df5204f8bbc092f Mon Sep 17 00:00:00 2001 From: Andreas Straub Date: Wed, 26 Aug 2015 15:32:49 +0200 Subject: Only announce device after publishing bundle --- .../crypto/axolotl/AxolotlService.java | 24 ++++++++++++++++------ .../services/XmppConnectionService.java | 3 +-- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java index 4452fcc4c..17d911b44 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java @@ -231,8 +231,7 @@ public class AxolotlService { axolotlStore.regenerate(); sessions.clear(); fetchStatusMap.clear(); - publishBundlesIfNeeded(); - publishOwnDeviceIdIfNeeded(); + publishBundlesIfNeeded(true); } public int getOwnDeviceId() { @@ -365,7 +364,7 @@ public class AxolotlService { } } - public void publishBundlesIfNeeded() { + public void publishBundlesIfNeeded(final boolean announceAfter) { if (pepBroken) { Log.d(Config.LOGTAG, getLogprefix(account) + "publishBundlesIfNeeded called, but PEP is broken. Ignoring... "); return; @@ -448,10 +447,23 @@ public class AxolotlService { mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { @Override public void onIqPacketReceived(Account account, IqPacket packet) { - // TODO: implement this! - Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Published bundle, got: " + packet); + if (packet.getType() == IqPacket.TYPE.RESULT) { + Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Successfully published bundle. "); + if (announceAfter) { + Log.d(Config.LOGTAG, getLogprefix(account) + "Announcing device " + getOwnDeviceId()); + publishOwnDeviceIdIfNeeded(); + } + } else { + Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing bundle: " + packet.findChild("error")); + } } }); + } else { + Log.d(Config.LOGTAG, getLogprefix(account) + "Bundle " + getOwnDeviceId() + " in PEP was current"); + if (announceAfter) { + Log.d(Config.LOGTAG, getLogprefix(account) + "Announcing device " + getOwnDeviceId()); + publishOwnDeviceIdIfNeeded(); + } } } catch (InvalidKeyException e) { Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Failed to publish bundle " + getOwnDeviceId() + ", reason: " + e.getMessage()); @@ -733,7 +745,7 @@ public class AxolotlService { plaintextMessage = message.decrypt(session, getOwnDeviceId()); Integer preKeyId = session.getPreKeyId(); if (preKeyId != null) { - publishBundlesIfNeeded(); + publishBundlesIfNeeded(false); session.resetPreKeyId(); } } catch (CryptoFailedException e) { diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index a2b101bbe..4edaa324c 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -165,8 +165,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa mMessageArchiveService.executePendingQueries(account); mJingleConnectionManager.cancelInTransmission(); syncDirtyContacts(account); - account.getAxolotlService().publishOwnDeviceIdIfNeeded(); - account.getAxolotlService().publishBundlesIfNeeded(); + account.getAxolotlService().publishBundlesIfNeeded(true); } }; private final OnMessageAcknowledged mOnMessageAcknowledgedListener = new OnMessageAcknowledged() { -- cgit v1.2.3