aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/crypto
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-06-16 11:47:40 +0200
committerChristian Schneppe <christian@pix-art.de>2016-06-19 20:12:29 +0200
commit87c28ba818428ac2b73a7c9add86de66a6d1d066 (patch)
treeef4bbb92de82018c656c6afc84755707dd2f1cf0 /src/main/java/eu/siacs/conversations/crypto
parent8b5b3393a45c5a739a19ec51ba8c4a6c31df0938 (diff)
synchronize message body changes for message correction
Diffstat (limited to 'src/main/java/eu/siacs/conversations/crypto')
-rw-r--r--src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java104
1 files changed, 53 insertions, 51 deletions
diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java
index 07de11649..30f9df677 100644
--- a/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java
+++ b/src/main/java/eu/siacs/conversations/crypto/PgpDecryptionService.java
@@ -111,57 +111,28 @@ public class PgpDecryptionService {
}
private void executeApi(Message message) {
- Intent params = new Intent();
- params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
- if (message.getType() == Message.TYPE_TEXT) {
- InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
- final OutputStream os = new ByteArrayOutputStream();
- Intent result = getOpenPgpApi().executeApi(params, is, os);
- switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
- case OpenPgpApi.RESULT_CODE_SUCCESS:
- try {
- os.flush();
- message.setBody(os.toString());
- message.setEncryption(Message.ENCRYPTION_DECRYPTED);
- final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager();
- if (message.trusted()
- && message.treatAsDownloadable() != Message.Decision.NEVER
- && manager.getAutoAcceptFileSize() > 0) {
- manager.createNewDownloadConnection(message);
- }
- } catch (IOException e) {
- message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
- }
- mXmppConnectionService.updateMessage(message);
- break;
- case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
- synchronized (PgpDecryptionService.this) {
- messages.addFirst(message);
- currentMessage = null;
- storePendingIntent((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
- }
- break;
- case OpenPgpApi.RESULT_CODE_ERROR:
- message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
- mXmppConnectionService.updateMessage(message);
- break;
- }
- } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
- try {
- final DownloadableFile inputFile = mXmppConnectionService.getFileBackend().getFile(message, false);
- final DownloadableFile outputFile = mXmppConnectionService.getFileBackend().getFile(message, true);
- outputFile.getParentFile().mkdirs();
- outputFile.createNewFile();
- InputStream is = new FileInputStream(inputFile);
- OutputStream os = new FileOutputStream(outputFile);
+ synchronized (message) {
+ Intent params = new Intent();
+ params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
+ if (message.getType() == Message.TYPE_TEXT) {
+ InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
+ final OutputStream os = new ByteArrayOutputStream();
Intent result = getOpenPgpApi().executeApi(params, is, os);
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
- URL url = message.getFileParams().url;
- mXmppConnectionService.getFileBackend().updateFileParams(message,url);
- message.setEncryption(Message.ENCRYPTION_DECRYPTED);
- inputFile.delete();
- mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile);
+ try {
+ os.flush();
+ message.setBody(os.toString());
+ message.setEncryption(Message.ENCRYPTION_DECRYPTED);
+ final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager();
+ if (message.trusted()
+ && message.treatAsDownloadable() != Message.Decision.NEVER
+ && manager.getAutoAcceptFileSize() > 0) {
+ manager.createNewDownloadConnection(message);
+ }
+ } catch (IOException e) {
+ message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
+ }
mXmppConnectionService.updateMessage(message);
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
@@ -176,9 +147,40 @@ public class PgpDecryptionService {
mXmppConnectionService.updateMessage(message);
break;
}
- } catch (final IOException e) {
- message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
- mXmppConnectionService.updateMessage(message);
+ } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
+ try {
+ final DownloadableFile inputFile = mXmppConnectionService.getFileBackend().getFile(message, false);
+ final DownloadableFile outputFile = mXmppConnectionService.getFileBackend().getFile(message, true);
+ outputFile.getParentFile().mkdirs();
+ outputFile.createNewFile();
+ InputStream is = new FileInputStream(inputFile);
+ OutputStream os = new FileOutputStream(outputFile);
+ Intent result = getOpenPgpApi().executeApi(params, is, os);
+ switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
+ case OpenPgpApi.RESULT_CODE_SUCCESS:
+ URL url = message.getFileParams().url;
+ mXmppConnectionService.getFileBackend().updateFileParams(message, url);
+ message.setEncryption(Message.ENCRYPTION_DECRYPTED);
+ inputFile.delete();
+ mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile);
+ mXmppConnectionService.updateMessage(message);
+ break;
+ case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
+ synchronized (PgpDecryptionService.this) {
+ messages.addFirst(message);
+ currentMessage = null;
+ storePendingIntent((PendingIntent) result.getParcelableExtra(OpenPgpApi.RESULT_INTENT));
+ }
+ break;
+ case OpenPgpApi.RESULT_CODE_ERROR:
+ message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
+ mXmppConnectionService.updateMessage(message);
+ break;
+ }
+ } catch (final IOException e) {
+ message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
+ mXmppConnectionService.updateMessage(message);
+ }
}
}
notifyIfPending(message);