Filter Android update offers by installed signing certificate
This commit is contained in:
@@ -18,6 +18,7 @@ class AppUpdate {
|
||||
this.headersFor,
|
||||
this.platform = 'android',
|
||||
this.sha256 = '',
|
||||
this.signingCertificateSha256 = '',
|
||||
});
|
||||
|
||||
final int versionCode;
|
||||
@@ -27,6 +28,7 @@ class AppUpdate {
|
||||
final String sourceName;
|
||||
final String platform;
|
||||
final String sha256;
|
||||
final String signingCertificateSha256;
|
||||
final Map<String, String> Function(Uri)? headersFor;
|
||||
|
||||
AppUpdate fromServer(
|
||||
@@ -40,6 +42,7 @@ class AppUpdate {
|
||||
platform: platform,
|
||||
sourceName: name,
|
||||
sha256: sha256,
|
||||
signingCertificateSha256: signingCertificateSha256,
|
||||
headersFor: headers,
|
||||
);
|
||||
|
||||
@@ -49,6 +52,7 @@ class AppUpdate {
|
||||
Uri base, {
|
||||
String platform = 'android',
|
||||
String architecture = 'arm64',
|
||||
String? installedSignature,
|
||||
}) {
|
||||
try {
|
||||
final json = jsonDecode(body);
|
||||
@@ -66,6 +70,19 @@ class AppUpdate {
|
||||
if (digest.isNotEmpty && !RegExp(r'^[a-fA-F0-9]{64}$').hasMatch(digest)) {
|
||||
return null;
|
||||
}
|
||||
final signer = json['signingCertificateSha256'];
|
||||
if (signer != null &&
|
||||
(signer is! String ||
|
||||
!RegExp(r'^[a-fA-F0-9]{64}$').hasMatch(signer))) {
|
||||
return null;
|
||||
}
|
||||
if (platform == 'android' &&
|
||||
signer is String &&
|
||||
installedSignature != null &&
|
||||
signer.toLowerCase() !=
|
||||
installedSignature.replaceAll(':', '').trim().toLowerCase()) {
|
||||
return null;
|
||||
}
|
||||
if (platform == 'android' &&
|
||||
json['platform'] != null &&
|
||||
json['platform'] != 'android') {
|
||||
@@ -81,6 +98,7 @@ class AppUpdate {
|
||||
versionCode: code,
|
||||
platform: platform,
|
||||
sha256: '${json['sha256'] ?? ''}',
|
||||
signingCertificateSha256: signer is String ? signer.toLowerCase() : '',
|
||||
versionName: '${json['versionName'] ?? ''}',
|
||||
apk: base.resolve(file),
|
||||
notes: '${json['notes'] ?? ''}',
|
||||
|
||||
@@ -86,6 +86,9 @@ Future<AppUpdate> fetchLatestScoped(
|
||||
feed,
|
||||
platform: platform,
|
||||
architecture: nativeArchitecture,
|
||||
installedSignature: platform == 'android'
|
||||
? (await PackageInfo.fromPlatform()).buildSignature
|
||||
: null,
|
||||
);
|
||||
if (update == null) {
|
||||
throw const FormatException('No compatible build is offered.');
|
||||
|
||||
Reference in New Issue
Block a user