1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 DeRec Alliance. All rights reserved.
//! The out-of-band confirmation gate.
//!
//! A pairing that cannot authenticate itself cryptographically completes as
//! [`ChannelStatus::Pending`](super::types::ChannelStatus) and carries no
//! secrets until a human compares fingerprints on both devices. Deriving that
//! string and acting on the comparison are the two halves here.
use super::DeRecProtocol;
use super::context::{Round, local};
use super::stores::borrow_stores;
use super::traits::{
DeRecChannelStore, DeRecSecretStore, DeRecShareStore, DeRecStateStore, DeRecTransport,
DeRecUserSecretStore,
};
use super::types::{SecretKind, SecretValue};
use crate::derec_message;
use crate::extensions::channel_store::ChannelStoreExt as _;
use crate::primitives::pairing;
use crate::protocol::handlers::pairing::claim_own_member;
use crate::protocol::types::{ChannelQuery, ChannelRecord, ChannelStatus, ReplicaFilter};
use crate::transport::TransportPolicy;
use crate::{Error, Result, types::ChannelId};
use derec_proto::TransportProtocol;
impl<
Ch: DeRecChannelStore,
Sh: DeRecShareStore,
Ss: DeRecSecretStore,
Us: DeRecUserSecretStore,
T: DeRecTransport,
St: DeRecStateStore,
> DeRecProtocol<Ch, Sh, Ss, Us, St, T>
{
/// Compute the fingerprint for a paired channel.
///
/// Returns a formatted string like `"1234-5678-9012-3456"` derived from
/// the channel's shared key via SHA-256. Both parties will derive the same
/// fingerprint for the same shared key, enabling visual out-of-band
/// verification.
///
/// Returns an error if the channel has no shared key (not yet paired).
#[cfg_attr(feature = "logging", tracing::instrument(skip_all, fields(channel_id = channel_id.0)))]
pub async fn get_fingerprint(&self, channel_id: ChannelId) -> Result<String> {
let shared_key = match self
.secret_store
.load(self.secret_id, channel_id, SecretKind::SharedKey)
.await?
{
Some(SecretValue::SharedKey(key)) => key,
_ => {
return Err(Error::InvalidInput(
"channel has no shared key — not yet paired",
));
}
};
Ok(pairing::fingerprint(&shared_key))
}
/// Verify that a fingerprint matches the one derived from a channel's shared key.
///
/// If the fingerprint matches, the channel status is updated from `Pending`
/// to `Paired`, enabling it to process protocol messages. Returns an error
/// if the channel has no shared key.
///
/// A mismatch fails with [`Error::FingerprintMismatch`]: the two sides
/// hold different keys, which is what a man-in-the-middle on the pairing
/// produces. The comparison is authoritative, so a `Pending` pairing is
/// revoked — its records, its channel key and its pairing material are
/// deleted, and pairing again is the only way forward. A channel already
/// `Paired` is left as it is; removing it is an unpair.
///
/// This is the confirmation step for both gated cases: every replica
/// pairing, and every [`derec_proto::ContactMode::NoKeys`] pairing —
/// helper channels included, since that mode binds nothing to the contact
/// and a man-in-the-middle on its plaintext `PrePair` leg would leave the
/// two sides holding different shared keys, and so different fingerprints.
/// Compare the two values out of band before calling this.
///
/// On a replica destination, confirming is also the decision to adopt
/// the group's vault: once the channel is `Paired`, the source's publish
/// is installed into this device's stores as it arrives, with no further
/// prompt. Ask the user whether to adopt before calling this; to decline,
/// never confirm: the channel stays `Pending`, is never used, and is
/// removed with its key by expired-channel cleanup.
///
/// A match promotes every row on the channel, not just the peer that was
/// confirmed: on a group channel that is every member, so the whole group
/// becomes usable at once and the roster stays reconstructible from the
/// stores. Confirming a replica pairing also writes this device's own
/// member row on the channel when it holds no `Paired` one yet: the first
/// confirmed replica pairing fixes the group's channel, and a device
/// already in a group keeps its own.
///
/// Confirming a replica destination publishes nothing: releasing the vault
/// and the group key is the application's decision. Once the owner knows
/// the joiner has confirmed too, the application calls
/// `start(`[`DeRecFlow::ProtectSecret`](crate::protocol::DeRecFlow::ProtectSecret)`)`
/// — with no secrets when there is nothing to share yet, since the
/// payload carries the roster and the group key. Publishing before the
/// joiner confirmed is not fatal: the joiner ignores that copy, and after
/// confirming it catches up with
/// [`DeRecFlow::ReplicaDiscovery`](crate::protocol::DeRecFlow::ReplicaDiscovery).
///
/// On a helper promotion the current snapshot is published to the newly
/// usable helper, because it was not an eligible target while `Pending`
/// and the pairing-time hook therefore skipped it. That is the only push
/// it gets — nothing else republishes before the next explicit
/// [`DeRecFlow::ProtectSecret`](crate::protocol::DeRecFlow::ProtectSecret). A device holding no snapshot
/// sends a promoted helper nothing, since an empty payload is inert to
/// it, unless a replica destination is paired, which needs the roster.
/// That publish reuses every Helper's stored
/// weight, and a newly promoted Helper is at `1`. A stored weight that is
/// invalid under the round's threshold fails it with
/// [`SharingError::InvalidWeight`](crate::primitives::sharing::SharingError::InvalidWeight)
/// before anything is sent, and this returns that error. The promotion
/// has already been saved and stands, so calling `verify_fingerprint`
/// again returns `Ok(())` and publishes nothing: the promoted peer
/// receives nothing until
/// `start(`[`DeRecFlow::ProtectSecret`](crate::protocol::DeRecFlow::ProtectSecret)`)`
/// runs with valid weights.
#[cfg_attr(feature = "logging", tracing::instrument(skip_all, fields(channel_id = channel_id.0)))]
pub async fn verify_fingerprint(
&mut self,
channel_id: ChannelId,
fingerprint: &str,
) -> Result<()> {
let local = self.get_fingerprint(channel_id).await?;
if local != fingerprint {
self.revoke_pending_pairing(channel_id).await?;
return Err(Error::FingerprintMismatch { channel_id });
}
let mut transitioned_helper = false;
if let Some(record) = self
.channel_store
.load(self.secret_id, ChannelQuery::Helper { channel_id })
.await?
&& let Some(helper) = record.as_helper()
&& helper.status == ChannelStatus::Pending
{
let mut helper = helper.clone();
helper.status = ChannelStatus::Paired;
self.channel_store
.save(self.secret_id, ChannelRecord::Helper(helper))
.await?;
transitioned_helper = true;
}
let mut confirmed_peer_role = None;
let members = self
.channel_store
.replicas_matching(
self.secret_id,
ReplicaFilter {
status: vec![ChannelStatus::Pending],
..Default::default()
},
)
.await?;
for mut member in members {
if member.channel_id != channel_id {
continue;
}
if Some(member.replica_id.0) != self.replica_id {
confirmed_peer_role = Some(member.role);
}
member.status = ChannelStatus::Paired;
self.channel_store
.save(self.secret_id, ChannelRecord::Replica(member))
.await?;
}
// The first confirmed replica pairing fixes the group's channel.
if let Some(peer_role) = confirmed_peer_role {
claim_own_member(
&mut borrow_stores!(self),
&local!(self),
channel_id,
peer_role.counterparty(),
)
.await?;
}
if transitioned_helper {
let snapshot = self.user_secret_store.load_latest(self.secret_id).await?;
let payload = match snapshot {
Some(s) => Some((s.secrets, s.description)),
None if self.has_paired_replica_destination().await? => Some((Vec::new(), None)),
None => None,
};
if let Some((secrets, description)) = payload {
let reply_to: Vec<TransportProtocol> = if self.auto_reply_to {
self.own_transports.clone()
} else {
Vec::new()
};
self.start_protect_secret(
secrets,
description,
None,
None,
&Round {
reply_to: &reply_to,
trace_id: derec_message::fresh_trace_id(),
},
)
.await?;
}
}
Ok(())
}
/// Delete the unconfirmed pairing on `channel_id`: its `Pending` helper
/// record or peer rows, then, once nothing else is recorded there, this
/// device's own `Pending` row, the channel key and the pairing material.
/// `Paired` records are left in place.
async fn revoke_pending_pairing(&mut self, channel_id: ChannelId) -> Result<()> {
if self
.channel_store
.load(self.secret_id, ChannelQuery::Helper { channel_id })
.await?
.and_then(|r| r.as_helper().cloned())
.is_some_and(|helper| helper.status == ChannelStatus::Pending)
{
self.channel_store
.remove(self.secret_id, ChannelQuery::Helper { channel_id })
.await?;
}
let peers = self
.channel_store
.replicas_matching(
self.secret_id,
ReplicaFilter {
status: vec![ChannelStatus::Pending],
exclude: self.exclude_self(),
..Default::default()
},
)
.await?;
for peer in peers.into_iter().filter(|m| m.channel_id == channel_id) {
self.channel_store
.remove(
self.secret_id,
ChannelQuery::Replica {
channel_id,
replica_id: peer.replica_id,
},
)
.await?;
}
self.release_if_unused(channel_id).await?;
Ok(())
}
/// The scheme policy this protocol applies to every transport endpoint
/// that reaches it. Built from
/// [`DeRecProtocolBuilder::with_unsafe_connection`](crate::protocol::DeRecProtocolBuilder::with_unsafe_connection); see
/// [`TransportPolicy`](crate::transport::TransportPolicy).
pub(crate) fn transport_policy(&self) -> TransportPolicy {
TransportPolicy::new(self.unsafe_connection)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::primitives::sharing::request;
use crate::protocol::builder::DeRecProtocolBuilder;
use crate::protocol::tests::{
InMemChannelStore, InMemSecretStore, InMemShareStore, InMemStateStore,
InMemUserSecretStore, NoopTransport, run_async,
};
use crate::protocol::types::UserSecrets;
use crate::protocol::types::{ChannelRecord, ChannelStatus, HelperChannel, SecretValue};
use crate::types::ReplicaId;
use crate::utils::now_secs;
use derec_proto::Protocol;
use derec_proto::SenderKind;
use std::collections::HashMap;
const SECRET_ID: u64 = 0xF1;
const CHANNEL: ChannelId = ChannelId(77);
fn endpoint() -> TransportProtocol {
TransportProtocol {
uri: "https://helper.example.com".to_owned(),
protocol: Protocol::Https as i32,
}
}
/// A helper channel mid-gate: pairing completed, fingerprint not yet
/// compared. This is the state a `NoKeys` helper pairing now lands in.
async fn seed_pending_helper(
channels: &mut InMemChannelStore,
secrets: &mut InMemSecretStore,
status: ChannelStatus,
) {
channels
.save(
SECRET_ID,
ChannelRecord::Helper(HelperChannel {
channel_id: CHANNEL,
transports: vec![endpoint()],
communication_info: HashMap::new(),
status,
created_at: now_secs(),
peer_role: SenderKind::Helper,
weight: 1,
}),
)
.await
.expect("seed helper channel");
secrets
.save(SECRET_ID, CHANNEL, SecretValue::SharedKey([7u8; 32]))
.await
.expect("seed shared key");
}
fn build(
channels: InMemChannelStore,
secrets: InMemSecretStore,
) -> DeRecProtocol<
InMemChannelStore,
InMemShareStore,
InMemSecretStore,
InMemUserSecretStore,
InMemStateStore,
NoopTransport,
> {
DeRecProtocolBuilder::new(SECRET_ID)
.with_channel_store(channels)
.with_share_store(InMemShareStore::default())
.with_secret_store(secrets)
.with_user_secret_store(InMemUserSecretStore::default())
.with_transport(NoopTransport)
.with_state_store(InMemStateStore)
.with_own_transports(["https://owner.example.com"])
.with_threshold(2)
.build()
.expect("test protocol builds")
}
async fn status_of(channels: &mut InMemChannelStore) -> ChannelStatus {
channels
.load(
SECRET_ID,
ChannelQuery::Helper {
channel_id: CHANNEL,
},
)
.await
.expect("load helper")
.expect("helper row present")
.status()
}
/// The gate opens. Without this the `Pending` status a `NoKeys` helper
/// pairing lands in would be terminal — `verify_fingerprint` only ever
/// walked `replicas()`, so the channel could never become usable.
#[test]
fn a_matching_fingerprint_promotes_a_pending_helper() {
run_async(async {
let channels = InMemChannelStore::default();
let secrets = InMemSecretStore::default();
let (mut seeded_ch, mut seeded_se) = (channels.clone(), secrets.clone());
seed_pending_helper(&mut seeded_ch, &mut seeded_se, ChannelStatus::Pending).await;
let mut protocol = build(channels.clone(), secrets.clone());
let fingerprint = protocol
.get_fingerprint(CHANNEL)
.await
.expect("fingerprint derives from the shared key");
protocol
.verify_fingerprint(CHANNEL, &fingerprint)
.await
.expect("a matching fingerprint must verify");
let mut check = channels.clone();
assert_eq!(
status_of(&mut check).await,
ChannelStatus::Paired,
"a verified helper channel must become usable"
);
});
}
fn has_key(secrets: &InMemSecretStore, channel_id: ChannelId) -> bool {
secrets.data.lock().unwrap().contains_key(&(
SECRET_ID,
channel_id.0,
SecretKind::SharedKey as u8,
))
}
/// A mismatch is the man-in-the-middle case the gate exists for: the
/// pairing is revoked, so no record and no key of it remain.
#[test]
fn a_wrong_fingerprint_revokes_the_pending_helper() {
run_async(async {
let channels = InMemChannelStore::default();
let secrets = InMemSecretStore::default();
let (mut seeded_ch, mut seeded_se) = (channels.clone(), secrets.clone());
seed_pending_helper(&mut seeded_ch, &mut seeded_se, ChannelStatus::Pending).await;
let mut protocol = build(channels.clone(), secrets.clone());
let err = protocol
.verify_fingerprint(CHANNEL, "not-the-fingerprint")
.await
.expect_err("a mismatched fingerprint must not verify");
assert!(
matches!(err, Error::FingerprintMismatch { channel_id } if channel_id == CHANNEL),
"{err:?}"
);
assert!(channels.helper_rows.lock().unwrap().is_empty());
assert!(!has_key(&secrets, CHANNEL));
});
}
/// A replica pairing is revoked the same way: the peer's row, this
/// device's own `Pending` row, and the key they shared.
#[test]
fn a_wrong_fingerprint_revokes_a_pending_replica_pairing() {
run_async(async {
use crate::protocol::types::{ReplicaMember, ReplicaRole};
const OWN: u64 = 9;
let channels = InMemChannelStore::default();
let secrets = InMemSecretStore::default();
let mut seeded = channels.clone();
for (id, role) in [(7, ReplicaRole::Source), (OWN, ReplicaRole::Destination)] {
seeded
.save(
SECRET_ID,
ChannelRecord::Replica(ReplicaMember {
channel_id: CHANNEL,
replica_id: ReplicaId(id),
transports: vec![endpoint()],
communication_info: HashMap::new(),
role,
status: ChannelStatus::Pending,
created_at: now_secs(),
handover_channel: None,
}),
)
.await
.expect("seed member");
}
secrets
.clone()
.save(SECRET_ID, CHANNEL, SecretValue::SharedKey([7u8; 32]))
.await
.expect("seed shared key");
let mut protocol = build(channels.clone(), secrets.clone());
protocol.replica_id = Some(OWN);
let err = protocol
.verify_fingerprint(CHANNEL, "not-the-fingerprint")
.await
.expect_err("a mismatched fingerprint must not verify");
assert!(matches!(err, Error::FingerprintMismatch { .. }), "{err:?}");
assert!(channels.member_rows.lock().unwrap().is_empty());
assert!(!has_key(&secrets, CHANNEL));
});
}
/// A working channel is not torn down by a comparison: removing a paired
/// peer is an unpair, which tells the peer.
#[test]
fn a_wrong_fingerprint_leaves_a_paired_channel_in_place() {
run_async(async {
let channels = InMemChannelStore::default();
let secrets = InMemSecretStore::default();
let (mut seeded_ch, mut seeded_se) = (channels.clone(), secrets.clone());
seed_pending_helper(&mut seeded_ch, &mut seeded_se, ChannelStatus::Paired).await;
let mut protocol = build(channels.clone(), secrets.clone());
let err = protocol
.verify_fingerprint(CHANNEL, "not-the-fingerprint")
.await
.expect_err("a mismatched fingerprint must not verify");
assert!(matches!(err, Error::FingerprintMismatch { .. }), "{err:?}");
let mut check = channels.clone();
assert_eq!(status_of(&mut check).await, ChannelStatus::Paired);
assert!(has_key(&secrets, CHANNEL));
});
}
/// An already-`Paired` helper — the `InlineKeys` / `HashedKeys` case — is
/// untouched, so re-confirming a channel is harmless and the promotion
/// branch cannot re-fire the publish hook.
#[test]
fn verifying_an_already_paired_helper_changes_nothing() {
run_async(async {
let channels = InMemChannelStore::default();
let secrets = InMemSecretStore::default();
let (mut seeded_ch, mut seeded_se) = (channels.clone(), secrets.clone());
seed_pending_helper(&mut seeded_ch, &mut seeded_se, ChannelStatus::Paired).await;
let mut protocol = build(channels.clone(), secrets.clone());
let fingerprint = protocol
.get_fingerprint(CHANNEL)
.await
.expect("fingerprint");
protocol
.verify_fingerprint(CHANNEL, &fingerprint)
.await
.expect("verify_fingerprint");
let mut check = channels.clone();
assert_eq!(status_of(&mut check).await, ChannelStatus::Paired);
});
}
/// Confirming a replica destination releases nothing: the application
/// publishes once the owner knows the joiner confirmed too.
#[test]
fn confirming_a_replica_destination_publishes_nothing() {
run_async(async {
use crate::protocol::tests::RecordingTransport;
use crate::protocol::types::{ReplicaMember, ReplicaRole};
const OWN: u64 = 9;
const JOINER: u64 = 7;
let mut channels = InMemChannelStore::default();
let mut secrets = InMemSecretStore::default();
channels
.save(
SECRET_ID,
ChannelRecord::Replica(ReplicaMember {
channel_id: CHANNEL,
replica_id: ReplicaId(JOINER),
transports: vec![endpoint()],
communication_info: HashMap::new(),
role: ReplicaRole::Destination,
status: ChannelStatus::Pending,
created_at: now_secs(),
handover_channel: None,
}),
)
.await
.expect("seed joiner");
secrets
.save(SECRET_ID, CHANNEL, SecretValue::SharedKey([7u8; 32]))
.await
.expect("seed shared key");
let mut user_secrets = InMemUserSecretStore::default();
user_secrets
.save_latest(
SECRET_ID,
UserSecrets {
version: 4,
secrets: Vec::new(),
description: None,
author_replica_id: Some(OWN),
threshold: None,
},
)
.await
.expect("seed snapshot");
let transport = RecordingTransport::default();
let mut protocol = DeRecProtocolBuilder::new(SECRET_ID)
.with_channel_store(channels.clone())
.with_share_store(InMemShareStore::default())
.with_secret_store(secrets)
.with_user_secret_store(user_secrets.clone())
.with_transport(transport.clone())
.with_state_store(InMemStateStore)
.with_own_transports(["https://owner.example.com"])
.with_threshold(2)
.with_replica_id(OWN)
.build()
.expect("test protocol builds");
let fingerprint = protocol
.get_fingerprint(CHANNEL)
.await
.expect("fingerprint");
protocol
.verify_fingerprint(CHANNEL, &fingerprint)
.await
.expect("verify_fingerprint");
let joiner = channels
.load(
SECRET_ID,
ChannelQuery::Replica {
channel_id: CHANNEL,
replica_id: ReplicaId(JOINER),
},
)
.await
.expect("load joiner")
.expect("joiner row present");
assert_eq!(joiner.status(), ChannelStatus::Paired);
assert!(transport.sent_envelopes().is_empty(), "nothing is sent");
assert_eq!(
user_secrets
.load_latest(SECRET_ID)
.await
.expect("load snapshot")
.map(|s| s.version),
Some(4),
"no version is consumed"
);
});
}
/// The publish a confirmation triggers is an ordinary sharing round, so
/// the application's `keepVersion` governs it like any other.
#[test]
fn the_confirmation_publish_sends_the_app_keep_version() {
run_async(async {
use crate::protocol::tests::RecordingTransport;
const OTHER: ChannelId = ChannelId(78);
let mut channels = InMemChannelStore::default();
let mut secrets = InMemSecretStore::default();
seed_pending_helper(&mut channels, &mut secrets, ChannelStatus::Pending).await;
channels
.save(
SECRET_ID,
ChannelRecord::Helper(HelperChannel {
channel_id: OTHER,
transports: vec![endpoint()],
communication_info: HashMap::new(),
status: ChannelStatus::Paired,
created_at: now_secs(),
peer_role: SenderKind::Helper,
weight: 1,
}),
)
.await
.expect("seed paired helper");
secrets
.save(SECRET_ID, OTHER, SecretValue::SharedKey([7u8; 32]))
.await
.expect("seed shared key");
let mut user_secrets = InMemUserSecretStore::default();
user_secrets
.save_latest(
SECRET_ID,
UserSecrets {
version: 4,
secrets: Vec::new(),
description: None,
author_replica_id: None,
threshold: None,
},
)
.await
.expect("seed snapshot");
let shares = InMemShareStore::default();
*shares.keep.lock().unwrap() = Some(2);
let transport = RecordingTransport::default();
let mut protocol = DeRecProtocolBuilder::new(SECRET_ID)
.with_channel_store(channels)
.with_share_store(shares.clone())
.with_secret_store(secrets)
.with_user_secret_store(user_secrets)
.with_transport(transport.clone())
.with_state_store(InMemStateStore)
.with_own_transports(["https://owner.example.com"])
.with_threshold(2)
.build()
.expect("test protocol builds");
let fingerprint = protocol
.get_fingerprint(CHANNEL)
.await
.expect("fingerprint");
protocol
.verify_fingerprint(CHANNEL, &fingerprint)
.await
.expect("verify_fingerprint");
assert_eq!(
*shares.keep_version_calls.lock().unwrap(),
vec![(SECRET_ID, 5)]
);
let keep_versions: Vec<u32> = transport
.sent_envelopes()
.iter()
.map(|envelope| {
request::extract(envelope, &[7u8; 32])
.expect("extract store-share request")
.request
.keep_version
})
.collect();
assert_eq!(keep_versions, vec![2, 2]);
});
}
}