got rid of MTM and mRandom variable in favor of using a reference to service

This commit is contained in:
iNPUTmice 2014-11-09 10:50:45 +01:00
parent 047aaf5d4f
commit acfbd44529
1 changed files with 7 additions and 12 deletions

View File

@ -23,7 +23,6 @@ import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -38,7 +37,6 @@ import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import de.duenndns.ssl.MemorizingTrustManager;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
@ -71,7 +69,6 @@ public class XmppConnection implements Runnable {
private final Context applicationContext; private final Context applicationContext;
protected Account account; protected Account account;
private WakeLock wakeLock; private WakeLock wakeLock;
private SecureRandom mRandom;
private Socket socket; private Socket socket;
private XmlReader tagReader; private XmlReader tagReader;
private TagWriter tagWriter; private TagWriter tagWriter;
@ -100,15 +97,14 @@ public class XmppConnection implements Runnable {
private OnStatusChanged statusListener = null; private OnStatusChanged statusListener = null;
private OnBindListener bindListener = null; private OnBindListener bindListener = null;
private OnMessageAcknowledged acknowledgedListener = null; private OnMessageAcknowledged acknowledgedListener = null;
private MemorizingTrustManager mMemorizingTrustManager; private XmppConnectionService mXmppConnectionService = null;
public XmppConnection(Account account, XmppConnectionService service) { public XmppConnection(Account account, XmppConnectionService service) {
this.mRandom = service.getRNG();
this.mMemorizingTrustManager = service.getMemorizingTrustManager();
this.account = account; this.account = account;
this.wakeLock = service.getPowerManager().newWakeLock( this.wakeLock = service.getPowerManager().newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, account.getJid()); PowerManager.PARTIAL_WAKE_LOCK, account.getJid());
tagWriter = new TagWriter(); tagWriter = new TagWriter();
mXmppConnectionService = service;
applicationContext = service.getApplicationContext(); applicationContext = service.getApplicationContext();
} }
@ -298,7 +294,7 @@ public class XmppConnection implements Runnable {
response.setAttribute("xmlns", response.setAttribute("xmlns",
"urn:ietf:params:xml:ns:xmpp-sasl"); "urn:ietf:params:xml:ns:xmpp-sasl");
response.setContent(CryptoHelper.saslDigestMd5(account, response.setContent(CryptoHelper.saslDigestMd5(account,
challange, mRandom)); challange, mXmppConnectionService.getRNG()));
tagWriter.writeElement(response); tagWriter.writeElement(response);
} else if (nextTag.isStart("enabled")) { } else if (nextTag.isStart("enabled")) {
Element enabled = tagReader.readElement(nextTag); Element enabled = tagReader.readElement(nextTag);
@ -547,16 +543,15 @@ public class XmppConnection implements Runnable {
try { try {
SSLContext sc = SSLContext.getInstance("TLS"); SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, sc.init(null,
new X509TrustManager[]{this.mMemorizingTrustManager}, new X509TrustManager[]{this.mXmppConnectionService.getMemorizingTrustManager()},
mRandom); mXmppConnectionService.getRNG());
SSLSocketFactory factory = sc.getSocketFactory(); SSLSocketFactory factory = sc.getSocketFactory();
if (factory == null) { if (factory == null) {
throw new IOException("SSLSocketFactory was null"); throw new IOException("SSLSocketFactory was null");
} }
HostnameVerifier verifier = this.mMemorizingTrustManager HostnameVerifier verifier = this.mXmppConnectionService.getMemorizingTrustManager().wrapHostnameVerifier(new StrictHostnameVerifier());
.wrapHostnameVerifier(new StrictHostnameVerifier());
if (socket == null) { if (socket == null) {
throw new IOException("socket was null"); throw new IOException("socket was null");
@ -879,7 +874,7 @@ public class XmppConnection implements Runnable {
} }
private String nextRandomId() { private String nextRandomId() {
return new BigInteger(50, mRandom).toString(32); return new BigInteger(50, mXmppConnectionService.getRNG()).toString(32);
} }
public void sendIqPacket(IqPacket packet, OnIqPacketReceived callback) { public void sendIqPacket(IqPacket packet, OnIqPacketReceived callback) {