From 3ca3603ed066fa8e27605241ddb95efc15bd7425 Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Tue, 19 Apr 2022 19:25:48 +0200 Subject: [PATCH] Show warning if no app data is exchanged --- .../java/com/emanuelef/remote_capture/Utils.java | 2 +- .../activities/EditFilterActivity.java | 4 ++-- .../fragments/ConnectionOverview.java | 13 +++++++++---- .../model/ConnectionDescriptor.java | 16 ++++++++++------ app/src/main/res/layout/edit_filter_activity.xml | 4 ++-- app/src/main/res/values/strings.xml | 3 ++- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/Utils.java b/app/src/main/java/com/emanuelef/remote_capture/Utils.java index 1bfe0e82..3d72596c 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/Utils.java +++ b/app/src/main/java/com/emanuelef/remote_capture/Utils.java @@ -1111,7 +1111,7 @@ public class Utils { case NOT_DECRYPTABLE: color = R.color.warning; break; - case TLS_ERROR: + case ERROR: color = R.color.danger; break; default: diff --git a/app/src/main/java/com/emanuelef/remote_capture/activities/EditFilterActivity.java b/app/src/main/java/com/emanuelef/remote_capture/activities/EditFilterActivity.java index 85c3f086..347ada0d 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/activities/EditFilterActivity.java +++ b/app/src/main/java/com/emanuelef/remote_capture/activities/EditFilterActivity.java @@ -101,9 +101,9 @@ public class EditFilterActivity extends BaseActivity { mDecChips = new ArrayList<>(Arrays.asList( new Pair<>(DecryptionStatus.DECRYPTED, findViewById(R.id.dec_status_decrypted)), - new Pair<>(DecryptionStatus.DECRYPTION_IN_PROGRESS, findViewById(R.id.dec_status_in_progress)), + new Pair<>(DecryptionStatus.WAITING_DATA, findViewById(R.id.dec_status_waiting_data)), new Pair<>(DecryptionStatus.NOT_DECRYPTABLE, findViewById(R.id.dec_status_not_decryptable)), - new Pair<>(DecryptionStatus.TLS_ERROR, findViewById(R.id.dec_status_error)) + new Pair<>(DecryptionStatus.ERROR, findViewById(R.id.dec_status_error)) )); if(CaptureService.isDecryptingTLS()) { diff --git a/app/src/main/java/com/emanuelef/remote_capture/fragments/ConnectionOverview.java b/app/src/main/java/com/emanuelef/remote_capture/fragments/ConnectionOverview.java index d2eb92ec..fa97297d 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/fragments/ConnectionOverview.java +++ b/app/src/main/java/com/emanuelef/remote_capture/fragments/ConnectionOverview.java @@ -54,7 +54,7 @@ public class ConnectionOverview extends Fragment implements ConnectionDetailsAct private ConnectionDescriptor mConn; private TableLayout mTable; private TextView mBytesView; - private TextView mPayload; + private TextView mPayloadLen; private TextView mPacketsView; private TextView mDurationView; private TextView mBlockedPkts; @@ -106,7 +106,7 @@ public class ConnectionOverview extends Fragment implements ConnectionDetailsAct FlagImageView country_flag = view.findViewById(R.id.country_flag); TextView asn = view.findViewById(R.id.asn); mTable = view.findViewById(R.id.table); - mPayload = view.findViewById(R.id.detail_payload); + mPayloadLen = view.findViewById(R.id.detail_payload); mBytesView = view.findViewById(R.id.detail_bytes); mPacketsView = view.findViewById(R.id.detail_packets); mBlockedPkts = view.findViewById(R.id.blocked_pkts); @@ -227,7 +227,7 @@ public class ConnectionOverview extends Fragment implements ConnectionDetailsAct public void connectionUpdated() { Context context = mBytesView.getContext(); - mPayload.setText(Utils.formatBytes(mConn.payload_length)); + mPayloadLen.setText(Utils.formatBytes(mConn.payload_length)); mBytesView.setText(String.format(getResources().getString(R.string.rcvd_and_sent), Utils.formatBytes(mConn.rcvd_bytes), Utils.formatBytes(mConn.sent_bytes))); mPacketsView.setText(String.format(getResources().getString(R.string.rcvd_and_sent), Utils.formatIntShort(mConn.rcvd_pkts), Utils.formatIntShort(mConn.sent_pkts))); @@ -254,6 +254,11 @@ public class ConnectionOverview extends Fragment implements ConnectionDetailsAct mError.setTextColor(ContextCompat.getColor(context, R.color.warning)); mError.setText(context.getString(R.string.connection_start_not_seen)); mError.setVisibility(View.VISIBLE); - } + } else if(mConn.payload_length == 0) { + mError.setTextColor(ContextCompat.getColor(context, R.color.warning)); + mError.setText(context.getString(R.string.warn_no_app_data)); + mError.setVisibility(View.VISIBLE); + } else + mError.setVisibility(View.GONE); } } diff --git a/app/src/main/java/com/emanuelef/remote_capture/model/ConnectionDescriptor.java b/app/src/main/java/com/emanuelef/remote_capture/model/ConnectionDescriptor.java index cf59ca2d..ced8753c 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/model/ConnectionDescriptor.java +++ b/app/src/main/java/com/emanuelef/remote_capture/model/ConnectionDescriptor.java @@ -68,8 +68,8 @@ public class ConnectionDescriptor { CLEARTEXT, DECRYPTED, NOT_DECRYPTABLE, - DECRYPTION_IN_PROGRESS, - TLS_ERROR, + WAITING_DATA, + ERROR, } /* Metadata */ @@ -136,7 +136,6 @@ public class ConnectionDescriptor { public void processUpdate(ConnectionUpdate update) { // The "update_type" is used to limit the amount of data sent via the JNI if((update.update_type & ConnectionUpdate.UPDATE_STATS) != 0) { - payload_length = update.payload_length; sent_bytes = update.sent_bytes; rcvd_bytes = update.rcvd_bytes; sent_pkts = update.sent_pkts; @@ -152,6 +151,10 @@ public class ConnectionDescriptor { // see MitmReceiver.handlePayload if((status == ConnectionDescriptor.CONN_STATUS_CLOSED) && (decryption_error != null)) status = ConnectionDescriptor.CONN_STATUS_CLIENT_ERROR; + + // with mitm we account the TLS payload length instead + if(!mitm_decrypt) + payload_length = update.payload_length; } if((update.update_type & ConnectionUpdate.UPDATE_INFO) != 0) { info = update.info; @@ -228,13 +231,13 @@ public class ConnectionDescriptor { if(isCleartext()) return DecryptionStatus.CLEARTEXT; else if(decryption_error != null) - return DecryptionStatus.TLS_ERROR; + return DecryptionStatus.ERROR; else if(isNotDecryptable()) return DecryptionStatus.NOT_DECRYPTABLE; else if(isDecrypted()) return DecryptionStatus.DECRYPTED; else - return DecryptionStatus.DECRYPTION_IN_PROGRESS; + return DecryptionStatus.WAITING_DATA; } public static String getDecryptionStatusLabel(DecryptionStatus status, Context ctx) { @@ -244,7 +247,7 @@ public class ConnectionDescriptor { case CLEARTEXT: resid = R.string.not_encrypted; break; case NOT_DECRYPTABLE: resid = R.string.not_decryptable; break; case DECRYPTED: resid = R.string.decrypted; break; - case DECRYPTION_IN_PROGRESS: resid = R.string.in_progress; break; + case WAITING_DATA: resid = R.string.waiting_application_data; break; default: resid = R.string.error; } @@ -289,6 +292,7 @@ public class ConnectionDescriptor { if(payload_chunks == null) payload_chunks = new ArrayList<>(); payload_chunks.add(chunk); + payload_length += chunk.payload.length; } private boolean hasHttp(boolean is_sent) { diff --git a/app/src/main/res/layout/edit_filter_activity.xml b/app/src/main/res/layout/edit_filter_activity.xml index 6c10a827..3d612473 100644 --- a/app/src/main/res/layout/edit_filter_activity.xml +++ b/app/src/main/res/layout/edit_filter_activity.xml @@ -121,11 +121,11 @@ android:text="@string/decrypted"/> + android:text="@string/waiting_application_data"/> Decrypted Decryption Decryption: %1$s - In progress PCAPdroid has not seen the start of this connection. Some information may be missing Traffic + No application data has been exchanged + Waiting data