mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-05-24 10:55:24 +00:00
Implement IETF protocol
This commit is contained in:
+23
-21
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017 Star Brilliant <m13253@hotmail.com>
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
@@ -27,17 +27,19 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
type dnsError struct {
|
||||
Status uint32 `json:"Status"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
Status uint32 `json:"Status"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
}
|
||||
|
||||
func FormatError(w http.ResponseWriter, comment string, errcode int) {
|
||||
errJson := dnsError {
|
||||
Status: dns.RcodeServerFailure,
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
errJson := dnsError{
|
||||
Status: dns.RcodeServerFailure,
|
||||
Comment: comment,
|
||||
}
|
||||
errStr, err := json.Marshal(errJson)
|
||||
|
||||
+61
-61
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017 Star Brilliant <m13253@hotmail.com>
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
@@ -28,80 +28,80 @@ import (
|
||||
)
|
||||
|
||||
// RFC6890
|
||||
var localIPv4Nets = []net.IPNet {
|
||||
var localIPv4Nets = []net.IPNet{
|
||||
// This host on this network
|
||||
net.IPNet {
|
||||
net.IP { 0, 0, 0, 0 },
|
||||
net.IPMask { 255, 0, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{0, 0, 0, 0},
|
||||
net.IPMask{255, 0, 0, 0},
|
||||
},
|
||||
// Private-Use Networks
|
||||
net.IPNet {
|
||||
net.IP { 10, 0, 0, 0 },
|
||||
net.IPMask { 255, 0, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{10, 0, 0, 0},
|
||||
net.IPMask{255, 0, 0, 0},
|
||||
},
|
||||
// Shared Address Space
|
||||
net.IPNet {
|
||||
net.IP { 100, 64, 0, 0 },
|
||||
net.IPMask { 255, 192, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{100, 64, 0, 0},
|
||||
net.IPMask{255, 192, 0, 0},
|
||||
},
|
||||
// Loopback
|
||||
net.IPNet {
|
||||
net.IP { 127, 0, 0, 0 },
|
||||
net.IPMask { 255, 0, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{127, 0, 0, 0},
|
||||
net.IPMask{255, 0, 0, 0},
|
||||
},
|
||||
// Link Local
|
||||
net.IPNet {
|
||||
net.IP { 169, 254, 0, 0 },
|
||||
net.IPMask { 255, 255, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{169, 254, 0, 0},
|
||||
net.IPMask{255, 255, 0, 0},
|
||||
},
|
||||
// Private-Use Networks
|
||||
net.IPNet {
|
||||
net.IP { 172, 16, 0, 0 },
|
||||
net.IPMask { 255, 240, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{172, 16, 0, 0},
|
||||
net.IPMask{255, 240, 0, 0},
|
||||
},
|
||||
// DS-Lite
|
||||
net.IPNet {
|
||||
net.IP { 192, 0, 0, 0 },
|
||||
net.IPMask { 255, 255, 255, 248 },
|
||||
net.IPNet{
|
||||
net.IP{192, 0, 0, 0},
|
||||
net.IPMask{255, 255, 255, 248},
|
||||
},
|
||||
// 6to4 Relay Anycast
|
||||
net.IPNet {
|
||||
net.IP { 192, 88, 99, 0 },
|
||||
net.IPMask { 255, 255, 255, 0 },
|
||||
net.IPNet{
|
||||
net.IP{192, 88, 99, 0},
|
||||
net.IPMask{255, 255, 255, 0},
|
||||
},
|
||||
// Private-Use Networks
|
||||
net.IPNet {
|
||||
net.IP { 192, 168, 0, 0 },
|
||||
net.IPMask { 255, 255, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{192, 168, 0, 0},
|
||||
net.IPMask{255, 255, 0, 0},
|
||||
},
|
||||
// Reserved for Future Use & Limited Broadcast
|
||||
net.IPNet {
|
||||
net.IP { 240, 0, 0, 0 },
|
||||
net.IPMask { 240, 0, 0, 0 },
|
||||
net.IPNet{
|
||||
net.IP{240, 0, 0, 0},
|
||||
net.IPMask{240, 0, 0, 0},
|
||||
},
|
||||
}
|
||||
|
||||
// RFC6890
|
||||
var localIPv6Nets = []net.IPNet {
|
||||
var localIPv6Nets = []net.IPNet{
|
||||
// Unspecified & Loopback Address
|
||||
net.IPNet {
|
||||
net.IP { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
net.IPMask { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe },
|
||||
net.IPNet{
|
||||
net.IP{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe},
|
||||
},
|
||||
// Discard-Only Prefix
|
||||
net.IPNet {
|
||||
net.IP { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
net.IPMask { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
net.IPNet{
|
||||
net.IP{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
},
|
||||
// Unique-Local
|
||||
net.IPNet {
|
||||
net.IP { 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
net.IPMask { 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
net.IPNet{
|
||||
net.IP{0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
},
|
||||
// Linked-Scoped Unicast
|
||||
net.IPNet {
|
||||
net.IP { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
net.IPMask { 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
net.IPNet{
|
||||
net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
net.IPMask{0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+21
-20
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017 Star Brilliant <m13253@hotmail.com>
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -44,7 +45,7 @@ func Marshal(msg *dns.Msg) *Response {
|
||||
|
||||
resp.Question = make([]Question, 0, len(msg.Question))
|
||||
for _, question := range msg.Question {
|
||||
jsonQuestion := Question {
|
||||
jsonQuestion := Question{
|
||||
Name: question.Name,
|
||||
Type: question.Qtype,
|
||||
}
|
||||
@@ -85,7 +86,7 @@ func Marshal(msg *dns.Msg) *Response {
|
||||
edns0 := option.(*dns.EDNS0_SUBNET)
|
||||
clientAddress := edns0.Address
|
||||
if clientAddress == nil {
|
||||
clientAddress = net.IP { 0, 0, 0, 0 }
|
||||
clientAddress = net.IP{0, 0, 0, 0}
|
||||
} else if ipv4 := clientAddress.To4(); ipv4 != nil {
|
||||
clientAddress = ipv4
|
||||
}
|
||||
@@ -106,7 +107,7 @@ func Marshal(msg *dns.Msg) *Response {
|
||||
}
|
||||
|
||||
func marshalRR(rr dns.RR, now time.Time) RR {
|
||||
jsonRR := RR {}
|
||||
jsonRR := RR{}
|
||||
rrHeader := rr.Header()
|
||||
jsonRR.Name = rrHeader.Name
|
||||
jsonRR.Type = rrHeader.Rrtype
|
||||
|
||||
+38
-38
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017 Star Brilliant <m13253@hotmail.com>
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
@@ -29,44 +29,44 @@ import (
|
||||
|
||||
type Response struct {
|
||||
// Standard DNS response code (32 bit integer)
|
||||
Status uint32 `json:"Status"`
|
||||
Status uint32 `json:"Status"`
|
||||
// Whether the response is truncated
|
||||
TC bool `json:"TC"`
|
||||
TC bool `json:"TC"`
|
||||
// Recursion desired
|
||||
RD bool `json:"RD"`
|
||||
RD bool `json:"RD"`
|
||||
// Recursion available
|
||||
RA bool `json:"RA"`
|
||||
RA bool `json:"RA"`
|
||||
// Whether all response data was validated with DNSSEC
|
||||
// FIXME: We don't have DNSSEC yet! This bit is not reliable!
|
||||
AD bool `json:"AD"`
|
||||
AD bool `json:"AD"`
|
||||
// Whether the client asked to disable DNSSEC
|
||||
CD bool `json:"CD"`
|
||||
Question []Question `json:"Question"`
|
||||
Answer []RR `json:"Answer,omitempty"`
|
||||
Authority []RR `json:"Authority,omitempty"`
|
||||
Additional []RR `json:"Additional,omitempty"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||
CD bool `json:"CD"`
|
||||
Question []Question `json:"Question"`
|
||||
Answer []RR `json:"Answer,omitempty"`
|
||||
Authority []RR `json:"Authority,omitempty"`
|
||||
Additional []RR `json:"Additional,omitempty"`
|
||||
Comment string `json:"Comment,omitempty"`
|
||||
EdnsClientSubnet string `json:"edns_client_subnet,omitempty"`
|
||||
// Least time-to-live
|
||||
HaveTTL bool `json:"-"`
|
||||
LeastTTL uint32 `json:"-"`
|
||||
EarliestExpires time.Time `json:"-"`
|
||||
HaveTTL bool `json:"-"`
|
||||
LeastTTL uint32 `json:"-"`
|
||||
EarliestExpires time.Time `json:"-"`
|
||||
}
|
||||
|
||||
type Question struct {
|
||||
// FQDN with trailing dot
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name"`
|
||||
// Standard DNS RR type
|
||||
Type uint16 `json:"type"`
|
||||
Type uint16 `json:"type"`
|
||||
}
|
||||
|
||||
type RR struct {
|
||||
Question
|
||||
// Record's time-to-live in seconds
|
||||
TTL uint32 `json:"TTL"`
|
||||
TTL uint32 `json:"TTL"`
|
||||
// TTL in absolute time
|
||||
Expires time.Time `json:"-"`
|
||||
ExpiresStr string `json:"Expires"`
|
||||
Expires time.Time `json:"-"`
|
||||
ExpiresStr string `json:"Expires"`
|
||||
// Data
|
||||
Data string `json:"data"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
+28
-27
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017 Star Brilliant <m13253@hotmail.com>
|
||||
DNS-over-HTTPS
|
||||
Copyright (C) 2017-2018 Star Brilliant <m13253@hotmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package jsonDNS
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
@@ -77,7 +78,7 @@ func Unmarshal(msg *dns.Msg, resp *Response, udpSize uint16, ednsClientNetmask u
|
||||
}
|
||||
}
|
||||
|
||||
reply.Extra = make([]dns.RR, 0, len(resp.Additional) + 1)
|
||||
reply.Extra = make([]dns.RR, 0, len(resp.Additional)+1)
|
||||
opt := new(dns.OPT)
|
||||
opt.Hdr.Name = "."
|
||||
opt.Hdr.Rrtype = dns.TypeOPT
|
||||
@@ -94,20 +95,20 @@ func Unmarshal(msg *dns.Msg, resp *Response, udpSize uint16, ednsClientNetmask u
|
||||
if ednsClientSubnet != "" {
|
||||
slash := strings.IndexByte(ednsClientSubnet, '/')
|
||||
if slash < 0 {
|
||||
log.Println(UnmarshalError { "Invalid client subnet" })
|
||||
log.Println(UnmarshalError{"Invalid client subnet"})
|
||||
} else {
|
||||
ednsClientAddress = net.ParseIP(ednsClientSubnet[:slash])
|
||||
if ednsClientAddress == nil {
|
||||
log.Println(UnmarshalError { "Invalid client subnet address" })
|
||||
log.Println(UnmarshalError{"Invalid client subnet address"})
|
||||
} else if ipv4 := ednsClientAddress.To4(); ipv4 != nil {
|
||||
ednsClientFamily = 1
|
||||
ednsClientAddress = ipv4
|
||||
} else {
|
||||
ednsClientFamily = 2
|
||||
}
|
||||
scope, err := strconv.ParseUint(ednsClientSubnet[slash + 1:], 10, 8)
|
||||
scope, err := strconv.ParseUint(ednsClientSubnet[slash+1:], 10, 8)
|
||||
if err != nil {
|
||||
log.Println(UnmarshalError { "Invalid client subnet address" })
|
||||
log.Println(UnmarshalError{"Invalid client subnet address"})
|
||||
} else {
|
||||
ednsClientScope = uint8(scope)
|
||||
}
|
||||
@@ -147,12 +148,12 @@ func Unmarshal(msg *dns.Msg, resp *Response, udpSize uint16, ednsClientNetmask u
|
||||
|
||||
func unmarshalRR(rr RR, now time.Time) (dnsRR dns.RR, err error) {
|
||||
if strings.ContainsAny(rr.Name, "\t\r\n \"();\\") {
|
||||
return nil, UnmarshalError { fmt.Sprintf("Record name contains space: %q", rr.Name) }
|
||||
return nil, UnmarshalError{fmt.Sprintf("Record name contains space: %q", rr.Name)}
|
||||
}
|
||||
if rr.ExpiresStr != "" {
|
||||
rr.Expires, err = time.Parse(time.RFC1123, rr.ExpiresStr)
|
||||
if err != nil {
|
||||
return nil, UnmarshalError { fmt.Sprintf("Invalid expire time: %q", rr.ExpiresStr) }
|
||||
return nil, UnmarshalError{fmt.Sprintf("Invalid expire time: %q", rr.ExpiresStr)}
|
||||
}
|
||||
ttl := rr.Expires.Sub(now) / time.Second
|
||||
if ttl >= 0 && ttl <= 0xffffffff {
|
||||
@@ -161,10 +162,10 @@ func unmarshalRR(rr RR, now time.Time) (dnsRR dns.RR, err error) {
|
||||
}
|
||||
rrType, ok := dns.TypeToString[rr.Type]
|
||||
if !ok {
|
||||
return nil, UnmarshalError { fmt.Sprintf("Unknown record type: %d", rr.Type) }
|
||||
return nil, UnmarshalError{fmt.Sprintf("Unknown record type: %d", rr.Type)}
|
||||
}
|
||||
if strings.ContainsAny(rr.Data, "\r\n") {
|
||||
return nil, UnmarshalError { fmt.Sprintf("Record data contains newline: %q", rr.Data) }
|
||||
return nil, UnmarshalError{fmt.Sprintf("Record data contains newline: %q", rr.Data)}
|
||||
}
|
||||
zone := fmt.Sprintf("%s %d IN %s %s", rr.Name, rr.TTL, rrType, rr.Data)
|
||||
dnsRR, err = dns.NewRR(zone)
|
||||
@@ -172,7 +173,7 @@ func unmarshalRR(rr RR, now time.Time) (dnsRR dns.RR, err error) {
|
||||
}
|
||||
|
||||
type UnmarshalError struct {
|
||||
err string
|
||||
err string
|
||||
}
|
||||
|
||||
func (e UnmarshalError) Error() string {
|
||||
|
||||
Reference in New Issue
Block a user