melos 0.1.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -10
  3. data/docs/roadmap.md +302 -0
  4. data/docs/validation.md +22 -18
  5. data/lib/melos/capabilities.rb +5 -2
  6. data/lib/melos/client.rb +184 -14
  7. data/lib/melos/credential/x509.rb +91 -0
  8. data/lib/melos/crypto.rb +25 -0
  9. data/lib/melos/epoch_secrets.rb +61 -8
  10. data/lib/melos/errors.rb +18 -0
  11. data/lib/melos/external_sender.rb +78 -0
  12. data/lib/melos/group/validation.rb +123 -50
  13. data/lib/melos/group.rb +597 -104
  14. data/lib/melos/key_package_bundle.rb +8 -0
  15. data/lib/melos/persistence.rb +45 -0
  16. data/lib/melos/private_tree.rb +23 -4
  17. data/lib/melos/ratchet_tree.rb +6 -6
  18. data/lib/melos/secret_tree.rb +87 -28
  19. data/lib/melos/struct/structs.rb +45 -2
  20. data/lib/melos/vec.rb +6 -6
  21. data/lib/melos/version.rb +1 -1
  22. data/lib/melos.rb +4 -0
  23. metadata +6 -17
  24. data/test_vectors/crypto-basics.json +0 -303
  25. data/test_vectors/deserialization.json +0 -58
  26. data/test_vectors/key-schedule.json +0 -926
  27. data/test_vectors/message-protection.json +0 -142
  28. data/test_vectors/messages.json +0 -5702
  29. data/test_vectors/passive-client-handling-commit.json +0 -2683
  30. data/test_vectors/passive-client-random.json +0 -2657
  31. data/test_vectors/passive-client-welcome.json +0 -814
  32. data/test_vectors/psk_secret.json +0 -2382
  33. data/test_vectors/secret-tree.json +0 -4846
  34. data/test_vectors/transcript-hashes.json +0 -58
  35. data/test_vectors/tree-math.json +0 -8276
  36. data/test_vectors/tree-operations.json +0 -47
  37. data/test_vectors/tree-validation.json +0 -11839
  38. data/test_vectors/treekem.json +0 -14877
  39. data/test_vectors/welcome.json +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f79041ce8bf4db3f70e527f732c1581533617e3d80f16bf9098bb7629dcdeb4a
4
- data.tar.gz: 641494ab2a7829bbdfbe61cd90d401a8d3848d2a4beb67c35e12fb49ac00902e
3
+ metadata.gz: be015b7f9296463b69d9c5026c935ce90e870f528b4c04a1ab0b7f21e1836ebe
4
+ data.tar.gz: b2f0d94ebad996af6f23aa166caf145d7ae9ddc61cbd1e94e6c59ad9938780c3
5
5
  SHA512:
6
- metadata.gz: c230d9ef5487be5be256ac46378921f716b3c5bcaf2b01752c5db74a63f450943497884c39a3688226daf8a2b5c1d323ea24c5326bce928b27f29fe61bd8ea54
7
- data.tar.gz: b4afcee3755000a00319251b7d4755b85e61378c6ea43296230a43e5ec6c4fd552188efe03e4cda5ac42d0fe5729ff647542a82c45e8b692342f67f68167f290
6
+ metadata.gz: 796f95da60f41517aea2ebbacacecf435f1ee74c1a60a2d0237aa35319683cac6ebdcf178cdb99c834b99801a2b56dbd536798562984ce28be122cac554a440f
7
+ data.tar.gz: cc550a93879a9c8c27a6d0dae56a92b6d665cc4fc69528f27a16df32ede7a3e6e6f67671c6936e343ca055c911436120b34518c741218e0733851acbb2f58efc
data/README.md CHANGED
@@ -17,20 +17,20 @@ As of version 0.1.0, this implements:
17
17
  - Groups: creating a group, Add / Remove / PreSharedKey / GroupContextExtensions proposals,
18
18
  commits with an UpdatePath and the matching Welcome, joining via Welcome,
19
19
  application messages as PrivateMessage, handshake messages as PublicMessage or PrivateMessage
20
- - Processing Update proposals and commits from other members
20
+ - Update proposals, commits without an UpdatePath where the RFC allows them, exporters
21
+ - The deletion schedule of Section 9.2 (as far as Ruby allows: references are dropped, strings are not zeroized)
22
+ - External senders and new-member proposals (`Melos::ExternalSender`, `Client#create_new_member_proposal`)
23
+ - Resumption PSKs, ReInit (`Group#create_reinit_proposal`, `Client#reinit_group`) and subgroup branching (`Client#branch_group`)
24
+ - External commits, including resync (`Group#group_info`, `Client#join_by_external_commit`)
25
+ - X.509 credentials (`Melos::Credential::X509`, a `credential_validator:` over an `OpenSSL::X509::Store`)
26
+ - Saving and restoring client and group state (`to_h` / `from_h`, JSON through `Melos::Persistence`)
27
+ - Out-of-order application messages and messages from recent epochs, with bounds on both (Section 15.3)
21
28
  - Most MUST-level validations of the RFC; [docs/validation.md](docs/validation.md) maps each one to the code
22
29
  - All test vectors in [mls-implementations/test-vectors.md](https://github.com/mlswg/mls-implementations/blob/main/test-vectors.md),
23
30
  plus round-trip tests in which several members create, join, message and leave a group
24
31
 
25
- It does not yet implement:
26
-
27
- - Creating Update proposals
28
- - ReInit, external commits (ExternalInit), external senders, resumption PSKs, subgroup branching
29
- - Decrypting application messages from earlier epochs, and keeping unused keys for out-of-order delivery
30
- - The deletion schedule of Section 9.2 beyond dropping the previous epoch
31
- - Credential validation beyond basic credentials (an application hook, `credential_validator:`, is provided)
32
- - Persistence of client and group state
33
- - Interop testing against other implementations
32
+ Interop with OpenMLS and MLS++ is tested through the mls-implementations harness; see
33
+ [interop/README.md](interop/README.md) for how to run it and the results.
34
34
 
35
35
  ## Usage
36
36
 
@@ -66,6 +66,14 @@ group.process_message(message).content.application_data # => "hello"
66
66
  `Melos::Group` holds one member's view of one group. `Melos::Client` holds the long-lived identity,
67
67
  the external PSKs and the KeyPackages it has published.
68
68
 
69
+ State can be saved and restored, which a client must do to avoid reusing nonces after a restart
70
+ (RFC 9420 6.3.1). The state holds private keys; encrypting it at rest is up to the application.
71
+
72
+ ```ruby
73
+ json = Melos::Persistence.dump_client(alice) # or alice.to_h, for Marshal or MessagePack
74
+ alice = Melos::Persistence.load_client(json) # pass credential_validator: etc. again here
75
+ ```
76
+
69
77
  ## Tests
70
78
 
71
79
  ```
data/docs/roadmap.md ADDED
@@ -0,0 +1,302 @@
1
+ # Roadmap: the missing features, smallest first
2
+
3
+ What melos does not implement yet, as of 0.1.0, ordered by implementation effort. Each item says
4
+ what the RFC asks for, what the code already has, what to build, and how to test it. Effort is
5
+ S (hours), M (a day or two), L (a week or more). Items are independent unless noted.
6
+
7
+ The list comes from the "not yet" section of the README, the deferred rows of
8
+ [validation.md](validation.md), and the `TODO` comments in `lib/`.
9
+
10
+ ## 1. Exporters (S) — RFC 8.5 — done in 7c57cac
11
+
12
+ **RFC.** `MLS-Exporter(Label, Context, Length) = ExpandWithLabel(DeriveSecret(exporter_secret, Label), "exported", Hash(Context), Length)`.
13
+
14
+ **Have.** `EpochSecrets#exporter_secret`, `Crypto.expand_with_label`, `Crypto.derive_secret`.
15
+
16
+ **Build.** `EpochSecrets#export(label, context, length)` and `Group#export_secret(label, context, length)`
17
+ delegating to the current epoch. Also expose `Group#epoch_authenticator` (exists) and the
18
+ `resumption_psk` of past epochs is already kept.
19
+
20
+ **Test.** There is no exporter vector in mls-implementations; test determinism between two members in
21
+ the round-trip test, and against a hand computation in `test_key_schedule.rb`.
22
+
23
+ ## 2. An error class hierarchy (S) — done in 43a039d
24
+
25
+ **Have.** Every rejection raises `ArgumentError` with a message. Callers cannot tell a malformed
26
+ message from a wrong argument, or a commit that removed them from a tampered one.
27
+
28
+ **Build.** `Melos::Error < StandardError`, with `Melos::ProtocolError` (malformed or invalid input: the
29
+ validation failures), `Melos::StateError` (wrong group state: inactive group, pending proposals,
30
+ unknown epoch) and `Melos::UnsupportedError` (features below). Replace the `raise ArgumentError` sites
31
+ in `group.rb`, `group/validation.rb`, `ratchet_tree.rb`, `secret_tree.rb`, `vec.rb` and `structs.rb`.
32
+ Keep `ArgumentError` for genuine caller mistakes. `test_validation.rb` then asserts the specific class.
33
+
34
+ Do this before 3 to 12, since all of them add error sites.
35
+
36
+ ## 3. Partial commits: omit the UpdatePath when allowed (S) — RFC 12.4 — done in e9a27c9
37
+
38
+ **RFC.** The path MAY be omitted when the commit covers at least one proposal and none of them is of a
39
+ path-required type (Update, Remove, ExternalInit, GroupContextExtensions). The commit secret is then
40
+ all zeros.
41
+
42
+ **Have.** `Group#stage` already handles `commit.path == nil` (zero commit secret, no decryption) and
43
+ enforces the path-required rule. `create_commit` always builds a path (`TODO` at group.rb:351).
44
+
45
+ **Build.** A `path:` option on `create_commit`: `:always` (default, keeps PCS for the committer),
46
+ `:if_required`. When omitted, no `create_update_path`, no private tree change, no `path_secret` in the
47
+ Welcome (`GroupSecrets.path_secret` nil, which `from_welcome` already accepts).
48
+
49
+ **Test.** Round trip: Alice adds Bob with `path: :if_required`; Bob joins without a path secret and
50
+ can decrypt Alice's next commit; a Remove with `path: :if_required` still produces a path.
51
+
52
+ ## 4. Update proposals (S/M) — RFC 12.1.2, 7.3 — done
53
+
54
+ **RFC.** A member replaces its own leaf with a fresh encryption key (`leaf_node_source = update`,
55
+ signed with group id and leaf index). When a commit applies the Update, the member's leaf private
56
+ key becomes the new one. The committer must not commit its own Update.
57
+
58
+ **Have.** Receiving side is complete: `apply_proposals` validates the leaf (context `:update`) and
59
+ replaces it. `KeyPackageBundle.generate` shows how a signed leaf is built.
60
+
61
+ **Build.** `Group#create_update_proposal(capabilities: nil, extensions: nil)`: new encryption key pair,
62
+ `LeafNode.create(leaf_node_source: UPDATE, ...)` from the current leaf, `sign(suite, key, group_id,
63
+ leaf_index)`, send via `create_proposal`. Remember the private key in a `@pending_updates` map keyed
64
+ by the new encryption key. In `merge_commit`, if our leaf now carries one of those keys, set
65
+ `private_tree[leaf_index * 2]` to it and drop the rest. `create_commit` already refuses our own
66
+ Update in the list (12.2), so a member with a pending Update must wait for someone else's commit, or
67
+ commit without it (its path replaces the leaf anyway).
68
+
69
+ **Test.** Bob proposes an Update, Alice commits it, both agree; Bob's private tree is consistent
70
+ and he can still decrypt the next commit. Two pending Updates from Bob: the committer applies one.
71
+
72
+ ## 5. Deletion schedule (M) — RFC 9.2, 7.5 — done
73
+
74
+ **RFC.** Consumed secrets MUST be deleted immediately: `commit_secret`, `joiner_secret`,
75
+ `epoch_secret`, `encryption_secret` of the epoch and `init_secret` of the previous one, the secret
76
+ tree node secrets on the path to a used leaf, used ratchet secrets, and the path and node secrets
77
+ used to derive updated nodes. Unconsumed values MAY be kept for a bounded time.
78
+
79
+ **Have.** `merge_commit` drops the previous `EpochSecrets` and the staged commit. `SecretTree::Ratchet`
80
+ forgets each ratchet secret as it steps. But `EpochSecrets` memoizes every derived secret for the
81
+ epoch's life, keeps `joiner_secret` and `psk_secret`, and `PrivateTree` keeps private keys for nodes
82
+ that no longer exist or were replaced (the stale-key case the treekem test notes).
83
+
84
+ **Build.** `EpochSecrets#consume!` dropping `epoch_secret`, `joiner_secret`, `init_secret` and
85
+ `encryption_secret` once the secret tree exists and the Welcome is built; `PrivateTree#prune!(tree)`
86
+ removing keys whose node is blank or has a different public key, called from `merge_commit`;
87
+ `StagedCommit` cleared of `path_secrets` once the Welcome exists. Ruby strings cannot be reliably
88
+ zeroized, so this is about not retaining references; say so in the docs.
89
+
90
+ **Test.** After a commit, the previous epoch's secrets are gone from the group; `private_tree`
91
+ holds exactly the keys for nodes on our direct path that exist.
92
+
93
+ ## 6. Out-of-order and old-epoch application messages (M) — RFC 9.1, 15.3, 12.4.2 — done
94
+
95
+ **RFC.** Receivers keep unused generation keys of a sender's ratchet for a while, and the secret
96
+ trees of recent epochs, so delayed and reordered messages decrypt. Applications SHOULD bound how
97
+ far a ratchet may be advanced by one message and how many unused keys are kept.
98
+
99
+ **Have.** `SecretTree::Ratchet#ratchet_until` refuses any generation older than the last derived
100
+ (`TODO` at secret_tree.rb:32); `Group#unprotect` rejects any epoch but the current one
101
+ (`TODO` at group.rb:219).
102
+
103
+ **Build.** In `Ratchet`, a `Hash` of unconsumed `generation => [key, nonce]` with a maximum size and a
104
+ maximum forward jump, both options; `ratchet_until` serves from it and deletes on use. In `Group`,
105
+ keep `EpochSecrets` of the last N epochs (option, default a small number) in `@past_epochs`, and let
106
+ `unprotect` select by `PrivateMessage.epoch` for application messages only. Handshake messages stay
107
+ current-epoch only. Interacts with 5: a retained epoch's secrets are not yet "consumed".
108
+
109
+ **Test.** Deliver two application messages in reverse order; deliver an application message from the
110
+ previous epoch after a commit; a generation jump beyond the bound is rejected.
111
+
112
+ **Done as.** `SecretTree::Ratchet` keeps skipped `generation => [key, nonce]`, bounded by
113
+ `out_of_order_tolerance:` (default 100, oldest dropped) and `max_forward_distance:` (default 1000,
114
+ `ProtocolError` beyond). `Group` keeps `PastEpoch` (secret tree and sender data secret only, plus the
115
+ GroupContext and tree for the signature check) for `max_past_epochs:` epochs (default 2). The
116
+ options go to `Group.create` / `.from_welcome` (and so `Client#create_group` / `#join_group`).
117
+ AEAD failures now raise `ProtocolError`.
118
+
119
+ ## 7. External senders and external proposals (M) — RFC 12.1.8, 12.1.8.1, 6.1 — done
120
+
121
+ **RFC.** With an `external_senders` GroupContext extension, listed signers may send Add, Remove,
122
+ PreSharedKey, ReInit and GroupContextExtensions proposals as PublicMessages with
123
+ `sender_type = external` and `sender_index` into the extension. A joiner may also send its own Add as
124
+ `new_member_proposal`, signed with the KeyPackage's key. Other proposal types from these senders
125
+ MUST be rejected.
126
+
127
+ **Have.** `Struct::ExternalSender` and `Struct::Sender.create_external` parse and build. `Group#unprotect`
128
+ rejects non-member senders (`TODO` at group.rb:488), `resolve_proposals` rejects proposals by
129
+ reference from non-members.
130
+
131
+ **Build.** Decode the extension in `Group` (like `required_capabilities`); `sender_signature_key` for
132
+ `external` (by index) and `new_member_proposal` (the KeyPackage inside the Add); the content-type
133
+ and proposal-type restrictions of 6.1 and 12.1.8; PublicMessage only; `resolve_proposals` passes
134
+ `nil` as the sender leaf of such proposals, and `apply_proposals` must not treat an external Remove
135
+ as touching the sender. An `ExternalSender` API for the sending side (sign a proposal with no
136
+ group membership) is a small separate class.
137
+
138
+ **Test.** An external signer removes Bob; a non-member sends its own Add; an external Update is
139
+ rejected.
140
+
141
+ **Done as.** `Struct::ExternalSenders` (the extension data, with `.extension(list)`), `Group#external_senders`,
142
+ `#validate_non_member_content!` and `#sender_signature_key` for `external` and `new_member_proposal`;
143
+ `resolve_proposals` gives such proposals a `nil` sender. `Melos::ExternalSender` signs proposals with
144
+ no group state (`create_add_proposal`, `create_remove_proposal`, `create_psk_proposal`,
145
+ `create_group_context_extensions_proposal`); `Client#create_new_member_proposal` sends a client's own
146
+ Add. Authorization (12.1.8) is the `external_proposal_validator:` group option, accepting by default.
147
+ Tests in `test/test_external_senders.rb`.
148
+
149
+ ## 8. Persistence of client and group state (M) — done
150
+
151
+ **RFC.** None, but 6.3.1 requires persistent ratchet state to avoid nonce reuse, so a client that
152
+ restarts without it is unsafe.
153
+
154
+ **Have.** All state lives in instance variables of `Client`, `Group`, `EpochSecrets`, `SecretTree`,
155
+ `PrivateTree`, `RatchetTree`; the public tree already round-trips through `raw`.
156
+
157
+ **Build.** `Group#to_h` / `Group.from_h` (and the same for `Client`) producing plain Hashes of binary
158
+ strings and integers, including the secret tree ratchet positions, pending proposals (as
159
+ `AuthenticatedContent.raw`), pending updates (4) and retained epochs (6). Serialization format is the
160
+ application's choice (Marshal, JSON with hex, MessagePack); provide the Hash and one JSON helper.
161
+ Encryption at rest is out of scope and should be stated.
162
+
163
+ **Test.** Save and restore both members between every step of the round-trip test; messages
164
+ encrypted before and after a restore decrypt.
165
+
166
+ **Done as.** `Group#to_h(include_external_psks:)` / `Group.from_h(hash, external_psks:, **hooks)` and
167
+ `Client#to_h` / `Client.from_h(hash, **hooks)`, built on `to_h` / `from_h` of `EpochSecrets`,
168
+ `SecretTree` and its `Ratchet`s, `KeyPackageBundle`, and `PrivateTree#to_a`. The Hashes have Symbol
169
+ keys and binary String values, plus a `format:` version. Data maps are arrays of pairs, so keys keep
170
+ their types. `Melos::Persistence` gives JSON with hex strings (`dump_client`, `load_client`,
171
+ `dump_group`, `load_group`); Marshal works on the Hash as it is. The procs (`credential_validator:`,
172
+ `external_proposal_validator:`) are passed again on load. A `StagedCommit` is not part of the state:
173
+ merge or discard it before saving. Tests in `test/test_persistence.rb`.
174
+
175
+ ## 9. X.509 credentials (M, application-dependent) — RFC 5.3, 5.3.1, 13.3 — done
176
+
177
+ **RFC.** The AS validates credentials; for X.509 the end-entity certificate's public key MUST equal the
178
+ leaf's `signature_key`, and the chain is verified by the application's policy.
179
+
180
+ **Have.** `Struct::Credential` parses `certificates`; the default `credential_validator` accepts basic
181
+ credentials only.
182
+
183
+ **Build.** `Melos::Credential::X509` helper: parse `cert_data` with `OpenSSL::X509::Certificate`, check
184
+ the key matches `signature_key`, verify the chain against a caller-supplied store, check validity
185
+ dates; offered as an alternative validator the application opts into. Capabilities default gains
186
+ credential type 2 only when the validator is installed.
187
+
188
+ **Test.** A self-signed chain generated in the test; a certificate whose key differs from the leaf's
189
+ is rejected.
190
+
191
+ **Done as.** `Melos::Credential::X509.new(store:, time:, identity_check:, accept_basic:)` is a callable
192
+ for `credential_validator:`: end-entity key equals the holder's `signature_key`, the chain verifies with
193
+ `OpenSSL::X509::StoreContext` (validity dates included, at `time:` or now), the application's
194
+ `identity_check:` for reference identifiers and successor policy (5.3.1); `#last_error` says why a
195
+ check failed. `.create_credential(certificates)` builds the credential. `Client.new` takes
196
+ `credential:`, `signature_private_key:` and `credential_types:` (what its leaves' capabilities list;
197
+ basic plus its own by default, so a basic client must opt in to X.509 to join a group using it,
198
+ 13.3). Also, 5.3.1: the credentials of an `external_senders` extension now go through the validator
199
+ when the extension is set, on creation, join and external join. Tests in `test/test_x509.rb`.
200
+
201
+ ## 10. Resumption PSKs, ReInit and subgroup branching (M/L) — RFC 8.4, 11.2, 11.3, 12.1.5, 12.4.3.1 — done
202
+
203
+ **RFC.** ReInit: a proposal (alone in its commit) ends the group; the committer creates a new group
204
+ with the proposed version, suite, id and extensions, and welcomes everyone with a resumption PSK of
205
+ usage `reinit` for the old group's last epoch; joiners verify the new group's parameters against the
206
+ proposal and that membership is preserved. Branching: a member creates a subgroup of existing
207
+ members with a resumption PSK of usage `branch`; joiners verify suite, version, epoch 1 and that
208
+ every leaf matches one in the old group. Resumption PSKs of these usages are invalid anywhere else.
209
+
210
+ **Have.** `Struct::ReInit` parses; `resumption_psks` by epoch are kept; `psk_secret_for` handles
211
+ resumption PSKs by epoch but ignores `usage` and `psk_group_id` (`TODO` at group.rb:560);
212
+ `from_welcome` rejects resumption PSKs in a Welcome (`TODO` at group.rb:134); `apply_proposals`
213
+ rejects ReInit as unsupported.
214
+
215
+ **Build.** `Client` keeps the resumption PSKs of groups it left or that were reinitialized, keyed by
216
+ group id and epoch. `Group#create_reinit_proposal`, ReInit handling in `stage`/`merge_commit` (the
217
+ group becomes inactive with a `pending_reinit`), `Client#create_reinit_group(old_group)` which creates
218
+ the new group and the Welcome with the PSK, `Client#create_branch(old_group, members)`, and the
219
+ joiner-side checks of 11.2, 11.3 and 12.4.3.1 in `from_welcome`. Needs 3 (the branch commit has
220
+ only Adds and a PSK) and benefits from 2.
221
+
222
+ **Test.** Reinit a three-member group to another cipher suite; branch Alice and Carol out of
223
+ Alice, Bob and Carol; a `reinit` PSK in an ordinary commit is rejected.
224
+
225
+ **Done as.** `PreSharedKeyID.create_resumption`; `Group#create_resumption_psk_proposal` (usage
226
+ application, this group or another the client knows), `#create_reinit_proposal`; a merged ReInit
227
+ sets `pending_reinit` and makes the group inactive. `Client#reinit_group(old_group, key_packages)`
228
+ (on a client of the ReInit's suite) and `Client#branch_group(old_group, key_packages, group_id:)`
229
+ create the new group in epoch 0 and make its first commit, with the Adds and the reinit/branch PSK
230
+ (`Group#create_resumption_commit`, the only place such a PSK is accepted). `Group.from_welcome` takes
231
+ `resumption_psk_lookup:`, `resumed_group_lookup:` and `member_matcher:` (identical credentials by
232
+ default) and runs the 11.2, 11.3 and 12.4.3.1 checks; `Client#join_group` supplies them, with
233
+ `resumed_groups:` for old groups held by a client of another suite. A client archives the resumption
234
+ PSKs of a group it replaces; groups keep `max_resumption_psks:` epochs (default 32, 8.6). Branch
235
+ membership is checked against the old group's current tree. Tests in `test/test_resumption.rb`.
236
+
237
+ ## 11. External commits (L) — RFC 12.4.3.2, 8.3, 12.1.6 — done
238
+
239
+ **RFC.** A member publishes a GroupInfo with an `external_pub` extension; a joiner builds a commit
240
+ with `sender_type = new_member_commit`, an ExternalInit proposal carrying the HPKE `kem_output`,
241
+ optionally a Remove of its old self, and a path from the leaf it takes; members derive the next
242
+ `init_secret` from the external secret, assign the joiner the leftmost blank leaf, and verify the
243
+ signature with the path leaf's key.
244
+
245
+ **Have.** `Struct::ExternalInit`, `Struct::ExternalPub`, `Struct::GroupInfo` parse and build;
246
+ `EpochSecrets#external_secret` is derived; `stage` rejects non-member committers and ExternalInit
247
+ (`TODO` at group.rb:409).
248
+
249
+ **Build.** `Group#group_info(external_pub: true)` deriving the external key pair from
250
+ `external_secret` (8.3); `Client#join_by_external_commit(group_info, ratchet_tree:)` producing the
251
+ commit and a new `Group`; in `stage`, the `new_member_commit` branch: leaf assignment, the external
252
+ init secret via `EpochSecrets#next` with an `init_secret:` override, the 12.2 external list rules,
253
+ signature from the path leaf. `validate_update_path!` must allow the joiner's leaf to be new.
254
+ Needs 2 and 3; shares the leaf-assignment code with Add.
255
+
256
+ **Test.** Carol joins Alice and Bob by external commit; a resync commit replaces an old Carol; an
257
+ external commit with a proposal by reference is rejected.
258
+
259
+ **Done as.** `Group#group_info(external_pub:, include_ratchet_tree:)` (the group now keeps the
260
+ epoch's confirmation tag, also persisted); `Crypto.external_key_pair`, `.external_init_sender`,
261
+ `.external_init_receiver` (8.3, checked against the key-schedule vectors' `external_pub`).
262
+ `Group.join_by_external_commit` builds a view of the epoch whose `EpochSecrets` holds only the
263
+ external init secret, so `stage` advances it like any other; `Client#join_by_external_commit(group_info,
264
+ remove:, psk_ids:)` merges and stores the new group. In `stage`, a `new_member_commit` sender gets the
265
+ 12.4.3.2 checks, the 12.2 external list rules (`#validate_external_proposal_list!`), the leftmost
266
+ blank leaf (after a resync's Remove, which `#validate_resync!` limits to an earlier appearance by
267
+ `member_matcher:`), the external init secret, and `validate_update_path!(new_leaf: true)`. Tests in
268
+ `test/test_external_commits.rb`.
269
+
270
+ ## 12. Interop testing (L) — done
271
+
272
+ **RFC.** None; the mls-implementations repository defines a gRPC interop harness
273
+ (`mls_client.proto`) that drives each implementation through a test runner.
274
+
275
+ **Have.** All test vectors pass, and the round-trip tests only pit melos against itself. The passive
276
+ vectors recorded from interop runs (`interop/passive`, in `test_vectors/interop-passive/`) pass too,
277
+ except 56 whose KeyPackages carry unlisted GREASE extensions, which melos rejects per RFC 10
278
+ (`test/test_passive_client_interop.rb`).
279
+
280
+ **Build.** A `melos-interop` executable implementing the gRPC `MLSClient` service with `grpc` and
281
+ `google-protobuf` gems (development dependencies only): state handles for groups, the
282
+ create/join/propose/commit/protect/unprotect operations mapped to `Client` and `Group`. Run the
283
+ upstream test runner against melos and at least one other implementation (OpenMLS has a ready
284
+ interop client). Expect this to surface issues that vectors cannot, particularly around 3, 6 and
285
+ 7. Depends on nothing but gets more valuable after each item above lands; 7 and 11 are exercised by
286
+ the runner's scripts.
287
+
288
+ **Test.** The runner's own scripts; keep a record of which pass in this file.
289
+
290
+ **Done as.** `interop/melos_interop.rb` (the `MLSClient` service over `Client` and `Group`, all 34 RPCs)
291
+ and `bin/melos-interop`, with `grpc` / `grpc-tools` in the Gemfile's `interop` group and the generated
292
+ code in `interop/proto/`. `interop/build-test-runner.sh` builds the Go runner from a local
293
+ mls-implementations checkout with `interop/test-runner.patch` (two upstream bugs in assigning clients
294
+ to actors); `interop/run.rb` and `interop/summarize.rb` run and report. The record of what passes is
295
+ in [interop/README.md](../interop/README.md): every config but `deep_random` passes against melos
296
+ itself and against OpenMLS (5316/5316 mixed runs); against MLS++ the only failures are its KeyPackages
297
+ with unlisted GREASE extensions, which melos rejects. `test/test_interop_service.rb` covers the service
298
+ in `rake test`. Also from this: `CipherSuite.new` raises `UnsupportedError` for an unknown suite.
299
+
300
+ ## Suggested sequence
301
+
302
+ ~~2 → 1 → 3 → 4 → 5 → 6 → 7 → 8 → 10 → 11 → 9 → 12~~: all done.
data/docs/validation.md CHANGED
@@ -6,8 +6,7 @@ mapped to the code; updated as validation lands (last: tier 5). Status:
6
6
  - **done**: enforced today, with where.
7
7
  - **partial**: enforced in some paths or weaker than the RFC asks.
8
8
  - **missing**: not enforced.
9
- - **n/a**: for features melos does not implement yet (external senders, external commits,
10
- ReInit, branching); the code rejects these inputs with a clear error instead.
9
+ - **n/a**: for features melos does not implement; none remain since external commits landed.
11
10
 
12
11
  Items marked *(application)* are MUSTs the RFC places on the application or the Authentication
13
12
  Service; melos should offer a hook or a documented default, not decide the policy.
@@ -16,16 +15,16 @@ Service; melos should offer a hook or a documented default, not decide the polic
16
15
 
17
16
  | # | Requirement | RFC | Status | Code |
18
17
  |---|---|---|---|---|
19
- | 1.1 | Verify the signature with the key selected by sender_type | 6.1 | partial | `Group#unprotect`, `#sender_signature_key`: member only; external, new_member_proposal, new_member_commit raise "not supported" |
20
- | 1.2 | external sender: content_type MUST be proposal, proposal_type MUST be one allowed for external senders | 6.1, 12.1.8 | n/a | rejected with 1.1 |
21
- | 1.3 | new_member_commit: content_type MUST be commit; new_member_proposal: proposal of type add | 6.1 | n/a | rejected with 1.1 |
18
+ | 1.1 | Verify the signature with the key selected by sender_type | 6.1 | done | `Group#unprotect`, `#sender_signature_key`: member (leaf), external (external_senders entry), new_member_proposal (the Add's KeyPackage leaf), new_member_commit (the path's leaf) |
19
+ | 1.2 | external sender: content_type MUST be proposal, proposal_type MUST be one allowed for external senders | 6.1, 12.1.8 | done | `#validate_non_member_content!` with `EXTERNAL_PROPOSAL_TYPES` |
20
+ | 1.3 | new_member_commit: content_type MUST be commit; new_member_proposal: proposal of type add | 6.1 | done | `#validate_non_member_content!` |
22
21
  | 1.4 | PublicMessage: check membership_tag for member senders | 6.2 | done | `PublicMessage#unprotect` returns nil, `Group#unprotect` raises |
23
22
  | 1.5 | FramedContentAuthData valid: signature and, for commits, confirmation_tag | 6.1, 6.2, 6.3.1 | done | signature in `Group#unprotect`; tag in `Group#stage` |
24
23
  | 1.6 | PrivateMessage padding MUST be all zero bytes; reject otherwise | 6.3.1 | done | `PrivateMessage#unprotect` via `PrivateMessageContent#padding_zero?` |
25
24
  | 1.7 | SenderData.leaf_index MUST identify a non-blank leaf | 6.3.2 | partial | caught later by `#sender_signature_key` ("sender leaf is blank") after decryption; the RFC wants it checked when the sender data is parsed |
26
25
  | 1.8 | Application data MUST be sent as PrivateMessage | 6 | done | `AuthenticatedContent#sign` raises on send; `#verify` returns false on receive |
27
26
  | 1.9 | Proposal and Commit epoch MUST equal the current epoch | 12.1, 12.4.2 | done | `Group#unprotect` |
28
- | 1.10 | Application messages from earlier epochs may be decrypted (15.3); not a MUST, but today `Group#unprotect` rejects any epoch other than the current one, which is stricter than the RFC | 15.3 | behavior gap | needs per-epoch secret trees kept for a while (also 9.2) |
27
+ | 1.10 | Application messages from earlier epochs and out of order may be decrypted, within application-chosen bounds (9.1, 15.3); handshake messages stay current-epoch only | 9.1, 15.3 | done | `Group#unprotect` selects a `PastEpoch` (`max_past_epochs:`) for application PrivateMessages; `SecretTree::Ratchet` keeps skipped keys (`out_of_order_tolerance:`) and refuses jumps over `max_forward_distance:` |
29
28
  | 1.11 | MLSMessage.version MUST be mls10 | 6 | done | `Group.check_message_version!` in `#unprotect`, `.from_welcome`, `#create_add_proposal` |
30
29
  | 1.12 | AAD plus ciphertext MUST fit the AEAD limits | 6.3.1, 15.2 | missing *(application)* | no size accounting anywhere |
31
30
 
@@ -35,13 +34,13 @@ Service; melos should offer a hook or a documented default, not decide the polic
35
34
  |---|---|---|---|---|
36
35
  | 2.1 | Verify signature and epoch before caching | 12.1 | done | `Group#unprotect`, `#process_proposal` |
37
36
  | 2.2 | Add: KeyPackage valid per 10.1 (see section 4) | 12.1.1 | done | `#apply_proposals` -> `#validate_key_package!` |
38
- | 2.3 | Update: LeafNode valid for an Update per 7.3, source `update`, encryption_key differs from the replaced leaf | 12.1.2, 7.3 | done | `#apply_proposals` -> `#validate_leaf_node!(context: :update)`; creating Update proposals is still unimplemented |
37
+ | 2.3 | Update: LeafNode valid for an Update per 7.3, source `update`, encryption_key differs from the replaced leaf | 12.1.2, 7.3 | done | `#apply_proposals` -> `#validate_leaf_node!(context: :update)`; sent by `#create_update_proposal` |
39
38
  | 2.4 | Remove: `removed` MUST be a non-blank leaf | 12.1.3 | done | `#apply_proposals` (both sides), `#create_remove_proposal` |
40
39
  | 2.5 | PreSharedKey: psk_nonce length MUST be KDF.Nh | 12.1.4 | done | `#psk_secret_for` |
41
- | 2.6 | PreSharedKey: resumption with usage reinit or branch is invalid outside those operations | 12.1.4, 11.2, 11.3 | **missing** | `#psk_secret_for` looks up any resumption PSK by epoch regardless of usage |
42
- | 2.7 | ReInit: version MUST NOT be lower than the current one | 12.1.5 | n/a | ReInit rejected as unsupported |
40
+ | 2.6 | PreSharedKey: resumption with usage reinit or branch is invalid outside those operations | 12.1.4, 11.2, 11.3 | done | `#psk_secret_for` accepts them only in the initial commit of a resumed group (`#create_resumption_commit`), which no other member processes |
41
+ | 2.7 | ReInit: version MUST NOT be lower than the current one | 12.1.5 | done | `#validate_proposal_list!` |
43
42
  | 2.8 | GroupContextExtensions: invalid if required_capabilities not supported by all members after the commit | 12.1.7, 11.1 | done | `#validate_members!` after the list is applied |
44
- | 2.9 | External proposals MUST be PublicMessage; only add, remove, psk, reinit, gce from external senders; external_senders extension must be present | 12.1.8 | n/a | rejected with 1.1 |
43
+ | 2.9 | External proposals MUST be PublicMessage; only add, remove, psk, reinit, gce from external senders; external_senders extension must be present; unauthorized external proposals are invalid | 12.1.8 | done | `#validate_non_member_content!`, `#sender_signature_key`; authorization is the `external_proposal_validator:` hook *(application)*, accepting by default |
45
44
  | 2.10 | Unknown (non-default) proposal types MUST be supported by every member that processes the commit | 12.2, 13.2 | done | `#apply_proposals` rejects any type outside `KNOWN_PROPOSAL_TYPES` |
46
45
 
47
46
  ## 3. Proposal list validation (Section 12.2), on both creating and processing a Commit
@@ -58,11 +57,11 @@ Service; melos should offer a hook or a documented default, not decide the polic
58
57
  | 3.6 | No Add of a client already in the group unless a Remove in the same list removes it | 12.2 | done (same signature key) |
59
58
  | 3.7 | No two PreSharedKey proposals with the same PreSharedKeyID | 12.2 | done |
60
59
  | 3.8 | At most one GroupContextExtensions proposal | 12.2 | done |
61
- | 3.9 | ReInit MUST be alone in the list | 12.2 | n/a (ReInit rejected) |
62
- | 3.10 | No ExternalInit in a regular commit | 12.2 | done by accident (`#apply_proposals` raises "unsupported") |
60
+ | 3.9 | ReInit MUST be alone in the list | 12.2 | done (`#create_commit` also leaves a pending ReInit out when other proposals are at hand, as 12.2 suggests) |
61
+ | 3.10 | No ExternalInit in a regular commit | 12.2 | done (`#apply_proposals` unless `external:`) |
63
62
  | 3.11 | After applying, every leaf in the tree is valid per 7.3 | 12.2 | done: capabilities and key uniqueness of every remaining leaf (`#validate_members!`); signatures were verified when each leaf entered |
64
63
  | 3.12 | Reject the Commit if the list is invalid | 12.2 | follows from the above |
65
- | 3.13 | External commit list rules (exactly one ExternalInit, at most one Remove, PSKs only) | 12.2 | n/a |
64
+ | 3.13 | External commit list rules (exactly one ExternalInit, at most one Remove, PSKs only; a Remove only of an earlier appearance of the joiner) | 12.2 | done (`#validate_external_proposal_list!`, `#validate_resync!` with the `member_matcher:` hook *(application)*); also 12.4.3.2: a path, no references, signed by the path leaf, PublicMessage |
66
65
 
67
66
  ## 4. KeyPackage validation (Sections 10, 10.1), when adding and when processing an Add
68
67
 
@@ -81,9 +80,14 @@ Service; melos should offer a hook or a documented default, not decide the polic
81
80
 
82
81
  ## 5. LeafNode validation (Section 7.3), for Add, Update, the Commit path leaf, and every leaf when joining
83
82
 
83
+ Not checked on purpose: that a leaf's `capabilities.cipher_suites` lists the group's cipher suite. 7.3
84
+ asks only that a leaf be "compatible with the group's parameters", and other implementations leave the
85
+ suite out (every suite-7 vector in mls-implementations' `interop/passive` does). An added KeyPackage's
86
+ own `cipher_suite` must still match the group's (4.1).
87
+
84
88
  | # | Requirement | RFC | Status | Code |
85
89
  |---|---|---|---|---|
86
- | 5.1 | Credential valid per 5.3.1 (Authentication Service) | 7.3, 5.3.1 | done (hook) | `credential_validator:` option; default accepts basic credentials only |
90
+ | 5.1 | Credential valid per 5.3.1 (Authentication Service), for leaves and external senders | 7.3, 5.3.1, 12.1.8.1 | done (hook) | `credential_validator:` option; default accepts basic credentials only; `Melos::Credential::X509` checks X.509 chains and the key match of 5.3; `#validate_external_senders!` |
87
91
  | 5.2 | Signature valid with signature_key (with group_id and leaf_index for update/commit sources) | 7.3 | done | `#validate_leaf_node!` |
88
92
  | 5.3 | If GroupContext has required_capabilities, its extensions, proposals and credential types MUST be in the leaf's capabilities | 7.3, 11.1, 13.4 | done | `#validate_capabilities!` |
89
93
  | 5.4 | Credential type supported by all members; leaf supports every credential type in use | 7.3, 13.3 | done | `#validate_leaf_node!`, `#validate_members!` |
@@ -109,10 +113,10 @@ Service; melos should offer a hook or a documented default, not decide the polic
109
113
  | 6.9 | Each UpdatePathNode's encrypted_path_secret length MUST equal the copath resolution excluding new leaves | 7.6 | done | `#validate_update_path!` checks every node |
110
114
  | 6.10 | Confirmation tag verifies against the new epoch | 12.4.2 | done | `Group#stage` |
111
115
  | 6.11 | A Commit that removes us: no further sending, delete state (SHOULD) | 12.4.2 | done | `#stage` returns `removes_us`, `#merge_commit` makes the group inactive; last epoch's secrets are kept for late messages |
112
- | 6.12 | After a ReInit commit the group MUST NOT be used; wait for the Welcome | 12.4.2 | n/a | ReInit rejected |
116
+ | 6.12 | After a ReInit commit the group MUST NOT be used; wait for the Welcome | 12.4.2 | done | `#merge_commit` makes the group inactive with `pending_reinit`; `Client#reinit_group` creates the successor |
113
117
  | 6.13 | A member that observed proposals MUST commit before sending application data | 12.4 | done | `#create_application_message` |
114
118
  | 6.14 | Generating a Commit MUST NOT modify state; Welcome MUST NOT be delivered until the Commit is accepted | 14 | done / *(application)* | `#create_commit` returns a `StagedCommit`; delivery is the caller's |
115
- | 6.15 | After processing a path, outdated key material MUST be deleted | 7.5, 9.2 | partial | old epochs are dropped on merge; the `PrivateTree` keeps stale keys for replaced nodes, and `EpochSecrets` memoizes derived secrets for the epoch's lifetime |
119
+ | 6.15 | After processing a path, outdated key material MUST be deleted | 7.5, 9.2 | done | `EpochSecrets#discard_consumed!`, `PrivateTree#prune!` in `#merge_commit`; retained past epochs keep only their secret tree and sender data secret. Ruby cannot zeroize strings |
116
120
 
117
121
  ## 7. Joining via Welcome (Sections 12.4.3, 12.4.3.1, 12.4.3.3, 13.4)
118
122
 
@@ -120,7 +124,7 @@ Service; melos should offer a hook or a documented default, not decide the polic
120
124
  |---|---|---|---|---|
121
125
  | 7.1 | Find the entry for one of our KeyPackages; error if none or if cipher suites differ | 12.4.3.1 | done | `Client#join_group` finds the entry; `Group.from_welcome` compares the KeyPackage's cipher_suite with the Welcome's |
122
126
  | 7.2 | Error if a PSK in GroupSecrets is unknown | 12.4.3.1 | done | `Group.from_welcome` |
123
- | 7.3 | A resumption PSK with usage reinit or branch MUST be the only such PSK; GroupInfo epoch MUST be 1; reinit/branch consistency checks | 12.4.3.1, 11.2, 11.3 | n/a | resumption PSKs in a Welcome rejected as unsupported |
127
+ | 7.3 | A resumption PSK with usage reinit or branch MUST be the only such PSK; GroupInfo epoch MUST be 1; reinit/branch consistency checks | 12.4.3.1, 11.2, 11.3 | done | `Group.from_welcome`, `#validate_resumption!`; "same member" is the `member_matcher:` hook *(application)*, identical credentials by default; branch membership is checked against the old group's current tree |
124
128
  | 7.4 | GroupInfo signature with the signer leaf's key; error if blank or invalid | 12.4.3 | done | `Group.from_welcome` |
125
129
  | 7.5 | group_id MUST be unique among the groups the client is in | 12.4.3 | done | `Client#ensure_group_id_free!` on create and join |
126
130
  | 7.6 | GroupInfo cipher_suite matches the KeyPackage's | 12.4.3.1 | done | see 7.1 |
@@ -165,4 +169,4 @@ Service; melos should offer a hook or a documented default, not decide the polic
165
169
  3. ~~**KeyPackage and LeafNode validation**: sections 4 and 5 as one `LeafNode` validator parameterized by context (key_package / update / commit / tree), used by Add processing, commit path processing and join; includes signature, source, extension and capability checks, key uniqueness. Credential validation and maximum lifetime become hooks with defaults.~~ Done.
166
170
  4. ~~**Join integrity**: 7.8 to 7.12 and 7.14 on top of the validator from step 3.~~ Done.
167
171
  5. ~~**Client-level**: 7.5 group_id uniqueness, 7.1 KeyPackage suite check.~~ Done.
168
- 6. **Later, with the features they belong to**: external senders (1.2, 2.9), resumption PSK rules (2.6, 7.3), ReInit, external commits, old-epoch application messages (1.10), deletion schedule (6.15).
172
+ 6. **Later, with the features they belong to**: ~~external senders (1.2, 2.9)~~, ~~resumption PSK rules (2.6, 7.3), ReInit, external commits~~, ~~old-epoch application messages (1.10), deletion schedule (6.15)~~.
@@ -1,8 +1,11 @@
1
1
  class Melos::Capabilities
2
2
  attr_accessor :versions, :cipher_suites, :extensions, :proposals, :credentials
3
3
 
4
- def initialize
4
+ # credentials: the credential types this client can validate in other members' leaves (13.3); a client
5
+ # that accepts X.509 credentials (Melos::Credential::X509) lists 2 as well as 1
6
+ def initialize(credentials: [Melos::Constants::CredentialType::BASIC])
5
7
  set_default
8
+ @credentials = credentials
6
9
  end
7
10
 
8
11
  def set_default
@@ -12,4 +15,4 @@ class Melos::Capabilities
12
15
  @proposals = [] # 7.2: the default proposal types (add .. group_context_extensions) MUST NOT be listed
13
16
  @credentials = [1]
14
17
  end
15
- end
18
+ end