@Override public void initWithMatrixSession(MXSession matrixSession, String roomId) { mCrypto = matrixSession.getCrypto(); mRoomId = roomId; }
@Override public void initWithMatrixSession(MXSession matrixSession, String roomId) { mSession = matrixSession; mCrypto = matrixSession.getCrypto(); mRoomId = roomId; mDeviceId = matrixSession.getCredentials().deviceId; // Default rotation periods // TODO: Make it configurable via parameters mSessionRotationPeriodMsgs = 100; mSessionRotationPeriodMs = 7 * 24 * 3600 * 1000; }
@Override public void initWithMatrixSession(MXSession matrixSession) { mSession = matrixSession; mOlmDevice = matrixSession.getCrypto().getOlmDevice(); }
/** * Init the object fields * * @param matrixSession the matrix session */ @Override public void initWithMatrixSession(MXSession matrixSession) { mSession = matrixSession; mOlmDevice = matrixSession.getCrypto().getOlmDevice(); mPendingEvents = new HashMap<>(); }
/** * Helper for the real decryptEvent and for _retryDecryption. If * requestKeysOnFail is true, we'll send an m.room_key_request when we fail * to decrypt the event due to missing megolm keys. * * @param event the event */ private void requestKeysForEvent(Event event) { String sender = event.getSender(); EncryptedEventContent wireContent = JsonUtils.toEncryptedEventContent(event.getWireContent()); List<Map<String, String>> recipients = new ArrayList<>(); Map<String, String> selfMap = new HashMap<>(); selfMap.put("userId", mSession.getMyUserId()); selfMap.put("deviceId", "*"); recipients.add(selfMap); if (!TextUtils.equals(sender, mSession.getMyUserId())) { Map<String, String> senderMap = new HashMap<>(); senderMap.put("userId", sender); senderMap.put("deviceId", wireContent.device_id); recipients.add(senderMap); } Map<String, String> requestBody = new HashMap<>(); requestBody.put("room_id", event.roomId); requestBody.put("algorithm", wireContent.algorithm); requestBody.put("sender_key", wireContent.sender_key); requestBody.put("session_id", wireContent.session_id); mSession.getCrypto().requestRoomKey(requestBody, recipients); }
@Override public void onSuccess(MXUsersDevicesMap<MXDeviceInfo> devicesMap) { final String deviceId = request.mDeviceId; final MXDeviceInfo deviceInfo = mSession.getCrypto().mCryptoStore.getUserDevice(deviceId, userId); devicesByUser.put(userId, new ArrayList<>(Arrays.asList(deviceInfo))); mSession.getCrypto().ensureOlmSessionsForDevices(devicesByUser, new ApiCallback<MXUsersDevicesMap<MXOlmSessionResult>>() { @Override public void onSuccess(MXUsersDevicesMap<MXOlmSessionResult> map) {
@Override public void onSuccess(List<RoomMember> members) { if (members.size() != 2) { // Safety check callback.onUnexpectedError(new Exception("Wrong number of members")); return; } String userId1 = members.get(0).getUserId(); String userId2 = members.get(1).getUserId(); // force the refresh to ensure that the devices list is up-to-date mSession.getCrypto().checkUnknownDevices(Arrays.asList(userId1, userId2), new SimpleApiCallback<Void>(callback) { @Override public void onSuccess(Void anything) { final IMXCall call = getCallWithCallId(null, true); call.setRooms(room, room); call.setIsVideo(isVideo); dispatchOnOutgoingCall(call); if (null != callback) { mUIThreadHandler.post(new Runnable() { @Override public void run() { callback.onSuccess(call); } }); } } }); } });
final Event fEvent = event; final MXEventDecryptionResult fResut = result; mSession.getCrypto().getUIHandler().post(new Runnable() { @Override public void run() {
@Test public void test01_testCryptoNoDeviceId() throws Exception { Log.e(LOG_TAG, "test01_testCryptoNoDeviceId"); Context context = InstrumentationRegistry.getContext(); final Map<String, Object> results = new HashMap<>(); MXSession bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, mCryptoTestHelper.getDefaultSessionParams()); Assert.assertNull(bobSession.getCrypto()); bobSession.getCredentials().deviceId = null; CountDownLatch lock1 = new CountDownLatch(1); bobSession.enableCrypto(true, new TestApiCallback<Void>(lock1) { @Override public void onSuccess(Void info) { results.put("enableCrypto", "enableCrypto"); super.onSuccess(info); } }); mTestHelper.await(lock1); Assert.assertTrue(results.containsKey("enableCrypto")); Assert.assertNotNull(bobSession.getCrypto()); Assert.assertNotNull(bobSession.getCredentials().deviceId); bobSession.clear(context); }
final MXSession bobSession = cryptoTestData.getSecondSession(); aliceSession.getCrypto().setWarnOnUnknownDevices(false); aliceSession.getCrypto().getDeviceList().downloadKeys(Arrays.asList(bobSession.getMyUserId()), false, new TestApiCallback<MXUsersDevicesMap<MXDeviceInfo>>(lock1) { @Override aliceSession.getCrypto().getDeviceList().downloadKeys(Arrays.asList(bobSession.getMyUserId()), false, new TestApiCallback<MXUsersDevicesMap<MXDeviceInfo>>(lock2) { @Override
final MXSession bobSession = cryptoTestData.getSecondSession(); bobSession.getCrypto().setWarnOnUnknownDevices(false); aliceSession.getCrypto().setWarnOnUnknownDevices(false); aliceSession.getCrypto().getDeviceList() .downloadKeys(Arrays.asList(bobSession.getMyUserId(), "@pppppppppppp:matrix.org"), false, new TestApiCallback<MXUsersDevicesMap<MXDeviceInfo>>(lock1) {
List<String> deviceInfos = unknownDevices.getUserDeviceIds(bobSession.getMyUserId()); Assert.assertEquals(1, deviceInfos.size()); Assert.assertEquals(deviceInfos.get(0), bobSession.getCrypto().getMyDevice().deviceId); aliceSession.getCrypto().setDevicesKnown(Arrays.asList(bobSession.getCrypto().getMyDevice()), new TestApiCallback<Void>(lock2) { @Override public void onSuccess(Void info) { Assert.assertTrue(results.containsKey("onLiveEvent")); Assert.assertEquals(MXDeviceList.TRACKING_STATUS_UP_TO_DATE, bobSession.getCrypto().getDeviceTrackingStatus(bobSession.getMyUserId())); Assert.assertEquals(MXDeviceList.TRACKING_STATUS_UP_TO_DATE, bobSession.getCrypto().getDeviceTrackingStatus(aliceSession.getMyUserId())); Assert.assertEquals(MXDeviceList.TRACKING_STATUS_UP_TO_DATE, aliceSession.getCrypto().getDeviceTrackingStatus(bobSession.getMyUserId())); Assert.assertEquals(MXDeviceList.TRACKING_STATUS_UP_TO_DATE, aliceSession.getCrypto().getDeviceTrackingStatus(aliceSession.getMyUserId()));
Assert.assertTrue(results.containsKey("onCryptoSyncComplete")); Assert.assertNotNull(bobSession2.getCrypto());
final MXSession bobSession = cryptoTestData.getSecondSession(); aliceSession.getCrypto().setWarnOnUnknownDevices(false);
final String aliceRoomId = cryptoTestData.getRoomId(); aliceSession.getCrypto().setWarnOnUnknownDevices(false);