Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add record removal and ZONEMD signature replacement methods to SortedRecords #458

Merged
merged 39 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
42cbd0d
Cargo format
mozzieongit Nov 20, 2024
90aae20
Implement FromStr for zonemd Scheme and Algorithm
mozzieongit Nov 20, 2024
7890d47
Add SortedRecords record deletion and rrsig replace methods
mozzieongit Nov 27, 2024
4808c70
Return bool from record removal methods
mozzieongit Nov 27, 2024
19fac46
Clippy
mozzieongit Nov 27, 2024
967c628
Breaking change: Update ZONEMD IANA types to use the iana macros to b…
ximon18 Nov 29, 2024
2712529
Merge branch 'zonemd-from-str' into sortedrecords-zonemd-remove-replace
ximon18 Nov 29, 2024
d3b9b55
Merge branch 'multiple-key-signing' into sortedrecords-zonemd-remove-…
ximon18 Nov 29, 2024
b0d14ed
Revert "Merge branch 'multiple-key-signing' into sortedrecords-zonemd…
ximon18 Nov 29, 2024
c71434e
Revert "Merge branch 'zonemd-from-str' into sortedrecords-zonemd-remo…
ximon18 Nov 29, 2024
82e7d2d
Merge branch 'multiple-key-signing' into sortedrecords-zonemd-remove-…
ximon18 Nov 29, 2024
df4992f
Merge branch 'multiple-key-signing' into sortedrecords-zonemd-remove-…
ximon18 Nov 29, 2024
d733a4e
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Nov 29, 2024
bf3f589
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 2, 2024
2136e47
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 2, 2024
b10cc2e
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 3, 2024
323a14a
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 3, 2024
94b0de2
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 3, 2024
3ce8640
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 3, 2024
9607ba0
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 5, 2024
e4a5bf9
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 5, 2024
5f6f7e7
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 5, 2024
6b7321c
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 6, 2024
8c583b5
Add a tab before the RDATA as well as within it, to match LDNS tabbed…
ximon18 Dec 6, 2024
8f97bd3
Update changelog.
ximon18 Dec 6, 2024
200f0bb
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 7, 2024
7f1bcb9
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 9, 2024
29cc4a1
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 9, 2024
2a956f7
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 9, 2024
3320bc9
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 12, 2024
529e6e6
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 12, 2024
931d134
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 16, 2024
d3b3da5
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 16, 2024
aeb6d93
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 16, 2024
d863dba
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 17, 2024
7deffd0
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 18, 2024
3319ec6
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 18, 2024
dd120bc
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 18, 2024
072cc4c
Merge branch 'byo-signing-sorter-impl' into sortedrecords-zonemd-remo…
ximon18 Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 108 additions & 2 deletions src/sign/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::string::{String, ToString};
use std::vec::Vec;
use std::{fmt, slice};

use bytes::Bytes;
use octseq::builder::{EmptyBuilder, FromBuilder, OctetsBuilder, Truncate};
use octseq::{FreezeBuilder, OctetsFrom, OctetsInto};
use tracing::{debug, enabled, Level};
Expand All @@ -26,7 +27,9 @@ use crate::base::record::Record;
use crate::base::{Name, NameBuilder, Ttl};
use crate::rdata::dnssec::{ProtoRrsig, RtypeBitmap, RtypeBitmapBuilder};
use crate::rdata::nsec3::{Nsec3Salt, OwnerHash};
use crate::rdata::{Dnskey, Nsec, Nsec3, Nsec3param, Soa, ZoneRecordData};
use crate::rdata::{
Dnskey, Nsec, Nsec3, Nsec3param, Rrsig, Soa, ZoneRecordData,
};
use crate::utils::base32;
use crate::validate::{nsec3_hash, Nsec3HashError};
use crate::zonetree::types::StoredRecordData;
Expand Down Expand Up @@ -126,6 +129,84 @@ where
}
}

/// Remove all records matching the owner name, class, and rtype.
/// Class and Rtype can be None to match any.
///
/// Returns:
/// - true: if one or more matching records were found (and removed)
/// - false: if no matching record was found
pub fn remove_all_by_name_class_rtype(
&mut self,
name: N,
class: Option<Class>,
rtype: Option<Rtype>,
) -> bool
where
N: ToName + Clone,
D: RecordData,
{
let mut found_one = false;
loop {
if self.remove_first_by_name_class_rtype(
name.clone(),
class,
rtype,
) {
found_one = true
} else {
break;
}
}

found_one
}

/// Remove first records matching the owner name, class, and rtype.
/// Class and Rtype can be None to match any.
///
/// Returns:
/// - true: if a matching record was found (and removed)
/// - false: if no matching record was found
pub fn remove_first_by_name_class_rtype(
&mut self,
name: N,
class: Option<Class>,
rtype: Option<Rtype>,
) -> bool
where
N: ToName,
D: RecordData,
{
let idx = self.records.binary_search_by(|stored| {
// Ordering based on base::Record::canonical_cmp excluding comparison of data

if let Some(class) = class {
match stored.class().cmp(&class) {
Ordering::Equal => {}
res => return res,
}
}

match stored.owner().name_cmp(&name) {
Ordering::Equal => {}
res => return res,
}

if let Some(rtype) = rtype {
stored.rtype().cmp(&rtype)
} else {
Ordering::Equal
}
});
match idx {
Ok(idx) => {
self.records.remove(idx);
true
}
Err(_) => false,
}
}

pub fn families(&self) -> RecordsIter<N, D> {
RecordsIter::new(&self.records)
}
Expand Down Expand Up @@ -155,7 +236,7 @@ where
}
}

impl<N: Send, S: Sorter> SortedRecords<N, StoredRecordData, S> {
impl<N: Send + ToName, S: Sorter> SortedRecords<N, StoredRecordData, S> {
pub fn replace_soa(&mut self, new_soa: Soa<StoredName>) {
if let Some(soa_rrset) = self
.records
Expand All @@ -167,6 +248,31 @@ impl<N: Send, S: Sorter> SortedRecords<N, StoredRecordData, S> {
}
}
}

pub fn replace_rrsig_for_apex_zonemd(
&mut self,
new_rrsig: Rrsig<Bytes, StoredName>,
apex: &FamilyName<StoredName>,
) {
if let Some(zonemd_rrsig) = self.records.iter_mut().find(|record| {
if record.rtype() == Rtype::RRSIG
&& record.owner().name_cmp(&apex.owner()) == Ordering::Equal
{
if let ZoneRecordData::Rrsig(rrsig) = record.data() {
if rrsig.type_covered() == Rtype::ZONEMD {
return true;
}
}
}
false
}) {
if let ZoneRecordData::Rrsig(current_rrsig) =
zonemd_rrsig.data_mut()
{
*current_rrsig = new_rrsig;
}
}
}
}

impl<N, D, S> SortedRecords<N, D, S>
Expand Down
Loading