Install and update extensions only from a store whose signing key matches
Updates come only from stores whose key the installed extension is signed with, the highest version among them. A downloaded apk must be signed with its store's key before it's installed.
This commit is contained in:
@@ -21,6 +21,26 @@ sealed interface Extension {
|
||||
*/
|
||||
sealed interface Installed : Extension {
|
||||
val isShared: Boolean
|
||||
|
||||
/** SHA-256 digests of the certificates its apk is signed with. */
|
||||
val signatures: List<String>
|
||||
|
||||
/**
|
||||
* The newest listing of this extension among the stores whose signing key it's signed with. An
|
||||
* apk from any other store can't replace it, so only these are where its updates come from.
|
||||
*/
|
||||
fun findListing(available: Collection<Available>): Available? {
|
||||
return available
|
||||
.filter { it.pkgName == pkgName && it.store.signingKey in signatures }
|
||||
.maxWithOrNull(compareBy<Available> { it.versionCode }.thenBy { it.libVersion })
|
||||
}
|
||||
|
||||
fun findUpdate(available: Collection<Available>): Available? {
|
||||
val installedLibVersion = libVersion
|
||||
return findListing(available)?.takeIf {
|
||||
it.versionCode > versionCode || (installedLibVersion != null && it.libVersion > installedLibVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,6 +88,7 @@ sealed interface Extension {
|
||||
override val lang: String,
|
||||
override val contentWarning: ContentWarning,
|
||||
override val isShared: Boolean,
|
||||
override val signatures: List<String>,
|
||||
val pkgFactory: String?,
|
||||
val sources: List<Source>,
|
||||
val icon: Drawable?,
|
||||
@@ -87,6 +108,7 @@ sealed interface Extension {
|
||||
override val versionCode: Long,
|
||||
override val isShared: Boolean,
|
||||
override val contentWarning: ContentWarning,
|
||||
override val signatures: List<String>,
|
||||
override val libVersion: Double? = null,
|
||||
override val lang: String? = null,
|
||||
val reason: Reason,
|
||||
|
||||
Reference in New Issue
Block a user