Merge branch 'worktree-agent-a5eba3669bc0e09ad' into worktree-agent-ac54c8919e940163a

This commit is contained in:
2026-11-10 01:02:08 +00:00
17 changed files with 1010 additions and 26 deletions
+102
View File
@@ -0,0 +1,102 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/updates/ed25519.dart';
List<int> hex(String text) => [
for (var i = 0; i < text.length; i += 2)
int.parse(text.substring(i, i + 2), radix: 16),
];
// RFC 8032 section 7.1, tests 1-3.
const vectors = [
(
'd75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a',
'',
'e5564300c360ac729086e2cc806e828a84877f1eb8e5d974d873e06522490155'
'5fb8821590a33bacc61e39701cf9b46bd25bf5f0595bbe24655141438e7a100b',
),
(
'3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c',
'72',
'92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da'
'085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00',
),
(
'fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025',
'af82',
'6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac'
'18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40a',
),
];
void main() {
test('RFC 8032 vectors verify', () {
for (final (key, message, signature) in vectors) {
expect(
ed25519Verify(
publicKey: hex(key),
message: hex(message),
signature: hex(signature),
),
isTrue,
reason: key,
);
}
});
test('a changed message, signature or key is refused', () {
final (key, message, signature) = vectors[2];
bool verify(List<int> k, List<int> m, List<int> s) =>
ed25519Verify(publicKey: k, message: m, signature: s);
expect(verify(hex(key), hex('af83'), hex(signature)), isFalse);
expect(verify(hex(key), hex(''), hex(signature)), isFalse);
for (final index in [0, 31, 32, 63]) {
final changed = hex(signature)..[index] ^= 1;
expect(verify(hex(key), hex(message), changed), isFalse);
}
final otherKey = hex(vectors[1].$1);
expect(verify(otherKey, hex(message), hex(signature)), isFalse);
final changedKey = hex(key)..[0] ^= 1;
expect(verify(changedKey, hex(message), hex(signature)), isFalse);
});
test('malformed inputs are refused rather than thrown', () {
final (key, message, signature) = vectors[1];
expect(
ed25519Verify(
publicKey: hex(key).sublist(1),
message: hex(message),
signature: hex(signature),
),
isFalse,
);
expect(
ed25519Verify(
publicKey: hex(key),
message: hex(message),
signature: hex(signature).sublist(1),
),
isFalse,
);
// S must be below the group order L (no malleable second form).
final high = hex(signature)..fillRange(32, 64, 0xff);
expect(
ed25519Verify(
publicKey: hex(key),
message: hex(message),
signature: high,
),
isFalse,
);
// y = p (non-canonical) does not decode as a key.
final invalidKey = List<int>.filled(32, 0xff)..[0] = 0xed;
invalidKey[31] = 0x7f;
expect(
ed25519Verify(
publicKey: invalidKey,
message: hex(message),
signature: hex(signature),
),
isFalse,
);
});
}
@@ -0,0 +1 @@
6Jo+xjitfGvKp28mdXIziIyDfs5UUP4xzFl92+xrAAU=
@@ -0,0 +1 @@
{"versionCode": 29400000, "versionName": "0.1.29400000", "platform": "linux", "architectures": ["x64"], "file": "pipelines-linux-x64-29400000-0123abcd.tar.gz", "sha256": "abababababababababababababababababababababababababababababababab", "notes": "fixture"}
@@ -0,0 +1 @@
{"algorithm": "ed25519", "publicKey": "6Jo+xjitfGvKp28mdXIziIyDfs5UUP4xzFl92+xrAAU=", "signature": "TpyvCl63pcKcO2Nu4uVI3tCLEN7w/SZe/yQWrs82OqY8C/2cP/o/uFWZ6aRJCo0yaoyTa30wQPSExhUJ08swDg=="}
@@ -0,0 +1,157 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/updates/app_updates.dart';
import 'package:pipelines_app/features/updates/app_updates_io.dart' as io;
import 'package:pipelines_app/features/updates/update_feed_signature.dart';
// Written by scripts/update_signing.py publish_feed with a throwaway key;
// scripts/test_update_signing.py checks the same files with OpenSSL.
const fixture = 'test/features/updates/fixtures/signed_feed';
void main() {
final feed = File('$fixture/version.json').readAsBytesSync();
final signature = File('$fixture/version.json.sig').readAsStringSync();
final key = File('$fixture/public_key.txt').readAsStringSync().trim();
final trusted = trustedUpdateKeys(key);
final otherKey = base64.encode(List<int>.generate(32, (i) => i));
test('a feed signed by the Python publisher verifies', () {
expect(trusted, hasLength(1));
expect(feedSignatureProblem(feed, signature, trusted), isNull);
// Trusted among several keys (this server's and another's).
expect(
feedSignatureProblem(
feed,
signature,
trustedUpdateKeys('$otherKey, $key'),
),
isNull,
);
});
test('a tampered feed or signature is refused', () {
final tampered = utf8.encode(utf8.decode(feed).replaceFirst('"ab', '"cd'));
expect(
feedSignatureProblem(tampered, signature, trusted),
contains('does not match'),
);
final document = jsonDecode(signature) as Map;
final bytes = base64.decode(document['signature'] as String)..[5] ^= 1;
final badSignature = jsonEncode({
...document,
'signature': base64.encode(bytes),
});
expect(
feedSignatureProblem(feed, badSignature, trusted),
contains('does not match'),
);
expect(
feedSignatureProblem(feed, '{"algorithm":"rsa"}', trusted),
contains('unreadable'),
);
expect(
feedSignatureProblem(feed, 'not json', trusted),
contains('unreadable'),
);
});
test('a missing signature is refused when the app has keys', () {
expect(feedSignatureProblem(feed, null, trusted), contains('not signed'));
// A development build without embedded keys keeps the old behaviour.
expect(feedSignatureProblem(feed, null, trustedUpdateKeys('')), isNull);
});
test('a signature by a key the app does not trust is refused', () {
expect(
feedSignatureProblem(feed, signature, trustedUpdateKeys(otherKey)),
contains('does not trust'),
);
// Swapping in the attacker's own key in the document does not help.
final document = jsonDecode(signature) as Map;
final swapped = jsonEncode({...document, 'publicKey': otherKey});
expect(
feedSignatureProblem(feed, swapped, trustedUpdateKeys('$key,$otherKey')),
contains('does not match'),
);
expect(trustedUpdateKeys('short, ${base64.encode([1])}'), isEmpty);
});
test('a signed feed must carry the artifact digest and Android signer', () {
final base = Uri.parse('https://mac.test/updates/');
final signer = 'a' * 64;
String android({bool digest = true, bool certificate = true}) =>
jsonEncode({
'versionCode': 9,
'apk': 'pipelines.apk',
if (digest) 'sha256': 'b' * 64,
if (certificate) 'signingCertificateSha256': signer,
});
AppUpdate? parse(String body, {bool signed = true}) =>
AppUpdate.parse(body, base, installedSignature: signer, signed: signed);
expect(parse(android()), isNotNull);
expect(parse(android(certificate: false)), isNull);
expect(parse(android(digest: false)), isNull);
expect(
AppUpdate.parse(android(), base, signed: true),
isNull,
reason: 'the installed signature is required to compare',
);
// Unsigned builds keep accepting legacy feeds; the OS installer checks.
expect(
parse(android(certificate: false, digest: false), signed: false),
isNotNull,
);
final linux = AppUpdate.parse(
utf8.decode(feed),
base,
platform: 'linux',
architecture: 'x64',
signed: true,
);
expect(linux?.sha256, 'ab' * 32);
});
test(
'the feed reader refuses unsigned and tampered feeds over HTTP',
() async {
final previous = HttpOverrides.current;
HttpOverrides.global = null;
final server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
var body = feed;
String? served = signature;
server.listen((request) async {
final path = request.uri.path;
if (path.endsWith('/version.json')) {
request.response.add(body);
} else if (path.endsWith('/version.json.sig') && served != null) {
request.response.write(served);
} else {
request.response.statusCode = 404;
}
await request.response.close();
});
final base = Uri.parse('http://127.0.0.1:${server.port}/updates/');
Future<Object?> read() => io
.fetchLatestScoped(base, (_) => {}, trustedKeys: trusted)
.then<Object?>((update) => update, onError: (Object error) => error);
try {
served = null;
expect('${await read()}', contains('not signed'));
served = signature;
body = utf8.encode(utf8.decode(feed).replaceFirst('"ab', '"cd'));
expect('${await read()}', contains('does not match'));
body = feed;
// A genuine feed passes the signature; the host's platform may then
// still find the fixture's Linux build incompatible.
final result = await read();
expect('$result', isNot(contains('sign')));
expect('$result', isNot(contains('trust')));
} finally {
await server.close(force: true);
HttpOverrides.global = previous;
}
},
);
}