tls-psk: show error message for unspecialized io exception

This commit is contained in:
Vincent Breitmoser
2017-06-12 16:28:22 +02:00
parent fa3a82ded2
commit af1d028520
4 changed files with 35 additions and 4 deletions

View File

@@ -78,7 +78,8 @@ public class KeyTransferInteractor {
private static final int CONNECTION_RECEIVE_OK = 4; private static final int CONNECTION_RECEIVE_OK = 4;
private static final int CONNECTION_LOST = 5; private static final int CONNECTION_LOST = 5;
private static final int CONNECTION_ERROR_CONNECT = 6; private static final int CONNECTION_ERROR_CONNECT = 6;
private static final int CONNECTION_ERROR_LISTEN = 7; private static final int CONNECTION_ERROR_WHILE_CONNECTED = 7;
private static final int CONNECTION_ERROR_LISTEN = 8;
private static final String QRCODE_URI_FORMAT = "PGP+TRANSFER://%s@%s:%s"; private static final String QRCODE_URI_FORMAT = "PGP+TRANSFER://%s@%s:%s";
private static final int TIMEOUT_RECEIVING = 2000; private static final int TIMEOUT_RECEIVING = 2000;
@@ -174,7 +175,8 @@ public class KeyTransferInteractor {
Log.d(Constants.TAG, "ssl handshake error!", e); Log.d(Constants.TAG, "ssl handshake error!", e);
invokeListener(CONNECTION_ERROR_CONNECT, null); invokeListener(CONNECTION_ERROR_CONNECT, null);
} catch (IOException e) { } catch (IOException e) {
Log.e(Constants.TAG, "error!", e); Log.e(Constants.TAG, "communication error!", e);
invokeListener(CONNECTION_ERROR_WHILE_CONNECTED, e.getLocalizedMessage());
} }
} finally { } finally {
closeQuietly(socket); closeQuietly(socket);
@@ -338,6 +340,9 @@ public class KeyTransferInteractor {
case CONNECTION_LOST: case CONNECTION_LOST:
callback.onConnectionLost(); callback.onConnectionLost();
break; break;
case CONNECTION_ERROR_WHILE_CONNECTED:
callback.onConnectionError(arg);
break;
case CONNECTION_ERROR_CONNECT: case CONNECTION_ERROR_CONNECT:
callback.onConnectionErrorConnect(); callback.onConnectionErrorConnect();
break; break;
@@ -392,6 +397,7 @@ public class KeyTransferInteractor {
void onConnectionErrorConnect(); void onConnectionErrorConnect();
void onConnectionErrorListen(); void onConnectionErrorListen();
void onConnectionError(String arg);
} }
/** /**
@@ -413,9 +419,11 @@ public class KeyTransferInteractor {
} }
String sAddr = addr.getHostAddress(); String sAddr = addr.getHostAddress();
boolean isIPv4 = sAddr.indexOf(':') < 0; boolean isIPv4 = sAddr.indexOf(':') < 0;
if (isIPv4 && useIPv4) { if (useIPv4) {
if (isIPv4) {
return sAddr; return sAddr;
} else if (!isIPv4) { }
} else {
int delimIndex = sAddr.indexOf('%'); // drop ip6 zone suffix int delimIndex = sAddr.indexOf('%'); // drop ip6 zone suffix
if (delimIndex >= 0) { if (delimIndex >= 0) {
sAddr = sAddr.substring(0, delimIndex); sAddr = sAddr.substring(0, delimIndex);

View File

@@ -276,6 +276,16 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
view.showErrorListenFailed(); view.showErrorListenFailed();
} }
@Override
public void onConnectionError(String errorMessage) {
view.showErrorConnectionError(errorMessage);
connectionClear();
if (wasConnected) {
view.showViewDisconnected();
secretKeyAdapter.setAllDisabled(true);
}
}
private void connectionStartConnect(String qrCodeContent) { private void connectionStartConnect(String qrCodeContent) {
connectionClear(); connectionClear();
@@ -367,6 +377,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
void showErrorBadKey(); void showErrorBadKey();
void showErrorConnectionFailed(); void showErrorConnectionFailed();
void showErrorListenFailed(); void showErrorListenFailed();
void showErrorConnectionError(String errorMessage);
void showResultNotification(ImportKeyResult result); void showResultNotification(ImportKeyResult result);
void setSecretKeyAdapter(Adapter adapter); void setSecretKeyAdapter(Adapter adapter);

View File

@@ -255,6 +255,16 @@ public class TransferFragment extends Fragment implements TransferMvpView {
Notify.create(getActivity(), R.string.transfer_error_listen, Style.ERROR).show(); Notify.create(getActivity(), R.string.transfer_error_listen, Style.ERROR).show();
} }
@Override
public void showErrorConnectionError(String errorMessage) {
if (errorMessage != null) {
String text = getString(R.string.transfer_error_generic_msg, errorMessage);
Notify.create(getActivity(), text, Style.ERROR).show();
} else {
Notify.create(getActivity(), R.string.transfer_error_generic, Style.ERROR).show();
}
}
@Override @Override
public void showResultNotification(ImportKeyResult result) { public void showResultNotification(ImportKeyResult result) {
result.createNotify(getActivity()).show(); result.createNotify(getActivity()).show();

View File

@@ -1901,6 +1901,8 @@
<string name="transfer_error_read_incoming">"Failed reading incoming key!"</string> <string name="transfer_error_read_incoming">"Failed reading incoming key!"</string>
<string name="transfer_error_connect">"Connection failed!"</string> <string name="transfer_error_connect">"Connection failed!"</string>
<string name="transfer_error_listen">"Error waiting for connection!"</string> <string name="transfer_error_listen">"Error waiting for connection!"</string>
<string name="transfer_error_generic">"Unknown communication error!"</string>
<string name="transfer_error_generic_msg">"Communication error: %s"</string>
<string name="transfer_not_available">"Sorry, this feature can only be used on Android 5 or newer :("</string> <string name="transfer_not_available">"Sorry, this feature can only be used on Android 5 or newer :("</string>
<string name="transfer_list_empty">No keys on this device that could be sent. Waiting for incoming keys…</string> <string name="transfer_list_empty">No keys on this device that could be sent. Waiting for incoming keys…</string>