support for pgp files
This commit is contained in:
parent
c7acfe85c3
commit
16847a30c8
|
@ -19,7 +19,7 @@ public final class Config {
|
||||||
public static final int MESSAGE_MERGE_WINDOW = 20;
|
public static final int MESSAGE_MERGE_WINDOW = 20;
|
||||||
|
|
||||||
public static final boolean PARSE_EMOTICONS = false;
|
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() {
|
private Config() {
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
try {
|
||||||
final DownloadableFile inputFile = this.mXmppConnectionService
|
final DownloadableFile inputFile = this.mXmppConnectionService
|
||||||
.getFileBackend().getFile(message, false);
|
.getFileBackend().getFile(message, false);
|
||||||
final DownloadableFile outputFile = this.mXmppConnectionService
|
final DownloadableFile outputFile = this.mXmppConnectionService
|
||||||
.getFileBackend().getFile(message, true);
|
.getFileBackend().getFile(message, true);
|
||||||
|
outputFile.getParentFile().mkdirs();
|
||||||
outputFile.createNewFile();
|
outputFile.createNewFile();
|
||||||
InputStream is = new FileInputStream(inputFile);
|
InputStream is = new FileInputStream(inputFile);
|
||||||
OutputStream os = new FileOutputStream(outputFile);
|
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 {
|
try {
|
||||||
DownloadableFile inputFile = this.mXmppConnectionService
|
DownloadableFile inputFile = this.mXmppConnectionService
|
||||||
.getFileBackend().getFile(message, true);
|
.getFileBackend().getFile(message, true);
|
||||||
DownloadableFile outputFile = this.mXmppConnectionService
|
DownloadableFile outputFile = this.mXmppConnectionService
|
||||||
.getFileBackend().getFile(message, false);
|
.getFileBackend().getFile(message, false);
|
||||||
|
outputFile.getParentFile().mkdirs();
|
||||||
outputFile.createNewFile();
|
outputFile.createNewFile();
|
||||||
InputStream is = new FileInputStream(inputFile);
|
InputStream is = new FileInputStream(inputFile);
|
||||||
OutputStream os = new FileOutputStream(outputFile);
|
OutputStream os = new FileOutputStream(outputFile);
|
||||||
|
|
|
@ -2,14 +2,12 @@ package eu.siacs.conversations.persistance;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.security.DigestOutputStream;
|
import java.security.DigestOutputStream;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -17,7 +15,6 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -60,30 +57,36 @@ public class FileBackend {
|
||||||
|
|
||||||
public DownloadableFile getFile(Message message, boolean decrypted) {
|
public DownloadableFile getFile(Message message, boolean decrypted) {
|
||||||
String path = message.getRelativeFilePath();
|
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("/")) {
|
if (path.startsWith("/")) {
|
||||||
return new DownloadableFile(path);
|
return new DownloadableFile(path);
|
||||||
} else {
|
} else {
|
||||||
return new DownloadableFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/"+path);
|
return new DownloadableFile(getConversationsFileDirectory()+path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
StringBuilder filename = new StringBuilder();
|
StringBuilder filename = new StringBuilder();
|
||||||
filename.append(getConversationsDirectory());
|
filename.append(getConversationsImageDirectory());
|
||||||
filename.append(message.getUuid());
|
filename.append(message.getUuid()+".webp");
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new DownloadableFile(filename.toString());
|
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(
|
return Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_PICTURES).getAbsolutePath()
|
Environment.DIRECTORY_PICTURES).getAbsolutePath()
|
||||||
+ "/Conversations/";
|
+ "/Conversations/";
|
||||||
|
|
|
@ -211,7 +211,7 @@ public class XmppConnectionService extends Service {
|
||||||
private Integer rosterChangedListenerCount = 0;
|
private Integer rosterChangedListenerCount = 0;
|
||||||
private SecureRandom mRandom;
|
private SecureRandom mRandom;
|
||||||
private FileObserver fileObserver = new FileObserver(
|
private FileObserver fileObserver = new FileObserver(
|
||||||
FileBackend.getConversationsDirectory()) {
|
FileBackend.getConversationsImageDirectory()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(int event, String path) {
|
public void onEvent(int event, String path) {
|
||||||
|
@ -311,7 +311,11 @@ public class XmppConnectionService extends Service {
|
||||||
if (path!=null) {
|
if (path!=null) {
|
||||||
message.setRelativeFilePath(path);
|
message.setRelativeFilePath(path);
|
||||||
getFileBackend().updateFileParams(message);
|
getFileBackend().updateFileParams(message);
|
||||||
callback.success(message);
|
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
|
getPgpEngine().encrypt(message, callback);
|
||||||
|
} else {
|
||||||
|
callback.success(message);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -319,7 +323,11 @@ public class XmppConnectionService extends Service {
|
||||||
try {
|
try {
|
||||||
getFileBackend().copyFileToPrivateStorage(message, uri);
|
getFileBackend().copyFileToPrivateStorage(message, uri);
|
||||||
getFileBackend().updateFileParams(message);
|
getFileBackend().updateFileParams(message);
|
||||||
callback.success(message);
|
if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
|
||||||
|
getPgpEngine().encrypt(message, callback);
|
||||||
|
} else {
|
||||||
|
callback.success(message);
|
||||||
|
}
|
||||||
} catch (FileBackend.FileCopyException e) {
|
} catch (FileBackend.FileCopyException e) {
|
||||||
callback.error(e.getResId(),message);
|
callback.error(e.getResId(),message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,6 +306,8 @@ public class JingleConnection implements Downloadable {
|
||||||
suffix = parts[parts.length - 1];
|
suffix = parts[parts.length - 1];
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
|
if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) {
|
||||||
suffix = suffix.substring(0,suffix.length() - 4);
|
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);
|
message.setRelativeFilePath(message.getUuid()+"_"+suffix);
|
||||||
|
|
Loading…
Reference in New Issue