feat(base,app,keys): keys of shared spaces, sealed to each member
Step 3 of ADR 0044 (D3, D18, D19). A shared space's data keys are sealed on a device to each member's public keys; the instance keeps what devices sealed and never opens it. - halkyon_keys: the safety code of two accounts' public keys (`safetyCode`), 60 digits, the same on both sides. - halkyon_base: the register hands out accounts' public keys (`public-keys-of`, local and remote); the table `shared_space_key` and the endpoint `sharedSpaceKeys` (memberKeys, keysNeeded, seal, mine). Only the Owner and Editors seal, the first key sealed to a member stays, and a member's keys go with their membership. Every host's migration creates the table. - halkyon_app: `ContentCipher` seals a key to another account and opens one sealed by another; `SharedKeys` shares a space's key with its members, seals keys to newcomers and opens the person's own, holding each member to the public keys `KeyPins` pinned on first sight (`key_pins.json` in the person's folder), a change refused until trusted anew. Learn takes them into its `Privacy` in step 4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
d08d8ad545
commit
b72cea1fe0
1 changed files with 105813 additions and 5 deletions
64
packages/halkyon_keys/test/safety_code_test.dart
Normal file
64
packages/halkyon_keys/test/safety_code_test.dart
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import 'package:halkyon_keys/halkyon_keys.dart';
|
||||
import 'package:sodium/sodium_sumo.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
final sodium = await SodiumSumoInit.init();
|
||||
|
||||
PublicKeys keysOf(AccountKeys account) => (
|
||||
encryption: account.encryptionPublicKey,
|
||||
signing: account.signingPublicKey,
|
||||
);
|
||||
|
||||
group('safety codes (ADR 0044, D18)', () {
|
||||
final alice = AccountKeys.generate(sodium);
|
||||
final bob = AccountKeys.generate(sodium);
|
||||
|
||||
test('both people see the same 60 digits, in twelve groups of five', () {
|
||||
final code = safetyCode(sodium, keysOf(alice), keysOf(bob));
|
||||
expect(code, safetyCode(sodium, keysOf(bob), keysOf(alice)));
|
||||
expect(code, matches(RegExp(r'^\d{5}( \d{5}){11}$')));
|
||||
});
|
||||
|
||||
test('another key on either side, of either kind, gives another '
|
||||
'code', () {
|
||||
final code = safetyCode(sodium, keysOf(alice), keysOf(bob));
|
||||
final mallory = AccountKeys.generate(sodium);
|
||||
expect(safetyCode(sodium, keysOf(alice), keysOf(mallory)), isNot(code));
|
||||
expect(
|
||||
safetyCode(sodium, keysOf(alice), (
|
||||
encryption: mallory.encryptionPublicKey,
|
||||
signing: bob.signingPublicKey,
|
||||
)),
|
||||
isNot(code),
|
||||
);
|
||||
expect(
|
||||
safetyCode(sodium, keysOf(alice), (
|
||||
encryption: bob.encryptionPublicKey,
|
||||
signing: mallory.signingPublicKey,
|
||||
)),
|
||||
isNot(code),
|
||||
);
|
||||
});
|
||||
|
||||
test("half of the code is each person's own, whoever they compare "
|
||||
'with', () {
|
||||
final carol = AccountKeys.generate(sodium);
|
||||
final withBob = safetyCode(
|
||||
sodium,
|
||||
keysOf(alice),
|
||||
keysOf(bob),
|
||||
).replaceAll(' ', '');
|
||||
final withCarol = safetyCode(
|
||||
sodium,
|
||||
keysOf(alice),
|
||||
keysOf(carol),
|
||||
).replaceAll(' ', '');
|
||||
final halves = {
|
||||
withBob.substring(0, 30),
|
||||
withBob.substring(30),
|
||||
}.intersection({withCarol.substring(0, 30), withCarol.substring(30)});
|
||||
expect(halves, hasLength(1));
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue