Remove support for legacy CSV files
This commit is contained in:
parent
3d67c81697
commit
f20da6b611
|
@ -104,7 +104,7 @@
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/jedisct1/go-dnsstamps"
|
name = "github.com/jedisct1/go-dnsstamps"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "d8908ceb62ed5ff9fe230d14cdde7727b90737e6"
|
revision = "1e4999280f861b465e03e21e4f84d838f2f02b38"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/csv"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -24,8 +23,7 @@ import (
|
||||||
type SourceFormat int
|
type SourceFormat int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SourceFormatV1 = iota
|
SourceFormatV2 = iota
|
||||||
SourceFormatV2
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -129,9 +127,7 @@ type URLToPrefetch struct {
|
||||||
func NewSource(xTransport *XTransport, urls []string, minisignKeyStr string, cacheFile string, formatStr string, refreshDelay time.Duration) (Source, []URLToPrefetch, error) {
|
func NewSource(xTransport *XTransport, urls []string, minisignKeyStr string, cacheFile string, formatStr string, refreshDelay time.Duration) (Source, []URLToPrefetch, error) {
|
||||||
_ = refreshDelay
|
_ = refreshDelay
|
||||||
source := Source{urls: urls}
|
source := Source{urls: urls}
|
||||||
if formatStr == "v1" {
|
if formatStr == "v2" {
|
||||||
source.format = SourceFormatV1
|
|
||||||
} else if formatStr == "v2" {
|
|
||||||
source.format = SourceFormatV2
|
source.format = SourceFormatV2
|
||||||
} else {
|
} else {
|
||||||
return source, []URLToPrefetch{}, fmt.Errorf("Unsupported source format: [%s]", formatStr)
|
return source, []URLToPrefetch{}, fmt.Errorf("Unsupported source format: [%s]", formatStr)
|
||||||
|
@ -210,58 +206,13 @@ func NewSource(xTransport *XTransport, urls []string, minisignKeyStr string, cac
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *Source) Parse(prefix string) ([]RegisteredServer, error) {
|
func (source *Source) Parse(prefix string) ([]RegisteredServer, error) {
|
||||||
if source.format == SourceFormatV1 {
|
if source.format == SourceFormatV2 {
|
||||||
return source.parseV1(prefix)
|
|
||||||
} else if source.format == SourceFormatV2 {
|
|
||||||
return source.parseV2(prefix)
|
return source.parseV2(prefix)
|
||||||
}
|
}
|
||||||
dlog.Fatal("Unexpected source format")
|
dlog.Fatal("Unexpected source format")
|
||||||
return []RegisteredServer{}, nil
|
return []RegisteredServer{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (source *Source) parseV1(prefix string) ([]RegisteredServer, error) {
|
|
||||||
var registeredServers []RegisteredServer
|
|
||||||
|
|
||||||
csvReader := csv.NewReader(strings.NewReader(source.in))
|
|
||||||
records, err := csvReader.ReadAll()
|
|
||||||
if err != nil {
|
|
||||||
return registeredServers, nil
|
|
||||||
}
|
|
||||||
for lineNo, record := range records {
|
|
||||||
if len(record) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if len(record) < 14 {
|
|
||||||
return registeredServers, fmt.Errorf("Parse error at line %d", 1+lineNo)
|
|
||||||
}
|
|
||||||
if lineNo == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
name := prefix + record[0]
|
|
||||||
description := record[2]
|
|
||||||
serverAddrStr := record[10]
|
|
||||||
providerName := record[11]
|
|
||||||
serverPkStr := record[12]
|
|
||||||
props := stamps.ServerInformalProperties(0)
|
|
||||||
if strings.EqualFold(record[7], "yes") {
|
|
||||||
props |= stamps.ServerInformalPropertyDNSSEC
|
|
||||||
}
|
|
||||||
if strings.EqualFold(record[8], "yes") {
|
|
||||||
props |= stamps.ServerInformalPropertyNoLog
|
|
||||||
}
|
|
||||||
stamp, err := stamps.NewDNSCryptServerStampFromLegacy(serverAddrStr, serverPkStr, providerName, props)
|
|
||||||
if err != nil {
|
|
||||||
return registeredServers, err
|
|
||||||
}
|
|
||||||
registeredServer := RegisteredServer{
|
|
||||||
name: name, stamp: stamp, description: description,
|
|
||||||
}
|
|
||||||
dlog.Debugf("Registered [%s] with stamp [%s]", name, stamp.String())
|
|
||||||
registeredServers = append(registeredServers, registeredServer)
|
|
||||||
}
|
|
||||||
return registeredServers, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
func (source *Source) parseV2(prefix string) ([]RegisteredServer, error) {
|
||||||
var registeredServers []RegisteredServer
|
var registeredServers []RegisteredServer
|
||||||
in := string(source.in)
|
in := string(source.in)
|
||||||
|
|
|
@ -1,18 +1,9 @@
|
||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/crypto"
|
|
||||||
packages = [
|
|
||||||
"ed25519",
|
|
||||||
"ed25519/internal/edwards25519"
|
|
||||||
]
|
|
||||||
revision = "d6449816ce06963d9d136eee5a56fca5b0616e7e"
|
|
||||||
|
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "5046e265393bd5e54f570ce29ae8bc6fa3f30ef5110e922996540400f287c64a"
|
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPort = 443
|
const DefaultPort = 443
|
||||||
|
@ -60,7 +58,7 @@ func NewDNSCryptServerStampFromLegacy(serverAddrStr string, serverPkStr string,
|
||||||
serverAddrStr = fmt.Sprintf("%s:%d", serverAddrStr, DefaultPort)
|
serverAddrStr = fmt.Sprintf("%s:%d", serverAddrStr, DefaultPort)
|
||||||
}
|
}
|
||||||
serverPk, err := hex.DecodeString(strings.Replace(serverPkStr, ":", "", -1))
|
serverPk, err := hex.DecodeString(strings.Replace(serverPkStr, ":", "", -1))
|
||||||
if err != nil || len(serverPk) != ed25519.PublicKeySize {
|
if err != nil || len(serverPk) != 32 {
|
||||||
return ServerStamp{}, fmt.Errorf("Unsupported public key: [%s]", serverPkStr)
|
return ServerStamp{}, fmt.Errorf("Unsupported public key: [%s]", serverPkStr)
|
||||||
}
|
}
|
||||||
return ServerStamp{
|
return ServerStamp{
|
||||||
|
|
Loading…
Reference in New Issue