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: &mut VoteVerifier,
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
48 .verify(&trusted.trusted)
49 .map_err(VVF::InvalidSignature)?;
50
51 let test_validity_at = |t| {
54 authcert
55 .check_valid_at(&t)
56 .map_err(VVF::AuthCertWrongValidity)
57 };
58
59 test_validity_at(*body.preamble.lifetime.valid_after)?;
61 test_validity_at(*body.preamble.lifetime.fresh_until)?;
62 test_validity_at(*body.preamble.lifetime.valid_until)?;
63 authcert.dangerously_assume_timely() };
65
66 let authority_id = body.authority.authority.dir_source.identity;
67 if authority_id != authcert.fingerprint {
68 return Err(VVF::AuthCertWrongAuthority);
69 }
70
71 SignatureGroup {
72 hashes: sigs.hashes,
73 signatures: vec![sigs.sigs.directory_signature],
74 }
75 .verify_general(
76 VerifyGeneralTrustedAuthorities::AnyOneOfThese {
77 trusted: &trusted.trusted,
78 },
79 slice::from_ref(&authcert),
80 |tv| tv.verify().map_err(VVF::InvalidSignature),
81 )?;
82
83 if !trusted.remaining_good.remove(&*authority_id) {
84 return Err(VVF::DuplicateAuthority(*authority_id));
85 }
86
87 body.authority.cert.set_verified(authcert);
88
89 let time_range = body.preamble.validity_time_range();
90 Ok(TimeRangeBound::new(body, time_range))
91 }
92
93 pub fn peek_alleged_authority(&self) -> RsaIdentity {
99 *self
100 .inspect_unverified()
101 .0
102 .authority
103 .authority
104 .dir_source
105 .identity
106 }
107}
108
109impl From<ConsensusVerifiabilityError> for VoteVerifyFailed {
110 fn from(cve: ConsensusVerifiabilityError) -> VoteVerifyFailed {
111 use ConsensusVerifiabilityError as CVE;
112 use VerifyFailed as VF;
113 use VoteVerifyFailed as VVF;
114
115 match cve {
116 CVE::InsufficientTrustedSigners => {
117 VVF::InvalidSignature(VF::InsufficientTrustedSigners)
118 }
119 CVE::MissingAuthCerts { .. } => {
120 VVF::AuthCertWrongAuthority
122 }
123 }
124 }
125}