Still tolerate hex-encoded pks, but emit a warning
This commit is contained in:
parent
ccbdd41f5d
commit
3a3535dcbc
|
@ -142,11 +142,15 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (serversInfo *ServersInfo) fetchServerInfo(proxy *Proxy, name string, stamp ServerStamp) (ServerInfo, error) {
|
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 {
|
||||||
if err != nil || len(serverPk) != ed25519.PublicKeySize {
|
serverPk, err := hex.DecodeString(strings.Replace(string(stamp.serverPk), ":", "", -1))
|
||||||
dlog.Fatalf("Unsupported public key: [%v]", stamp.serverPkStr)
|
if err != nil || len(serverPk) != ed25519.PublicKeySize {
|
||||||
|
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
|
||||||
}
|
}
|
||||||
certInfo, rtt, err := FetchCurrentCert(proxy, &name, proxy.mainProto, serverPk, stamp.serverAddrStr, stamp.providerName)
|
certInfo, rtt, err := FetchCurrentCert(proxy, &name, proxy.mainProto, stamp.serverPk, stamp.serverAddrStr, stamp.providerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ServerInfo{}, err
|
return ServerInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,12 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jedisct1/dlog"
|
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerStamp struct {
|
type ServerStamp struct {
|
||||||
serverAddrStr string
|
serverAddrStr string
|
||||||
serverPkStr string
|
serverPk []uint8
|
||||||
providerName string
|
providerName string
|
||||||
props ServerInformalProperties
|
props ServerInformalProperties
|
||||||
}
|
}
|
||||||
|
@ -24,9 +23,13 @@ func NewServerStampFromLegacy(serverAddrStr string, serverPkStr string, provider
|
||||||
if net.ParseIP(serverAddrStr) != nil {
|
if net.ParseIP(serverAddrStr) != nil {
|
||||||
serverAddrStr = fmt.Sprintf("%s:%d", serverAddrStr, DefaultPort)
|
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{
|
return ServerStamp{
|
||||||
serverAddrStr: serverAddrStr,
|
serverAddrStr: serverAddrStr,
|
||||||
serverPkStr: serverPkStr,
|
serverPk: serverPk,
|
||||||
providerName: providerName,
|
providerName: providerName,
|
||||||
props: props,
|
props: props,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -66,11 +69,7 @@ func NewServerStampFromString(stampStr string) (ServerStamp, error) {
|
||||||
return stamp, errors.New("Invalid stamp")
|
return stamp, errors.New("Invalid stamp")
|
||||||
}
|
}
|
||||||
pos++
|
pos++
|
||||||
if len == ed25519.PublicKeySize {
|
stamp.serverPk = bin[pos : pos+len]
|
||||||
stamp.serverPkStr = hex.EncodeToString(bin[pos : pos+len])
|
|
||||||
} else {
|
|
||||||
stamp.serverPkStr = string(bin[pos : pos+len])
|
|
||||||
}
|
|
||||||
pos += len
|
pos += len
|
||||||
|
|
||||||
len = int(bin[pos])
|
len = int(bin[pos])
|
||||||
|
@ -95,12 +94,8 @@ func (stamp *ServerStamp) String() string {
|
||||||
bin = append(bin, uint8(len(stamp.serverAddrStr)))
|
bin = append(bin, uint8(len(stamp.serverAddrStr)))
|
||||||
bin = append(bin, []uint8(stamp.serverAddrStr)...)
|
bin = append(bin, []uint8(stamp.serverAddrStr)...)
|
||||||
|
|
||||||
serverPk, err := hex.DecodeString(strings.Replace(stamp.serverPkStr, ":", "", -1))
|
bin = append(bin, uint8(len(stamp.serverPk)))
|
||||||
if err != nil || len(serverPk) != ed25519.PublicKeySize {
|
bin = append(bin, stamp.serverPk...)
|
||||||
dlog.Fatalf("Unsupported public key: [%s]", stamp.serverPkStr)
|
|
||||||
}
|
|
||||||
bin = append(bin, uint8(len(serverPk)))
|
|
||||||
bin = append(bin, serverPk...)
|
|
||||||
|
|
||||||
bin = append(bin, uint8(len(stamp.providerName)))
|
bin = append(bin, uint8(len(stamp.providerName)))
|
||||||
bin = append(bin, []uint8(stamp.providerName)...)
|
bin = append(bin, []uint8(stamp.providerName)...)
|
||||||
|
|
Loading…
Reference in New Issue