Update go-dnsstamps
This commit is contained in:
parent
0e8ca9009e
commit
67f46b3c3e
2
go.mod
2
go.mod
|
@ -14,7 +14,7 @@ require (
|
||||||
github.com/hashicorp/golang-lru v0.5.3
|
github.com/hashicorp/golang-lru v0.5.3
|
||||||
github.com/jedisct1/dlog v0.0.0-20190909160351-692385b00b84
|
github.com/jedisct1/dlog v0.0.0-20190909160351-692385b00b84
|
||||||
github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c
|
github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c
|
||||||
github.com/jedisct1/go-dnsstamps v0.0.0-20190803222545-08225c1155d6
|
github.com/jedisct1/go-dnsstamps v0.0.0-20191014002100-c2d13697a562
|
||||||
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
|
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
|
||||||
github.com/jedisct1/xsecretbox v0.0.0-20190909160646-b731c21297f9
|
github.com/jedisct1/xsecretbox v0.0.0-20190909160646-b731c21297f9
|
||||||
github.com/k-sone/critbitgo v1.3.0
|
github.com/k-sone/critbitgo v1.3.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -29,8 +29,8 @@ github.com/jedisct1/dlog v0.0.0-20190909160351-692385b00b84 h1:7Q8p5MNx7fMvIRFir
|
||||||
github.com/jedisct1/dlog v0.0.0-20190909160351-692385b00b84/go.mod h1:YXh1b5j+lwirsCCtTJW19DrbpaL9/5UzwNjI78Cvrg8=
|
github.com/jedisct1/dlog v0.0.0-20190909160351-692385b00b84/go.mod h1:YXh1b5j+lwirsCCtTJW19DrbpaL9/5UzwNjI78Cvrg8=
|
||||||
github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c h1:a/NQUT7AXkEfhaZ+nb7Uzqijo1Qc7C7SZpRrv+6UQDA=
|
github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c h1:a/NQUT7AXkEfhaZ+nb7Uzqijo1Qc7C7SZpRrv+6UQDA=
|
||||||
github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c/go.mod h1:SAINchklztk2jcLWJ4bpNF4KnwDUSUTX+cJbspWC2Rw=
|
github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c/go.mod h1:SAINchklztk2jcLWJ4bpNF4KnwDUSUTX+cJbspWC2Rw=
|
||||||
github.com/jedisct1/go-dnsstamps v0.0.0-20190803222545-08225c1155d6 h1:0vwkpax+Bn4kD4WfTt5zjJopa87vIJhSeTA//hv0uG0=
|
github.com/jedisct1/go-dnsstamps v0.0.0-20191014002100-c2d13697a562 h1:IAhd67mYXfbNe3HEasqunc2Bz6ZK1FF5eDLBnyKUyB4=
|
||||||
github.com/jedisct1/go-dnsstamps v0.0.0-20190803222545-08225c1155d6/go.mod h1:PCThSkefP5QIL83fIkZ3Qi5Jt02JlWTFB1j9h69Sf2Y=
|
github.com/jedisct1/go-dnsstamps v0.0.0-20191014002100-c2d13697a562/go.mod h1:PCThSkefP5QIL83fIkZ3Qi5Jt02JlWTFB1j9h69Sf2Y=
|
||||||
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e h1:UvSe12bq+Uj2hWd8aOlwPmoZ+CITRFrdit+sDGfAg8U=
|
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e h1:UvSe12bq+Uj2hWd8aOlwPmoZ+CITRFrdit+sDGfAg8U=
|
||||||
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU=
|
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU=
|
||||||
github.com/jedisct1/xsecretbox v0.0.0-20190909160646-b731c21297f9 h1:nGfB2s9K0GyHuNkJmXkIjP+m7je6Q6gjirr+weAEtDo=
|
github.com/jedisct1/xsecretbox v0.0.0-20190909160646-b731c21297f9 h1:nGfB2s9K0GyHuNkJmXkIjP+m7je6Q6gjirr+weAEtDo=
|
||||||
|
|
|
@ -28,6 +28,7 @@ const (
|
||||||
StampProtoTypeDNSCrypt = StampProtoType(0x01)
|
StampProtoTypeDNSCrypt = StampProtoType(0x01)
|
||||||
StampProtoTypeDoH = StampProtoType(0x02)
|
StampProtoTypeDoH = StampProtoType(0x02)
|
||||||
StampProtoTypeTLS = StampProtoType(0x03)
|
StampProtoTypeTLS = StampProtoType(0x03)
|
||||||
|
StampProtoTypeDNSCryptRelay = StampProtoType(0x81)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (stampProtoType *StampProtoType) String() string {
|
func (stampProtoType *StampProtoType) String() string {
|
||||||
|
@ -38,6 +39,8 @@ func (stampProtoType *StampProtoType) String() string {
|
||||||
return "DNSCrypt"
|
return "DNSCrypt"
|
||||||
case StampProtoTypeDoH:
|
case StampProtoTypeDoH:
|
||||||
return "DoH"
|
return "DoH"
|
||||||
|
case StampProtoTypeDNSCryptRelay:
|
||||||
|
return "Anonymized DNSCrypt"
|
||||||
default:
|
default:
|
||||||
panic("Unexpected protocol")
|
panic("Unexpected protocol")
|
||||||
}
|
}
|
||||||
|
@ -89,6 +92,8 @@ func NewServerStampFromString(stampStr string) (ServerStamp, error) {
|
||||||
return newDNSCryptServerStamp(bin)
|
return newDNSCryptServerStamp(bin)
|
||||||
} else if bin[0] == uint8(StampProtoTypeDoH) {
|
} else if bin[0] == uint8(StampProtoTypeDoH) {
|
||||||
return newDoHServerStamp(bin)
|
return newDoHServerStamp(bin)
|
||||||
|
} else if bin[0] == uint8(StampProtoTypeDNSCryptRelay) {
|
||||||
|
return newDNSCryptRelayStamp(bin)
|
||||||
}
|
}
|
||||||
return ServerStamp{}, errors.New("Unsupported stamp version or protocol")
|
return ServerStamp{}, errors.New("Unsupported stamp version or protocol")
|
||||||
}
|
}
|
||||||
|
@ -236,11 +241,56 @@ func newDoHServerStamp(bin []byte) (ServerStamp, error) {
|
||||||
return stamp, nil
|
return stamp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// id(u8)=0x81 addrLen(1) serverAddr
|
||||||
|
|
||||||
|
func newDNSCryptRelayStamp(bin []byte) (ServerStamp, error) {
|
||||||
|
stamp := ServerStamp{Proto: StampProtoTypeDNSCryptRelay}
|
||||||
|
if len(bin) < 13 {
|
||||||
|
return stamp, errors.New("Stamp is too short")
|
||||||
|
}
|
||||||
|
binLen := len(bin)
|
||||||
|
pos := 0
|
||||||
|
length := int(bin[pos])
|
||||||
|
if 1+length >= binLen-pos {
|
||||||
|
return stamp, errors.New("Invalid stamp")
|
||||||
|
}
|
||||||
|
pos++
|
||||||
|
stamp.ServerAddrStr = string(bin[pos : pos+length])
|
||||||
|
pos += length
|
||||||
|
|
||||||
|
colIndex := strings.LastIndex(stamp.ServerAddrStr, ":")
|
||||||
|
bracketIndex := strings.LastIndex(stamp.ServerAddrStr, "]")
|
||||||
|
if colIndex < bracketIndex {
|
||||||
|
colIndex = -1
|
||||||
|
}
|
||||||
|
if colIndex < 0 {
|
||||||
|
colIndex = len(stamp.ServerAddrStr)
|
||||||
|
stamp.ServerAddrStr = fmt.Sprintf("%s:%d", stamp.ServerAddrStr, DefaultPort)
|
||||||
|
}
|
||||||
|
if colIndex >= len(stamp.ServerAddrStr)-1 {
|
||||||
|
return stamp, errors.New("Invalid stamp (empty port)")
|
||||||
|
}
|
||||||
|
ipOnly := stamp.ServerAddrStr[:colIndex]
|
||||||
|
portOnly := stamp.ServerAddrStr[colIndex+1:]
|
||||||
|
if _, err := strconv.ParseUint(portOnly, 10, 16); err != nil {
|
||||||
|
return stamp, errors.New("Invalid stamp (port range)")
|
||||||
|
}
|
||||||
|
if net.ParseIP(strings.TrimRight(strings.TrimLeft(ipOnly, "["), "]")) == nil {
|
||||||
|
return stamp, errors.New("Invalid stamp (IP address)")
|
||||||
|
}
|
||||||
|
if pos != binLen {
|
||||||
|
return stamp, errors.New("Invalid stamp (garbage after end)")
|
||||||
|
}
|
||||||
|
return stamp, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (stamp *ServerStamp) String() string {
|
func (stamp *ServerStamp) String() string {
|
||||||
if stamp.Proto == StampProtoTypeDNSCrypt {
|
if stamp.Proto == StampProtoTypeDNSCrypt {
|
||||||
return stamp.dnsCryptString()
|
return stamp.dnsCryptString()
|
||||||
} else if stamp.Proto == StampProtoTypeDoH {
|
} else if stamp.Proto == StampProtoTypeDoH {
|
||||||
return stamp.dohString()
|
return stamp.dohString()
|
||||||
|
} else if stamp.Proto == StampProtoTypeDNSCryptRelay {
|
||||||
|
return stamp.dnsCryptRelayString()
|
||||||
}
|
}
|
||||||
panic("Unsupported protocol")
|
panic("Unsupported protocol")
|
||||||
}
|
}
|
||||||
|
@ -300,3 +350,19 @@ func (stamp *ServerStamp) dohString() string {
|
||||||
|
|
||||||
return "sdns://" + str
|
return "sdns://" + str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (stamp *ServerStamp) dnsCryptRelayString() string {
|
||||||
|
bin := make([]uint8, 1)
|
||||||
|
bin[0] = uint8(StampProtoTypeDNSCryptRelay)
|
||||||
|
|
||||||
|
serverAddrStr := stamp.ServerAddrStr
|
||||||
|
if strings.HasSuffix(serverAddrStr, ":"+strconv.Itoa(DefaultPort)) {
|
||||||
|
serverAddrStr = serverAddrStr[:len(serverAddrStr)-1-len(strconv.Itoa(DefaultPort))]
|
||||||
|
}
|
||||||
|
bin = append(bin, uint8(len(serverAddrStr)))
|
||||||
|
bin = append(bin, []uint8(serverAddrStr)...)
|
||||||
|
|
||||||
|
str := base64.RawURLEncoding.EncodeToString(bin)
|
||||||
|
|
||||||
|
return "sdns://" + str
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ github.com/hashicorp/golang-lru/simplelru
|
||||||
github.com/jedisct1/dlog
|
github.com/jedisct1/dlog
|
||||||
# github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c
|
# github.com/jedisct1/go-clocksmith v0.0.0-20190707124905-73e087c7979c
|
||||||
github.com/jedisct1/go-clocksmith
|
github.com/jedisct1/go-clocksmith
|
||||||
# github.com/jedisct1/go-dnsstamps v0.0.0-20190803222545-08225c1155d6
|
# github.com/jedisct1/go-dnsstamps v0.0.0-20191014002100-c2d13697a562
|
||||||
github.com/jedisct1/go-dnsstamps
|
github.com/jedisct1/go-dnsstamps
|
||||||
# github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
|
# github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e
|
||||||
github.com/jedisct1/go-minisign
|
github.com/jedisct1/go-minisign
|
||||||
|
|
Loading…
Reference in New Issue