Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
switched to cobratbq's OTR implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed May 23, 2018
1 parent b3fac39 commit 0ff9d6b
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 410 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ dependencies {
implementation fileTree(include: '*.jar', dir: 'libs')
//implementation project(':otr4jandroid')

implementation 'com.github.otr4j:otr4j:0.22'
// implementation 'com.github.otr4j:otr4j:0.22'
implementation 'com.github.cobratbq:otr4j:1ed70336c6'

// implementation 'com.github.otr4j:otr4j:aac20b11de'
implementation project(':tibetanTextLibrary')
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/awesomeapp/messenger/ImApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ public void onCreate() {
mCacheWord.connectToService();

if (sThreadPoolExecutor == null) {
int corePoolSize = 20;
int maximumPoolSize = 120;
int keepAliveTime = 30;
int corePoolSize = 10;
int maximumPoolSize = 20;
int keepAliveTime = 5;
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(maximumPoolSize);
sThreadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, workQueue);
sThreadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MINUTES, workQueue);
}

IntentFilter intentFilter = new IntentFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@
import java.util.Set;
import java.util.Vector;

import net.java.otr4j.OtrKeyManager;
import net.java.otr4j.OtrKeyManagerListener;
import net.java.otr4j.OtrKeyManagerStore;
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoEngine;
import net.java.otr4j.crypto.OtrCryptoException;
import net.java.otr4j.session.SessionID;
import net.java.otr4j.api.SessionID;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
Expand All @@ -57,11 +54,10 @@

import info.guardianproject.iocipher.*;

public class OtrAndroidKeyManagerImpl extends IOtrKeyManager.Stub implements OtrKeyManager {
public class OtrAndroidKeyManagerImpl extends IOtrKeyManager.Stub {

private SimplePropertiesStore store;

private OtrCryptoEngineImpl cryptoEngine;

private final static String KEY_ALG = "DSA";
private final static int KEY_SIZE = 1024;
Expand Down Expand Up @@ -100,7 +96,7 @@ private OtrAndroidKeyManagerImpl(File filepath) throws IOException {

store = new SimplePropertiesStore(filepath);

cryptoEngine = new OtrCryptoEngineImpl();


}

Expand Down Expand Up @@ -167,7 +163,7 @@ private void upgradeStore() {
}
*/

static class SimplePropertiesStore implements OtrKeyManagerStore {
static class SimplePropertiesStore {

private Properties mProperties = new Properties();
private File mStoreFile;
Expand Down Expand Up @@ -374,20 +370,6 @@ public Set<Object> getKeySet ()
}
}

private List<OtrKeyManagerListener> listeners = new Vector<OtrKeyManagerListener>();

public void addListener(OtrKeyManagerListener l) {
synchronized (listeners) {
if (!listeners.contains(l))
listeners.add(l);
}
}

public void removeListener(OtrKeyManagerListener l) {
synchronized (listeners) {
listeners.remove(l);
}
}

public void generateLocalKeyPair(SessionID sessionID) {
if (sessionID == null)
Expand All @@ -407,7 +389,7 @@ public void regenerateLocalPublicKey(KeyFactory factory, String fullUserId, DSAP
PublicKey pubKey;
try {
pubKey = factory.generatePublic(keySpec);
storeLocalPublicKey(userId, pubKey);
storePublicKey(userId, pubKey);

} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -447,8 +429,7 @@ public void storeKeyPair (String userId, KeyPair keyPair)
{
// Store Public Key.
PublicKey pubKey = keyPair.getPublic();
storeLocalPublicKey(userId, pubKey); //this will do saving

storePublicKey(userId, pubKey); //this will do saving
}
catch (Exception e)
{
Expand Down Expand Up @@ -497,11 +478,11 @@ public void generateLocalKeyPair(String fullUserId) {
}*/
}

public void storeLocalPublicKey(String fullUserId, PublicKey pubKey) throws OtrCryptoException {
public void storePublicKey(String fullUserId, PublicKey pubKey) throws OtrCryptoException {

String userId = Address.stripResource(fullUserId);

String fingerprintString = cryptoEngine.getFingerprint(pubKey);
String fingerprintString = OtrCryptoEngine.getFingerprint(pubKey);
String fingerprintKey = userId + ".fingerprint";

//check if we already have this
Expand Down Expand Up @@ -561,7 +542,6 @@ public String getLocalFingerprint(SessionID sessionID) {
return getLocalFingerprint(sessionID.getAccountID());
}

@Override
public byte[] getLocalFingerprintRaw(SessionID sessionID) {
String userId = Address.stripResource(sessionID.getAccountID());

Expand All @@ -571,7 +551,7 @@ public byte[] getLocalFingerprintRaw(SessionID sessionID) {
return null;

try {
return cryptoEngine.getFingerprintRaw(keyPair.getPublic());
return OtrCryptoEngine.getFingerprintRaw(keyPair.getPublic());
}
catch (Exception e)
{
Expand All @@ -594,15 +574,12 @@ public String getLocalFingerprint(String fullUserId) {

public String getFingerprint (PublicKey pubKey)
{
try {
String fingerprint = cryptoEngine.getFingerprint(pubKey);

String fingerprint = OtrCryptoEngine.getFingerprint(pubKey);
// OtrDebugLogger.log("got fingerprint for: " + userId + "=" + fingerprint);
return fingerprint;

} catch (OtrCryptoException e) {
e.printStackTrace();
return null;
}

}

public String getRemoteFingerprint(SessionID sessionID) {
Expand Down Expand Up @@ -651,11 +628,11 @@ public String getRemoteFingerprint(String fullUserId) {

try {
// Store the fingerprint, for posterity.
String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(remotePublicKey);
String fingerprintString = OtrCryptoEngine.getFingerprint(remotePublicKey);
this.store.setProperty(fullUserId + ".fingerprint", fingerprintString);

return fingerprintString;
} catch (OtrCryptoException e) {
} catch (Exception e) {
throw new RuntimeException("OtrCryptoException getting remote fingerprint",e);

}
Expand Down Expand Up @@ -763,7 +740,7 @@ public KeyPair loadLocalKeyPair(SessionID sessionID) {
if (sessionID == null)
return null;

return loadLocalKeyPair(sessionID.getUserID());
return loadLocalKeyPair(sessionID.getAccountID());
}

private KeyPair loadLocalKeyPair(String fullUserId) {
Expand Down Expand Up @@ -835,8 +812,6 @@ private PublicKey loadRemotePublicKeyFromStore(String fullUserId) {
}

public void savePublicKey(SessionID sessionID, PublicKey pubKey) {
if (sessionID == null)
return;

X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(pubKey.getEncoded());

Expand All @@ -849,7 +824,7 @@ public void savePublicKey(SessionID sessionID, PublicKey pubKey) {
// Stash the associated fingerprint. This saves calculating it in the future
// and is useful for transferring rosters to other apps.
try {
String fingerprintString = new OtrCryptoEngineImpl().getFingerprint(pubKey);
String fingerprintString = OtrCryptoEngine.getFingerprint(pubKey);
String verifiedToken = buildPublicKeyVerifiedId(sessionID.getUserID(), fingerprintString);
String fingerprintKey = fullUserId + ".fingerprint";

Expand All @@ -866,7 +841,7 @@ public void savePublicKey(SessionID sessionID, PublicKey pubKey) {
}


} catch (OtrCryptoException e) {
} catch (Exception e) {
Log.e(ImApp.LOG_TAG,"otr error: " + e.getMessage(),e);
}
}
Expand All @@ -880,9 +855,6 @@ public void unverify(SessionID sessionID) {

unverifyUser(sessionID.getUserID());

for (OtrKeyManagerListener l : listeners)
l.verificationStatusChanged(sessionID);

}

public void unverifyUser(String fullUserId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.awesomeapp.messenger.crypto.otr;

import android.text.TextUtils;
import android.util.Log;

import net.java.otr4j.api.SessionID;
import net.java.otr4j.api.SessionStatus;
import net.java.otr4j.api.TLV;

import org.awesomeapp.messenger.model.ChatSession;
import org.awesomeapp.messenger.model.ImErrorInfo;
Expand All @@ -11,10 +16,6 @@
import java.util.ArrayList;
import java.util.List;

import net.java.otr4j.OtrException;
import net.java.otr4j.session.SessionID;
import net.java.otr4j.session.SessionStatus;
import net.java.otr4j.session.TLV;

public class OtrChatListener implements MessageListener {

Expand Down Expand Up @@ -98,9 +99,9 @@ public boolean onIncomingMessage(ChatSession session, Message msg, boolean notif
}
}

} catch (OtrException oe) {
} catch (Exception oe) {

OtrDebugLogger.log("error decrypting message: " + msg.getID());
OtrDebugLogger.log("error decrypting message: " + msg.getID(),oe);
// mOtrChatManager.refreshSession(sessionID.getLocalUserId(),sessionID.getRemoteUserId());
// msg.setBody("[" + "You received an unreadable encrypted message" + "]");
// mMessageListener.onIncomingMessage(session, msg);
Expand Down
Loading

0 comments on commit 0ff9d6b

Please sign in to comment.