1
//! Directory Authority Key Certificates
2

            
3
use super::*;
4

            
5
/// SHA1 hash as used in directory authority certificates
6
//
7
// We don't have a better name for this!
8
type DirKeyCertificateHash = [u8; 20];
9

            
10
pub use crate::doc::authcert::AuthCert as DirAuthKeyCert;
11
pub use crate::doc::authcert::AuthCertSigned as DirAuthKeyCertSigned;
12

            
13
impl DirAuthKeyCertSigned {
14
    /// Verify the signatures (and check validity times)
15
    ///
16
    /// # Security considerations
17
    ///
18
    /// The caller must check that the KP_auth_id is correct/relevant.
19
10
    pub fn verify_selfcert(self, now: SystemTime) -> Result<DirAuthKeyCert, VF> {
20
        // verify main document signature (and timestamp)
21
10
        let hash = self.signatures.dir_key_certification.hash;
22
10
        let body = &self.inspect_unverified().0;
23

            
24
10
        let validity = body.dir_key_published.0..=body.dir_key_expires.0;
25
10
        check_validity_time(now, validity)?;
26
10
        body.dir_identity_key
27
10
            .verify(&hash, &self.signatures.dir_key_certification.signature)?;
28

            
29
        // double-check the id hash
30
10
        if *body.fingerprint != body.dir_identity_key.to_rsa_identity() {
31
            return Err(VF::Inconsistent);
32
10
        }
33

            
34
        // verify cross-cert
35
10
        let h_kp_auth_id_rsa: DirKeyCertificateHash =
36
10
            tor_llcrypto::d::Sha1::digest(body.dir_identity_key.to_der()).into();
37
        // Cross-cert has no timestamp.  Whatever.
38
10
        body.dir_signing_key
39
10
            .verify(&h_kp_auth_id_rsa, &body.dir_key_crosscert.signature)?;
40

            
41
10
        Ok(self.unwrap_unverified().0)
42
10
    }
43
}