Skip to content

Commit

Permalink
Allow RRSIG algorithm mnemonics (#1456)
Browse files Browse the repository at this point in the history
* Allow RRSIG algorithm mnemonics

Java outputs these *and* the RFC says we should parse them, so parse
them. We'll never output them though. Throwback to the "be lenient to
what you accept, but strict with what you output". Anyhow the diff is
tiny and it helps interop.

Fixes: #1447

Signed-off-by: Miek Gieben <miek@miek.nl>

* Check parsed algorithm

Signed-off-by: Miek Gieben <miek@miek.nl>

---------

Signed-off-by: Miek Gieben <miek@miek.nl>
  • Loading branch information
miekg committed Apr 28, 2023
1 parent f07f1e6 commit d4a9e37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
23 changes: 23 additions & 0 deletions parse_test.go
Expand Up @@ -1975,3 +1975,26 @@ func TestParseOPENPGPKEY(t *testing.T) {
}
}
}

func TestParseRRSIGAlgNames(t *testing.T) {
tests := map[string]uint8{
`miek.nl. IN RRSIG SOA RSASHA1 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: RSASHA1,
`miek.nl. IN RRSIG SOA RSAMD5 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: RSAMD5,
`miek.nl. IN RRSIG SOA ECC-GOST 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ECCGOST,
`miek.nl. IN RRSIG SOA ED448 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ED448,
`miek.nl. IN RRSIG SOA ECDSAP256SHA256 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ECDSAP256SHA256,
`miek.nl. IN RRSIG SOA INDIRECT 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: INDIRECT,
`miek.nl. IN RRSIG SOA BLA 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: 0,
`miek.nl. IN RRSIG SOA - 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: 0,
}
for r, alg := range tests {
rr, err := NewRR(r)
if alg != 0 && err != nil {
t.Error(err)
continue
}
if alg != 0 && rr.(*RRSIG).Algorithm != alg {
t.Errorf("expecting alg %d, got %d", alg, rr.(*RRSIG).Algorithm)
}
}
}
13 changes: 10 additions & 3 deletions scan_rr.go
Expand Up @@ -904,11 +904,18 @@ func (rr *RRSIG) parse(c *zlexer, o string) *ParseError {

c.Next() // zBlank
l, _ = c.Next()
i, e := strconv.ParseUint(l.token, 10, 8)
if e != nil || l.err {
if l.err {
return &ParseError{"", "bad RRSIG Algorithm", l}
}
rr.Algorithm = uint8(i)
i, e := strconv.ParseUint(l.token, 10, 8)
rr.Algorithm = uint8(i) // if 0 we'll check the mnemonic in the if
if e != nil {
v, ok := StringToAlgorithm[l.token]
if !ok {
return &ParseError{"", "bad RRSIG Algorithm", l}
}
rr.Algorithm = v
}

c.Next() // zBlank
l, _ = c.Next()
Expand Down

0 comments on commit d4a9e37

Please sign in to comment.