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

Commit

Permalink
massive changes round 1 to switch to otrj4 official library
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed May 22, 2018
1 parent 93f4028 commit b3fac39
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 246 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ ext {

dependencies {
implementation fileTree(include: '*.jar', dir: 'libs')
implementation project(':otr4jandroid')
//implementation project(':otr4jandroid')

implementation 'com.github.otr4j:otr4j:0.22'

// implementation 'com.github.otr4j:otr4j:aac20b11de'
implementation project(':tibetanTextLibrary')
implementation project.ext.appcompat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public void generateLocalKeyPair(SessionID sessionID) {
if (sessionID == null)
return;

generateLocalKeyPair(sessionID.getLocalUserId());
generateLocalKeyPair(sessionID.getAccountID());
}

public void regenerateLocalPublicKey(KeyFactory factory, String fullUserId, DSAPrivateKey privKey) {
Expand Down Expand Up @@ -558,7 +558,25 @@ public boolean importKeyStore(String filePath, String password, boolean overWrit
}

public String getLocalFingerprint(SessionID sessionID) {
return getLocalFingerprint(sessionID.getLocalUserId());
return getLocalFingerprint(sessionID.getAccountID());
}

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

KeyPair keyPair = loadLocalKeyPair(userId);

if (keyPair == null)
return null;

try {
return cryptoEngine.getFingerprintRaw(keyPair.getPublic());
}
catch (Exception e)
{
return null;
}
}

public String getLocalFingerprint(String fullUserId) {
Expand Down Expand Up @@ -588,7 +606,7 @@ public String getFingerprint (PublicKey pubKey)
}

public String getRemoteFingerprint(SessionID sessionID) {
return getRemoteFingerprint(sessionID.getRemoteUserId());
return getRemoteFingerprint(sessionID.getUserID());
}

public boolean hasRemoteFingerprint (String userId)
Expand Down Expand Up @@ -704,7 +722,7 @@ public String[] getRemoteFingerprints(String userId) {
public boolean isVerified(SessionID sessionID) {
if (sessionID == null)
return false;
return isVerified(sessionID.getRemoteUserId(),null);
return isVerified(sessionID.getUserID(),null);
}

public boolean isVerified(String remoteUserId, String remoteFingerprint) {
Expand Down Expand Up @@ -745,7 +763,7 @@ public KeyPair loadLocalKeyPair(SessionID sessionID) {
if (sessionID == null)
return null;

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

private KeyPair loadLocalKeyPair(String fullUserId) {
Expand Down Expand Up @@ -785,7 +803,7 @@ private KeyPair loadLocalKeyPair(String fullUserId) {

public PublicKey loadRemotePublicKey(SessionID sessionID) {

return loadRemotePublicKeyFromStore(sessionID.getRemoteUserId());
return loadRemotePublicKeyFromStore(sessionID.getUserID());
}

private PublicKey loadRemotePublicKeyFromStore(String fullUserId) {
Expand Down Expand Up @@ -825,14 +843,14 @@ public void savePublicKey(SessionID sessionID, PublicKey pubKey) {
// if (!Address.hasResource(sessionID.getRemoteUserId()))
// return;

String fullUserId = sessionID.getRemoteUserId();
String fullUserId = sessionID.getUserID();

this.store.setProperty(fullUserId + ".publicKey", x509EncodedKeySpec.getEncoded());
// 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 verifiedToken = buildPublicKeyVerifiedId(sessionID.getRemoteUserId(), fingerprintString);
String verifiedToken = buildPublicKeyVerifiedId(sessionID.getUserID(), fingerprintString);
String fingerprintKey = fullUserId + ".fingerprint";

//if a fingerprint for this userid exists, then check if the key is verified
Expand Down Expand Up @@ -860,7 +878,7 @@ public void unverify(SessionID sessionID) {
if (!isVerified(sessionID))
return;

unverifyUser(sessionID.getRemoteUserId());
unverifyUser(sessionID.getUserID());

for (OtrKeyManagerListener l : listeners)
l.verificationStatusChanged(sessionID);
Expand All @@ -884,17 +902,10 @@ public void verify(SessionID sessionID) {
if (this.isVerified(sessionID))
return;

verifyUser(sessionID.getRemoteUserId());
verifyUser(sessionID.getUserID());

}

public void remoteVerifiedUs(SessionID sessionID) {
if (sessionID == null)
return;

for (OtrKeyManagerListener l : listeners)
l.remoteVerifiedUs(sessionID);
}

private static String buildPublicKeyVerifiedId(String userId, String fingerprint) {
if (fingerprint == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean onIncomingMessage(ChatSession session, Message msg, boolean notif
}


SessionStatus newStatus = mOtrChatManager.getSessionStatus(sessionID.getLocalUserId(), sessionID.getRemoteUserId());
SessionStatus newStatus = mOtrChatManager.getSessionStatus(sessionID.getAccountID(), sessionID.getUserID());
if (newStatus != otrStatus) {

OtrDebugLogger.log("OTR status changed from: " + otrStatus + " to " + newStatus);
Expand Down
Loading

0 comments on commit b3fac39

Please sign in to comment.