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
//! The receive-side check of the trusted keys, which runs each verifier of
//! each axis on the blocking pool.
use ostrya_core::Value;
use crate::error::Result;
use crate::verify::{CrlScope, Payload, TrustedKeys};
impl TrustedKeys {
/// Verifies `payload` against every axis of this set.
///
/// `detached` is the detached-metadata dict that holds the signatures. It
/// is `None` if the payload has no detached metadata. `subject` names the
/// payload in a message.
///
/// Each verifier of each axis runs on the blocking pool, because a
/// verifier does its work in the call. A client controls the number of
/// signature blobs, and an RSA verify with a 16384-bit key takes
/// milliseconds of CPU time. The check reads at most
/// [`MAX_SIGNATURES_PER_ENGINE`](crate::sign::MAX_SIGNATURES_PER_ENGINE)
/// blobs under the key of one engine. If `detached` holds more under the
/// key of a verifier of an axis, the check fails with
/// [`Error::Signature`](crate::Error::Signature) before a verifier of that
/// axis runs. The axes run in order, so the verifier of the GPG axis can
/// run before the check reads the blobs of the sign-api axis.
///
/// `crls` gives the X.509 CRL cache that the check reads, and writes for
/// an admission.
pub(crate) async fn check<'p>(
&self,
subject: &str,
payload: impl Into<Payload<'p>>,
detached: Option<&Value>,
crls: &CrlScope,
) -> Result<()> {
self.policy().check(subject, payload, detached, crls).await
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::verify::trust::tests::{PAYLOAD, ThreadRecorder, dict_with};
/// The trust check runs the verifiers on the blocking pool, so a verifier
/// that works in the call does not hold the async executor.
#[test]
fn the_trust_check_verifies_on_the_blocking_pool() {
let recorder = ThreadRecorder::new("ostree.sign.ed25519");
let keys = TrustedKeys::new(vec![std::sync::Arc::new(recorder.clone())]).unwrap();
let dict = dict_with("ostree.sign.ed25519", vec![7; 64]);
ostrya_rt::block_on(keys.check("commit", PAYLOAD, Some(&dict), &CrlScope::default()))
.unwrap();
recorder.assert_one_foreign_call();
}
}