diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-07-29 23:45:37 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-07-29 23:45:37 +0200 |
commit | 58d80f58be2f75b858e93766c61857a78d161005 (patch) | |
tree | fe395f0cc34dc70b3b327abcec74cf4400780ab5 /src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java | |
parent | b7c64cd19d011ad24d64e13ab9154ae07f06a872 (diff) |
use gcm for file encryption over http
Diffstat (limited to 'src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java index 30d9a393a..51479836a 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpDownloadConnection.java @@ -2,10 +2,17 @@ package eu.siacs.conversations.http; import android.content.Intent; import android.net.Uri; -import android.os.SystemClock; import android.util.Log; +import org.bouncycastle.crypto.engines.AESEngine; +import org.bouncycastle.crypto.io.CipherOutputStream; +import org.bouncycastle.crypto.modes.AEADBlockCipher; +import org.bouncycastle.crypto.modes.GCMBlockCipher; +import org.bouncycastle.crypto.params.AEADParameters; +import org.bouncycastle.crypto.params.KeyParameter; + import java.io.BufferedInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; @@ -206,7 +213,7 @@ public class HttpDownloadConnection implements Transferable { } } - private void download() throws SSLHandshakeException, IOException { + private void download() throws IOException { HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection(); if (connection instanceof HttpsURLConnection) { mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, interactive); @@ -215,9 +222,13 @@ public class HttpDownloadConnection implements Transferable { BufferedInputStream is = new BufferedInputStream(connection.getInputStream()); file.getParentFile().mkdirs(); file.createNewFile(); - OutputStream os = file.createOutputStream(); - if (os == null) { - throw new IOException(); + OutputStream os; + if (file.getKey() != null) { + AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine()); + cipher.init(false, new AEADParameters(new KeyParameter(file.getKey()), 128, file.getIv())); + os = new CipherOutputStream(new FileOutputStream(file), cipher); + } else { + os = new FileOutputStream(file); } long transmitted = 0; long expected = file.getExpectedSize(); |