flamingo-verifier-client 0.11.2

Attestation-verifying client for the Flamingo verifier
Documentation
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
//! Configuration for the verifier client.
//!
//! Follows the shape `world-id-protocol` uses for authenticator configuration. Configuration
//! is explicit — nothing is read from the environment.

use std::time::Duration;

use serde::{Deserialize, Serialize};

use crate::client::Attestations;
use crate::error::Error;
use url::Url;

use flamingo_verifier_sealed_types::MAX_ATTESTATION_AGE;
use pontifex::attestation::{PcrConfig, PcrMeasurement, Verifier};

/// Default freshness bound, matching the few-hour lifetime of a Nitro certificate.
const fn default_max_attestation_age_millis() -> u64 {
    60 * 60 * 1000
}

const fn default_connect_timeout_millis() -> u64 {
    5_000
}

const fn default_request_timeout_millis() -> u64 {
    60_000
}

/// WIP-201 §4.6 step 3: at most 8 slots, so a response's timing reveals at most 3 bits.
const fn default_max_response_slots() -> usize {
    8
}

/// Configuration to interact with a Flamingo Verifier host.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
    /// Base URL of the host, e.g. `https://verifier.example.com`.
    host_url: Url,
    /// Measurements to trust. A document is accepted if it matches any one configuration in
    /// full, which lets several enclave versions be trusted at once during a rollout.
    #[serde(default, with = "pcr_configs")]
    allowed_pcr_configs: Vec<Vec<PcrMeasurement>>,
    /// Explicit development-only bypass of all PCR measurement checks.
    #[serde(default)]
    dangerously_skip_measurements: bool,
    /// Test-only acceptance of the unsigned attestations of a `dev` Verifier instead of Nitro's.
    #[cfg(feature = "dev")]
    #[serde(default)]
    dangerously_accept_dev_attestation: bool,
    /// How old an attestation document's own timestamp may be.
    #[serde(default = "default_max_attestation_age_millis")]
    max_attestation_age_millis: u64,
    /// Bound on establishing a connection.
    #[serde(default = "default_connect_timeout_millis")]
    connect_timeout_millis: u64,
    /// Bound on a whole exchange.
    #[serde(default = "default_request_timeout_millis")]
    request_timeout_millis: u64,
    /// Most response slots a pipeline may list before the client sends biometrics to it.
    #[serde(default = "default_max_response_slots")]
    max_response_slots: usize,
}

impl Config {
    /// Instantiates a configuration with the default bounds.
    ///
    /// # Errors
    ///
    /// Returns an error if `host_url` is not a valid URL or the measurement policy fails
    /// the requirements of [`Self::verifier`].
    pub fn new(
        host_url: &str,
        allowed_pcr_configs: Vec<Vec<PcrMeasurement>>,
    ) -> Result<Self, Error> {
        Self::new_inner(host_url, allowed_pcr_configs, false)
    }

    /// Creates a configuration that bypasses all PCR measurement checks.
    ///
    /// No measurements are required. Certificate chain, signature, freshness, and
    /// channel public-key commitment verification remain enabled.
    ///
    /// # Warning
    /// Accepts any enclave code with otherwise valid attestation, including Nitro
    /// debug enclaves. Use only for development, never in production.
    ///
    /// # Errors
    ///
    /// Returns an error if `host_url` is not a valid URL.
    pub fn dangerously_skip_measurements(host_url: &str) -> Result<Self, Error> {
        Self::new_inner(host_url, vec![], true)
    }

    /// Creates a configuration that accepts only the unsigned attestations of an in-process `dev`
    /// Verifier, with the channel key commitment and `release_hash` bound as for Nitro documents.
    ///
    /// # Warning
    /// Nothing proves the Verifier runs in an enclave. Use only in tests, never in production.
    ///
    /// # Errors
    ///
    /// Returns an error if `host_url` is not a valid URL.
    #[cfg(feature = "dev")]
    pub fn dangerously_accept_dev_attestation(host_url: &str) -> Result<Self, Error> {
        let mut config = Self::new_inner(host_url, vec![], true)?;
        config.dangerously_accept_dev_attestation = true;
        Ok(config)
    }

    fn new_inner(
        host_url: &str,
        allowed_pcr_configs: Vec<Vec<PcrMeasurement>>,
        dangerously_skip_measurements: bool,
    ) -> Result<Self, Error> {
        let host_url = Url::parse(host_url).map_err(|error| Error::InvalidConfig {
            attribute: "host_url".to_string(),
            reason: error.to_string(),
        })?;

        let config = Self {
            host_url,
            allowed_pcr_configs,
            dangerously_skip_measurements,
            #[cfg(feature = "dev")]
            dangerously_accept_dev_attestation: false,
            max_attestation_age_millis: default_max_attestation_age_millis(),
            connect_timeout_millis: default_connect_timeout_millis(),
            request_timeout_millis: default_request_timeout_millis(),
            max_response_slots: default_max_response_slots(),
        };
        config.validate()?;

        Ok(config)
    }

    /// Bounds how old an attestation document's own timestamp may be.
    #[must_use]
    pub fn with_max_attestation_age(mut self, max_age: Duration) -> Self {
        self.max_attestation_age_millis = u64::try_from(max_age.as_millis()).unwrap_or(u64::MAX);
        self
    }

    /// Bounds each WebSocket exchange phase. Connecting uses `connect_timeout_millis` instead.
    #[must_use]
    pub fn with_request_timeout(mut self, timeout: Duration) -> Self {
        self.request_timeout_millis = u64::try_from(timeout.as_millis()).unwrap_or(u64::MAX);
        self
    }

    /// Bounds how many response slots a pipeline may list (WIP-201 §4.6 step 3).
    #[must_use]
    pub const fn with_max_response_slots(mut self, max_slots: usize) -> Self {
        self.max_response_slots = max_slots;
        self
    }

    /// Loads a configuration from JSON.
    ///
    /// # Errors
    ///
    /// Returns an error if the JSON is invalid or the resulting configuration is not usable.
    pub fn from_json(json: &str) -> Result<Self, Error> {
        let config: Self = serde_json::from_str(json)
            .map_err(|error| Error::MalformedConfig(error.to_string()))?;
        config.validate()?;

        Ok(config)
    }

    /// Validates the measurement policy before constructing the verifier.
    fn validate(&self) -> Result<(), Error> {
        #[cfg(feature = "dev")]
        if self.dangerously_accept_dev_attestation && !self.dangerously_skip_measurements {
            return Err(Error::InvalidConfig {
                attribute: "dangerously_accept_dev_attestation".to_owned(),
                reason: "requires dangerously_skip_measurements".to_owned(),
            });
        }
        self.verifier().map(|_| ())
    }

    /// Builds a Pontifex verifier applying the configured measurements and freshness bound.
    ///
    /// # Errors
    ///
    /// Rejects a zero `max_response_slots`, and a zero age or one above WIP-201
    /// `MAX_ATTESTATION_AGE`. Without the explicit measurement bypass, also rejects an empty
    /// policy, missing or zero PCR0–2, duplicate indices, or malformed measurements.
    pub fn verifier(&self) -> Result<Verifier, Error> {
        // Checked here, not only in `validate`, so the builder methods cannot bypass it.
        if self.max_response_slots == 0 {
            return Err(Error::InvalidConfig {
                attribute: "max_response_slots".to_owned(),
                reason: "must be nonzero".to_owned(),
            });
        }
        let max_age = Duration::from_millis(self.max_attestation_age_millis);
        if max_age.is_zero() || max_age > MAX_ATTESTATION_AGE {
            return Err(Error::InvalidConfig {
                attribute: "max_attestation_age_millis".to_owned(),
                reason: "must be nonzero and at most WIP-201 MAX_ATTESTATION_AGE (3 hours)"
                    .to_owned(),
            });
        }
        if self.dangerously_skip_measurements {
            return Ok(Verifier::new(vec![], max_age).dangerously_skip_measurements());
        }
        let invalid = || Error::InvalidConfig {
            attribute: "allowed_pcr_configs".to_owned(),
            reason: "each configuration must pin nonzero 48-byte PCR0, PCR1 and PCR2; \
                     all measurements must be 48 bytes with unique indices"
                .to_owned(),
        };
        if self.allowed_pcr_configs.is_empty() {
            return Err(invalid());
        }
        let mut configs = Vec::new();
        for measurements in &self.allowed_pcr_configs {
            let mut indices = std::collections::BTreeSet::new();
            if measurements
                .iter()
                .any(|pcr| pcr.value.len() != 48 || !indices.insert(pcr.index))
            {
                return Err(invalid());
            }
            // WIP-201 §3.7: PCR0–2 together are the Verifier's measurement.
            let pinned = |index| {
                measurements
                    .iter()
                    .any(|pcr| pcr.index == index && pcr.value.iter().any(|&byte| byte != 0))
            };
            if !(0..=2).all(pinned) {
                return Err(invalid());
            }
            let pcr0 = measurements
                .iter()
                .find(|pcr| pcr.index == 0)
                .ok_or_else(invalid)?;
            let image = <[u8; 48]>::try_from(pcr0.value.as_slice()).map_err(|_| invalid())?;
            if image == [0; 48] {
                return Err(invalid());
            }
            let mut config = PcrConfig::new(image);
            for pcr in measurements.iter().filter(|pcr| pcr.index != 0) {
                config = config.with_pcr(pcr.index, pcr.value.clone());
            }
            configs.push(config);
        }
        Ok(Verifier::new(configs, max_age))
    }

    /// How the client verifies the enclave's attestations, after [`Self::verifier`] validated the
    /// configuration.
    pub(crate) fn attestations(&self) -> Result<Attestations, Error> {
        let verifier = self.verifier()?;
        #[cfg(feature = "dev")]
        if self.dangerously_accept_dev_attestation {
            return Ok(Attestations::Dev {
                max_age: Duration::from_millis(self.max_attestation_age_millis),
            });
        }
        Ok(Attestations::Nitro(verifier))
    }

    /// The host to call.
    #[must_use]
    pub const fn host_url(&self) -> &Url {
        &self.host_url
    }

    /// Bound on establishing a connection.
    #[must_use]
    pub const fn connect_timeout(&self) -> Duration {
        Duration::from_millis(self.connect_timeout_millis)
    }

    /// Bound on a whole exchange.
    #[must_use]
    pub const fn request_timeout(&self) -> Duration {
        Duration::from_millis(self.request_timeout_millis)
    }

    /// Most response slots a pipeline may list before the client sends biometrics to it.
    #[must_use]
    pub const fn max_response_slots(&self) -> usize {
        self.max_response_slots
    }
}

mod pcr_configs {
    use pontifex::PcrMeasurement;
    use serde::{Deserialize, Serialize};

    #[derive(Serialize, Deserialize)]
    struct Measurement {
        index: u32,
        #[serde(
            serialize_with = "hex::serde::serialize",
            deserialize_with = "deserialize_pcr"
        )]
        value: Vec<u8>,
    }

    fn deserialize_pcr<'de, D: serde::Deserializer<'de>>(
        deserializer: D,
    ) -> Result<Vec<u8>, D::Error> {
        let value = String::deserialize(deserializer)?;
        hex::decode(value.strip_prefix("0x").unwrap_or(&value)).map_err(serde::de::Error::custom)
    }

    pub(super) fn serialize<S: serde::Serializer>(
        configs: &[Vec<PcrMeasurement>],
        serializer: S,
    ) -> Result<S::Ok, S::Error> {
        let configs: Vec<Vec<Measurement>> = configs
            .iter()
            .map(|measurements| {
                measurements
                    .iter()
                    .map(|pcr| Measurement {
                        index: pcr.index,
                        value: pcr.value.clone(),
                    })
                    .collect()
            })
            .collect();
        configs.serialize(serializer)
    }

    pub(super) fn deserialize<'de, D: serde::Deserializer<'de>>(
        deserializer: D,
    ) -> Result<Vec<Vec<PcrMeasurement>>, D::Error> {
        let configs = Vec::<Vec<Measurement>>::deserialize(deserializer)?;
        Ok(configs
            .into_iter()
            .map(|measurements| {
                measurements
                    .into_iter()
                    .map(|pcr| PcrMeasurement::new(pcr.index, pcr.value))
                    .collect()
            })
            .collect())
    }
}

#[cfg(test)]
mod tests {
    use std::time::Duration;

    use super::PcrMeasurement;
    use super::{Config, MAX_ATTESTATION_AGE};
    use crate::error::Error;

    fn pcrs() -> Vec<Vec<PcrMeasurement>> {
        vec![
            (0..=2)
                .map(|index| PcrMeasurement::new(index, [0xab; 48]))
                .collect(),
        ]
    }

    #[test]
    fn rejects_a_configuration_that_pins_nothing() {
        let error = Config::new("http://localhost:8000", Vec::new())
            .expect_err("an empty policy must fail closed");

        assert!(matches!(error, Error::InvalidConfig { .. }));
    }

    #[test]
    fn attestation_age_is_bounded_by_wip_201() {
        let config = Config::new("http://localhost:8000", pcrs()).unwrap();
        assert!(
            config
                .clone()
                .with_max_attestation_age(MAX_ATTESTATION_AGE)
                .verifier()
                .is_ok()
        );
        for age in [
            Duration::ZERO,
            Duration::from_secs(10_800) + Duration::from_millis(1),
            Duration::from_hours(24),
        ] {
            assert!(matches!(
                config.clone().with_max_attestation_age(age).verifier(),
                Err(Error::InvalidConfig { .. })
            ));
        }
    }

    #[test]
    fn a_zero_slot_budget_is_rejected_whichever_way_it_is_set() {
        let config = Config::new("http://localhost:8000", pcrs()).unwrap();
        assert!(matches!(
            config.clone().with_max_response_slots(0).verifier(),
            Err(Error::InvalidConfig { .. })
        ));
        assert!(matches!(
            crate::FlamingoVerifierClient::new(config.clone().with_max_response_slots(0)),
            Err(Error::InvalidConfig { .. })
        ));
        let mut json = serde_json::to_value(&config).unwrap();
        json["max_response_slots"] = 0.into();
        assert!(Config::from_json(&json.to_string()).is_err());
    }

    #[test]
    fn requires_each_release_measurement_even_when_pcr0_is_pinned() {
        for missing in 0..=2 {
            let mut policy = pcrs().pop().unwrap();
            policy.retain(|pcr| pcr.index != missing);
            assert!(Config::new("http://localhost:8000", vec![policy]).is_err());
            let mut policy = pcrs().pop().unwrap();
            policy
                .iter_mut()
                .find(|pcr| pcr.index == missing)
                .unwrap()
                .value
                .fill(0);
            assert!(Config::new("http://localhost:8000", vec![policy]).is_err());
        }
    }

    #[test]
    fn rejects_an_invalid_host_url() {
        let error =
            Config::new("not a url", pcrs()).expect_err("an unparseable URL must be rejected");

        assert!(matches!(error, Error::InvalidConfig { .. }));
    }

    #[test]
    fn rejects_missing_zero_malformed_and_duplicate_measurements() {
        let policies = [
            vec![],
            vec![PcrMeasurement::new(1, [0xab; 48])],
            vec![PcrMeasurement::new(0, [0; 48])],
            vec![PcrMeasurement::new(0, [0xab; 32])],
            vec![
                PcrMeasurement::new(0, [0xab; 48]),
                PcrMeasurement::new(1, [0xab; 32]),
            ],
            vec![
                PcrMeasurement::new(0, [0xab; 48]),
                PcrMeasurement::new(0, [0xcd; 48]),
            ],
        ];
        for policy in policies {
            let error = Config::new("http://localhost:8000", vec![policy]).unwrap_err();
            assert!(matches!(error, Error::InvalidConfig { .. }));
        }
    }

    #[test]
    fn deserialization_cannot_bypass_client_policy_validation() {
        let config: Config = serde_json::from_value(serde_json::json!({
            "host_url": "http://localhost:8000",
            "allowed_pcr_configs": []
        }))
        .unwrap();
        assert!(matches!(
            crate::FlamingoVerifierClient::new(config),
            Err(Error::InvalidConfig { .. })
        ));
    }

    #[test]
    fn measurement_skip_is_explicit_and_survives_json_round_trip() {
        assert!(Config::dangerously_skip_measurements("not a URL").is_err());
        let config = Config::dangerously_skip_measurements("http://localhost:8000").unwrap();
        assert!(config.verifier().is_ok());
        let mut json = serde_json::to_value(config).unwrap();
        assert_eq!(json["dangerously_skip_measurements"], true);
        assert_eq!(json["allowed_pcr_configs"], serde_json::json!([]));
        assert!(
            Config::from_json(&json.to_string())
                .unwrap()
                .verifier()
                .is_ok()
        );
        json.as_object_mut().unwrap().remove("allowed_pcr_configs");
        assert!(
            Config::from_json(&json.to_string())
                .unwrap()
                .verifier()
                .is_ok()
        );
        json.as_object_mut()
            .unwrap()
            .remove("dangerously_skip_measurements");
        assert!(Config::from_json(&json.to_string()).is_err());
        json["dangerously_skip_measurements"] = serde_json::json!(false);
        assert!(Config::from_json(&json.to_string()).is_err());
        json.as_object_mut()
            .unwrap()
            .remove("dangerously_skip_measurements");
        json["allow_debug_measurements"] = serde_json::json!(true);
        assert!(Config::from_json(&json.to_string()).is_err());
    }

    #[cfg(not(feature = "dev"))]
    #[test]
    fn dev_attestations_need_the_dev_feature() {
        let mut json = serde_json::to_value(
            Config::dangerously_skip_measurements("http://localhost:8000").unwrap(),
        )
        .unwrap();
        json["dangerously_accept_dev_attestation"] = serde_json::json!(true);
        assert!(Config::from_json(&json.to_string()).is_err());
    }

    #[cfg(feature = "dev")]
    #[test]
    fn dev_attestations_are_explicit_and_survive_json_round_trip() {
        use crate::client::Attestations;

        let nitro = Config::dangerously_skip_measurements("http://localhost:8000").unwrap();
        assert!(matches!(nitro.attestations(), Ok(Attestations::Nitro(_))));
        let config = Config::dangerously_accept_dev_attestation("http://localhost:8000").unwrap();
        let json = serde_json::to_value(config).unwrap();
        assert_eq!(json["dangerously_accept_dev_attestation"], true);
        assert!(matches!(
            Config::from_json(&json.to_string()).unwrap().attestations(),
            Ok(Attestations::Dev { .. })
        ));
    }

    #[cfg(feature = "dev")]
    #[test]
    fn dev_attestations_require_skipping_measurements() {
        let mut json =
            serde_json::to_value(Config::new("http://localhost:8000", pcrs()).unwrap()).unwrap();
        json["dangerously_accept_dev_attestation"] = serde_json::json!(true);
        assert!(matches!(
            Config::from_json(&json.to_string()),
            Err(Error::InvalidConfig { .. })
        ));
        json["dangerously_skip_measurements"] = serde_json::json!(true);
        json["allowed_pcr_configs"] = serde_json::json!([]);
        assert!(matches!(
            Config::from_json(&json.to_string()).unwrap().attestations(),
            Ok(crate::client::Attestations::Dev { .. })
        ));
    }

    #[test]
    fn measurement_skip_ignores_supplied_pins() {
        for pins in [
            vec![],
            vec![PcrMeasurement::new(1, [0; 48])],
            vec![PcrMeasurement::new(0, [0; 48])],
            vec![PcrMeasurement::new(0, [0; 47])],
            vec![
                PcrMeasurement::new(0, [1; 48]),
                PcrMeasurement::new(1, [0; 49]),
            ],
            vec![
                PcrMeasurement::new(0, [1; 48]),
                PcrMeasurement::new(0, [1; 48]),
            ],
        ] {
            let mut config =
                Config::dangerously_skip_measurements("http://localhost:8000").unwrap();
            config.allowed_pcr_configs = vec![pins];
            let mut json = serde_json::to_value(config).unwrap();
            assert!(
                Config::from_json(&json.to_string())
                    .unwrap()
                    .verifier()
                    .is_ok()
            );
            json["dangerously_skip_measurements"] = serde_json::json!(false);
            assert!(Config::from_json(&json.to_string()).is_err());
        }
    }

    #[test]
    fn accepts_pcr_values_with_and_without_the_0x_prefix() {
        // Release metadata records PCRs 0x-prefixed; both spellings should be accepted.
        let json = r#"{
            "host_url": "http://localhost:8000",
            "allowed_pcr_configs": [[
                { "index": 0, "value": "0xab01" },
                { "index": 1, "value": "ab01" },
                { "index": 2, "value": "ab01" }
            ]]
        }"#;

        let json = json
            .replace("0xab01", &format!("0x{}", "ab".repeat(48)))
            .replace("ab01", &"ab".repeat(48));
        let config = Config::from_json(&json).expect("both spellings should parse");

        let pcrs = &config.allowed_pcr_configs[0];
        assert_eq!(pcrs[0].value, pcrs[1].value);

        Config::from_json(
            r#"{
            "host_url": "http://localhost:8000",
            "allowed_pcr_configs": [[{ "index": 0, "value": "0xzz" }]]
        }"#,
        )
        .expect_err("non-hex must still be rejected");
    }

    #[test]
    fn round_trips_through_json_with_defaults_applied() {
        let config = Config::new(
            "http://localhost:8000",
            vec![
                vec![
                    pontifex::PcrMeasurement::new(0, [0xab; 48]),
                    pontifex::PcrMeasurement::new(1, [0xcd; 48]),
                    pontifex::PcrMeasurement::new(2, [0xde; 48]),
                ],
                (0..=2)
                    .map(|index| PcrMeasurement::new(index, [0xef; 48]))
                    .collect(),
            ],
        )
        .expect("Pontifex measurements should be accepted");
        let json = serde_json::to_value(&config).expect("config should serialize");
        assert_eq!(json["dangerously_skip_measurements"], false);
        assert_eq!(
            json["allowed_pcr_configs"],
            serde_json::json!([
                [
                    { "index": 0, "value": "ab".repeat(48) },
                    { "index": 1, "value": "cd".repeat(48) },
                    { "index": 2, "value": "de".repeat(48) }
                ],
                [
                    { "index": 0, "value": "ef".repeat(48) },
                    { "index": 1, "value": "ef".repeat(48) },
                    { "index": 2, "value": "ef".repeat(48) }
                ]
            ])
        );

        let decoded = Config::from_json(&json.to_string()).expect("config should parse");
        assert_eq!(decoded.request_timeout(), Duration::from_mins(1));
        assert_eq!(decoded.max_response_slots(), 8);
        assert_eq!(serde_json::to_value(decoded).unwrap(), json);
    }
}