Split stamps into package

This commit is contained in:
gdm85 2018-04-14 15:03:21 +02:00 committed by Frank Denis
parent e49ce4f12b
commit eb5f391fa6
6 changed files with 113 additions and 107 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/jedisct1/dlog"
"github.com/jedisct1/dnscrypt-proxy/stamps"
)
type Config struct {
@ -380,11 +381,11 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) {
var summary []ServerSummary
for _, registeredServer := range proxy.registeredServers {
addrStr, port := registeredServer.stamp.serverAddrStr, DefaultPort
addrStr, port := registeredServer.stamp.ServerAddrStr, stamps.DefaultPort
port = ExtractPort(addrStr, port)
addrs := make([]string, 0)
if registeredServer.stamp.proto == StampProtoTypeDoH && len(registeredServer.stamp.providerName) > 0 {
providerName := registeredServer.stamp.providerName
if registeredServer.stamp.Proto == stamps.StampProtoTypeDoH && len(registeredServer.stamp.ProviderName) > 0 {
providerName := registeredServer.stamp.ProviderName
var host string
host, port = ExtractHostAndPort(providerName, port)
addrs = append(addrs, host)
@ -394,13 +395,13 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) {
}
serverSummary := ServerSummary{
Name: registeredServer.name,
Proto: registeredServer.stamp.proto.String(),
Proto: registeredServer.stamp.Proto.String(),
IPv6: strings.HasPrefix(addrStr, "["),
Ports: []int{port},
Addrs: addrs,
DNSSEC: registeredServer.stamp.props&ServerInformalPropertyDNSSEC != 0,
NoLog: registeredServer.stamp.props&ServerInformalPropertyNoLog != 0,
NoFilter: registeredServer.stamp.props&ServerInformalPropertyNoFilter != 0,
DNSSEC: registeredServer.stamp.Props&stamps.ServerInformalPropertyDNSSEC != 0,
NoLog: registeredServer.stamp.Props&stamps.ServerInformalPropertyNoLog != 0,
NoFilter: registeredServer.stamp.Props&stamps.ServerInformalPropertyNoFilter != 0,
Description: registeredServer.description,
}
if jsonOutput {
@ -419,15 +420,15 @@ func (config *Config) printRegisteredServers(proxy *Proxy, jsonOutput bool) {
}
func (config *Config) loadSources(proxy *Proxy) error {
requiredProps := ServerInformalProperties(0)
var requiredProps stamps.ServerInformalProperties
if config.SourceRequireDNSSEC {
requiredProps |= ServerInformalPropertyDNSSEC
requiredProps |= stamps.ServerInformalPropertyDNSSEC
}
if config.SourceRequireNoLog {
requiredProps |= ServerInformalPropertyNoLog
requiredProps |= stamps.ServerInformalPropertyNoLog
}
if config.SourceRequireNoFilter {
requiredProps |= ServerInformalPropertyNoFilter
requiredProps |= stamps.ServerInformalPropertyNoFilter
}
for cfgSourceName, cfgSource := range config.SourcesConfig {
if err := config.loadSource(proxy, requiredProps, cfgSourceName, &cfgSource); err != nil {
@ -447,7 +448,7 @@ func (config *Config) loadSources(proxy *Proxy) error {
if len(staticConfig.Stamp) == 0 {
dlog.Fatalf("Missing stamp for the static [%s] definition", serverName)
}
stamp, err := NewServerStampFromString(staticConfig.Stamp)
stamp, err := stamps.NewServerStampFromString(staticConfig.Stamp)
if err != nil {
return err
}
@ -456,7 +457,7 @@ func (config *Config) loadSources(proxy *Proxy) error {
return nil
}
func (config *Config) loadSource(proxy *Proxy, requiredProps ServerInformalProperties, cfgSourceName string, cfgSource *SourceConfig) error {
func (config *Config) loadSource(proxy *Proxy, requiredProps stamps.ServerInformalProperties, cfgSourceName string, cfgSource *SourceConfig) error {
if len(cfgSource.URLs) == 0 {
if len(cfgSource.URL) == 0 {
dlog.Debugf("Missing URLs for source [%s]", cfgSourceName)
@ -492,23 +493,23 @@ func (config *Config) loadSource(proxy *Proxy, requiredProps ServerInformalPrope
if !includesName(config.ServerNames, registeredServer.name) {
continue
}
} else if registeredServer.stamp.props&requiredProps != requiredProps {
} else if registeredServer.stamp.Props&requiredProps != requiredProps {
continue
}
if config.SourceIPv4 || config.SourceIPv6 {
isIPv4, isIPv6 := true, false
if registeredServer.stamp.proto == StampProtoTypeDoH {
if registeredServer.stamp.Proto == stamps.StampProtoTypeDoH {
isIPv4, isIPv6 = true, true
}
if strings.HasPrefix(registeredServer.stamp.serverAddrStr, "[") {
if strings.HasPrefix(registeredServer.stamp.ServerAddrStr, "[") {
isIPv4, isIPv6 = false, true
}
if !(config.SourceIPv4 == isIPv4 || config.SourceIPv6 == isIPv6) {
continue
}
}
if !((config.SourceDNSCrypt && registeredServer.stamp.proto == StampProtoTypeDNSCrypt) ||
(config.SourceDoH && registeredServer.stamp.proto == StampProtoTypeDoH)) {
if !((config.SourceDNSCrypt && registeredServer.stamp.Proto == stamps.StampProtoTypeDNSCrypt) ||
(config.SourceDoH && registeredServer.stamp.Proto == stamps.StampProtoTypeDoH)) {
continue
}
dlog.Debugf("Adding [%s] to the set of wanted resolvers", registeredServer.name)

View File

@ -11,6 +11,7 @@ import (
"github.com/jedisct1/dlog"
clocksmith "github.com/jedisct1/go-clocksmith"
"golang.org/x/crypto/curve25519"
"github.com/jedisct1/dnscrypt-proxy/stamps"
)
type Proxy struct {
@ -274,7 +275,7 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
}
if len(response) == 0 {
var ttl *uint32
if serverInfo.Proto == StampProtoTypeDNSCrypt {
if serverInfo.Proto == stamps.StampProtoTypeDNSCrypt {
sharedKey, encryptedQuery, clientNonce, err := proxy.Encrypt(serverInfo, query, serverProto)
if err != nil {
return
@ -289,7 +290,7 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
serverInfo.noticeFailure(proxy)
return
}
} else if serverInfo.Proto == StampProtoTypeDoH {
} else if serverInfo.Proto == stamps.StampProtoTypeDoH {
tid := TransactionID(query)
SetTransactionID(query, 0)
serverInfo.noticeBegin(proxy)

View File

@ -17,31 +17,23 @@ import (
"github.com/VividCortex/ewma"
"github.com/jedisct1/dlog"
"github.com/jedisct1/dnscrypt-proxy/stamps"
"golang.org/x/crypto/ed25519"
)
const (
RTTEwmaDecay = 10.0
DefaultPort = 443
)
type ServerInformalProperties uint64
const (
ServerInformalPropertyDNSSEC = ServerInformalProperties(1) << 0
ServerInformalPropertyNoLog = ServerInformalProperties(1) << 1
ServerInformalPropertyNoFilter = ServerInformalProperties(1) << 2
)
type RegisteredServer struct {
name string
stamp ServerStamp
stamp stamps.ServerStamp
description string
}
type ServerInfo struct {
sync.RWMutex
Proto StampProtoType
Proto stamps.StampProtoType
MagicQuery [8]byte
ServerPk [32]byte
SharedKey [32]byte
@ -77,7 +69,7 @@ type ServersInfo struct {
lbStrategy LBStrategy
}
func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp ServerStamp) error {
func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp stamps.ServerStamp) error {
newRegisteredServer := RegisteredServer{name: name, stamp: stamp}
serversInfo.Lock()
defer serversInfo.Unlock()
@ -91,7 +83,7 @@ func (serversInfo *ServersInfo) registerServer(proxy *Proxy, name string, stamp
return nil
}
func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp ServerStamp) error {
func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp stamps.ServerStamp) error {
serversInfo.Lock()
defer serversInfo.Unlock()
previousIndex := -1
@ -206,38 +198,38 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
return serverInfo
}
func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp ServerStamp, isNew bool) (ServerInfo, error) {
if stamp.proto == StampProtoTypeDNSCrypt {
func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew bool) (ServerInfo, error) {
if stamp.Proto == stamps.StampProtoTypeDNSCrypt {
return serversInfo.fetchDNSCryptServerInfo(proxy, name, stamp, isNew)
} else if stamp.proto == StampProtoTypeDoH {
} else if stamp.Proto == stamps.StampProtoTypeDoH {
return serversInfo.fetchDoHServerInfo(proxy, name, stamp, isNew)
}
return ServerInfo{}, errors.New("Unsupported protocol")
}
func (serversInfo *ServersInfo) fetchDNSCryptServerInfo(proxy *Proxy, name string, stamp ServerStamp, isNew bool) (ServerInfo, error) {
if len(stamp.serverPk) != ed25519.PublicKeySize {
serverPk, err := hex.DecodeString(strings.Replace(string(stamp.serverPk), ":", "", -1))
func (serversInfo *ServersInfo) fetchDNSCryptServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew bool) (ServerInfo, error) {
if len(stamp.ServerPk) != ed25519.PublicKeySize {
serverPk, err := hex.DecodeString(strings.Replace(string(stamp.ServerPk), ":", "", -1))
if err != nil || len(serverPk) != ed25519.PublicKeySize {
dlog.Fatalf("Unsupported public key for [%s]: [%s]", name, stamp.serverPk)
dlog.Fatalf("Unsupported public key for [%s]: [%s]", name, stamp.ServerPk)
}
dlog.Warnf("Public key [%s] shouldn't be hex-encoded any more", string(stamp.serverPk))
stamp.serverPk = serverPk
dlog.Warnf("Public key [%s] shouldn't be hex-encoded any more", string(stamp.ServerPk))
stamp.ServerPk = serverPk
}
certInfo, rtt, err := FetchCurrentDNSCryptCert(proxy, &name, proxy.mainProto, stamp.serverPk, stamp.serverAddrStr, stamp.providerName, isNew)
certInfo, rtt, err := FetchCurrentDNSCryptCert(proxy, &name, proxy.mainProto, stamp.ServerPk, stamp.ServerAddrStr, stamp.ProviderName, isNew)
if err != nil {
return ServerInfo{}, err
}
remoteUDPAddr, err := net.ResolveUDPAddr("udp", stamp.serverAddrStr)
remoteUDPAddr, err := net.ResolveUDPAddr("udp", stamp.ServerAddrStr)
if err != nil {
return ServerInfo{}, err
}
remoteTCPAddr, err := net.ResolveTCPAddr("tcp", stamp.serverAddrStr)
remoteTCPAddr, err := net.ResolveTCPAddr("tcp", stamp.ServerAddrStr)
if err != nil {
return ServerInfo{}, err
}
return ServerInfo{
Proto: StampProtoTypeDNSCrypt,
Proto: stamps.StampProtoTypeDNSCrypt,
MagicQuery: certInfo.MagicQuery,
ServerPk: certInfo.ServerPk,
SharedKey: certInfo.SharedKey,
@ -250,18 +242,18 @@ func (serversInfo *ServersInfo) fetchDNSCryptServerInfo(proxy *Proxy, name strin
}, nil
}
func (serversInfo *ServersInfo) fetchDoHServerInfo(proxy *Proxy, name string, stamp ServerStamp, isNew bool) (ServerInfo, error) {
if len(stamp.serverAddrStr) > 0 {
addrStr := stamp.serverAddrStr
func (serversInfo *ServersInfo) fetchDoHServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew bool) (ServerInfo, error) {
if len(stamp.ServerAddrStr) > 0 {
addrStr := stamp.ServerAddrStr
ipOnly := addrStr[:strings.LastIndex(addrStr, ":")]
proxy.xTransport.cachedIPs.Lock()
proxy.xTransport.cachedIPs.cache[stamp.providerName] = ipOnly
proxy.xTransport.cachedIPs.cache[stamp.ProviderName] = ipOnly
proxy.xTransport.cachedIPs.Unlock()
}
url := &url.URL{
Scheme: "https",
Host: stamp.providerName,
Path: stamp.path,
Host: stamp.ProviderName,
Path: stamp.Path,
}
body := []byte{
0xca, 0xfe, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x29, 0x10, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
@ -293,7 +285,7 @@ func (serversInfo *ServersInfo) fetchDoHServerInfo(proxy *Proxy, name string, st
} else {
dlog.Debugf("Advertised cert: [%s] [%x]", cert.Subject, h)
}
for _, hash := range stamp.hashes {
for _, hash := range stamp.Hashes {
if len(hash) == len(wantedHash) {
copy(wantedHash[:], hash)
if h == wantedHash {
@ -306,7 +298,7 @@ func (serversInfo *ServersInfo) fetchDoHServerInfo(proxy *Proxy, name string, st
break
}
}
if !found && len(stamp.hashes) > 0 {
if !found && len(stamp.Hashes) > 0 {
return ServerInfo{}, fmt.Errorf("Certificate hash [%x] not found for [%s]", wantedHash, name)
}
respBody, err := ioutil.ReadAll(io.LimitReader(resp.Body, MaxHTTPBodyLength))
@ -323,11 +315,11 @@ func (serversInfo *ServersInfo) fetchDoHServerInfo(proxy *Proxy, name string, st
dlog.Infof("[%s] OK (DoH) - rtt: %dms", name, rtt.Nanoseconds()/1000000)
}
return ServerInfo{
Proto: StampProtoTypeDoH,
Proto: stamps.StampProtoTypeDoH,
Name: name,
Timeout: proxy.timeout,
URL: url,
HostName: stamp.providerName,
HostName: stamp.ProviderName,
initialRtt: int(rtt.Nanoseconds() / 1000000),
useGet: useGet,
}, nil

View File

@ -18,6 +18,7 @@ import (
"github.com/jedisct1/dlog"
"github.com/jedisct1/go-minisign"
"github.com/jedisct1/dnscrypt-proxy/stamps"
)
type SourceFormat int
@ -241,14 +242,14 @@ func (source *Source) parseV1(prefix string) ([]RegisteredServer, error) {
serverAddrStr := record[10]
providerName := record[11]
serverPkStr := record[12]
props := ServerInformalProperties(0)
props := stamps.ServerInformalProperties(0)
if strings.EqualFold(record[7], "yes") {
props |= ServerInformalPropertyDNSSEC
props |= stamps.ServerInformalPropertyDNSSEC
}
if strings.EqualFold(record[8], "yes") {
props |= ServerInformalPropertyNoLog
props |= stamps.ServerInformalPropertyNoLog
}
stamp, err := NewDNSCryptServerStampFromLegacy(serverAddrStr, serverPkStr, providerName, props)
stamp, err := stamps.NewDNSCryptServerStampFromLegacy(serverAddrStr, serverPkStr, providerName, props)
if err != nil {
return registeredServers, err
}
@ -301,7 +302,7 @@ func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
if len(stampStr) < 8 {
return registeredServers, fmt.Errorf("Missing stamp for server [%s] in source from [%v]", name, source.urls)
}
stamp, err := NewServerStampFromString(stampStr)
stamp, err := stamps.NewServerStampFromString(stampStr)
if err != nil {
return registeredServers, err
}

View File

@ -16,7 +16,8 @@ import (
"strings"
"sync"
"time"
"github.com/jedisct1/dnscrypt-proxy/stamps"
"github.com/jedisct1/dlog"
"github.com/miekg/dns"
"golang.org/x/net/http2"
@ -83,7 +84,7 @@ func (xTransport *XTransport) rebuildTransport() {
ExpectContinueTimeout: timeout,
MaxResponseHeaderBytes: 4096,
DialContext: func(ctx context.Context, network, addrStr string) (net.Conn, error) {
host, port := ExtractHostAndPort(addrStr, DefaultPort)
host, port := ExtractHostAndPort(addrStr, stamps.DefaultPort)
ipOnly := host
xTransport.cachedIPs.RLock()
cachedIP := xTransport.cachedIPs.cache[host]

View File

@ -1,4 +1,4 @@
package main
package stamps
import (
"encoding/base64"
@ -14,6 +14,16 @@ import (
"golang.org/x/crypto/ed25519"
)
const DefaultPort = 443
type ServerInformalProperties uint64
const (
ServerInformalPropertyDNSSEC = ServerInformalProperties(1) << 0
ServerInformalPropertyNoLog = ServerInformalProperties(1) << 1
ServerInformalPropertyNoFilter = ServerInformalProperties(1) << 2
)
type StampProtoType uint8
const (
@ -36,13 +46,13 @@ func (stampProtoType *StampProtoType) String() string {
}
type ServerStamp struct {
serverAddrStr string
serverPk []uint8
hashes [][]uint8
providerName string
path string
props ServerInformalProperties
proto StampProtoType
ServerAddrStr string
ServerPk []uint8
Hashes [][]uint8
ProviderName string
Path string
Props ServerInformalProperties
Proto StampProtoType
}
func NewDNSCryptServerStampFromLegacy(serverAddrStr string, serverPkStr string, providerName string, props ServerInformalProperties) (ServerStamp, error) {
@ -54,11 +64,11 @@ func NewDNSCryptServerStampFromLegacy(serverAddrStr string, serverPkStr string,
return ServerStamp{}, fmt.Errorf("Unsupported public key: [%s]", serverPkStr)
}
return ServerStamp{
serverAddrStr: serverAddrStr,
serverPk: serverPk,
providerName: providerName,
props: props,
proto: StampProtoTypeDNSCrypt,
ServerAddrStr: serverAddrStr,
ServerPk: serverPk,
ProviderName: providerName,
Props: props,
Proto: StampProtoTypeDNSCrypt,
}, nil
}
@ -84,11 +94,11 @@ func NewServerStampFromString(stampStr string) (ServerStamp, error) {
// id(u8)=0x01 props addrLen(1) serverAddr pkStrlen(1) pkStr providerNameLen(1) providerName
func newDNSCryptServerStamp(bin []byte) (ServerStamp, error) {
stamp := ServerStamp{proto: StampProtoTypeDNSCrypt}
stamp := ServerStamp{Proto: StampProtoTypeDNSCrypt}
if len(bin) < 66 {
return stamp, errors.New("Stamp is too short")
}
stamp.props = ServerInformalProperties(binary.LittleEndian.Uint64(bin[1:9]))
stamp.Props = ServerInformalProperties(binary.LittleEndian.Uint64(bin[1:9]))
binLen := len(bin)
pos := 9
@ -97,10 +107,10 @@ func newDNSCryptServerStamp(bin []byte) (ServerStamp, error) {
return stamp, errors.New("Invalid stamp")
}
pos++
stamp.serverAddrStr = string(bin[pos : pos+len])
stamp.ServerAddrStr = string(bin[pos : pos+len])
pos += len
if net.ParseIP(strings.TrimRight(strings.TrimLeft(stamp.serverAddrStr, "["), "]")) != nil {
stamp.serverAddrStr = fmt.Sprintf("%s:%d", stamp.serverAddrStr, DefaultPort)
if net.ParseIP(strings.TrimRight(strings.TrimLeft(stamp.ServerAddrStr, "["), "]")) != nil {
stamp.ServerAddrStr = fmt.Sprintf("%s:%d", stamp.ServerAddrStr, DefaultPort)
}
len = int(bin[pos])
@ -108,7 +118,7 @@ func newDNSCryptServerStamp(bin []byte) (ServerStamp, error) {
return stamp, errors.New("Invalid stamp")
}
pos++
stamp.serverPk = bin[pos : pos+len]
stamp.ServerPk = bin[pos : pos+len]
pos += len
len = int(bin[pos])
@ -116,7 +126,7 @@ func newDNSCryptServerStamp(bin []byte) (ServerStamp, error) {
return stamp, errors.New("Invalid stamp")
}
pos++
stamp.providerName = string(bin[pos : pos+len])
stamp.ProviderName = string(bin[pos : pos+len])
pos += len
if pos != binLen {
@ -128,11 +138,11 @@ func newDNSCryptServerStamp(bin []byte) (ServerStamp, error) {
// id(u8)=0x02 props addrLen(1) serverAddr hashLen(1) hash providerNameLen(1) providerName pathLen(1) path
func newDoHServerStamp(bin []byte) (ServerStamp, error) {
stamp := ServerStamp{proto: StampProtoTypeDoH, hashes: [][]byte{}}
stamp := ServerStamp{Proto: StampProtoTypeDoH}
if len(bin) < 22 {
return stamp, errors.New("Stamp is too short")
}
stamp.props = ServerInformalProperties(binary.LittleEndian.Uint64(bin[1:9]))
stamp.Props = ServerInformalProperties(binary.LittleEndian.Uint64(bin[1:9]))
binLen := len(bin)
pos := 9
@ -141,7 +151,7 @@ func newDoHServerStamp(bin []byte) (ServerStamp, error) {
return stamp, errors.New("Invalid stamp")
}
pos++
stamp.serverAddrStr = string(bin[pos : pos+len])
stamp.ServerAddrStr = string(bin[pos : pos+len])
pos += len
for {
@ -152,7 +162,7 @@ func newDoHServerStamp(bin []byte) (ServerStamp, error) {
}
pos++
if len > 0 {
stamp.hashes = append(stamp.hashes, bin[pos:pos+len])
stamp.Hashes = append(stamp.Hashes, bin[pos:pos+len])
}
pos += len
if vlen&0x80 != 0x80 {
@ -165,7 +175,7 @@ func newDoHServerStamp(bin []byte) (ServerStamp, error) {
return stamp, errors.New("Invalid stamp")
}
pos++
stamp.providerName = string(bin[pos : pos+len])
stamp.ProviderName = string(bin[pos : pos+len])
pos += len
len = int(bin[pos])
@ -173,24 +183,24 @@ func newDoHServerStamp(bin []byte) (ServerStamp, error) {
return stamp, errors.New("Invalid stamp")
}
pos++
stamp.path = string(bin[pos : pos+len])
stamp.Path = string(bin[pos : pos+len])
pos += len
if pos != binLen {
return stamp, errors.New("Invalid stamp (garbage after end)")
}
if net.ParseIP(strings.TrimRight(strings.TrimLeft(stamp.serverAddrStr, "["), "]")) != nil {
stamp.serverAddrStr = fmt.Sprintf("%s:%d", stamp.serverAddrStr, DefaultPort)
if net.ParseIP(strings.TrimRight(strings.TrimLeft(stamp.ServerAddrStr, "["), "]")) != nil {
stamp.ServerAddrStr = fmt.Sprintf("%s:%d", stamp.ServerAddrStr, DefaultPort)
}
return stamp, nil
}
func (stamp *ServerStamp) String() string {
if stamp.proto == StampProtoTypeDNSCrypt {
if stamp.Proto == StampProtoTypeDNSCrypt {
return stamp.dnsCryptString()
} else if stamp.proto == StampProtoTypeDoH {
} else if stamp.Proto == StampProtoTypeDoH {
return stamp.dohString()
}
dlog.Fatal("Unsupported protocol")
@ -200,20 +210,20 @@ func (stamp *ServerStamp) String() string {
func (stamp *ServerStamp) dnsCryptString() string {
bin := make([]uint8, 9)
bin[0] = uint8(StampProtoTypeDNSCrypt)
binary.LittleEndian.PutUint64(bin[1:9], uint64(stamp.props))
binary.LittleEndian.PutUint64(bin[1:9], uint64(stamp.Props))
serverAddrStr := stamp.serverAddrStr
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)...)
bin = append(bin, uint8(len(stamp.serverPk)))
bin = append(bin, stamp.serverPk...)
bin = append(bin, uint8(len(stamp.ServerPk)))
bin = append(bin, stamp.ServerPk...)
bin = append(bin, uint8(len(stamp.providerName)))
bin = append(bin, []uint8(stamp.providerName)...)
bin = append(bin, uint8(len(stamp.ProviderName)))
bin = append(bin, []uint8(stamp.ProviderName)...)
str := base64.RawURLEncoding.EncodeToString(bin)
@ -223,17 +233,17 @@ func (stamp *ServerStamp) dnsCryptString() string {
func (stamp *ServerStamp) dohString() string {
bin := make([]uint8, 9)
bin[0] = uint8(StampProtoTypeDoH)
binary.LittleEndian.PutUint64(bin[1:9], uint64(stamp.props))
binary.LittleEndian.PutUint64(bin[1:9], uint64(stamp.Props))
serverAddrStr := stamp.serverAddrStr
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)...)
last := len(stamp.hashes) - 1
for i, hash := range stamp.hashes {
last := len(stamp.Hashes) - 1
for i, hash := range stamp.Hashes {
vlen := len(hash)
if i < last {
vlen |= 0x80
@ -242,11 +252,11 @@ func (stamp *ServerStamp) dohString() string {
bin = append(bin, hash...)
}
bin = append(bin, uint8(len(stamp.providerName)))
bin = append(bin, []uint8(stamp.providerName)...)
bin = append(bin, uint8(len(stamp.ProviderName)))
bin = append(bin, []uint8(stamp.ProviderName)...)
bin = append(bin, uint8(len(stamp.path)))
bin = append(bin, []uint8(stamp.path)...)
bin = append(bin, uint8(len(stamp.Path)))
bin = append(bin, []uint8(stamp.Path)...)
str := base64.RawURLEncoding.EncodeToString(bin)