mirror of
https://github.com/moparisthebest/Conversations
synced 2024-12-01 05:02:21 -05:00
more error handling for http connection
This commit is contained in:
parent
21069003b0
commit
ec9c264cf7
@ -1,5 +1,11 @@
|
|||||||
package eu.siacs.conversations.http;
|
package eu.siacs.conversations.http;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import org.apache.http.conn.ssl.StrictHostnameVerifier;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -15,12 +21,6 @@ import javax.net.ssl.SSLContext;
|
|||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
|
|
||||||
import org.apache.http.conn.ssl.StrictHostnameVerifier;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Downloadable;
|
import eu.siacs.conversations.entities.Downloadable;
|
||||||
import eu.siacs.conversations.entities.DownloadableFile;
|
import eu.siacs.conversations.entities.DownloadableFile;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
@ -74,7 +74,7 @@ public class HttpConnection implements Downloadable {
|
|||||||
if (reference != null && reference.length() == 96) {
|
if (reference != null && reference.length() == 96) {
|
||||||
this.file.setKey(CryptoHelper.hexToBytes(reference));
|
this.file.setKey(CryptoHelper.hexToBytes(reference));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.message.getEncryption() == Message.ENCRYPTION_OTR
|
if (this.message.getEncryption() == Message.ENCRYPTION_OTR
|
||||||
&& this.file.getKey() == null) {
|
&& this.file.getKey() == null) {
|
||||||
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
this.message.setEncryption(Message.ENCRYPTION_NONE);
|
||||||
@ -113,7 +113,7 @@ public class HttpConnection implements Downloadable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupTrustManager(HttpsURLConnection connection,
|
private void setupTrustManager(HttpsURLConnection connection,
|
||||||
boolean interactive) {
|
boolean interactive) {
|
||||||
X509TrustManager trustManager;
|
X509TrustManager trustManager;
|
||||||
HostnameVerifier hostnameVerifier;
|
HostnameVerifier hostnameVerifier;
|
||||||
if (interactive) {
|
if (interactive) {
|
||||||
@ -131,7 +131,7 @@ public class HttpConnection implements Downloadable {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
SSLContext sc = SSLContext.getInstance("TLS");
|
SSLContext sc = SSLContext.getInstance("TLS");
|
||||||
sc.init(null, new X509TrustManager[] { trustManager },
|
sc.init(null, new X509TrustManager[]{trustManager},
|
||||||
mXmppConnectionService.getRNG());
|
mXmppConnectionService.getRNG());
|
||||||
connection.setSSLSocketFactory(sc.getSocketFactory());
|
connection.setSSLSocketFactory(sc.getSocketFactory());
|
||||||
connection.setHostnameVerifier(hostnameVerifier);
|
connection.setHostnameVerifier(hostnameVerifier);
|
||||||
@ -230,6 +230,9 @@ public class HttpConnection implements Downloadable {
|
|||||||
BufferedInputStream is = new BufferedInputStream(
|
BufferedInputStream is = new BufferedInputStream(
|
||||||
connection.getInputStream());
|
connection.getInputStream());
|
||||||
OutputStream os = file.createOutputStream();
|
OutputStream os = file.createOutputStream();
|
||||||
|
if (os == null) {
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
int count = -1;
|
int count = -1;
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
while ((count = is.read(buffer)) != -1) {
|
while ((count = is.read(buffer)) != -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user