Remove serverInfoReq function
This commit is contained in:
parent
67c05fd4a2
commit
b3bae0bf86
25
client.go
25
client.go
@ -192,12 +192,7 @@ func (c Client) lookup(resource, id string, all bool, dest any) error {
|
|||||||
return ErrSignatureMismatch
|
return ErrSignatureMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := serverInfoReq(pfdURL.Scheme, pfdURL.Host)
|
serverData, infoSig, sigs, err := getServerInfo(pfdURL.Scheme, pfdURL.Host)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
serverData, err := io.ReadAll(io.LimitReader(res.Body, responseSizeLimit))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -213,12 +208,13 @@ func (c Client) lookup(resource, id string, all bool, dest any) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the pubkey hasn't changed but we couldn't
|
||||||
|
// verify the signature, return an error immediately.
|
||||||
if bytes.Equal(pubkey, newPubkey) {
|
if bytes.Equal(pubkey, newPubkey) {
|
||||||
return ErrSignatureMismatch
|
return ErrSignatureMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
verified := false
|
verified := false
|
||||||
sigs := getPrevSignatures(res)
|
|
||||||
for _, sig := range sigs {
|
for _, sig := range sigs {
|
||||||
if ed25519.Verify(pubkey, serverData, sig) {
|
if ed25519.Verify(pubkey, serverData, sig) {
|
||||||
verified = true
|
verified = true
|
||||||
@ -230,11 +226,6 @@ func (c Client) lookup(resource, id string, all bool, dest any) error {
|
|||||||
return ErrSignatureMismatch
|
return ErrSignatureMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
infoSig, err := getSignature(res)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !ed25519.Verify(newPubkey, infoSig, serverData) {
|
if !ed25519.Verify(newPubkey, infoSig, serverData) {
|
||||||
return ErrSignatureMismatch
|
return ErrSignatureMismatch
|
||||||
}
|
}
|
||||||
@ -252,19 +243,15 @@ func (c Client) lookup(resource, id string, all bool, dest any) error {
|
|||||||
return json.Unmarshal(data, dest)
|
return json.Unmarshal(data, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// serverInfoReq performs an HTTP request to retrieve server information.
|
// getServerInfo retrieves server information.
|
||||||
func serverInfoReq(scheme, host string) (*http.Response, error) {
|
func getServerInfo(scheme, host string) (data, sig []byte, prevSigs [][]byte, err error) {
|
||||||
serverInfoURL := url.URL{
|
serverInfoURL := url.URL{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
Host: host,
|
Host: host,
|
||||||
Path: "/_profilefed/server",
|
Path: "/_profilefed/server",
|
||||||
}
|
}
|
||||||
return http.Get(serverInfoURL.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
// getServerInfo retrieves server information.
|
res, err := http.Get(serverInfoURL.String())
|
||||||
func getServerInfo(scheme, host string) (data, sig []byte, prevSigs [][]byte, err error) {
|
|
||||||
res, err := serverInfoReq(scheme, host)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user