Search in sources :

Example 6 with OlmSession

use of org.matrix.olm.OlmSession in project matrix-android-sdk by matrix-org.

the class MXOlmDevice method createOutboundSession.

/**
 * Generate a new outbound session.
 * The new session will be stored in the MXStore.
 *
 * @param theirIdentityKey the remote user's Curve25519 identity key
 * @param theirOneTimeKey  the remote user's one-time Curve25519 key
 * @return the session id for the outbound session. @TODO OLMSession?
 */
public String createOutboundSession(String theirIdentityKey, String theirOneTimeKey) {
    Log.d(LOG_TAG, "## createOutboundSession() ; theirIdentityKey " + theirIdentityKey + " theirOneTimeKey " + theirOneTimeKey);
    OlmSession olmSession = null;
    try {
        olmSession = new OlmSession();
        olmSession.initOutboundSession(mOlmAccount, theirIdentityKey, theirOneTimeKey);
        mStore.storeSession(olmSession, theirIdentityKey);
        String sessionIdentifier = olmSession.sessionIdentifier();
        Log.d(LOG_TAG, "## createOutboundSession() ;  olmSession.sessionIdentifier: " + sessionIdentifier);
        return sessionIdentifier;
    } catch (Exception e) {
        Log.e(LOG_TAG, "## createOutboundSession() failed ; " + e.getMessage());
        if (null != olmSession) {
            olmSession.releaseSession();
        }
    }
    return null;
}
Also used : OlmSession(org.matrix.olm.OlmSession)

Example 7 with OlmSession

use of org.matrix.olm.OlmSession in project matrix-android-sdk by matrix-org.

the class MXOlmDevice method decryptMessage.

/**
 * Decrypt an incoming message using an existing session.
 *
 * @param ciphertext             the base64-encoded body from the received message.
 * @param messageType            message_type field from the received message.
 * @param theirDeviceIdentityKey the Curve25519 identity key for the remote device.
 * @param sessionId              the id of the active session.
 * @return the decrypted payload.
 */
public String decryptMessage(String ciphertext, int messageType, String sessionId, String theirDeviceIdentityKey) {
    String payloadString = null;
    OlmSession olmSession = getSessionForDevice(theirDeviceIdentityKey, sessionId);
    if (null != olmSession) {
        OlmMessage olmMessage = new OlmMessage();
        olmMessage.mCipherText = ciphertext;
        olmMessage.mType = messageType;
        try {
            payloadString = olmSession.decryptMessage(olmMessage);
            mStore.storeSession(olmSession, theirDeviceIdentityKey);
        } catch (Exception e) {
            Log.e(LOG_TAG, "## decryptMessage() : decryptMessage failed " + e.getMessage());
        }
    }
    return payloadString;
}
Also used : OlmSession(org.matrix.olm.OlmSession) OlmMessage(org.matrix.olm.OlmMessage)

Aggregations

OlmSession (org.matrix.olm.OlmSession)7 HashMap (java.util.HashMap)3 OlmMessage (org.matrix.olm.OlmMessage)3 File (java.io.File)2 MXOlmInboundGroupSession2 (org.matrix.androidsdk.crypto.data.MXOlmInboundGroupSession2)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 OutgoingRoomKeyRequest (org.matrix.androidsdk.crypto.OutgoingRoomKeyRequest)1 MXOlmInboundGroupSession (org.matrix.androidsdk.crypto.data.MXOlmInboundGroupSession)1 MXUsersDevicesMap (org.matrix.androidsdk.crypto.data.MXUsersDevicesMap)1