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

validate: ensure scan canonicalizes SecAlg and validation as well #127

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions src/base/iana/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ macro_rules! int_enum_str_with_decimal {
scanner: &mut $crate::master::scan::Scanner<C>,
) -> Result<Self, $crate::master::scan::ScanError> {
scanner.scan_string_word(|word| {
core::str::FromStr::from_str(&word).map_err(|_| {
$crate::master::scan::SyntaxError::UnknownMnemonic
})
core::str::FromStr::from_str(&word)
.map_err(|_| {
$crate::master::scan::SyntaxError::UnknownMnemonic
})
.map($ianatype::from_int)
})
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,19 @@ impl<Octets: AsRef<[u8]>, Name: Compose> RrsigExt for Rrsig<Octets, Name> {
let signature = self.signature().as_ref();
let signed_data = signed_data.as_ref();

match self.algorithm() {
// Caller needs to ensure that the signature matches the key, but enforce the algorithm match
if self.algorithm() != dnskey.algorithm() {
return Err(AlgorithmError::InvalidData);
}

// Note: Canonicalize the algorithm, otherwise matching named variants against Int(_) is not going to work
let sec_alg = SecAlg::from_int(self.algorithm().to_int());
match sec_alg {
SecAlg::RsaSha1
| SecAlg::RsaSha1Nsec3Sha1
| SecAlg::RsaSha256
| SecAlg::RsaSha512 => {
let (algorithm, min_bytes) = match self.algorithm() {
let (algorithm, min_bytes) = match sec_alg {
SecAlg::RsaSha1 | SecAlg::RsaSha1Nsec3Sha1 => (
&signature::RSA_PKCS1_1024_8192_SHA1_FOR_LEGACY_USE_ONLY,
1024 / 8,
Expand All @@ -240,7 +247,7 @@ impl<Octets: AsRef<[u8]>, Name: Compose> RrsigExt for Rrsig<Octets, Name> {
.map_err(|_| AlgorithmError::BadSig)
}
SecAlg::EcdsaP256Sha256 | SecAlg::EcdsaP384Sha384 => {
let algorithm = match self.algorithm() {
let algorithm = match sec_alg {
SecAlg::EcdsaP256Sha256 => {
&signature::ECDSA_P256_SHA256_FIXED
}
Expand Down