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;
}
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;
}
Aggregations