Rename ODoHTarget to ODoHTargetConfig for clarity

This commit is contained in:
Frank Denis 2021-06-05 17:49:19 +02:00
parent 2cf29f9fab
commit 0a1d3b725c
3 changed files with 26 additions and 25 deletions

View File

@ -14,7 +14,7 @@ const (
odohVersion = uint16(0xff06)
)
type ODoHTarget struct {
type ODoHTargetConfig struct {
suite *hpkecompact.Suite
keyID []byte
publicKey []byte
@ -26,48 +26,48 @@ func encodeLengthValue(b []byte) []byte {
return append(lengthBuffer, b...)
}
func parseODoHTargetConfig(config []byte) (ODoHTarget, error) {
func parseODoHTargetConfig(config []byte) (ODoHTargetConfig, error) {
if len(config) < 8 {
return ODoHTarget{}, fmt.Errorf("Malformed config")
return ODoHTargetConfig{}, fmt.Errorf("Malformed config")
}
kemID := binary.BigEndian.Uint16(config[0:2])
kdfID := binary.BigEndian.Uint16(config[2:4])
aeadID := binary.BigEndian.Uint16(config[4:6])
publicKeyLength := binary.BigEndian.Uint16(config[6:8])
if len(config[8:]) != int(publicKeyLength) {
return ODoHTarget{}, fmt.Errorf("Malformed config")
return ODoHTargetConfig{}, fmt.Errorf("Malformed config")
}
suite, err := hpkecompact.NewSuite(hpkecompact.KemID(kemID), hpkecompact.KdfID(kdfID), hpkecompact.AeadID(aeadID))
if err != nil {
return ODoHTarget{}, err
return ODoHTargetConfig{}, err
}
publicKey := config[8:]
_, _, err = suite.NewClientContext(publicKey, []byte("odoh query"), nil)
if err != nil {
return ODoHTarget{}, err
return ODoHTargetConfig{}, err
}
keyID, err := suite.Expand(suite.Extract(config, nil), []byte("odoh key id"), uint16(suite.Hash().Size()))
if err != nil {
return ODoHTarget{}, err
return ODoHTargetConfig{}, err
}
return ODoHTarget{
return ODoHTargetConfig{
suite: suite,
publicKey: publicKey,
keyID: encodeLengthValue(keyID),
}, nil
}
func parseODoHTargetConfigs(configs []byte) ([]ODoHTarget, error) {
func parseODoHTargetConfigs(configs []byte) ([]ODoHTargetConfig, error) {
length := binary.BigEndian.Uint16(configs)
if len(configs) != int(length)+2 {
return nil, fmt.Errorf("Malformed configs")
}
targets := make([]ODoHTarget, 0)
targets := make([]ODoHTargetConfig, 0)
offset := 2
for {
if offset+4 > len(configs) {
@ -93,7 +93,7 @@ type ODoHQuery struct {
odohMessage []byte
}
func (t ODoHTarget) encryptQuery(query []byte) (ODoHQuery, error) {
func (t ODoHTargetConfig) encryptQuery(query []byte) (ODoHQuery, error) {
clientCtx, encryptedSharedSecret, err := t.suite.NewClientContext(t.publicKey, []byte("odoh query"), nil)
if err != nil {
return ODoHQuery{}, err

View File

@ -680,7 +680,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
}
} else if serverInfo.Proto == stamps.StampProtoTypeODoHTarget {
tid := TransactionID(query)
target := serverInfo.odohTargets[0]
target := serverInfo.odohTargetConfigs[0]
odohQuery, err := target.encryptQuery(query)
if err != nil {
dlog.Errorf("Failed to encrypt query for [%v]", serverName)

View File

@ -63,7 +63,7 @@ type ServerInfo struct {
knownBugs ServerBugs
Proto stamps.StampProtoType
useGet bool
odohTargets []ODoHTarget
odohTargetConfigs []ODoHTargetConfig
}
type LBStrategy interface {
@ -658,7 +658,7 @@ func fetchDoHServerInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isN
}, nil
}
func fetchTargetConfigsFromWellKnown(url string) ([]ODoHTarget, error) {
func fetchTargetConfigsFromWellKnown(url string) ([]ODoHTargetConfig, error) {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
@ -679,8 +679,8 @@ func fetchTargetConfigsFromWellKnown(url string) ([]ODoHTarget, error) {
}
func fetchODoHTargetInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, isNew bool) (ServerInfo, error) {
odohTargets, err := fetchTargetConfigsFromWellKnown("https://" + stamp.ProviderName + "/.well-known/odohconfigs")
if err != nil || len(odohTargets) == 0 {
odohTargetConfigs, err := fetchTargetConfigsFromWellKnown("https://" + url.PathEscape(stamp.ProviderName) + "/.well-known/odohconfigs")
if err != nil || len(odohTargetConfigs) == 0 {
return ServerInfo{}, fmt.Errorf("[%s] does not have an Oblivious DoH configuration", name)
}
@ -693,7 +693,7 @@ func fetchODoHTargetInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, is
}
if relay == nil {
dlog.Notice("Relay is empty for " + name)
dlog.Noticef("Relay is empty for [%v]", name)
}
url := &url.URL{
@ -703,14 +703,15 @@ func fetchODoHTargetInfo(proxy *Proxy, name string, stamp stamps.ServerStamp, is
}
return ServerInfo{
Proto: stamps.StampProtoTypeODoHTarget,
Name: name,
Timeout: proxy.timeout,
URL: url,
HostName: stamp.ProviderName,
useGet: false,
odohTargets: odohTargets,
Relay: relay,
Proto: stamps.StampProtoTypeODoHTarget,
Name: name,
Timeout: proxy.timeout,
URL: url,
HostName: stamp.ProviderName,
initialRtt: 100000,
useGet: false,
Relay: relay,
odohTargetConfigs: odohTargetConfigs,
}, nil
}