Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk user story #5952

Merged
merged 22 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.d/5952.sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Some `val` have been changed to `fun` to increase their visibility in the generated documentation. Just add `()` if you were using them.
- `KeysBackupService.state` has been replaced by `KeysBackupService.getState()`
- `KeysBackupService.isStucked` has been replaced by `KeysBackupService.isStuck()`
- SDK documentation improved
4 changes: 4 additions & 0 deletions matrix-sdk-android/docs/packages.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Package org.matrix.android.sdk.userstories

This package contains some user stories (**Us** prefix) of the SDK usage. You will find example of what it is possible to do with the SDK and the API which can be used to do it.

# Package org.matrix.android.sdk.api

This is the root package of the API exposed by this SDK.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.api.session.securestorage.EmptyKeySigner
import org.matrix.android.sdk.api.session.securestorage.SharedSecretStorageService
import org.matrix.android.sdk.api.session.securestorage.KeyRef
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.awaitCallback
import org.matrix.android.sdk.api.util.toBase64NoPadding
Expand Down Expand Up @@ -361,19 +361,19 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
ssssService.storeSecret(
MASTER_KEY_SSSS_NAME,
session.cryptoService().crossSigningService().getCrossSigningPrivateKeys()!!.master!!,
listOf(SharedSecretStorageService.KeyRef(keyInfo.keyId, keyInfo.keySpec))
listOf(KeyRef(keyInfo.keyId, keyInfo.keySpec))
)

ssssService.storeSecret(
SELF_SIGNING_KEY_SSSS_NAME,
session.cryptoService().crossSigningService().getCrossSigningPrivateKeys()!!.selfSigned!!,
listOf(SharedSecretStorageService.KeyRef(keyInfo.keyId, keyInfo.keySpec))
listOf(KeyRef(keyInfo.keyId, keyInfo.keySpec))
)

ssssService.storeSecret(
USER_SIGNING_KEY_SSSS_NAME,
session.cryptoService().crossSigningService().getCrossSigningPrivateKeys()!!.user!!,
listOf(SharedSecretStorageService.KeyRef(keyInfo.keyId, keyInfo.keySpec))
listOf(KeyRef(keyInfo.keyId, keyInfo.keySpec))
)

// set up megolm backup
Expand All @@ -390,7 +390,7 @@ class CryptoTestHelper(private val testHelper: CommonTestHelper) {
ssssService.storeSecret(
KEYBACKUP_SECRET_SSSS_NAME,
secret,
listOf(SharedSecretStorageService.KeyRef(keyInfo.keyId, keyInfo.keySpec))
listOf(KeyRef(keyInfo.keyId, keyInfo.keySpec))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class KeysBackupTest : InstrumentedTest {

val stateObserver = StateObserver(keysBackup)

assertFalse(keysBackup.isEnabled)
assertFalse(keysBackup.isEnabled())

val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> {
keysBackup.prepareKeysBackupVersion(null, null, it)
Expand Down Expand Up @@ -143,21 +143,21 @@ class KeysBackupTest : InstrumentedTest {

val stateObserver = StateObserver(keysBackup)

assertFalse(keysBackup.isEnabled)
assertFalse(keysBackup.isEnabled())

val megolmBackupCreationInfo = testHelper.doSync<MegolmBackupCreationInfo> {
keysBackup.prepareKeysBackupVersion(null, null, it)
}

assertFalse(keysBackup.isEnabled)
assertFalse(keysBackup.isEnabled())

// Create the version
val version = testHelper.doSync<KeysVersion> {
keysBackup.createKeysBackupVersion(megolmBackupCreationInfo, it)
}

// Backup must be enable now
assertTrue(keysBackup.isEnabled)
assertTrue(keysBackup.isEnabled())

// Check that it's signed with MSK
val versionResult = testHelper.doSync<KeysVersionResult?> {
Expand Down Expand Up @@ -441,8 +441,8 @@ class KeysBackupTest : InstrumentedTest {

// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())

// - Trust the backup from the new device
testHelper.doSync<Unit> {
Expand All @@ -458,7 +458,7 @@ class KeysBackupTest : InstrumentedTest {

// - Backup must be enabled on the new device, on the same version
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())

// - Retrieve the last version from the server
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
Expand Down Expand Up @@ -504,8 +504,8 @@ class KeysBackupTest : InstrumentedTest {

// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())

// - Trust the backup from the new device with the recovery key
testHelper.doSync<Unit> {
Expand All @@ -521,7 +521,7 @@ class KeysBackupTest : InstrumentedTest {

// - Backup must be enabled on the new device, on the same version
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())

// - Retrieve the last version from the server
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
Expand Down Expand Up @@ -565,8 +565,8 @@ class KeysBackupTest : InstrumentedTest {

// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())

// - Try to trust the backup from the new device with a wrong recovery key
val latch = CountDownLatch(1)
Expand All @@ -579,8 +579,8 @@ class KeysBackupTest : InstrumentedTest {

// - The new device must still see the previous backup as not trusted
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())

stateObserver.stopAndCheckStates(null)
testData.cleanUp(testHelper)
Expand Down Expand Up @@ -612,8 +612,8 @@ class KeysBackupTest : InstrumentedTest {

// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())

// - Trust the backup from the new device with the password
testHelper.doSync<Unit> {
Expand All @@ -629,7 +629,7 @@ class KeysBackupTest : InstrumentedTest {

// - Backup must be enabled on the new device, on the same version
assertEquals(testData.prepareKeysBackupDataResult.version, testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion?.version)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertTrue(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())

// - Retrieve the last version from the server
val keysVersionResult = testHelper.doSync<KeysBackupLastVersionResult> {
Expand Down Expand Up @@ -676,8 +676,8 @@ class KeysBackupTest : InstrumentedTest {

// - The new device must see the previous backup as not trusted
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())

// - Try to trust the backup from the new device with a wrong password
val latch = CountDownLatch(1)
Expand All @@ -690,8 +690,8 @@ class KeysBackupTest : InstrumentedTest {

// - The new device must still see the previous backup as not trusted
assertNotNull(testData.aliceSession2.cryptoService().keysBackupService().keysBackupVersion)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled)
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().state)
assertFalse(testData.aliceSession2.cryptoService().keysBackupService().isEnabled())
assertEquals(KeysBackupState.NotTrusted, testData.aliceSession2.cryptoService().keysBackupService().getState())

stateObserver.stopAndCheckStates(null)
testData.cleanUp(testHelper)
Expand Down Expand Up @@ -969,7 +969,7 @@ class KeysBackupTest : InstrumentedTest {

val stateObserver = StateObserver(keysBackup)

assertFalse(keysBackup.isEnabled)
assertFalse(keysBackup.isEnabled())

// Wait for keys backup to be finished
val latch0 = CountDownLatch(1)
Expand All @@ -993,7 +993,7 @@ class KeysBackupTest : InstrumentedTest {
// - Make alice back up her keys to her homeserver
keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)

assertTrue(keysBackup.isEnabled)
assertTrue(keysBackup.isEnabled())

testHelper.await(latch0)

Expand All @@ -1012,8 +1012,8 @@ class KeysBackupTest : InstrumentedTest {
testHelper.await(latch2)

// -> That must fail and her backup state must be WrongBackUpVersion
assertEquals(KeysBackupState.WrongBackUpVersion, keysBackup.state)
assertFalse(keysBackup.isEnabled)
assertEquals(KeysBackupState.WrongBackUpVersion, keysBackup.getState())
assertFalse(keysBackup.isEnabled())

stateObserver.stopAndCheckStates(null)
cryptoTestData.cleanUp(testHelper)
Expand Down Expand Up @@ -1069,7 +1069,7 @@ class KeysBackupTest : InstrumentedTest {
// - Try to backup all in aliceSession2, it must fail
val keysBackup2 = aliceSession2.cryptoService().keysBackupService()

assertFalse("Backup should not be enabled", keysBackup2.isEnabled)
assertFalse("Backup should not be enabled", keysBackup2.isEnabled())

val stateObserver2 = StateObserver(keysBackup2)

Expand All @@ -1088,8 +1088,8 @@ class KeysBackupTest : InstrumentedTest {
assertFalse(isSuccessful)

// Backup state must be NotTrusted
assertEquals("Backup state must be NotTrusted", KeysBackupState.NotTrusted, keysBackup2.state)
assertFalse("Backup should not be enabled", keysBackup2.isEnabled)
assertEquals("Backup state must be NotTrusted", KeysBackupState.NotTrusted, keysBackup2.getState())
assertFalse("Backup should not be enabled", keysBackup2.isEnabled())

// - Validate the old device from the new one
aliceSession2.cryptoService().setDeviceVerification(
Expand All @@ -1103,7 +1103,7 @@ class KeysBackupTest : InstrumentedTest {
keysBackup2.addListener(object : KeysBackupStateListener {
override fun onStateChange(newState: KeysBackupState) {
// Check the backup completes
if (keysBackup2.state == KeysBackupState.ReadyToBackUp) {
if (keysBackup2.getState() == KeysBackupState.ReadyToBackUp) {
// Remove itself from the list of listeners
keysBackup2.removeListener(this)

Expand All @@ -1121,7 +1121,7 @@ class KeysBackupTest : InstrumentedTest {
}

// -> It must success
assertTrue(aliceSession2.cryptoService().keysBackupService().isEnabled)
assertTrue(aliceSession2.cryptoService().keysBackupService().isEnabled())

stateObserver.stopAndCheckStates(null)
stateObserver2.stopAndCheckStates(null)
Expand All @@ -1146,17 +1146,17 @@ class KeysBackupTest : InstrumentedTest {

val stateObserver = StateObserver(keysBackup)

assertFalse(keysBackup.isEnabled)
assertFalse(keysBackup.isEnabled())

val keyBackupCreationInfo = keysBackupTestHelper.prepareAndCreateKeysBackupData(keysBackup)

assertTrue(keysBackup.isEnabled)
assertTrue(keysBackup.isEnabled())

// Delete the backup
testHelper.doSync<Unit> { keysBackup.deleteBackup(keyBackupCreationInfo.version, it) }

// Backup is now disabled
assertFalse(keysBackup.isEnabled)
assertFalse(keysBackup.isEnabled())

stateObserver.stopAndCheckStates(null)
cryptoTestData.cleanUp(testHelper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal class KeysBackupTestHelper(

Assert.assertNotNull(megolmBackupCreationInfo)

Assert.assertFalse("Key backup should not be enabled before creation", keysBackup.isEnabled)
Assert.assertFalse("Key backup should not be enabled before creation", keysBackup.isEnabled())

// Create the version
val keysVersion = testHelper.doSync<KeysVersion> {
Expand All @@ -116,7 +116,7 @@ internal class KeysBackupTestHelper(
Assert.assertNotNull("Key backup version should not be null", keysVersion.version)

// Backup must be enable now
Assert.assertTrue(keysBackup.isEnabled)
Assert.assertTrue(keysBackup.isEnabled())

stateObserver.stopAndCheckStates(null)
return PrepareKeysBackupDataResult(megolmBackupCreationInfo, keysVersion.version)
Expand All @@ -128,7 +128,7 @@ internal class KeysBackupTestHelper(
*/
fun waitForKeysBackupToBeInState(session: Session, state: KeysBackupState) {
// If already in the wanted state, return
if (session.cryptoService().keysBackupService().state == state) {
if (session.cryptoService().keysBackupService().getState() == state) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import org.matrix.android.sdk.api.crypto.SSSS_ALGORITHM_AES_HMAC_SHA2
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataEvent
import org.matrix.android.sdk.api.session.securestorage.EncryptedSecretContent
import org.matrix.android.sdk.api.session.securestorage.KeyRef
import org.matrix.android.sdk.api.session.securestorage.KeySigner
import org.matrix.android.sdk.api.session.securestorage.RawBytesKeySpec
import org.matrix.android.sdk.api.session.securestorage.SecretStorageKeyContent
import org.matrix.android.sdk.api.session.securestorage.SharedSecretStorageError
import org.matrix.android.sdk.api.session.securestorage.SharedSecretStorageService
import org.matrix.android.sdk.api.session.securestorage.SsssKeyCreationInfo
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toBase64NoPadding
Expand Down Expand Up @@ -123,7 +123,7 @@ class QuadSTests : InstrumentedTest {
aliceSession.sharedSecretStorageService().storeSecret(
"secret.of.life",
clearSecret,
listOf(SharedSecretStorageService.KeyRef(null, keySpec)) // default key
listOf(KeyRef(null, keySpec)) // default key
)
}

Expand Down Expand Up @@ -191,8 +191,8 @@ class QuadSTests : InstrumentedTest {
"my.secret",
mySecretText.toByteArray().toBase64NoPadding(),
listOf(
SharedSecretStorageService.KeyRef(keyId1, RawBytesKeySpec.fromRecoveryKey(key1Info.recoveryKey)),
SharedSecretStorageService.KeyRef(keyId2, RawBytesKeySpec.fromRecoveryKey(key2Info.recoveryKey))
KeyRef(keyId1, RawBytesKeySpec.fromRecoveryKey(key1Info.recoveryKey)),
KeyRef(keyId2, RawBytesKeySpec.fromRecoveryKey(key2Info.recoveryKey))
)
)
}
Expand Down Expand Up @@ -241,7 +241,7 @@ class QuadSTests : InstrumentedTest {
aliceSession.sharedSecretStorageService().storeSecret(
"my.secret",
mySecretText.toByteArray().toBase64NoPadding(),
listOf(SharedSecretStorageService.KeyRef(keyId1, RawBytesKeySpec.fromRecoveryKey(key1Info.recoveryKey)))
listOf(KeyRef(keyId1, RawBytesKeySpec.fromRecoveryKey(key1Info.recoveryKey)))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface AuthenticationService {
/**
* True when login and password has been sent with success to the homeserver.
*/
val isRegistrationStarted: Boolean
fun isRegistrationStarted(): Boolean

/**
* Cancel pending login or pending registration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,31 @@ package org.matrix.android.sdk.api.auth.registration

import org.matrix.android.sdk.api.session.Session

// Either a session or an object containing data about registration stages
/**
* Either a session or an object containing data about registration stages.
*/
Comment on lines +21 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have a basic documentation, you could replace by a single line comment. This avoids overloading the file with comment lines

Suggested change
/**
* Either a session or an object containing data about registration stages.
*/
/** Either a session or an object containing data about registration stages. */

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely more compact. I will think about it for next changes.
With the current format, it's easier to add new lines.

sealed class RegistrationResult {
/**
* The registration is successful, the [Session] is provided.
*/
data class Success(val session: Session) : RegistrationResult()

/**
* The registration still miss some steps. See [FlowResult] to know the details.
*/
data class FlowResponse(val flowResult: FlowResult) : RegistrationResult()
}

/**
* Information about the missing and completed [Stage].
*/
data class FlowResult(
/**
* List of missing stages.
*/
val missingStages: List<Stage>,
/**
* List of completed stages.
*/
val completedStages: List<Stage>
)
Loading