tor_netdoc/doc/netstatus/
vote.rs1use super::*;
7
8ns_do_variety_vote! {}
10
11const NETSTATUS_DOCTYPE_FOR_ERROR: &str = "network status vote";
13
14pub type VarietyKeyword = NoMoreArguments;
25
26impl NetworkStatusUnverified {
27 pub fn verify(
33 self,
34 trusted: &[RsaIdentity],
35 ) -> Result<TimeRangeBound<NetworkStatus>, VoteVerifyFailed> {
36 use VoteVerifyFailed as VVF;
37
38 let (mut body, sigs) = self.unwrap_unverified();
39
40 let authcert = {
41 let input = parse2::ParseInput::new(
42 body.authority.cert.raw_unverified().as_ref(),
43 "<authcert>",
44 );
45 let authcert = parse2::parse_netdoc::<AuthCertUnverified>(&input)
46 .map_err(VVF::AuthCertParseError)?;
47 let authcert = authcert.verify(trusted).map_err(VVF::InvalidSignature)?;
48
49 let test_validity_at = |t| {
52 authcert
53 .check_valid_at(&t)
54 .map_err(VVF::AuthCertWrongValidity)
55 };
56
57 test_validity_at(*body.preamble.lifetime.valid_after)?;
59 test_validity_at(*body.preamble.lifetime.fresh_until)?;
60 test_validity_at(*body.preamble.lifetime.valid_until)?;
61 authcert.dangerously_assume_timely() };
63
64 if body.authority.authority.dir_source.identity != authcert.fingerprint {
65 return Err(VVF::AuthCertWrongAuthority);
66 }
67
68 SignatureGroup {
69 hashes: sigs.hashes,
70 signatures: vec![sigs.sigs.directory_signature],
71 }
72 .verify_general(
73 VerifyGeneralTrustedAuthorities::AnyOneOfThese { trusted },
74 slice::from_ref(&authcert),
75 |tv| tv.verify().map_err(VVF::InvalidSignature),
76 )?;
77
78 body.authority.cert.set_verified(authcert);
79
80 let time_range = body.preamble.validity_time_range();
81 Ok(TimeRangeBound::new(body, time_range))
82 }
83
84 pub fn peek_alleged_authority(&self) -> RsaIdentity {
90 *self
91 .inspect_unverified()
92 .0
93 .authority
94 .authority
95 .dir_source
96 .identity
97 }
98}
99
100impl From<ConsensusVerifiabilityError> for VoteVerifyFailed {
101 fn from(cve: ConsensusVerifiabilityError) -> VoteVerifyFailed {
102 use ConsensusVerifiabilityError as CVE;
103 use VerifyFailed as VF;
104 use VoteVerifyFailed as VVF;
105
106 match cve {
107 CVE::InsufficientTrustedSigners => {
108 VVF::InvalidSignature(VF::InsufficientTrustedSigners)
109 }
110 CVE::MissingAuthCerts { .. } => {
111 VVF::AuthCertWrongAuthority
113 }
114 }
115 }
116}