~singpolyma/cheogram-android

be1fcfe4f93d9f06cae82cfe43c8c45bde591ed3 — Daniel Gultsch 2 years ago a3085fb
store encrypted pgp files in private cache dir
M src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java => src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +4 -3
@@ 119,7 119,7 @@ public class HttpDownloadConnection implements Transferable {
    private void setupFile() {
        final String reference = mUrl.fragment();
        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));
            Log.d(Config.LOGTAG, "create temporary OMEMO encrypted file: " + this.file.getAbsolutePath() + "(" + message.getMimeType() + ")");
        } 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 + ")");
                }
                file.getParentFile().mkdirs();
                Log.d(Config.LOGTAG,"creating file: "+file.getAbsolutePath());
                if (!file.exists() && !file.createNewFile()) {
                    throw new FileWriterException();
                    throw new FileWriterException(file);
                }
                outputStream = AbstractConnectionManager.createOutputStream(file, false, false);
            }


@@ 428,7 429,7 @@ public class HttpDownloadConnection implements Transferable {
                try {
                    outputStream.write(buffer, 0, count);
                } catch (IOException e) {
                    throw new FileWriterException();
                    throw new FileWriterException(file);
                }
                updateProgress(Math.round(((double) transmitted / expected) * 100));
            }

M src/main/java/eu/siacs/conversations/persistance/FileBackend.java => src/main/java/eu/siacs/conversations/persistance/FileBackend.java +5 -4
@@ 1,6 1,5 @@
package eu.siacs.conversations.persistance;

import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;


@@ 535,7 534,9 @@ public class FileBackend {
        }
        final DownloadableFile file = getFileForPath(path, message.getMimeType());
        if (encrypted) {
            return new DownloadableFile(getLegacyStorageLocation("Files"), file.getName() + ".pgp");
            return new DownloadableFile(
                    mXmppConnectionService.getCacheDir(),
                    String.format("%s.%s", file.getName(), "pgp"));
        } else {
            return file;
        }


@@ 651,12 652,12 @@ public class FileBackend {
            try {
                ByteStreams.copy(is, os);
            } catch (IOException e) {
                throw new FileWriterException();
                throw new FileWriterException(file);
            }
            try {
                os.flush();
            } catch (IOException e) {
                throw new FileWriterException();
                throw new FileWriterException(file);
            }
        } catch (final FileNotFoundException e) {
            cleanup(file);

M src/main/java/eu/siacs/conversations/utils/FileWriterException.java => src/main/java/eu/siacs/conversations/utils/FileWriterException.java +10 -0
@@ 1,4 1,14 @@
package eu.siacs.conversations.utils;

import java.io.File;

public class FileWriterException extends Exception {

    public FileWriterException(File file) {
        super(String.format("Could not write to %s", file.getAbsolutePath()));
    }

    FileWriterException() {

    }
}