tls-psk: improve error handling
This commit is contained in:
@@ -51,6 +51,7 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
import javax.net.ssl.KeyManager;
|
import javax.net.ssl.KeyManager;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLEngine;
|
import javax.net.ssl.SSLEngine;
|
||||||
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
import javax.net.ssl.SSLServerSocket;
|
import javax.net.ssl.SSLServerSocket;
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
import javax.net.ssl.TrustManager;
|
import javax.net.ssl.TrustManager;
|
||||||
@@ -145,6 +146,8 @@ public class KeyTransferInteractor {
|
|||||||
try {
|
try {
|
||||||
handleOpenConnection(socket);
|
handleOpenConnection(socket);
|
||||||
Log.d(Constants.TAG, "connection closed ok!");
|
Log.d(Constants.TAG, "connection closed ok!");
|
||||||
|
} catch (SSLHandshakeException e) {
|
||||||
|
invokeListener(CONNECTION_ERROR_CONNECT, null);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "error!", e);
|
Log.e(Constants.TAG, "error!", e);
|
||||||
}
|
}
|
||||||
@@ -172,7 +175,6 @@ public class KeyTransferInteractor {
|
|||||||
invokeListener(CONNECTION_LISTENING, qrCodeData);
|
invokeListener(CONNECTION_LISTENING, qrCodeData);
|
||||||
|
|
||||||
socket = serverSocket.accept();
|
socket = serverSocket.accept();
|
||||||
invokeListener(CONNECTION_ESTABLISHED, socket.getInetAddress().toString());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "error while listening!", e);
|
Log.e(Constants.TAG, "error while listening!", e);
|
||||||
invokeListener(CONNECTION_ERROR_LISTEN, null);
|
invokeListener(CONNECTION_ERROR_LISTEN, null);
|
||||||
@@ -187,7 +189,6 @@ public class KeyTransferInteractor {
|
|||||||
sslSocket.setEnabledCipherSuites(enabledCipherSuites);
|
sslSocket.setEnabledCipherSuites(enabledCipherSuites);
|
||||||
|
|
||||||
socket = sslSocket;
|
socket = sslSocket;
|
||||||
invokeListener(CONNECTION_ESTABLISHED, socket.getInetAddress().toString());
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(Constants.TAG, "error while connecting!", e);
|
Log.e(Constants.TAG, "error while connecting!", e);
|
||||||
invokeListener(CONNECTION_ERROR_CONNECT, null);
|
invokeListener(CONNECTION_ERROR_CONNECT, null);
|
||||||
@@ -211,9 +212,10 @@ public class KeyTransferInteractor {
|
|||||||
|
|
||||||
private void handleOpenConnection(Socket socket) throws IOException {
|
private void handleOpenConnection(Socket socket) throws IOException {
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
|
|
||||||
OutputStream outputStream = new BufferedOutputStream(socket.getOutputStream());
|
OutputStream outputStream = new BufferedOutputStream(socket.getOutputStream());
|
||||||
|
|
||||||
|
invokeListener(CONNECTION_ESTABLISHED, socket.getInetAddress().toString());
|
||||||
|
|
||||||
socket.setSoTimeout(500);
|
socket.setSoTimeout(500);
|
||||||
while (!isInterrupted() && socket.isConnected() && !socket.isClosed()) {
|
while (!isInterrupted() && socket.isConnected() && !socket.isClosed()) {
|
||||||
sendDataIfAvailable(socket, outputStream);
|
sendDataIfAvailable(socket, outputStream);
|
||||||
|
|||||||
@@ -220,22 +220,25 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDataReceivedOk(String receivedData) {
|
public void onDataReceivedOk(String receivedData) {
|
||||||
Log.d(Constants.TAG, "received: " + receivedData);
|
Log.d(Constants.TAG, "received key");
|
||||||
view.showReceivingKeys();
|
|
||||||
|
|
||||||
|
UncachedKeyRing uncachedKeyRing;
|
||||||
try {
|
try {
|
||||||
// TODO move to worker thread?
|
uncachedKeyRing = UncachedKeyRing.decodeFromData(receivedData.getBytes());
|
||||||
UncachedKeyRing uncachedKeyRing = UncachedKeyRing.decodeFromData(receivedData.getBytes());
|
} catch (PgpGeneralException | IOException | RuntimeException e) {
|
||||||
String primaryUserId = uncachedKeyRing.getPublicKey().getPrimaryUserIdWithFallback();
|
|
||||||
UserId userId = OpenPgpUtils.splitUserId(primaryUserId);
|
|
||||||
|
|
||||||
ReceivedKeyItem receivedKeyItem = new ReceivedKeyItem(receivedData, uncachedKeyRing.getMasterKeyId(),
|
|
||||||
uncachedKeyRing.getCreationTime(), userId.name, userId.email);
|
|
||||||
receivedKeyAdapter.addItem(receivedKeyItem);
|
|
||||||
} catch (PgpGeneralException | IOException e) {
|
|
||||||
Log.e(Constants.TAG, "error parsing incoming key", e);
|
Log.e(Constants.TAG, "error parsing incoming key", e);
|
||||||
view.showErrorBadKey();
|
view.showErrorBadKey();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String primaryUserId = uncachedKeyRing.getPublicKey().getPrimaryUserIdWithFallback();
|
||||||
|
UserId userId = OpenPgpUtils.splitUserId(primaryUserId);
|
||||||
|
|
||||||
|
ReceivedKeyItem receivedKeyItem = new ReceivedKeyItem(receivedData, uncachedKeyRing.getMasterKeyId(),
|
||||||
|
uncachedKeyRing.getCreationTime(), userId.name, userId.email);
|
||||||
|
receivedKeyAdapter.addItem(receivedKeyItem);
|
||||||
|
|
||||||
|
view.showReceivingKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user