fix(netxlite): reject replies with wrong queryID (#732)

This diff has been extracted from c2f7ccab0e

See https://github.com/ooni/probe/issues/2096

While there, export DecodeReply to decode a raw reply without
interpreting the Rcode or parsing the results, which seems a
nice extra feature to have to more flexibly parse DNS replies
in other parts of the codebase.
This commit is contained in:
Simone Basso 2022-05-14 19:38:46 +02:00 committed by GitHub
commit 9d2301cae2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 261 additions and 128 deletions

View file

@ -84,7 +84,7 @@ func (r *SerialResolver) LookupHost(ctx context.Context, hostname string) ([]str
// LookupHTTPS implements Resolver.LookupHTTPS.
func (r *SerialResolver) LookupHTTPS(
ctx context.Context, hostname string) (*model.HTTPSSvc, error) {
querydata, err := r.Encoder.Encode(
querydata, queryID, err := r.Encoder.Encode(
hostname, dns.TypeHTTPS, r.Txp.RequiresPadding())
if err != nil {
return nil, err
@ -93,7 +93,7 @@ func (r *SerialResolver) LookupHTTPS(
if err != nil {
return nil, err
}
return r.Decoder.DecodeHTTPS(replydata)
return r.Decoder.DecodeHTTPS(replydata, queryID)
}
func (r *SerialResolver) lookupHostWithRetry(
@ -126,7 +126,7 @@ func (r *SerialResolver) lookupHostWithRetry(
// qtype (dns.A or dns.AAAA) without retrying on failure.
func (r *SerialResolver) lookupHostWithoutRetry(
ctx context.Context, hostname string, qtype uint16) ([]string, error) {
querydata, err := r.Encoder.Encode(hostname, qtype, r.Txp.RequiresPadding())
querydata, queryID, err := r.Encoder.Encode(hostname, qtype, r.Txp.RequiresPadding())
if err != nil {
return nil, err
}
@ -134,5 +134,5 @@ func (r *SerialResolver) lookupHostWithoutRetry(
if err != nil {
return nil, err
}
return r.Decoder.DecodeLookupHost(qtype, replydata)
return r.Decoder.DecodeLookupHost(qtype, replydata, queryID)
}