Preliminary implementation of stamps
This commit is contained in:
parent
88414e1448
commit
ed50798049
|
@ -227,7 +227,7 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
|
|||
var stamp ServerStamp
|
||||
var err error
|
||||
if len(serverConfig.Stamp) > 0 {
|
||||
dlog.Fatal("Stamps are not implemented yet")
|
||||
stamp, err = NewServerStampFromString(serverConfig.Stamp)
|
||||
} else {
|
||||
props := ServerInformalProperties(0)
|
||||
if serverConfig.DNSSEC {
|
||||
|
@ -237,9 +237,9 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
|
|||
props |= ServerInformalPropertyNoLog
|
||||
}
|
||||
stamp, err = NewServerStampFromLegacy(serverConfig.Address, serverConfig.PublicKey, serverConfig.ProviderName, props)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
proxy.registeredServers = append(proxy.registeredServers,
|
||||
RegisteredServer{name: serverName, stamp: stamp})
|
||||
|
|
|
@ -205,6 +205,4 @@ format = 'tsv'
|
|||
|
||||
[servers]
|
||||
[servers.'dnscrypt.org-fr']
|
||||
provider_name = '2.dnscrypt-cert.fr.dnscrypt.org'
|
||||
address = '212.47.228.136:443'
|
||||
public_key = 'E801:B84E:A606:BFB0:BAC0:CE43:445B:B15E:BA64:B02F:A3C4:AA31:AE10:636A:0790:324D'
|
||||
stamp = 'dnsc://AQMAAAAAAAAAEjIxMi40Ny4yMjguMTM2OjQ0M09FODAxOkI4NEU6QTYwNjpCRkIwOkJBQzA6Q0U0Mzo0NDVCOkIxNUU6QkE2NDpCMDJGOkEzQzQ6QUEzMTpBRTEwOjYzNkE6MDc5MDozMjREHzIuZG5zY3J5cHQtY2VydC5mci5kbnNjcnlwdC5vcmc'
|
||||
|
|
|
@ -3,8 +3,10 @@ package main
|
|||
import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ServerStamp struct {
|
||||
|
@ -30,6 +32,50 @@ func NewServerStampFromLegacy(serverAddrStr string, serverPkStr string, provider
|
|||
|
||||
func NewServerStampFromString(stampStr string) (ServerStamp, error) {
|
||||
stamp := ServerStamp{}
|
||||
if !strings.HasPrefix(stampStr, "dnsc://") {
|
||||
return stamp, errors.New("Stamps are expected to start with dnsc://")
|
||||
}
|
||||
bin, err := base64.RawURLEncoding.DecodeString(stampStr[7:])
|
||||
if err != nil {
|
||||
return stamp, err
|
||||
}
|
||||
if len(bin) < 24 {
|
||||
return stamp, errors.New("Stamp is too short")
|
||||
}
|
||||
if bin[0] != 0x01 {
|
||||
return stamp, errors.New("Unsupported stamp version")
|
||||
}
|
||||
stamp.props = ServerInformalProperties(binary.LittleEndian.Uint64(bin[1:9]))
|
||||
binLen := len(bin)
|
||||
pos := 9
|
||||
|
||||
len := int(bin[pos])
|
||||
if len >= binLen-pos {
|
||||
return stamp, errors.New("Invalid stamp")
|
||||
}
|
||||
pos++
|
||||
stamp.serverAddrStr = string(bin[pos : pos+len])
|
||||
pos += len
|
||||
|
||||
len = int(bin[pos])
|
||||
if len >= binLen-pos {
|
||||
return stamp, errors.New("Invalid stamp")
|
||||
}
|
||||
pos++
|
||||
stamp.serverPkStr = string(bin[pos : pos+len])
|
||||
pos += len
|
||||
|
||||
len = int(bin[pos])
|
||||
if len >= binLen-pos {
|
||||
return stamp, errors.New("Invalid stamp")
|
||||
}
|
||||
pos++
|
||||
stamp.providerName = string(bin[pos : pos+len])
|
||||
pos += len
|
||||
|
||||
if pos != binLen {
|
||||
return stamp, errors.New("Invalid stamp (garbage after end)")
|
||||
}
|
||||
return stamp, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue