fixes case issues with rollernet described in #27

This commit is contained in:
Benjamin Fry 2016-08-11 23:19:06 -07:00
parent 57488aee1f
commit fb82133b4c
7 changed files with 69 additions and 20 deletions

View File

@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## 0.7.2 2016-08-10
### Fixed
- Issue #27: label case sensitivity revisited for RRSIG signing
## 0.7.2 2016-08-10
### Fixed
- Issue #28: RRSIG validation of wildcards, label length > wildcard length

2
Cargo.lock generated
View File

@ -1,6 +1,6 @@
[root]
name = "trust-dns"
version = "0.7.1"
version = "0.7.2"
dependencies = [
"backtrace 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,6 @@
[package]
name = "trust-dns"
version = "0.7.2"
version = "0.7.3"
authors = ["Benjamin Fry <benjaminfry@me.com>"]
# A short blurb about the package. This is not rendered in any format when

View File

@ -54,7 +54,7 @@ impl PartialOrd for RrKey {
impl Ord for RrKey {
fn cmp(&self, other: &Self) -> Ordering {
let order = self.name.cmp_with_case(&other.name, true);
let order = self.name.cmp(&other.name);
if order == Ordering::Equal {
self.record_type.cmp(&other.record_type)
} else {

View File

@ -1085,10 +1085,10 @@ mod test {
let response = response.unwrap();
println!("response records: {:?}", response);
assert_eq!(response.get_queries().first().expect("expected query").get_name(), &name);
assert_eq!(response.get_queries().first().expect("expected query").get_name().cmp_with_case(&name, false), Ordering::Equal);
let record = &response.get_answers()[0];
assert_eq!(record.get_name().cmp_with_case(&name, true), Ordering::Equal);
assert_eq!(record.get_name(), &name);
assert_eq!(record.get_rr_type(), RecordType::A);
assert_eq!(record.get_dns_class(), DNSClass::IN);
@ -1168,9 +1168,6 @@ mod test {
#[test]
#[ignore]
fn test_dnssec_rollernet_td_udp() {
use ::udp::UdpClientConnection;
use ::client::Client;
use ::rr::Name;
use ::logger::TrustDnsLogger;
use log::LogLevel;
@ -1178,7 +1175,7 @@ mod test {
let c = Client::new(UdpClientConnection::new("8.8.8.8:53".parse().unwrap()).unwrap());
c.secure_query(
&Name::parse("rollernet.us.", None).unwrap(),
&domain::Name::parse("rollernet.us.", None).unwrap(),
DNSClass::IN,
RecordType::DS,
).unwrap();
@ -1187,9 +1184,6 @@ mod test {
#[test]
#[ignore]
fn test_dnssec_rollernet_td_tcp() {
use ::tcp::TcpClientConnection;
use ::client::Client;
use ::rr::Name;
use ::logger::TrustDnsLogger;
use log::LogLevel;
@ -1197,7 +1191,23 @@ mod test {
let c = Client::new(TcpClientConnection::new("8.8.8.8:53".parse().unwrap()).unwrap());
c.secure_query(
&Name::parse("rollernet.us.", None).unwrap(),
&domain::Name::parse("rollernet.us.", None).unwrap(),
DNSClass::IN,
RecordType::DS,
).unwrap();
}
#[test]
#[ignore]
fn test_dnssec_rollernet_td_tcp_mixed_case() {
use ::logger::TrustDnsLogger;
use log::LogLevel;
TrustDnsLogger::enable_logging(LogLevel::Debug);
let c = Client::new(TcpClientConnection::new("8.8.8.8:53".parse().unwrap()).unwrap());
c.secure_query(
&domain::Name::parse("RollErnet.Us.", None).unwrap(),
DNSClass::IN,
RecordType::DS,
).unwrap();

View File

@ -458,14 +458,14 @@ impl Signer {
// in canonical form.
assert!(sig::emit_pre_sig(&mut encoder, type_covered, algorithm,
name.num_labels(), original_ttl, sig_expiration,
sig_inception, key_tag, signer_name).is_ok());
sig_inception, key_tag, &signer_name).is_ok());
// construct the rrset signing data
for record in rrset {
// RR(i) = name | type | class | OrigTTL | RDATA length | RDATA
//
// name is calculated according to the function in the RFC 4035
assert!(name.emit_as_canonical(&mut encoder, true).is_ok());
assert!(name.to_lowercase().emit_as_canonical(&mut encoder, true).is_ok());
//
// type is the RRset type and all RRs in the class
assert!(type_covered.emit(&mut encoder).is_ok());

View File

@ -19,8 +19,9 @@
use std::ops::Index;
use std::sync::Arc as Rc;
use std::fmt;
use std::cmp::Ordering;
use std::cmp::{Ordering, PartialEq};
use std::char;
use std::hash::{Hash, Hasher};
use ::serialize::binary::*;
use ::error::*;
@ -28,7 +29,7 @@ use ::error::*;
/// TODO: all Names should be stored in a global "intern" space, and then everything that uses
/// them should be through references. As a workaround the Strings are all Rc as well as the array
/// TODO: Currently this probably doesn't support binary names, it would be nice to do that.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[derive(Debug, Eq, Clone)]
pub struct Name {
labels: Rc<Vec<Rc<String>>>
}
@ -95,7 +96,26 @@ impl Name {
self
}
/// Creates a new Name with all labels lowercased
///
/// ```
/// use trust_dns::rr::domain::Name;
/// use std::cmp::Ordering;
///
/// let example_com = Name::new().label("Example").label("Com");
/// assert_eq!(example_com.to_lowercase().cmp_with_case(&Name::new().label("example").label("com"), false), Ordering::Equal);
/// ```
pub fn to_lowercase(&self) -> Name {
let mut new_labels = Vec::with_capacity(self.labels.len());
for label in self.labels.iter() {
new_labels.push(label.to_lowercase());
}
Self::with_labels(new_labels)
}
/// Trims off the first part of the name, to help with searching for the domain piece
///
/// ```
/// use trust_dns::rr::domain::Name;
///
@ -114,6 +134,7 @@ impl Name {
}
/// Trims to the number of labels specified
///
/// ```
/// use trust_dns::rr::domain::Name;
///
@ -296,6 +317,20 @@ impl Name {
}
}
impl Hash for Name {
fn hash<H>(&self, state: &mut H) where H: Hasher {
for label in self.labels.iter() {
state.write(label.to_lowercase().as_bytes());
}
}
}
impl PartialEq<Name> for Name {
fn eq(&self, other: &Self) -> bool {
self.cmp_with_case(other, true) == Ordering::Equal
}
}
enum ParseState {
Label,
Escape1,
@ -443,7 +478,7 @@ impl Ord for Name {
/// \200.z.example
/// ```
fn cmp(&self, other: &Self) -> Ordering {
self.cmp_with_case(other, false)
self.cmp_with_case(other, true)
}
}
@ -592,7 +627,7 @@ mod tests {
for (left, right) in comparisons {
println!("left: {}, right: {}", left, right);
assert_eq!(left.cmp_with_case(&right, true), Ordering::Less);
assert_eq!(left.cmp(&right), Ordering::Less);
}
}
@ -606,7 +641,7 @@ mod tests {
for (left, right) in comparisons {
println!("left: {}, right: {}", left, right);
assert_eq!(left.cmp_with_case(&right, true), Ordering::Equal);
assert_eq!(left, right);
}
}
}