]> git.bitcoin.ninja Git - dnssec-prover/commitdiff
Include the resolver-provided TTL in the response
authorMatt Corallo <git@bluematt.me>
Tue, 6 Feb 2024 05:04:54 +0000 (05:04 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 6 Feb 2024 05:04:54 +0000 (05:04 +0000)
src/query.rs
src/ser.rs

index 901f37e16334be4f4baaa04708cd37a6bae93c26..8ce551955cf0f03497c2918f221c99b50611b383 100644 (file)
@@ -83,8 +83,8 @@ fn handle_response(resp: &[u8], proof: &mut Vec<u8>) -> Result<Option<RRSig>, Er
        // Only read the answers (skip authorities and additional) as that's all we care about.
        let mut rrsig_opt = None;
        for _ in 0..answers {
-               let rr = emap(parse_wire_packet_rr(&mut read, &resp))?;
-               write_rr(&rr, 0, proof);
+               let (rr, ttl) = emap(parse_wire_packet_rr(&mut read, &resp))?;
+               write_rr(&rr, ttl, proof);
                if let RR::RRSig(rrsig) = rr { rrsig_opt = Some(rrsig); }
        }
        Ok(rrsig_opt)
index e88c9ba63a5b5700ed06ae6c2a0cac1bcb341c23..462ad9260deb8c19623b9233577f280a2d8a32d0 100644 (file)
@@ -80,33 +80,34 @@ pub(crate) fn name_len(name: &Name) -> u16 {
        }
 }
 
-pub(crate) fn parse_wire_packet_rr(inp: &mut &[u8], wire_packet: &[u8]) -> Result<RR, ()> {
+pub(crate) fn parse_wire_packet_rr(inp: &mut &[u8], wire_packet: &[u8]) -> Result<(RR, u32), ()> {
        let name = read_wire_packet_name(inp, wire_packet)?;
        let ty = read_u16(inp)?;
        let class = read_u16(inp)?;
        if class != 1 { return Err(()); } // We only support the INternet
-       let _ttl = read_u32(inp)?;
+       let ttl = read_u32(inp)?;
        let data_len = read_u16(inp)? as usize;
        if inp.len() < data_len { return Err(()); }
        let data = &inp[..data_len];
        *inp = &inp[data_len..];
 
-       match ty {
-               A::TYPE => Ok(RR::A(A::read_from_data(name, data, wire_packet)?)),
-               AAAA::TYPE => Ok(RR::AAAA(AAAA::read_from_data(name, data, wire_packet)?)),
-               NS::TYPE => Ok(RR::NS(NS::read_from_data(name, data, wire_packet)?)),
-               Txt::TYPE => Ok(RR::Txt(Txt::read_from_data(name, data, wire_packet)?)),
-               CName::TYPE => Ok(RR::CName(CName::read_from_data(name, data, wire_packet)?)),
-               TLSA::TYPE => Ok(RR::TLSA(TLSA::read_from_data(name, data, wire_packet)?)),
-               DnsKey::TYPE => Ok(RR::DnsKey(DnsKey::read_from_data(name, data, wire_packet)?)),
-               DS::TYPE => Ok(RR::DS(DS::read_from_data(name, data, wire_packet)?)),
-               RRSig::TYPE => Ok(RR::RRSig(RRSig::read_from_data(name, data, wire_packet)?)),
-               _ => Err(()),
-       }
+       let rr = match ty {
+               A::TYPE => RR::A(A::read_from_data(name, data, wire_packet)?),
+               AAAA::TYPE => RR::AAAA(AAAA::read_from_data(name, data, wire_packet)?),
+               NS::TYPE => RR::NS(NS::read_from_data(name, data, wire_packet)?),
+               Txt::TYPE => RR::Txt(Txt::read_from_data(name, data, wire_packet)?),
+               CName::TYPE => RR::CName(CName::read_from_data(name, data, wire_packet)?),
+               TLSA::TYPE => RR::TLSA(TLSA::read_from_data(name, data, wire_packet)?),
+               DnsKey::TYPE => RR::DnsKey(DnsKey::read_from_data(name, data, wire_packet)?),
+               DS::TYPE => RR::DS(DS::read_from_data(name, data, wire_packet)?),
+               RRSig::TYPE => RR::RRSig(RRSig::read_from_data(name, data, wire_packet)?),
+               _ => return Err(()),
+       };
+       Ok((rr, ttl))
 }
 
 pub(crate) fn parse_rr(inp: &mut &[u8]) -> Result<RR, ()> {
-       parse_wire_packet_rr(inp, &[])
+       parse_wire_packet_rr(inp, &[]).map(|(rr, _)| rr)
 }
 
 pub(crate) fn bytes_to_rsa_pk<'a>(pubkey: &'a [u8])