Filter Android update offers by installed signing certificate
This commit is contained in:
@@ -18,6 +18,7 @@ class AppUpdate {
|
|||||||
this.headersFor,
|
this.headersFor,
|
||||||
this.platform = 'android',
|
this.platform = 'android',
|
||||||
this.sha256 = '',
|
this.sha256 = '',
|
||||||
|
this.signingCertificateSha256 = '',
|
||||||
});
|
});
|
||||||
|
|
||||||
final int versionCode;
|
final int versionCode;
|
||||||
@@ -27,6 +28,7 @@ class AppUpdate {
|
|||||||
final String sourceName;
|
final String sourceName;
|
||||||
final String platform;
|
final String platform;
|
||||||
final String sha256;
|
final String sha256;
|
||||||
|
final String signingCertificateSha256;
|
||||||
final Map<String, String> Function(Uri)? headersFor;
|
final Map<String, String> Function(Uri)? headersFor;
|
||||||
|
|
||||||
AppUpdate fromServer(
|
AppUpdate fromServer(
|
||||||
@@ -40,6 +42,7 @@ class AppUpdate {
|
|||||||
platform: platform,
|
platform: platform,
|
||||||
sourceName: name,
|
sourceName: name,
|
||||||
sha256: sha256,
|
sha256: sha256,
|
||||||
|
signingCertificateSha256: signingCertificateSha256,
|
||||||
headersFor: headers,
|
headersFor: headers,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -49,6 +52,7 @@ class AppUpdate {
|
|||||||
Uri base, {
|
Uri base, {
|
||||||
String platform = 'android',
|
String platform = 'android',
|
||||||
String architecture = 'arm64',
|
String architecture = 'arm64',
|
||||||
|
String? installedSignature,
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
final json = jsonDecode(body);
|
final json = jsonDecode(body);
|
||||||
@@ -66,6 +70,19 @@ class AppUpdate {
|
|||||||
if (digest.isNotEmpty && !RegExp(r'^[a-fA-F0-9]{64}$').hasMatch(digest)) {
|
if (digest.isNotEmpty && !RegExp(r'^[a-fA-F0-9]{64}$').hasMatch(digest)) {
|
||||||
return null;
|
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' &&
|
if (platform == 'android' &&
|
||||||
json['platform'] != null &&
|
json['platform'] != null &&
|
||||||
json['platform'] != 'android') {
|
json['platform'] != 'android') {
|
||||||
@@ -81,6 +98,7 @@ class AppUpdate {
|
|||||||
versionCode: code,
|
versionCode: code,
|
||||||
platform: platform,
|
platform: platform,
|
||||||
sha256: '${json['sha256'] ?? ''}',
|
sha256: '${json['sha256'] ?? ''}',
|
||||||
|
signingCertificateSha256: signer is String ? signer.toLowerCase() : '',
|
||||||
versionName: '${json['versionName'] ?? ''}',
|
versionName: '${json['versionName'] ?? ''}',
|
||||||
apk: base.resolve(file),
|
apk: base.resolve(file),
|
||||||
notes: '${json['notes'] ?? ''}',
|
notes: '${json['notes'] ?? ''}',
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ Future<AppUpdate> fetchLatestScoped(
|
|||||||
feed,
|
feed,
|
||||||
platform: platform,
|
platform: platform,
|
||||||
architecture: nativeArchitecture,
|
architecture: nativeArchitecture,
|
||||||
|
installedSignature: platform == 'android'
|
||||||
|
? (await PackageInfo.fromPlatform()).buildSignature
|
||||||
|
: null,
|
||||||
);
|
);
|
||||||
if (update == null) {
|
if (update == null) {
|
||||||
throw const FormatException('No compatible build is offered.');
|
throw const FormatException('No compatible build is offered.');
|
||||||
|
|||||||
@@ -44,3 +44,9 @@ native-update capability override to the Root test host. Existing server-switch
|
|||||||
fixtures disable native network probing; production defaults still enable all
|
fixtures disable native network probing; production defaults still enable all
|
||||||
supported native platforms. This resolved two pending-timer fixture failures
|
supported native platforms. This resolved two pending-timer fixture failures
|
||||||
introduced when Linux became supported. Analyzer clean (9sOpy3).
|
introduced when Linux became supported. Analyzer clean (9sOpy3).
|
||||||
|
|
||||||
|
Android feeds may advertise `signingCertificateSha256`. The app rejects malformed
|
||||||
|
fingerprints and compares valid ones with `PackageInfo.buildSignature` before
|
||||||
|
considering a build, so a newer APK signed independently on another machine does
|
||||||
|
not hide an installable peer. Legacy feeds without the field retain Android's
|
||||||
|
installer signature validation. Desktop archive feeds are unaffected.
|
||||||
|
|||||||
@@ -10,6 +10,65 @@ import 'package:pipelines_app/features/updates/app_updates.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
test('newer differently signed APK is skipped for compatible peer', () async {
|
||||||
|
SharedPreferences.setMockInitialValues({});
|
||||||
|
final signer = 'a' * 64;
|
||||||
|
final compatible = SavedServer.validated(
|
||||||
|
id: 'compatible',
|
||||||
|
name: 'Mac',
|
||||||
|
endpoints: ['wss://compatible.test/connect'],
|
||||||
|
);
|
||||||
|
final different = SavedServer.validated(
|
||||||
|
id: 'different',
|
||||||
|
name: 'Linux',
|
||||||
|
endpoints: ['wss://different.test/connect'],
|
||||||
|
);
|
||||||
|
final update = await newestServerUpdate(
|
||||||
|
[different, compatible],
|
||||||
|
read: (base, headers) async {
|
||||||
|
final parsed = AppUpdate.parse(
|
||||||
|
jsonEncode({
|
||||||
|
'versionCode': base.host == 'different.test' ? 30 : 20,
|
||||||
|
'apk': 'pipelines.apk',
|
||||||
|
'signingCertificateSha256': base.host == 'different.test'
|
||||||
|
? 'b' * 64
|
||||||
|
: signer,
|
||||||
|
}),
|
||||||
|
base,
|
||||||
|
installedSignature: signer.toUpperCase(),
|
||||||
|
);
|
||||||
|
if (parsed == null) throw const FormatException('Incompatible signer');
|
||||||
|
return parsed;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
expect(update.versionCode, 20);
|
||||||
|
expect(update.sourceName, 'Mac');
|
||||||
|
expect(update.signingCertificateSha256, signer);
|
||||||
|
final base = Uri.parse('https://compatible.test/updates/');
|
||||||
|
for (final invalid in ['', 'sha256:bad', 42, 'g' * 64]) {
|
||||||
|
expect(
|
||||||
|
AppUpdate.parse(
|
||||||
|
jsonEncode({
|
||||||
|
'versionCode': 40,
|
||||||
|
'apk': 'pipelines.apk',
|
||||||
|
'signingCertificateSha256': invalid,
|
||||||
|
}),
|
||||||
|
base,
|
||||||
|
installedSignature: signer,
|
||||||
|
),
|
||||||
|
isNull,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Legacy feeds retain OS installer validation rather than disappearing.
|
||||||
|
expect(
|
||||||
|
AppUpdate.parse(
|
||||||
|
'{"versionCode":1,"apk":"pipelines.apk"}',
|
||||||
|
base,
|
||||||
|
installedSignature: signer,
|
||||||
|
),
|
||||||
|
isNotNull,
|
||||||
|
);
|
||||||
|
});
|
||||||
test(
|
test(
|
||||||
'retained update refuses credentials after alias/profile removal',
|
'retained update refuses credentials after alias/profile removal',
|
||||||
() async {
|
() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user