Add support for shorter stamps with binary public keys
This commit is contained in:
parent
2d7920af22
commit
ccbdd41f5d
|
@ -254,4 +254,4 @@ format = 'tsv'
|
|||
|
||||
[servers]
|
||||
[servers.'scaleway-fr']
|
||||
stamp = 'sdns://AQMAAAAAAAAAEjIxMi40Ny4yMjguMTM2OjQ0M09FODAxOkI4NEU6QTYwNjpCRkIwOkJBQzA6Q0U0Mzo0NDVCOkIxNUU6QkE2NDpCMDJGOkEzQzQ6QUEzMTpBRTEwOjYzNkE6MDc5MDozMjREHzIuZG5zY3J5cHQtY2VydC5mci5kbnNjcnlwdC5vcmc'
|
||||
stamp = 'dnsc://AQMAAAAAAAAAEjIxMi40Ny4yMjguMTM2OjQ0MyDoAbhOpga_sLrAzkNEW7FeumSwL6PEqjGuEGNqB5AyTR8yLmRuc2NyeXB0LWNlcnQuZnIuZG5zY3J5cHQub3Jn'
|
||||
|
|
|
@ -144,7 +144,7 @@ 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 err != nil || len(serverPk) != ed25519.PublicKeySize {
|
||||
dlog.Fatalf("Unsupported public key: [%v]", serverPk)
|
||||
dlog.Fatalf("Unsupported public key: [%v]", stamp.serverPkStr)
|
||||
}
|
||||
certInfo, rtt, err := FetchCurrentCert(proxy, &name, proxy.mainProto, serverPk, stamp.serverAddrStr, stamp.providerName)
|
||||
if err != nil {
|
||||
|
|
|
@ -3,10 +3,14 @@ package main
|
|||
import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/jedisct1/dlog"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
)
|
||||
|
||||
type ServerStamp struct {
|
||||
|
@ -62,7 +66,11 @@ func NewServerStampFromString(stampStr string) (ServerStamp, error) {
|
|||
return stamp, errors.New("Invalid stamp")
|
||||
}
|
||||
pos++
|
||||
stamp.serverPkStr = string(bin[pos : pos+len])
|
||||
if len == ed25519.PublicKeySize {
|
||||
stamp.serverPkStr = hex.EncodeToString(bin[pos : pos+len])
|
||||
} else {
|
||||
stamp.serverPkStr = string(bin[pos : pos+len])
|
||||
}
|
||||
pos += len
|
||||
|
||||
len = int(bin[pos])
|
||||
|
@ -87,8 +95,12 @@ func (stamp *ServerStamp) String() string {
|
|||
bin = append(bin, uint8(len(stamp.serverAddrStr)))
|
||||
bin = append(bin, []uint8(stamp.serverAddrStr)...)
|
||||
|
||||
bin = append(bin, uint8(len(stamp.serverPkStr)))
|
||||
bin = append(bin, []uint8(stamp.serverPkStr)...)
|
||||
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.providerName)))
|
||||
bin = append(bin, []uint8(stamp.providerName)...)
|
||||
|
|
Loading…
Reference in New Issue