Still tolerate hex-encoded pks, but emit a warning

This commit is contained in:
Frank Denis 2018-01-23 15:42:22 +01:00
parent ccbdd41f5d
commit 3a3535dcbc
2 changed files with 17 additions and 18 deletions

View File

@ -142,11 +142,15 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
}
func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp ServerStamp) (ServerInfo, error) {
serverPk, err := hex.DecodeString(strings.Replace(stamp.serverPkStr, ":", "", -1))
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: [%v]", stamp.serverPkStr)
dlog.Fatalf("Unsupported public key for [%s]: [%s]", name, stamp.serverPk)
}
certInfo, rtt, err := FetchCurrentCert(proxy, &name, proxy.mainProto, serverPk, stamp.serverAddrStr, stamp.providerName)
dlog.Warnf("Public key [%s] shouldn't be hex-encoded any more", string(stamp.serverPk))
stamp.serverPk = serverPk
}
certInfo, rtt, err := FetchCurrentCert(proxy, &name, proxy.mainProto, stamp.serverPk, stamp.serverAddrStr, stamp.providerName)
if err != nil {
return ServerInfo{}, err
}

View File

@ -9,13 +9,12 @@ import (
"net"
"strings"
"github.com/jedisct1/dlog"
"golang.org/x/crypto/ed25519"
)
type ServerStamp struct {
serverAddrStr string
serverPkStr string
serverPk []uint8
providerName string
props ServerInformalProperties
}
@ -24,9 +23,13 @@ func NewServerStampFromLegacy(serverAddrStr string, serverPkStr string, provider
if net.ParseIP(serverAddrStr) != nil {
serverAddrStr = fmt.Sprintf("%s:%d", serverAddrStr, DefaultPort)
}
serverPk, err := hex.DecodeString(strings.Replace(serverPkStr, ":", "", -1))
if err != nil || len(serverPk) != ed25519.PublicKeySize {
return ServerStamp{}, fmt.Errorf("Unsupported public key: [%s]", serverPkStr)
}
return ServerStamp{
serverAddrStr: serverAddrStr,
serverPkStr: serverPkStr,
serverPk: serverPk,
providerName: providerName,
props: props,
}, nil
@ -66,11 +69,7 @@ func NewServerStampFromString(stampStr string) (ServerStamp, error) {
return stamp, errors.New("Invalid stamp")
}
pos++
if len == ed25519.PublicKeySize {
stamp.serverPkStr = hex.EncodeToString(bin[pos : pos+len])
} else {
stamp.serverPkStr = string(bin[pos : pos+len])
}
stamp.serverPk = bin[pos : pos+len]
pos += len
len = int(bin[pos])
@ -95,12 +94,8 @@ func (stamp *ServerStamp) String() string {
bin = append(bin, uint8(len(stamp.serverAddrStr)))
bin = append(bin, []uint8(stamp.serverAddrStr)...)
serverPk, err := hex.DecodeString(strings.Replace(stamp.serverPkStr, ":", "", -1))
if err != nil || len(serverPk) != ed25519.PublicKeySize {
dlog.Fatalf("Unsupported public key: [%s]", stamp.serverPkStr)
}
bin = append(bin, uint8(len(serverPk)))
bin = append(bin, 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)...)