store encrypted pgp files in private cache dir
This commit is contained in:
parent
a3085fbf1f
commit
be1fcfe4f9
|
@ -119,7 +119,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
private void setupFile() {
|
private void setupFile() {
|
||||||
final String reference = mUrl.fragment();
|
final String reference = mUrl.fragment();
|
||||||
if (reference != null && AesGcmURL.IV_KEY.matcher(reference).matches()) {
|
if (reference != null && AesGcmURL.IV_KEY.matcher(reference).matches()) {
|
||||||
this.file = new DownloadableFile(mXmppConnectionService.getCacheDir().getAbsolutePath() + "/" + message.getUuid());
|
this.file = new DownloadableFile(mXmppConnectionService.getCacheDir(), message.getUuid());
|
||||||
this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
|
this.file.setKeyAndIv(CryptoHelper.hexToBytes(reference));
|
||||||
Log.d(Config.LOGTAG, "create temporary OMEMO encrypted file: " + this.file.getAbsolutePath() + "(" + message.getMimeType() + ")");
|
Log.d(Config.LOGTAG, "create temporary OMEMO encrypted file: " + this.file.getAbsolutePath() + "(" + message.getMimeType() + ")");
|
||||||
} else {
|
} else {
|
||||||
|
@ -416,8 +416,9 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
Log.d(Config.LOGTAG, "content-length reported on GET (" + size + ") did not match Content-Length reported on HEAD (" + expected + ")");
|
Log.d(Config.LOGTAG, "content-length reported on GET (" + size + ") did not match Content-Length reported on HEAD (" + expected + ")");
|
||||||
}
|
}
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
|
Log.d(Config.LOGTAG,"creating file: "+file.getAbsolutePath());
|
||||||
if (!file.exists() && !file.createNewFile()) {
|
if (!file.exists() && !file.createNewFile()) {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException(file);
|
||||||
}
|
}
|
||||||
outputStream = AbstractConnectionManager.createOutputStream(file, false, false);
|
outputStream = AbstractConnectionManager.createOutputStream(file, false, false);
|
||||||
}
|
}
|
||||||
|
@ -428,7 +429,7 @@ public class HttpDownloadConnection implements Transferable {
|
||||||
try {
|
try {
|
||||||
outputStream.write(buffer, 0, count);
|
outputStream.write(buffer, 0, count);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException(file);
|
||||||
}
|
}
|
||||||
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
updateProgress(Math.round(((double) transmitted / expected) * 100));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package eu.siacs.conversations.persistance;
|
package eu.siacs.conversations.persistance;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -535,7 +534,9 @@ public class FileBackend {
|
||||||
}
|
}
|
||||||
final DownloadableFile file = getFileForPath(path, message.getMimeType());
|
final DownloadableFile file = getFileForPath(path, message.getMimeType());
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
return new DownloadableFile(getLegacyStorageLocation("Files"), file.getName() + ".pgp");
|
return new DownloadableFile(
|
||||||
|
mXmppConnectionService.getCacheDir(),
|
||||||
|
String.format("%s.%s", file.getName(), "pgp"));
|
||||||
} else {
|
} else {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -651,12 +652,12 @@ public class FileBackend {
|
||||||
try {
|
try {
|
||||||
ByteStreams.copy(is, os);
|
ByteStreams.copy(is, os);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException(file);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
os.flush();
|
os.flush();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new FileWriterException();
|
throw new FileWriterException(file);
|
||||||
}
|
}
|
||||||
} catch (final FileNotFoundException e) {
|
} catch (final FileNotFoundException e) {
|
||||||
cleanup(file);
|
cleanup(file);
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
package eu.siacs.conversations.utils;
|
package eu.siacs.conversations.utils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class FileWriterException extends Exception {
|
public class FileWriterException extends Exception {
|
||||||
|
|
||||||
|
public FileWriterException(File file) {
|
||||||
|
super(String.format("Could not write to %s", file.getAbsolutePath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
FileWriterException() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue