Search in sources :

Example 1 with OtrAndroidKeyManagerImpl

use of org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl in project Zom-Android by zom.

the class RemoteImService method initOtrChatManager.

private synchronized OtrChatManager initOtrChatManager() {
    int otrPolicy = convertPolicy();
    if (mOtrChatManager == null) {
        try {
            OtrAndroidKeyManagerImpl otrKeyManager = OtrAndroidKeyManagerImpl.getInstance(this);
            if (otrKeyManager != null) {
                mOtrChatManager = OtrChatManager.getInstance(otrPolicy, this, otrKeyManager);
                mOtrChatManager.addOtrEngineListener(this);
                otrKeyManager.addListener(new OtrKeyManagerListener() {

                    public void verificationStatusChanged(SessionID session) {
                        boolean isVerified = mOtrChatManager.getKeyManager().isVerified(session);
                        String msg = session + ": verification status=" + isVerified;
                        OtrDebugLogger.log(msg);
                    }

                    public void remoteVerifiedUs(SessionID session) {
                        String msg = session + ": remote verified us";
                        OtrDebugLogger.log(msg);
                        showToast(getString(R.string.remote_verified_us), Toast.LENGTH_SHORT);
                    // if (!isRemoteKeyVerified(session))
                    // showWarning(session, mContext.getApplicationContext().getString(R.string.remote_verified_us));
                    }
                });
            }
        } catch (Exception e) {
            OtrDebugLogger.log("unable to init OTR manager", e);
        }
    } else {
        mOtrChatManager.setPolicy(otrPolicy);
    }
    return mOtrChatManager;
}
Also used : OtrKeyManagerListener(net.java.otr4j.OtrKeyManagerListener) OtrAndroidKeyManagerImpl(org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl) SessionID(net.java.otr4j.session.SessionID) GeneralSecurityException(java.security.GeneralSecurityException) ImException(org.awesomeapp.messenger.model.ImException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 2 with OtrAndroidKeyManagerImpl

use of org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl in project Zom-Android by zom.

the class MigrateAccountTask method doInBackground.

@Override
protected OnboardingAccount doInBackground(String... newDomains) {
    // get existing account username
    String nickname = Imps.Account.getNickname(mContext.getContentResolver(), mAccountId);
    String username = Imps.Account.getUserName(mContext.getContentResolver(), mAccountId);
    String password = Imps.Account.getPassword(mContext.getContentResolver(), mAccountId);
    OtrAndroidKeyManagerImpl keyMan = OtrAndroidKeyManagerImpl.getInstance(mContext);
    KeyPair keyPair = keyMan.generateLocalKeyPair();
    String fingerprint = keyMan.getFingerprint(keyPair.getPublic());
    // find or use provided new server/domain
    String domain = newDomains[0];
    // register account on new domain with same password
    mNewAccount = registerNewAccount(nickname, username, password, domain, null);
    if (mNewAccount == null) {
        username = username + '.' + fingerprint.substring(fingerprint.length() - 8, fingerprint.length()).toLowerCase();
        mNewAccount = registerNewAccount(nickname, username, password, domain, null);
        if (mNewAccount == null)
            return null;
    }
    String newJabberId = mNewAccount.username + '@' + mNewAccount.domain;
    keyMan.storeKeyPair(newJabberId, keyPair);
    // send migration message to existing contacts and/or sessions
    try {
        boolean loggedInToOldAccount = mConn.getState() == ImConnection.LOGGED_IN;
        // login and set new default account
        SignInHelper signInHelper = new SignInHelper(mContext, mHandler);
        signInHelper.activateAccount(mNewAccount.providerId, mNewAccount.accountId);
        signInHelper.signIn(mNewAccount.password, mNewAccount.providerId, mNewAccount.accountId, true);
        mNewConn = mApp.getConnection(mNewAccount.providerId, mNewAccount.accountId);
        while (mNewConn.getState() != ImConnection.LOGGED_IN) {
            try {
                Thread.sleep(500);
            } catch (Exception e) {
            }
        }
        String inviteLink = OnboardingManager.generateInviteLink(mContext, newJabberId, fingerprint, nickname, true);
        String migrateMessage = mContext.getString(R.string.migrate_message) + ' ' + inviteLink;
        IChatSessionManager sessionMgr = mConn.getChatSessionManager();
        IContactListManager clManager = mConn.getContactListManager();
        List<IContactList> listOfLists = clManager.getContactLists();
        if (loggedInToOldAccount) {
            for (IContactList contactList : listOfLists) {
                String[] contacts = contactList.getContacts();
                for (String contact : contacts) {
                    mContacts.add(contact);
                    IChatSession session = sessionMgr.getChatSession(contact);
                    if (session == null) {
                        session = sessionMgr.createChatSession(contact, true);
                    }
                    if (!session.isEncrypted()) {
                        // try to kick off some encryption here
                        session.getDefaultOtrChatSession().startChatEncryption();
                        try {
                            Thread.sleep(500);
                        }// just wait a half second here?
                         catch (Exception e) {
                        }
                    }
                    session.sendMessage(migrateMessage, false);
                    // archive existing contact
                    clManager.archiveContact(contact, session.isGroupChatSession() ? Imps.Contacts.TYPE_NORMAL : Imps.Contacts.TYPE_GROUP, true);
                }
            }
        } else {
            String[] offlineAddresses = clManager.getOfflineAddresses();
            for (String address : offlineAddresses) {
                mContacts.add(address);
                clManager.archiveContact(address, Imps.Contacts.TYPE_NORMAL, true);
            }
        }
        for (String contact : mContacts) {
            addToContactList(mNewConn, contact, keyMan.getRemoteFingerprint(contact), null);
        }
        if (loggedInToOldAccount) {
            // archive existing conversations and contacts
            List<IChatSession> listSession = mConn.getChatSessionManager().getActiveChatSessions();
            for (IChatSession session : listSession) {
                session.leave();
            }
            mConn.broadcastMigrationIdentity(newJabberId);
        }
        migrateAvatars(username, newJabberId);
        mApp.setDefaultAccount(mNewAccount.providerId, mNewAccount.accountId);
        // logout of existing account
        setKeepSignedIn(mAccountId, false);
        if (loggedInToOldAccount)
            mConn.logout();
        return mNewAccount;
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error with migration", e);
    }
    // failed
    return null;
}
Also used : KeyPair(java.security.KeyPair) OtrAndroidKeyManagerImpl(org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl) IContactList(org.awesomeapp.messenger.service.IContactList) SignInHelper(org.awesomeapp.messenger.ui.legacy.SignInHelper) IChatSession(org.awesomeapp.messenger.service.IChatSession) RemoteException(android.os.RemoteException) JSONException(org.json.JSONException) IOException(java.io.IOException) IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) IContactListManager(org.awesomeapp.messenger.service.IContactListManager)

Example 3 with OtrAndroidKeyManagerImpl

use of org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl in project Zom-Android by zom.

the class AccountActivity method checkForKey.

private boolean checkForKey(String userid) {
    try {
        OtrAndroidKeyManagerImpl otrKeyMan = OtrAndroidKeyManagerImpl.getInstance(AccountActivity.this);
        String fp = otrKeyMan.getLocalFingerprint(userid);
        if (fp == null) {
            otrKeyMan.generateLocalKeyPair(userid);
            fp = otrKeyMan.getLocalFingerprint(userid);
            return true;
        } else
            return true;
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error checking for key", e);
        return false;
    }
}
Also used : OtrAndroidKeyManagerImpl(org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl) RemoteException(android.os.RemoteException)

Example 4 with OtrAndroidKeyManagerImpl

use of org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl in project Zom-Android by zom.

the class AccountViewFragment method checkForKey.

private boolean checkForKey(String userid) {
    try {
        OtrAndroidKeyManagerImpl otrKeyMan = OtrAndroidKeyManagerImpl.getInstance(getActivity());
        String fp = otrKeyMan.getLocalFingerprint(userid);
        if (fp == null) {
            otrKeyMan.generateLocalKeyPair(userid);
            fp = otrKeyMan.getLocalFingerprint(userid);
            return true;
        } else
            return true;
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error checking for key", e);
        return false;
    }
}
Also used : OtrAndroidKeyManagerImpl(org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl) RemoteException(android.os.RemoteException)

Aggregations

RemoteException (android.os.RemoteException)4 OtrAndroidKeyManagerImpl (org.awesomeapp.messenger.crypto.otr.OtrAndroidKeyManagerImpl)4 IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyPair (java.security.KeyPair)1 OtrKeyManagerListener (net.java.otr4j.OtrKeyManagerListener)1 SessionID (net.java.otr4j.session.SessionID)1 ImException (org.awesomeapp.messenger.model.ImException)1 IChatSession (org.awesomeapp.messenger.service.IChatSession)1 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)1 IContactList (org.awesomeapp.messenger.service.IContactList)1 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)1 SignInHelper (org.awesomeapp.messenger.ui.legacy.SignInHelper)1 JSONException (org.json.JSONException)1