Search in sources :

Example 1 with OtrSm

use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.

the class OtrChatManager method abortSmp.

public void abortSmp(SessionID sessionID) throws OtrException {
    OtrSm otrSm = mOtrSms.get(sessionID.toString());
    if (otrSm == null)
        return;
    List<TLV> tlvs = otrSm.abortSmp();
    String encrypted = mOtrEngine.transformSending(sessionID, "", tlvs);
    mOtrEngineHost.injectMessage(sessionID, encrypted);
}
Also used : OtrSm(net.java.otr4j.session.OtrSm) TLV(net.java.otr4j.session.TLV)

Example 2 with OtrSm

use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.

the class OtrChatManager method sessionStatusChanged.

@Override
public void sessionStatusChanged(final SessionID sessionID) {
    SessionStatus sStatus = mOtrEngine.getSessionStatus(sessionID);
    OtrDebugLogger.log("session status changed: " + sStatus);
    final Session session = mOtrEngine.getSession(sessionID);
    OtrSm otrSm = mOtrSms.get(sessionID.toString());
    if (sStatus == SessionStatus.ENCRYPTED) {
        PublicKey remoteKey = mOtrEngine.getRemotePublicKey(sessionID);
        mOtrEngineHost.storeRemoteKey(sessionID, remoteKey);
        if (otrSm == null) {
            // SMP handler - make sure we only add this once per session!
            otrSm = new OtrSm(session, mOtrEngineHost.getKeyManager(), sessionID, OtrChatManager.this);
            session.addTlvHandler(otrSm);
            mOtrSms.put(sessionID.toString(), otrSm);
        }
    } else if (sStatus == SessionStatus.PLAINTEXT) {
        if (otrSm != null) {
            session.removeTlvHandler(otrSm);
            mOtrSms.remove(sessionID.toString());
        }
        mOtrEngineHost.removeSessionResource(sessionID);
    } else if (sStatus == SessionStatus.FINISHED) {
    // Do nothing.  The user must take affirmative action to
    // restart or end the session, so that they don't send
    // plaintext by mistake.
    }
}
Also used : PublicKey(java.security.PublicKey) SessionStatus(net.java.otr4j.session.SessionStatus) OtrSm(net.java.otr4j.session.OtrSm) Session(net.java.otr4j.session.Session)

Example 3 with OtrSm

use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.

the class OtrChatManager method respondSmp.

public void respondSmp(SessionID sessionID, String secret) throws OtrException {
    OtrSm otrSm = mOtrSms.get(sessionID.toString());
    List<TLV> tlvs;
    if (otrSm == null) {
        showError(sessionID, "Could not respond to verification because conversation is not encrypted");
        return;
    }
    tlvs = otrSm.initRespondSmp(null, secret, false);
    String encrypted = mOtrEngine.transformSending(sessionID, "", tlvs);
    mOtrEngineHost.injectMessage(sessionID, encrypted);
}
Also used : OtrSm(net.java.otr4j.session.OtrSm) TLV(net.java.otr4j.session.TLV)

Example 4 with OtrSm

use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.

the class OtrChatManager method decryptMessage.

public String decryptMessage(String localUserId, String remoteUserId, String msg, List<TLV> tlvs) throws OtrException {
    String plain = null;
    SessionID sessionId = getSessionId(localUserId, remoteUserId);
    if (mOtrEngine != null && sessionId != null) {
        mOtrEngineHost.putSessionResource(sessionId, processResource(remoteUserId));
        plain = mOtrEngine.transformReceiving(sessionId, msg, tlvs);
        OtrSm otrSm = mOtrSms.get(sessionId.toString());
        if (otrSm != null) {
            List<TLV> smTlvs = otrSm.getPendingTlvs();
            if (smTlvs != null) {
                String encrypted = mOtrEngine.transformSending(sessionId, "", smTlvs);
                mOtrEngineHost.injectMessage(sessionId, encrypted);
            }
        }
        // not null, but empty so make it null!
        if (TextUtils.isEmpty(plain))
            return null;
    }
    return plain;
}
Also used : OtrSm(net.java.otr4j.session.OtrSm) SessionID(net.java.otr4j.session.SessionID) TLV(net.java.otr4j.session.TLV)

Example 5 with OtrSm

use of net.java.otr4j.session.OtrSm in project Zom-Android by zom.

the class OtrChatManager method initSmp.

public void initSmp(SessionID sessionID, String question, String secret) throws OtrException {
    OtrSm otrSm = mOtrSms.get(sessionID.toString());
    List<TLV> tlvs;
    if (otrSm == null) {
        showError(sessionID, "Could not perform verification because conversation is not encrypted");
        return;
    }
    tlvs = otrSm.initRespondSmp(question, secret, true);
    String encrypted = mOtrEngine.transformSending(sessionID, "", tlvs);
    mOtrEngineHost.injectMessage(sessionID, encrypted);
}
Also used : OtrSm(net.java.otr4j.session.OtrSm) TLV(net.java.otr4j.session.TLV)

Aggregations

OtrSm (net.java.otr4j.session.OtrSm)5 TLV (net.java.otr4j.session.TLV)4 PublicKey (java.security.PublicKey)1 Session (net.java.otr4j.session.Session)1 SessionID (net.java.otr4j.session.SessionID)1 SessionStatus (net.java.otr4j.session.SessionStatus)1