feat: add Gemini and Spartan protocol support

This commit is contained in:
randogoth 2026-10-11 22:07:25 +03:00
parent a4a49f41d7
commit fa7aa5557c
48 changed files with 4992 additions and 161 deletions

43
app/test/tofu_test.dart Normal file
View file

@ -0,0 +1,43 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mews/protocols/tofu.dart';
void main() {
test('a first visit accepts and pins what was presented', () {
final now = DateTime(2026, 10, 11);
expect(decideTofu(null, 'aa', now), TofuDecision.firstUse);
});
test('the pinned certificate is accepted again', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: DateTime(2030));
expect(decideTofu(pin, 'aa', now), TofuDecision.match);
});
test('a change is a renewal when the pin has expired', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: DateTime(2020));
expect(decideTofu(pin, 'bb', now), TofuDecision.rePin);
});
test('a change is refused while the pin is still valid', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: DateTime(2030));
expect(decideTofu(pin, 'bb', now), TofuDecision.refuse);
});
test('a pin that ends exactly now counts as expired', () {
final now = DateTime(2026, 10, 11);
final pin = TofuPin(fingerprint: 'aa', expires: now);
expect(decideTofu(pin, 'bb', now), TofuDecision.rePin);
});
test('a fingerprint comes from the DER encoding', () {
final pin = pinOf([1, 2, 3], expires: DateTime(2030));
// sha256 of the three bytes, as lowercase hex.
expect(
pin.fingerprint,
'039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81',
);
});
}