Skip to content

Commit d4a9e37

Browse files
authored
Allow RRSIG algorithm mnemonics (#1456)
* 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 <[email protected]> * Check parsed algorithm Signed-off-by: Miek Gieben <[email protected]> --------- Signed-off-by: Miek Gieben <[email protected]>
1 parent f07f1e6 commit d4a9e37

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

parse_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,3 +1975,26 @@ func TestParseOPENPGPKEY(t *testing.T) {
19751975
}
19761976
}
19771977
}
1978+
1979+
func TestParseRRSIGAlgNames(t *testing.T) {
1980+
tests := map[string]uint8{
1981+
`miek.nl. IN RRSIG SOA RSASHA1 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: RSASHA1,
1982+
`miek.nl. IN RRSIG SOA RSAMD5 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: RSAMD5,
1983+
`miek.nl. IN RRSIG SOA ECC-GOST 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ECCGOST,
1984+
`miek.nl. IN RRSIG SOA ED448 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ED448,
1985+
`miek.nl. IN RRSIG SOA ECDSAP256SHA256 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: ECDSAP256SHA256,
1986+
`miek.nl. IN RRSIG SOA INDIRECT 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: INDIRECT,
1987+
`miek.nl. IN RRSIG SOA BLA 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: 0,
1988+
`miek.nl. IN RRSIG SOA - 2 43200 20140210031301 20140111031301 12051 miek.nl. MVZUyrYwq0iZhMFDDnVXD2Bvu7pcBoc=`: 0,
1989+
}
1990+
for r, alg := range tests {
1991+
rr, err := NewRR(r)
1992+
if alg != 0 && err != nil {
1993+
t.Error(err)
1994+
continue
1995+
}
1996+
if alg != 0 && rr.(*RRSIG).Algorithm != alg {
1997+
t.Errorf("expecting alg %d, got %d", alg, rr.(*RRSIG).Algorithm)
1998+
}
1999+
}
2000+
}

scan_rr.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,18 @@ func (rr *RRSIG) parse(c *zlexer, o string) *ParseError {
904904

905905
c.Next() // zBlank
906906
l, _ = c.Next()
907-
i, e := strconv.ParseUint(l.token, 10, 8)
908-
if e != nil || l.err {
907+
if l.err {
909908
return &ParseError{"", "bad RRSIG Algorithm", l}
910909
}
911-
rr.Algorithm = uint8(i)
910+
i, e := strconv.ParseUint(l.token, 10, 8)
911+
rr.Algorithm = uint8(i) // if 0 we'll check the mnemonic in the if
912+
if e != nil {
913+
v, ok := StringToAlgorithm[l.token]
914+
if !ok {
915+
return &ParseError{"", "bad RRSIG Algorithm", l}
916+
}
917+
rr.Algorithm = v
918+
}
912919

913920
c.Next() // zBlank
914921
l, _ = c.Next()

0 commit comments

Comments
 (0)