From: Matt Corallo Date: Tue, 6 Feb 2024 05:04:54 +0000 (+0000) Subject: Include the resolver-provided TTL in the response X-Git-Tag: v0.5.4~96 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=25970aa9e4402fbcaded35bc5c01b30f096b8caa;p=dnssec-prover Include the resolver-provided TTL in the response --- diff --git a/src/query.rs b/src/query.rs index 901f37e..8ce5519 100644 --- a/src/query.rs +++ b/src/query.rs @@ -83,8 +83,8 @@ fn handle_response(resp: &[u8], proof: &mut Vec) -> Result, 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) diff --git a/src/ser.rs b/src/ser.rs index e88c9ba..462ad92 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -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 { +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 { - parse_wire_packet_rr(inp, &[]) + parse_wire_packet_rr(inp, &[]).map(|(rr, _)| rr) } pub(crate) fn bytes_to_rsa_pk<'a>(pubkey: &'a [u8])