9f38e38f6a
Each installation generates a private Ed25519 key once (0600, under ~/.config/pipelines), signs version.json with a detached version.json.sig when publishing APK and desktop builds, and embeds its own and listed trusted public keys in app builds. The app verifies the feed signature before trusting the artifact sha256, refuses unsigned or foreign feeds when it has keys, and requires the sha256 and Android signer in signed feeds.
103 lines
3.1 KiB
Dart
103 lines
3.1 KiB
Dart
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,
|
|
);
|
|
});
|
|
}
|