This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5053: Closes #2229: Encrypted-at-rest FxA state storage support r=csadilek a=grigoryk This patch adds a version of `AccountStorage` which is backed by an encrypted-at-rest shared-prefs implementation, `SecureAbove22Preferences`. As the name suggests, encryption at rest is enabled only for Android API levels 23+. Otherwise, plaintext storage is used. `SecureAbove22Preferences` will handle API level upgrades behind the scenes, if necessary. In order to support rolling this out, `SecureAbove22AccountStorage` automatically migrates account state if it was present in `SharedPrefAccountStorage`. And vice-versa, `SharedPrefAccountStorage` will automatically migrate account state if it was present in `SecureAbove22AccountStorage`. This allows applications to easily switch between two implementations, without any ill-effects. In order to monitor storage implementations for abnormalities (such as disappearing encryption keys), an optional `CrashReporter` instance may be configured now via FxaAccountManager. `DeviceConfig` gained a `secureStateAtRest` flag, which allows applications to specify if they'd like to encrypt account state. This config object isn't a perfect fit for this flag, but it's close enough conceptually. Co-authored-by: Grisha Kruglov <[email protected]>
- Loading branch information
Showing
9 changed files
with
329 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import org.junit.Assert.assertEquals | |
import org.junit.Assert.assertNull | ||
import org.mockito.Mockito.never | ||
import org.mockito.Mockito.verify | ||
import org.robolectric.annotation.Config | ||
|
||
// Same as the actual account manager, except we get to control how FirefoxAccountShaped instances | ||
// are created. This is necessary because due to some build issues (native dependencies not available | ||
|
@@ -57,6 +58,10 @@ class FirefoxAccountsAuthFeatureTest { | |
} | ||
} | ||
|
||
// Note that tests that involve secure storage specify API=21, because of issues testing secure storage on | ||
// 23+ API levels. See https://github.com/mozilla-mobile/android-components/issues/4956 | ||
|
||
@Config(sdk = [22]) | ||
@Test | ||
fun `begin authentication`() { | ||
val manager = prepareAccountManagerForSuccessfulAuthentication() | ||
|
@@ -75,6 +80,7 @@ class FirefoxAccountsAuthFeatureTest { | |
assertEquals("auth://url", authLabmda.url) | ||
} | ||
|
||
@Config(sdk = [22]) | ||
@Test | ||
fun `begin pairing authentication`() { | ||
val manager = prepareAccountManagerForSuccessfulAuthentication() | ||
|
@@ -93,6 +99,7 @@ class FirefoxAccountsAuthFeatureTest { | |
assertEquals("auth://url", authLabmda.url) | ||
} | ||
|
||
@Config(sdk = [22]) | ||
@Test | ||
fun `begin authentication with errors`() { | ||
val manager = prepareAccountManagerForFailedAuthentication() | ||
|
@@ -112,6 +119,7 @@ class FirefoxAccountsAuthFeatureTest { | |
assertEquals("https://accounts.firefox.com/signin", authLambda.url) | ||
} | ||
|
||
@Config(sdk = [22]) | ||
@Test | ||
fun `begin pairing authentication with errors`() { | ||
val manager = prepareAccountManagerForFailedAuthentication() | ||
|
@@ -203,6 +211,7 @@ class FirefoxAccountsAuthFeatureTest { | |
) | ||
} | ||
|
||
@Config(sdk = [22]) | ||
private fun prepareAccountManagerForSuccessfulAuthentication(): TestableFxaAccountManager { | ||
val mockAccount: OAuthAccount = mock() | ||
val profile = Profile(uid = "testUID", avatar = null, email = "[email protected]", displayName = "test profile") | ||
|
@@ -227,6 +236,7 @@ class FirefoxAccountsAuthFeatureTest { | |
return manager | ||
} | ||
|
||
@Config(sdk = [22]) | ||
private fun prepareAccountManagerForFailedAuthentication(): TestableFxaAccountManager { | ||
val mockAccount: OAuthAccount = mock() | ||
val profile = Profile(uid = "testUID", avatar = null, email = "[email protected]", displayName = "test profile") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.