diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-11-14 03:27:18 +0100 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-11-15 15:34:12 +0100 |
commit | 16847a30c88246381a026bce9f2435be2bd77422 (patch) | |
tree | cbd5afe1282f9ec4faca5be4cff14c7e6112c807 /src/main/java/eu | |
parent | c7acfe85c379b99c05cef98dbbab6f815b99ed83 (diff) |
support for pgp files
Diffstat (limited to 'src/main/java/eu')
5 files changed, 38 insertions, 23 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index b1d915d24..a40cff916 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -19,7 +19,7 @@ public final class Config { public static final int MESSAGE_MERGE_WINDOW = 20; public static final boolean PARSE_EMOTICONS = false; - public static final int PROGRESS_UI_UPDATE_INTERVAL = 750; + public static final int PROGRESS_UI_UPDATE_INTERVAL = 750; private Config() { diff --git a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java index 3d7cc6715..3f84daf66 100644 --- a/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java +++ b/src/main/java/eu/siacs/conversations/crypto/PgpEngine.java @@ -80,12 +80,13 @@ public class PgpEngine { } } }); - } else if (message.getType() == Message.TYPE_IMAGE) { + } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { try { final DownloadableFile inputFile = this.mXmppConnectionService .getFileBackend().getFile(message, false); final DownloadableFile outputFile = this.mXmppConnectionService .getFileBackend().getFile(message, true); + outputFile.getParentFile().mkdirs(); outputFile.createNewFile(); InputStream is = new FileInputStream(inputFile); OutputStream os = new FileOutputStream(outputFile); @@ -199,12 +200,13 @@ public class PgpEngine { } } }); - } else if (message.getType() == Message.TYPE_IMAGE) { + } else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) { try { DownloadableFile inputFile = this.mXmppConnectionService .getFileBackend().getFile(message, true); DownloadableFile outputFile = this.mXmppConnectionService .getFileBackend().getFile(message, false); + outputFile.getParentFile().mkdirs(); outputFile.createNewFile(); InputStream is = new FileInputStream(inputFile); OutputStream os = new FileOutputStream(outputFile); diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 7b0ae1807..3d771572a 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -2,14 +2,12 @@ package eu.siacs.conversations.persistance; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; -import java.net.URLConnection; import java.security.DigestOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -17,7 +15,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -import android.content.ContentResolver; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -60,30 +57,36 @@ public class FileBackend { public DownloadableFile getFile(Message message, boolean decrypted) { String path = message.getRelativeFilePath(); - if (path != null && !path.isEmpty()) { + if (!decrypted && (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED)) { + String extension; + if (path != null && !path.isEmpty()) { + String[] parts = path.split("\\."); + extension = "."+parts[parts.length - 1]; + } else if (message.getType() == Message.TYPE_IMAGE) { + extension = ".webp"; + } else { + extension = ""; + } + return new DownloadableFile(getConversationsFileDirectory()+message.getUuid()+extension+".pgp"); + } else if (path != null && !path.isEmpty()) { if (path.startsWith("/")) { return new DownloadableFile(path); } else { - return new DownloadableFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/"+path); + return new DownloadableFile(getConversationsFileDirectory()+path); } } else { StringBuilder filename = new StringBuilder(); - filename.append(getConversationsDirectory()); - filename.append(message.getUuid()); - if ((decrypted) || (message.getEncryption() == Message.ENCRYPTION_NONE)) { - filename.append(".webp"); - } else { - if (message.getEncryption() == Message.ENCRYPTION_OTR) { - filename.append(".webp"); - } else { - filename.append(".webp.pgp"); - } - } + filename.append(getConversationsImageDirectory()); + filename.append(message.getUuid()+".webp"); return new DownloadableFile(filename.toString()); } } - public static String getConversationsDirectory() { + public static String getConversationsFileDirectory() { + return Environment.getExternalStorageDirectory().getAbsolutePath()+"/Conversations/"; + } + + public static String getConversationsImageDirectory() { return Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES).getAbsolutePath() + "/Conversations/"; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index babcce266..4565ce30f 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -211,7 +211,7 @@ public class XmppConnectionService extends Service { private Integer rosterChangedListenerCount = 0; private SecureRandom mRandom; private FileObserver fileObserver = new FileObserver( - FileBackend.getConversationsDirectory()) { + FileBackend.getConversationsImageDirectory()) { @Override public void onEvent(int event, String path) { @@ -311,7 +311,11 @@ public class XmppConnectionService extends Service { if (path!=null) { message.setRelativeFilePath(path); getFileBackend().updateFileParams(message); - callback.success(message); + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + getPgpEngine().encrypt(message, callback); + } else { + callback.success(message); + } } else { new Thread(new Runnable() { @Override @@ -319,7 +323,11 @@ public class XmppConnectionService extends Service { try { getFileBackend().copyFileToPrivateStorage(message, uri); getFileBackend().updateFileParams(message); - callback.success(message); + if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { + getPgpEngine().encrypt(message, callback); + } else { + callback.success(message); + } } catch (FileBackend.FileCopyException e) { callback.error(e.getResId(),message); } diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java index f42e89a99..793c6c54d 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleConnection.java @@ -306,6 +306,8 @@ public class JingleConnection implements Downloadable { suffix = parts[parts.length - 1]; if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) { suffix = suffix.substring(0,suffix.length() - 4); + } else if (message.getEncryption() == Message.ENCRYPTION_PGP && (suffix.endsWith(".pgp") || suffix.endsWith(".gpg"))) { + suffix = suffix.substring(0,suffix.length() - 4); } } message.setRelativeFilePath(message.getUuid()+"_"+suffix); |