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

[APT-10393] Support Rotating Content URLs #46

Merged
merged 4 commits into from
Sep 18, 2024
Merged

Conversation

kabliz
Copy link
Contributor

@kabliz kabliz commented Sep 18, 2024

Change the internal download tracking to be based on the ID passed in from the client, not by the URL of the audio content. This gives the client full control over the content downloaded by Armadillo, regardless if the URL changes or not at a later time.

Beforehand, a changed URL could fail to be found in Armadillo, even though it has been downloaded. These downloads should no longer be lost.

Removed unused storage reference in the WidevineSessionEventListener.

Protect EncryptedSharedPref Instability: Throw an exception that will be caught when a device needs DRM but isn't able to safely store it.

Throw an exception that will be caught when a device needs DRM but isn't able to safely store it.
Change the internal download tracking to be based on the ID passed in from the client, not by the URL of the audio content.  This gives the client full control over the content downloaded by Armadillo, regardless if the URL changes or not at a later time.

Beforehand, a changed URL could fail to be found in Armadillo, even though it has been downloaded. These downloads should no longer be lost.

Removed unused storage reference in the WidevineSessionEventListener.
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
} catch (ex: Exception) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What exception can actually happen here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I think this one should maybe fall back to unencrypted storage? It seems better than not being able to do anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont know exactly, im following second hand reports on problems with EncryptedSharedPrefs.

Failing into an insecure mode would not be appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend maybe doing something like this?

        val keySpec = KeyGenParameterSpec.Builder("armadilloStandard", PURPOSE_ENCRYPT or PURPOSE_DECRYPT)
            .setKeySize(256)
            .setBlockModes(BLOCK_MODE_GCM)
            .setEncryptionPaddings(ENCRYPTION_PADDING_NONE)
            .build()

        val keys = try {
            MasterKeys.getOrCreate(keyspec)
        } catch (ex: Exception){
                val keyStore = KeyStore.getInstance("AndroidKeyStore")
                keyStore.load(null)
                keyStore.deleteEntry("armadilloStandard")
                context.getSharedPreferences("armadillo.standard.secure", Context.MODE_PRIVATE).edit().clear().apply()
                MasterKeys.getOrCreate(keySpec)
        }

        return EncryptedSharedPreferences.create(
            "armadillo.standard.secure",
            keys,
            context,
            EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
            EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
        )

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you may be fine to use MasterKeys.AES256_GCM_SPEC for both instead of a custom keyspec for each too, but your call

@@ -71,48 +72,53 @@ internal class ArmadilloSecureStorage @Inject constructor(
}

override fun saveDrmDownload(context: Context, audioUrl: String, drmDownload: DrmDownload) {
if(secureDrmStorage == null){
throw DrmDownloadException(UnsupportedOperationException("This device cannot encrypt downloads"))
Copy link
Contributor

Choose a reason for hiding this comment

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

What should the user experience be if this happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Download failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there anything they can do to fix it?

Copy link
Contributor Author

@kabliz kabliz Sep 18, 2024

Choose a reason for hiding this comment

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

No. If their device is in the failed mode they can't download. They can still stream even this component fails to initialize.


downloadHelper.prepare(object : DownloadHelper.Callback {
override fun onPrepared(helper: DownloadHelper) {
val request = helper.getDownloadRequest(audioPlayable.id.encodeInByteArray())
var request = helper.getDownloadRequest(audioPlayable.id.encodeInByteArray())
request = request.copyWithId(audioPlayable.id.toString())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing from the byte array to the string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's string everywhere else, and the audioplayable.id is not what's being set as the ID there, its being set as the URL, and then i have to override it back to being the audioplayable.id instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of scope: I don't think we use the audioPlayable.id.encodeInByteArray() data anywhere, it's a bit of a red herring. I think we can pass null

Also, the var threw me off for a moment thinking there was reason to reassign it.

Any reason not to do:

val request = helper.getDownloadRequest(audioPlayable.id.encodeInByteArray()).copyWithId(audioPlayable.id.toString())?

@SeanoAndroid SeanoAndroid self-assigned this Sep 18, 2024
Clears the keystore if the EncryptedSharedPref key is lost, which can happen in some random OEMs.
The data isn't used as an ID, but its passed into Exoplayer. We still have to set the ID ourselves.
@kabliz kabliz merged commit 51a8c21 into main Sep 18, 2024
6 checks passed
@kabliz kabliz deleted the kabliz/APT-10393-playback branch September 18, 2024 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants